mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 09:45:13 +08:00
🏅 Sync 2026-03-24 02:21:05
This commit is contained in:
1 parent
97ceabd8ac
commit
84ef65c684
14 files changed
+356
-68
No files matched your search
+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
|
||||
|
||||
|
||||
Reference in new issue
Block a user