mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 20:55:13 +08:00
🏅 Sync 2026-03-24 02:21:05
This commit is contained in:
1 parent
ca3783e295
commit
e665eecc31
14 files changed
+356
-68
No files matched your search
@@ -1,12 +1,12 @@
|
||||
#
|
||||
# (с) 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_RELEASE:=1
|
||||
PKG_VERSION:=1.7.2
|
||||
PKG_RELEASE:=2
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
@@ -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)))
|
||||
+33
-3
@@ -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
|
||||
|
||||
|
||||
+10
@@ -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" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+125
@@ -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 };
|
||||
Reference in new issue
Block a user