mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2025-12-06 03:26:50 +03:00
main.InternetDetector.debugOutput().
This commit is contained in:
30
README.md
30
README.md
@@ -17,22 +17,22 @@ Internet-detector is an application for checking the availability of the Interne
|
||||
## Installation notes:
|
||||
|
||||
opkg update
|
||||
wget --no-check-certificate -O /tmp/internet-detector_1.5.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.5.1-r1_all.ipk
|
||||
opkg install /tmp/internet-detector_1.5.1-r1_all.ipk
|
||||
rm /tmp/internet-detector_1.5.1-r1_all.ipk
|
||||
wget --no-check-certificate -O /tmp/internet-detector_1.5.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.5.2-r1_all.ipk
|
||||
opkg install /tmp/internet-detector_1.5.2-r1_all.ipk
|
||||
rm /tmp/internet-detector_1.5.2-r1_all.ipk
|
||||
service internet-detector start
|
||||
service internet-detector enable
|
||||
|
||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.5.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.5.1-r1_all.ipk
|
||||
opkg install /tmp/luci-app-internet-detector_1.5.1-r1_all.ipk
|
||||
rm /tmp/luci-app-internet-detector_1.5.1-r1_all.ipk
|
||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.5.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.5.2-r1_all.ipk
|
||||
opkg install /tmp/luci-app-internet-detector_1.5.2-r1_all.ipk
|
||||
rm /tmp/luci-app-internet-detector_1.5.2-r1_all.ipk
|
||||
service rpcd restart
|
||||
|
||||
i18n-ru:
|
||||
|
||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.5.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.5.1-r1_all.ipk
|
||||
opkg install /tmp/luci-i18n-internet-detector-ru_1.5.1-r1_all.ipk
|
||||
rm /tmp/luci-i18n-internet-detector-ru_1.5.1-r1_all.ipk
|
||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.5.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.5.2-r1_all.ipk
|
||||
opkg install /tmp/luci-i18n-internet-detector-ru_1.5.2-r1_all.ipk
|
||||
rm /tmp/luci-i18n-internet-detector-ru_1.5.2-r1_all.ipk
|
||||
|
||||
## Screenshots:
|
||||
|
||||
@@ -44,9 +44,9 @@ i18n-ru:
|
||||
|
||||
**Dependences:** modemmanager.
|
||||
|
||||
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.5.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.5.1-r1_all.ipk
|
||||
opkg install /tmp/internet-detector-mod-modem-restart_1.5.1-r1_all.ipk
|
||||
rm /tmp/internet-detector-mod-modem-restart_1.5.1-r1_all.ipk
|
||||
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.5.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.5.2-r1_all.ipk
|
||||
opkg install /tmp/internet-detector-mod-modem-restart_1.5.2-r1_all.ipk
|
||||
rm /tmp/internet-detector-mod-modem-restart_1.5.2-r1_all.ipk
|
||||
service internet-detector restart
|
||||
|
||||

|
||||
@@ -55,9 +55,9 @@ i18n-ru:
|
||||
|
||||
**Dependences:** mailsend.
|
||||
|
||||
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||
opkg install /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||
rm /tmp/internet-detector-mod-email_1.5.1-r2_all.ipk
|
||||
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.5.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.5.2-r1_all.ipk
|
||||
opkg install /tmp/internet-detector-mod-email_1.5.2-r1_all.ipk
|
||||
rm /tmp/internet-detector-mod-email_1.5.2-r1_all.ipk
|
||||
service internet-detector restart
|
||||
|
||||

|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=internet-detector-mod-email
|
||||
PKG_VERSION:=1.5.1
|
||||
PKG_RELEASE:=2
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
@@ -11,6 +11,7 @@ local Module = {
|
||||
debug = false,
|
||||
},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
deadPeriod = 0,
|
||||
@@ -122,8 +123,7 @@ function Module:sendMessage(msg, textPattern)
|
||||
-- Debug
|
||||
if self.config.debug then
|
||||
verboseArg = " -v"
|
||||
io.stdout:write(string.format("--- %s ---\n", self.name))
|
||||
io.stdout:flush()
|
||||
self.debugOutput(string.format("--- %s ---", self.name))
|
||||
end
|
||||
|
||||
local securityArgs = "-starttls -auth-login"
|
||||
@@ -141,8 +141,7 @@ function Module:sendMessage(msg, textPattern)
|
||||
|
||||
-- Debug
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format("%s: %s\n", self.name, mtaCmd))
|
||||
io.stdout:flush()
|
||||
self.debugOutput(string.format("%s: %s", self.name, mtaCmd))
|
||||
self.syslog("debug", string.format("%s: %s", self.name, mtaCmd))
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=internet-detector-mod-modem-restart
|
||||
PKG_VERSION:=1.5.1
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ local Module = {
|
||||
runPrio = 40,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
mmcli = "/usr/bin/mmcli",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=internet-detector
|
||||
PKG_VERSION:=1.5.1
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
|
||||
@@ -157,6 +157,13 @@ function InternetDetector:writeLogMessage(level, msg)
|
||||
end
|
||||
end
|
||||
|
||||
function InternetDetector:debugOutput(msg)
|
||||
if self.debug then
|
||||
io.stdout:write(string.format("[%s] %s\n", os.date("%Y.%m.%d-%H:%M:%S"), msg))
|
||||
io.stdout:flush()
|
||||
end
|
||||
end
|
||||
|
||||
function InternetDetector:loadModules()
|
||||
self.modules = {}
|
||||
local ok, modulesDir = pcall(dirent.files, self.modulesDir)
|
||||
@@ -180,10 +187,11 @@ function InternetDetector:loadModules()
|
||||
m = self:prequire(string.format("%s.modules.%s", self.appName, modName))
|
||||
end
|
||||
if m then
|
||||
m.config = self
|
||||
m.syslog = function(level, msg) self:writeLogMessage(level, msg) end
|
||||
m.writeValue = function(filePath, str) return self:writeValueToFile(filePath, str) end
|
||||
m.readValue = function(filePath) return self:readValueFromFile(filePath) end
|
||||
m.config = self
|
||||
m.syslog = function(level, msg) self:writeLogMessage(level, msg) end
|
||||
m.debugOutput = function(msg) self:debugOutput(msg) end
|
||||
m.writeValue = function(filePath, str) return self:writeValueToFile(filePath, str) end
|
||||
m.readValue = function(filePath) return self:readValueFromFile(filePath) end
|
||||
m:init(modConfig)
|
||||
self.modules[#self.modules + 1] = m
|
||||
end
|
||||
@@ -223,12 +231,8 @@ function InternetDetector:pingHost(host)
|
||||
)
|
||||
local retCode = os.execute(ping)
|
||||
|
||||
if self.debug then
|
||||
io.stdout:write(string.format(
|
||||
"--- Ping ---\ntime = %s\n%s\nretCode = %s\n", os.time(), ping, retCode)
|
||||
)
|
||||
io.stdout:flush()
|
||||
end
|
||||
self:debugOutput(string.format(
|
||||
"--- Ping ---\ntime = %s\n%s\nretCode = %s", os.time(), ping, retCode))
|
||||
|
||||
return retCode
|
||||
end
|
||||
@@ -238,21 +242,16 @@ function InternetDetector:TCPConnectionToHost(host, port)
|
||||
local saTable, errMsg, errNum = socket.getaddrinfo(host, port or self.serviceConfig.tcp_port)
|
||||
|
||||
if not saTable then
|
||||
if self.debug then
|
||||
io.stdout:write(string.format(
|
||||
"GETADDRINFO ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self:debugOutput(string.format(
|
||||
"GETADDRINFO ERROR: %s, %s", errMsg, errNum))
|
||||
else
|
||||
local family = saTable[1].family
|
||||
|
||||
if family then
|
||||
local sock, errMsg, errNum = socket.socket(family, socket.SOCK_STREAM, 0)
|
||||
|
||||
if not sock then
|
||||
if self.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self:debugOutput(string.format(
|
||||
"SOCKET ERROR: %s, %s", errMsg, errNum))
|
||||
return retCode
|
||||
end
|
||||
|
||||
@@ -265,10 +264,8 @@ function InternetDetector:TCPConnectionToHost(host, port)
|
||||
local ok, errMsg, errNum = socket.setsockopt(sock, socket.SOL_SOCKET,
|
||||
socket.SO_BINDTODEVICE, self.serviceConfig.iface)
|
||||
if not ok then
|
||||
if self.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self:debugOutput(string.format(
|
||||
"SOCKET ERROR: %s, %s", errMsg, errNum))
|
||||
unistd.close(sock)
|
||||
return retCode
|
||||
end
|
||||
@@ -278,23 +275,23 @@ function InternetDetector:TCPConnectionToHost(host, port)
|
||||
|
||||
if self.debug then
|
||||
if not success then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET CONNECT ERROR: %s\n", tostring(success)))
|
||||
self:debugOutput(string.format(
|
||||
"SOCKET CONNECT ERROR: %s", tostring(success)))
|
||||
end
|
||||
local sockTable, err_s, e_s = socket.getsockname(sock)
|
||||
local peerTable, err_p, e_p = socket.getpeername(sock)
|
||||
if not sockTable then
|
||||
sockTable = {}
|
||||
io.stdout:write(
|
||||
string.format("SOCKET ERROR: %s, %s\n", err_s, e_s))
|
||||
self:debugOutput(
|
||||
string.format("SOCKET ERROR: %s, %s", err_s, e_s))
|
||||
end
|
||||
if not peerTable then
|
||||
peerTable = {}
|
||||
io.stdout:write(
|
||||
string.format("SOCKET ERROR: %s, %s\n", err_p, e_p))
|
||||
self:debugOutput(
|
||||
string.format("SOCKET ERROR: %s, %s", err_p, e_p))
|
||||
end
|
||||
io.stdout:write(string.format(
|
||||
"--- TCP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nhost:port = [%s]:%s\nsockname = [%s]:%s\npeername = [%s]:%s\nsuccess = %s\n",
|
||||
self:debugOutput(string.format(
|
||||
"--- TCP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nhost:port = [%s]:%s\nsockname = [%s]:%s\npeername = [%s]:%s\nsuccess = %s",
|
||||
os.time(),
|
||||
self.serviceConfig.connection_timeout,
|
||||
tostring(self.serviceConfig.iface),
|
||||
@@ -306,7 +303,6 @@ function InternetDetector:TCPConnectionToHost(host, port)
|
||||
tostring(peerTable.port),
|
||||
tostring(success))
|
||||
)
|
||||
io.stdout:flush()
|
||||
end
|
||||
|
||||
socket.shutdown(sock, socket.SHUT_RDWR)
|
||||
@@ -400,6 +396,7 @@ function InternetDetector:mainLoop()
|
||||
mTimeDiff = 1
|
||||
end
|
||||
mLastTime = mTimeNow
|
||||
|
||||
if self.debug then
|
||||
e:run(currentStatus, lastStatus, mTimeDiff, mTimeNow, inetChecked)
|
||||
else
|
||||
@@ -423,7 +420,6 @@ function InternetDetector:mainLoop()
|
||||
end
|
||||
|
||||
lastStatus = currentStatus
|
||||
|
||||
unistd.sleep(1)
|
||||
counter = counter + 1
|
||||
|
||||
@@ -589,8 +585,8 @@ function InternetDetector:run()
|
||||
f = function(t, prefix)
|
||||
tables[t] = true
|
||||
for k, v in pairs(t) do
|
||||
io.stdout:write(string.format(
|
||||
"%s%s = %s\n", prefix, k, tostring(v))
|
||||
self:debugOutput(string.format(
|
||||
"%s%s = %s", prefix, k, tostring(v))
|
||||
)
|
||||
if type(v) == "table" and not tables[v] then
|
||||
f(v, string.format("%s%s.", prefix, k))
|
||||
@@ -600,9 +596,8 @@ function InternetDetector:run()
|
||||
return f
|
||||
end
|
||||
|
||||
io.stdout:write("--- Config ---\n")
|
||||
self:debugOutput("--- Config ---")
|
||||
inspectTable()(self, "self.")
|
||||
io.stdout:flush()
|
||||
end
|
||||
|
||||
self:writeValueToFile(
|
||||
|
||||
@@ -7,6 +7,7 @@ local Module = {
|
||||
runPrio = 10,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
runInterval = 5,
|
||||
|
||||
@@ -6,6 +6,7 @@ local Module = {
|
||||
runPrio = 30,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
deadPeriod = 900,
|
||||
|
||||
@@ -14,6 +14,7 @@ local Module = {
|
||||
},
|
||||
},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
port = 53,
|
||||
@@ -136,29 +137,21 @@ function Module:sendUDPMessage(message, server, port)
|
||||
local retCode = 1
|
||||
local data
|
||||
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format("--- %s ---\n", self.name))
|
||||
io.stdout:flush()
|
||||
end
|
||||
self.debugOutput(string.format("--- %s ---", self.name))
|
||||
|
||||
local saTable, errMsg, errNum = socket.getaddrinfo(server, port)
|
||||
|
||||
if not saTable then
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"GETADDRINFO ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self.debugOutput(string.format(
|
||||
"GETADDRINFO ERROR: %s, %s", errMsg, errNum))
|
||||
else
|
||||
local family = saTable[1].family
|
||||
|
||||
if family then
|
||||
local sock, errMsg, errNum = socket.socket(family, socket.SOCK_DGRAM, 0)
|
||||
|
||||
if not sock then
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self.debugOutput(string.format(
|
||||
"SOCKET ERROR: %s, %s", errMsg, errNum))
|
||||
return retCode
|
||||
end
|
||||
|
||||
@@ -171,10 +164,8 @@ function Module:sendUDPMessage(message, server, port)
|
||||
local ok, errMsg, errNum = socket.setsockopt(sock, socket.SOL_SOCKET,
|
||||
socket.SO_BINDTODEVICE, self.config.serviceConfig.iface)
|
||||
if not ok then
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET ERROR: %s, %s\n", errMsg, errNum))
|
||||
end
|
||||
self.debugOutput(string.format(
|
||||
"SOCKET ERROR: %s, %s", errMsg, errNum))
|
||||
unistd.close(sock)
|
||||
return retCode
|
||||
end
|
||||
@@ -189,17 +180,17 @@ function Module:sendUDPMessage(message, server, port)
|
||||
success = true
|
||||
response = resp
|
||||
elseif self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET RECV ERROR: %s, %s\n", tostring(resp), tostring(errNum)))
|
||||
self.debugOutput(string.format(
|
||||
"SOCKET RECV ERROR: %s, %s", tostring(resp), tostring(errNum)))
|
||||
end
|
||||
elseif self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"SOCKET SEND ERROR: %s, %s\n", tostring(errMsg), tostring(errNum)))
|
||||
self.debugOutput(string.format(
|
||||
"SOCKET SEND ERROR: %s, %s", tostring(errMsg), tostring(errNum)))
|
||||
end
|
||||
|
||||
if self.config.debug then
|
||||
io.stdout:write(string.format(
|
||||
"--- UDP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nserver = %s:%s\nsockname = %s:%s\nsuccess = %s\n",
|
||||
self.debugOutput(string.format(
|
||||
"--- UDP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nserver = %s:%s\nsockname = %s:%s\nsuccess = %s",
|
||||
os.time(),
|
||||
self.timeout,
|
||||
tostring(self.config.serviceConfig.iface),
|
||||
@@ -209,7 +200,6 @@ function Module:sendUDPMessage(message, server, port)
|
||||
tostring(response.port),
|
||||
tostring(success))
|
||||
)
|
||||
io.stdout:flush()
|
||||
end
|
||||
|
||||
unistd.close(sock)
|
||||
@@ -239,7 +229,7 @@ end
|
||||
|
||||
function Module:decodeMessage(message)
|
||||
local retTable = {}
|
||||
local t = {}
|
||||
local t = {}
|
||||
for i = 1, #message do
|
||||
t[#t + 1] = string.format("%.2x", string.byte(message, i))
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ local Module = {
|
||||
runPrio = 20,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
deadPeriod = 3600,
|
||||
|
||||
@@ -8,6 +8,7 @@ local Module = {
|
||||
runPrio = 90,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
inetState = 2, -- 0: connected, 1: disconnected, 2: both
|
||||
|
||||
@@ -6,6 +6,7 @@ local Module = {
|
||||
runPrio = 80,
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
debugOutput = function(msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
deadPeriod = 0,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-internet-detector
|
||||
PKG_VERSION:=1.5.1
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_RELEASE:=1
|
||||
LUCI_TITLE:=LuCI support for internet-detector
|
||||
LUCI_DEPENDS:=+internet-detector
|
||||
|
||||
@@ -919,6 +919,7 @@ return view.extend({
|
||||
o.value(3);
|
||||
o.value(4);
|
||||
o.value(5);
|
||||
o.value(10);
|
||||
o.value(0, _('infinitely'));
|
||||
o.default = '1';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user