Added proxy settings for "URL test" and mod-telegram.

This commit is contained in:
gSpot
2026-03-23 21:12:09 +03:00
parent 8df099b718
commit ca2a4469b4
13 changed files with 379 additions and 91 deletions

View File

@@ -23,42 +23,42 @@ Internet-detector is an application for checking the availability of the Interne
**OpenWrt >= 25.12:**
opkg update
wget --no-check-certificate -O /tmp/internet-detector-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-1.7.1-r1.apk
apk --allow-untrusted add /tmp/internet-detector-1.7.1-r1.apk
rm /tmp/internet-detector-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/internet-detector-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-1.7.2-r1.apk
apk --allow-untrusted add /tmp/internet-detector-1.7.2-r1.apk
rm /tmp/internet-detector-1.7.2-r1.apk
service internet-detector start
service internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/luci-app-internet-detector-1.7.1-r1.apk
apk --allow-untrusted add /tmp/luci-app-internet-detector-1.7.1-r1.apk
rm /tmp/luci-app-internet-detector-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/luci-app-internet-detector-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/luci-app-internet-detector-1.7.2-r1.apk
apk --allow-untrusted add /tmp/luci-app-internet-detector-1.7.2-r1.apk
rm /tmp/luci-app-internet-detector-1.7.2-r1.apk
service rpcd restart
i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/luci-i18n-internet-detector-ru-1.7.1-r1.apk
apk --allow-untrusted add /tmp/luci-i18n-internet-detector-ru-1.7.1-r1.apk
rm /tmp/luci-i18n-internet-detector-ru-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/luci-i18n-internet-detector-ru-1.7.2-r1.apk
apk --allow-untrusted add /tmp/luci-i18n-internet-detector-ru-1.7.2-r1.apk
rm /tmp/luci-i18n-internet-detector-ru-1.7.2-r1.apk
**OpenWrt <= 24.10:**
opkg update
wget --no-check-certificate -O /tmp/internet-detector_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector_1.7.1-r1_all.ipk
opkg install /tmp/internet-detector_1.7.1-r1_all.ipk
rm /tmp/internet-detector_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector_1.7.2-r1_all.ipk
opkg install /tmp/internet-detector_1.7.2-r1_all.ipk
rm /tmp/internet-detector_1.7.2-r1_all.ipk
service internet-detector start
service internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/luci-app-internet-detector_1.7.1-r1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.7.1-r1_all.ipk
rm /tmp/luci-app-internet-detector_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/luci-app-internet-detector_1.7.2-r1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.7.2-r1_all.ipk
rm /tmp/luci-app-internet-detector_1.7.2-r1_all.ipk
service rpcd restart
i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/luci-i18n-internet-detector-ru_1.7.1-r1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.7.1-r1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/luci-i18n-internet-detector-ru_1.7.2-r1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.7.2-r1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.7.2-r1_all.ipk
## Screenshots:
@@ -72,16 +72,16 @@ i18n-ru:
**OpenWrt >= 25.12:**
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-modem-restart-1.7.1-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-modem-restart-1.7.1-r1.apk
rm /tmp/internet-detector-mod-modem-restart-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-modem-restart-1.7.2-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-modem-restart-1.7.2-r1.apk
rm /tmp/internet-detector-mod-modem-restart-1.7.2-r1.apk
service internet-detector restart
**OpenWrt <= 24.10:**
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-modem-restart_1.7.1-r1_all.ipk
opkg install /tmp/internet-detector-mod-modem-restart_1.7.1-r1_all.ipk
rm /tmp/internet-detector-mod-modem-restart_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-modem-restart_1.7.2-r1_all.ipk
opkg install /tmp/internet-detector-mod-modem-restart_1.7.2-r1_all.ipk
rm /tmp/internet-detector-mod-modem-restart_1.7.2-r1_all.ipk
service internet-detector restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg)
@@ -92,36 +92,38 @@ i18n-ru:
**OpenWrt >= 25.12:**
wget --no-check-certificate -O /tmp/internet-detector-mod-email-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-email-1.7.1-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-email-1.7.1-r1.apk
rm /tmp/internet-detector-mod-email-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/internet-detector-mod-email-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-email-1.7.2-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-email-1.7.2-r1.apk
rm /tmp/internet-detector-mod-email-1.7.2-r1.apk
service internet-detector restart
**OpenWrt <= 24.10:**
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-email_1.7.1-r1_all.ipk
opkg install /tmp/internet-detector-mod-email_1.7.1-r1_all.ipk
rm /tmp/internet-detector-mod-email_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-email_1.7.2-r1_all.ipk
opkg install /tmp/internet-detector-mod-email_1.7.2-r1_all.ipk
rm /tmp/internet-detector-mod-email_1.7.2-r1_all.ipk
service internet-detector restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg)
## Telegram notification module (internet-detector-mod-telegram):
**Dependences:** curl.
**Dependences:** curl, ucode, ucode-mod-fs.
**OpenWrt >= 25.12:**
wget --no-check-certificate -O /tmp/internet-detector-mod-telegram-1.7.1-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-telegram-1.7.1-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-telegram-1.7.1-r1.apk
rm /tmp/internet-detector-mod-telegram-1.7.1-r1.apk
wget --no-check-certificate -O /tmp/internet-detector-mod-telegram-1.7.2-r1.apk https://github.com/gSpotx2f/packages-openwrt/raw/master/25.12/internet-detector-mod-telegram-1.7.2-r1.apk
apk --allow-untrusted add /tmp/internet-detector-mod-telegram-1.7.2-r1.apk
rm /tmp/internet-detector-mod-telegram-1.7.2-r1.apk
service internet-detector restart
service rpcd restart
**OpenWrt <= 24.10:**
wget --no-check-certificate -O /tmp/internet-detector-mod-telegram_1.7.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-telegram_1.7.1-r1_all.ipk
opkg install /tmp/internet-detector-mod-telegram_1.7.1-r1_all.ipk
rm /tmp/internet-detector-mod-telegram_1.7.1-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector-mod-telegram_1.7.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/24.10/internet-detector-mod-telegram_1.7.2-r1_all.ipk
opkg install /tmp/internet-detector-mod-telegram_1.7.2-r1_all.ipk
rm /tmp/internet-detector-mod-telegram_1.7.2-r1_all.ipk
service internet-detector restart
service rpcd restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/06.jpg)

View File

@@ -1,11 +1,11 @@
#
# (с) 2025 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
# (с) 2026 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
#
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-email
PKG_VERSION:=1.7.1
PKG_VERSION:=1.7.2
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -1,11 +1,11 @@
#
# (с) 2025 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
# (с) 2026 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
#
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-modem-restart
PKG_VERSION:=1.7.1
PKG_VERSION:=1.7.2
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -1,11 +1,11 @@
#
# (с) 2025 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
# (с) 2026 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
#
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-telegram
PKG_VERSION:=1.7.1
PKG_VERSION:=1.7.2
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
@@ -17,7 +17,7 @@ define Package/$(PKG_NAME)
TITLE:=Telegram messenger module for internet-detector
URL:=https://github.com/gSpotx2f/luci-app-internet-detector
PKGARCH:=all
DEPENDS:=+internet-detector +curl
DEPENDS:=+internet-detector +curl +ucode +ucode-mod-fs
endef
define Package/$(PKG_NAME)/description
@@ -36,6 +36,10 @@ endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector/modules
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_telegram.lua $(1)/usr/lib/lua/internet-detector/modules/mod_telegram.lua
$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
$(INSTALL_DATA) ./files/usr/share/rpcd/acl.d/luci-app-internet-detector-mod-telegram.json $(1)/usr/share/rpcd/acl.d/luci-app-internet-detector-mod-telegram.json
$(INSTALL_DIR) $(1)/usr/share/rpcd/ucode
$(INSTALL_DATA) ./files/usr/share/rpcd/ucode/luci.internet-detector-mod-telegram $(1)/usr/share/rpcd/ucode/luci.internet-detector-mod-telegram
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@@ -29,6 +29,8 @@ local Module = {
msgSendTimeout = 5,
curlExec = "/usr/bin/curl",
curlParams = "-s -g --no-keepalive",
proxyAuthString = "",
proxyString = "",
status = nil,
_enabled = false,
_deadCounter = 0,
@@ -69,6 +71,20 @@ function Module:init(t)
if t.chat_id ~= nil then
self.tgChatId = t.chat_id
end
if (t.proxy_type and t.proxy_host and t.proxy_port) then
if t.proxy_user and t.proxy_passwd then
self.proxyAuthString = string.format(
' --proxy-user "%s:%s"',
t.proxy_user,
t.proxy_passwd)
end
self.proxyString = string.format(
" --proxy %s://%s:%d%s",
t.proxy_type,
t.proxy_host,
t.proxy_port,
self.proxyAuthString)
end
if tonumber(t.message_at_startup) == 1 then
self._msgSentDisconnect = false
self._disconnected = false
@@ -119,13 +135,21 @@ end
function Module:httpRequest(url)
local retCode = 1, data
local fh = io.popen(string.format(
'%s --connect-timeout %s %s "%s"; printf "\n$?";',
self.debugOutput(string.format("--- %s ---", self.name))
local curl = string.format(
'%s%s --connect-timeout %s %s "%s"; printf "\n$?";',
self.curlExec,
self.proxyString,
self.connectTimeout,
self.curlParams,
url
), "r")
)
self.debugOutput(curl)
local fh = io.popen(curl, "r")
if fh then
data = fh:read("*a")
fh:close()
@@ -140,6 +164,12 @@ function Module:httpRequest(url)
else
retCode = 1
end
self.debugOutput(string.format(
"data = %s; retCode = %s\n",
tostring(data),
tostring(retCode)))
return retCode, data
end

View File

@@ -0,0 +1,10 @@
{
"luci-app-internet-detector-mod-telegram": {
"description": "Grant access to internet-detector-mod-telegram procedures",
"read": {
"ubus": {
"luci.internet-detector-mod-telegram": [ "GetTgChatId" ]
}
}
}
}

View File

@@ -0,0 +1,125 @@
'use strict';
import { popen, stat } from 'fs';
const curlPath = '/usr/bin/curl';
const curlExec = (stat(curlPath)?.perm?.user_exec) ? curlPath : null;
const curlParams = '-s -g --no-keepalive';
const curlConnectTimeout = 15;
const tgUpdatesURLPattern = 'https://api.telegram.org/bot%s/getUpdates';
if(!curlExec) {
die('Error! Curl not found!');
}
function httpRequest(url, proxyType, proxyHost, proxyPort, proxyUser, proxyPasswd) {
let retCode = 1;
let data = '';
let proxyAuthString = '';
let proxyString = '';
if(!url) {
return { retCode: 1, data };
}
if(proxyType && proxyHost && proxyPort) {
if(proxyUser && proxyPasswd) {
proxyAuthString = sprintf(
' --proxy-user "%s:%s"',
proxyUser,
proxyPasswd);
}
proxyString = sprintf(
' --proxy %s://%s:%d%s',
proxyType,
proxyHost,
proxyPort,
proxyAuthString);
}
const curl = sprintf(
'%s%s --connect-timeout %s %s "%s"; printf "\n$?";',
curlExec,
proxyString,
curlConnectTimeout,
curlParams,
url
);
const fd = popen(curl, 'r');
if(fd) {
data = fd.read('all');
fd.close();
if(data) {
const retCodeRegexp = /[0-9]+\n?$/;
const r = match(data, retCodeRegexp);
if(length(r) > 0) {
retCode = r[0];
}
data = replace(data, retCodeRegexp, '');
}
}
return { retCode, data };
}
function parseResponse(str) {
let ok = null;
let chatId = [];
let errCode = null;
let errDesc = null;
const data = json(str);
ok = data.ok;
if(ok == false) {
errCode = data.error_code;
errDesc = data.description;
} else {
let chats = [];
if(data.result) {
for(let i in data.result) {
if(i.message && i.message.chat && i.message.chat.id) {
push(chats, i.message.chat.id);
}
}
}
if(length(chats) > 0) {
chatId = uniq(chats);
}
}
return { ok, chatId, errCode, errDesc };
}
const methods = {
GetTgChatId: {
args: {
botToken : 'String',
proxyType : 'String',
proxyHost : 'String',
proxyPort : 'String',
proxyUser : 'String',
proxyPasswd: 'String',
},
call: function(request) {
const botToken = request.args?.botToken;
if(botToken) {
const ret = httpRequest(
sprintf(tgUpdatesURLPattern, botToken),
request.args.proxyType,
request.args.proxyHost,
request.args.proxyPort,
request.args.proxyUser,
request.args.proxyPasswd
);
if(ret.retCode == 0 && length(ret.data) > 0) {
return parseResponse(ret.data);
} else {
return { ok: null, chatId: [], errCode: ret.retCode, errDesc: 'Network request error' };
}
} else {
return { ok: null, chatId: [], errCode: 1, errDesc: 'Bot token missing' };
}
},
},
};
return { 'luci.internet-detector-mod-telegram': methods };

View File

@@ -1,11 +1,11 @@
#
# (с) 2025 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
# (с) 2026 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
#
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector
PKG_VERSION:=1.7.1
PKG_VERSION:=1.7.2
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -53,15 +53,18 @@ local InternetDetector = {
proxy_type = nil,
proxy_host = nil,
proxy_port = nil,
proxy_user = nil,
proxy_passwd = nil,
iface = nil,
instance = nil,
},
modules = {},
parsedHosts = {},
proxyString = "",
uiCounter = 0,
pidFile = nil,
statusFile = nil,
modules = {},
parsedHosts = {},
proxyAuthString = "",
proxyString = "",
uiCounter = 0,
pidFile = nil,
statusFile = nil,
}
InternetDetector.configDir = string.format("/etc/%s", InternetDetector.appName)
InternetDetector.modulesDir = string.format(
@@ -277,6 +280,7 @@ function InternetDetector:TCPConnectionToHost(host, port)
if not ok then
self:debugOutput(string.format(
"SOCKET ERROR: %s, %s", errMsg, errNum))
unistd.close(sock)
return retCode
end
@@ -357,6 +361,7 @@ function InternetDetector:httpRequest(url)
curl,
retCode,
tostring(data)))
return retCode, data
end
@@ -420,11 +425,18 @@ function InternetDetector:mainLoop()
self:parseUrls()
if (self.serviceConfig.proxy_type and self.serviceConfig.proxy_host and
self.serviceConfig.proxy_port) then
if self.serviceConfig.proxy_user and self.serviceConfig.proxy_passwd then
self.proxyAuthString = string.format(
' --proxy-user "%s:%s"',
self.serviceConfig.proxy_user,
self.serviceConfig.proxy_passwd)
end
self.proxyString = string.format(
" --proxy %s://%s:%d",
" --proxy %s://%s:%d%s",
self.serviceConfig.proxy_type,
self.serviceConfig.proxy_host,
self.serviceConfig.proxy_port)
self.serviceConfig.proxy_port,
self.proxyAuthString)
end
else
self:parseHosts()
@@ -516,7 +528,7 @@ function InternetDetector:mainLoop()
end
end
mTimeDiff = 0
mTimeDiff = 0
for _, e in ipairs(self.modules) do
mTimeNow = time.clock_gettime(time.CLOCK_MONOTONIC).tv_sec
if mLastTime then

View File

@@ -1,11 +1,11 @@
#
# (с) 2025 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
# (с) 2026 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
#
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-internet-detector
PKG_VERSION:=1.7.1
PKG_VERSION:=1.7.2
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector

View File

@@ -196,7 +196,6 @@ return view.extend({
{ name: 'icanhazip', title: 'icanhazip.com (HTTP)' },
],
},
tgUpdatesURLPattern : 'https://api.telegram.org/bot%s/getUpdates',
mm : false,
mmInit : false,
email : false,
@@ -292,6 +291,20 @@ return view.extend({
});
},
callTgChatId: rpc.declare({
object: 'luci.internet-detector-mod-telegram',
method: 'GetTgChatId',
params: [ 'botToken', 'proxyType', 'proxyHost', 'proxyPort', 'proxyUser', 'proxyPasswd' ],
expect: { '': {} }
}),
getTgChatId(botToken, proxyType, proxyHost, proxyPort, proxyUser, proxyPasswd) {
return this.callTgChatId(
botToken, proxyType, proxyHost, proxyPort, proxyUser, proxyPasswd).then(data => {
return data;
});
},
setInternetStatus() {
this.inetStatusArea.innerHTML = '';
@@ -303,7 +316,6 @@ return view.extend({
this.inetStatusArea.append(label);
} else {
this.inetStatus.instances.sort((a, b) => a.num - b.num);
for(let i of this.inetStatus.instances) {
let status = _('Disconnected');
let className = 'id-label-status id-disconnected';
@@ -382,6 +394,7 @@ return view.extend({
getTgChatIdHandler(ev, instance) {
ev.preventDefault();
let botToken;
let botTokenInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_api_token'.format(this.appName, instance));
@@ -392,41 +405,60 @@ return view.extend({
alert(_('Bot API token is missing!'));
return;
};
let apiURL = this.tgUpdatesURLPattern.format(botToken);
let proxyType = null;
let proxyTypeInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_proxy_type'.format(this.appName, instance));
if(proxyTypeInput) {
proxyType = proxyTypeInput.value;
};
let proxyHost = null;
let proxyHostInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_proxy_host'.format(this.appName, instance));
if(proxyTypeInput) {
proxyHost = proxyHostInput.value;
};
let proxyPort = null;
let proxyPortInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_proxy_port'.format(this.appName, instance));
if(proxyTypeInput) {
proxyPort = proxyPortInput.value;
};
let proxyUser = null;
let proxyUserInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_proxy_user'.format(this.appName, instance));
if(proxyTypeInput) {
proxyUser = proxyUserInput.value;
};
let proxyPasswd = null;
let proxyPasswdInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_proxy_passwd'.format(this.appName, instance));
if(proxyTypeInput) {
proxyPasswd = proxyPasswdInput.value;
};
console.log(`Requesting chat ID: ${apiURL}`);
return fetch(apiURL).then(r => {
return this.getTgChatId(botToken, proxyType, proxyHost, proxyPort, proxyUser, proxyPasswd).then(r => {
if(r.ok) {
r.json().then(j => {
let chats = [];
if(j.ok && j.result) {
j.result.forEach(i => {
if(i.message && i.message.chat && i.message.chat.id) {
if(!chats.includes(i.message.chat.id)) {
chats.push(i.message.chat.id);
};
};
});
};
if(r.chatId) {
let tgChatIdInput = document.getElementById(
'widget.cbid.%s.%s.mod_telegram_chat_id'.format(this.appName, instance));
if(tgChatIdInput) {
if(chats.length == 0) {
if(r.chatId.length == 0) {
alert(_('No messages available. Write something to the bot and try again.'));
} else {
tgChatIdInput.value = chats[chats.length - 1];
tgChatIdInput.value = r.chatId[r.chatId.length - 1];
tgChatIdInput.focus();
tgChatIdInput.blur();
};
};
});
} else {
let status = r.status;
let errorString = `${_('Error')} ${r.status}.`;
if(status == 404) {
errorString += ` ${_('Incorrect bot token?')}`;
};
} else {
let errCode = r.errCode;
let errorString = `${_('Error')} ${errCode}.`;
if(errCode == 401 || errCode == 404) {
errorString += ` ${_('Incorrect bot token?')}`;
} else {
errorString += ` ${r.errDesc}.`;
}
alert(errorString);
};
}).catch(e => {
@@ -890,6 +922,21 @@ return view.extend({
o.rmempty = false;
o.depends({ proxy_type: /.+/ });
o.modalonly = true;
// proxy_user
o = s.taboption('main', form.Value,
'proxy_user', _('Proxy user')
);
o.depends({ proxy_type: /(http|socks5h?)/ });
o.modalonly = true;
// proxy_passwd
o = s.taboption('main', form.Value,
'proxy_passwd', _('Proxy password')
);
o.depends({ proxy_type: /(http|socks5h?)/ });
o.modalonly = true;
o.password = true;
};
// iface
@@ -1713,6 +1760,52 @@ return view.extend({
o.rmempty = false;
o.depends({ 'mod_telegram_api_token': /.+/ });
// proxy_type
o = s.taboption('telegram', form.ListValue,
'mod_telegram_proxy_type', _('Proxy')
);
o.value('', _('Disabled'));
o.value('http');
o.value('socks4');
o.value('socks4a');
o.value('socks5');
o.value('socks5h');
o.default = '';
o.modalonly = true;
// proxy_host
o = s.taboption('telegram', form.Value,
'mod_telegram_proxy_host', _('Proxy host')
);
o.datatype = 'host';
o.rmempty = false;
o.depends({ mod_telegram_proxy_type: /.+/ });
o.modalonly = true;
// proxy_port
o = s.taboption('telegram', form.Value,
'mod_telegram_proxy_port', _('Proxy port')
);
o.datatype = 'port';
o.rmempty = false;
o.depends({ mod_telegram_proxy_type: /.+/ });
o.modalonly = true;
// proxy_user
o = s.taboption('telegram', form.Value,
'mod_telegram_proxy_user', _('Proxy user')
);
o.depends({ mod_telegram_proxy_type: /(http|socks5h?)/ });
o.modalonly = true;
// proxy_passwd
o = s.taboption('telegram', form.Value,
'mod_telegram_proxy_passwd', _('Proxy password')
);
o.depends({ mod_telegram_proxy_type: /(http|socks5h?)/ });
o.modalonly = true;
o.password = true;
// message_at_startup
o = s.taboption('telegram', form.Flag,
'mod_telegram_message_at_startup',

View File

@@ -435,9 +435,6 @@ msgid ""
msgstr ""
"Период времени отсутствия доступа в Интренет перед перезагрузкой устройства."
msgid "Regular script"
msgstr "Регулярный скрипт"
msgid "Polling interval"
msgstr "Интервал опроса"
@@ -450,9 +447,15 @@ msgstr "Прокси"
msgid "Proxy host"
msgstr "Хост прокси"
msgid "Proxy password"
msgstr "Пароль прокси"
msgid "Proxy port"
msgstr "Порт прокси"
msgid "Proxy user"
msgstr "Пользователь прокси"
msgid "Public IP"
msgstr "Публичный IP"
@@ -471,6 +474,9 @@ msgstr "Приём"
msgid "Recipient"
msgstr "Получатель"
msgid "Regular script"
msgstr "Регулярный скрипт"
msgid "Request chat ID from bot API"
msgstr "Запросить ID чата через API бота"

View File

@@ -406,9 +406,6 @@ msgid ""
"Period of time without Internet access until the device is rebooted."
msgstr ""
msgid "Regular script"
msgstr ""
msgid "Polling interval"
msgstr ""
@@ -421,9 +418,15 @@ msgstr ""
msgid "Proxy host"
msgstr ""
msgid "Proxy password"
msgstr ""
msgid "Proxy port"
msgstr ""
msgid "Proxy user"
msgstr ""
msgid "Public IP"
msgstr ""
@@ -442,6 +445,9 @@ msgstr ""
msgid "Recipient"
msgstr ""
msgid "Regular script"
msgstr ""
msgid "Request chat ID from bot API"
msgstr ""