diff --git a/README.md b/README.md index dee894a..99ec230 100644 --- a/README.md +++ b/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 ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg) @@ -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 ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg) diff --git a/internet-detector-mod-email/Makefile b/internet-detector-mod-email/Makefile index 14f3283..3a67b94 100644 --- a/internet-detector-mod-email/Makefile +++ b/internet-detector-mod-email/Makefile @@ -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 include $(INCLUDE_DIR)/package.mk diff --git a/internet-detector-mod-email/files/usr/lib/lua/internet-detector/modules/mod_email.lua b/internet-detector-mod-email/files/usr/lib/lua/internet-detector/modules/mod_email.lua index dcfb881..dfc190b 100644 --- a/internet-detector-mod-email/files/usr/lib/lua/internet-detector/modules/mod_email.lua +++ b/internet-detector-mod-email/files/usr/lib/lua/internet-detector/modules/mod_email.lua @@ -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 diff --git a/internet-detector-mod-modem-restart/Makefile b/internet-detector-mod-modem-restart/Makefile index b998c94..0b8ac35 100644 --- a/internet-detector-mod-modem-restart/Makefile +++ b/internet-detector-mod-modem-restart/Makefile @@ -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 diff --git a/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua b/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua index edd6b28..d292196 100644 --- a/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua +++ b/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua @@ -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", diff --git a/internet-detector/Makefile b/internet-detector/Makefile index 7f92377..8d84084 100644 --- a/internet-detector/Makefile +++ b/internet-detector/Makefile @@ -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 diff --git a/internet-detector/files/usr/lib/lua/internet-detector/main.lua b/internet-detector/files/usr/lib/lua/internet-detector/main.lua index 7c58cca..7f56224 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/main.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/main.lua @@ -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( diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_led_control.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_led_control.lua index 8dc8fb9..2f0650b 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_led_control.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_led_control.lua @@ -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, diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_network_restart.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_network_restart.lua index 72c983d..0b136cb 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_network_restart.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_network_restart.lua @@ -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, diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_public_ip.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_public_ip.lua index 20fc635..ce184f6 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_public_ip.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_public_ip.lua @@ -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 diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_reboot.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_reboot.lua index 911f144..f3c4f9c 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_reboot.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_reboot.lua @@ -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, diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_regular_script.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_regular_script.lua index 339e1b7..3aa7515 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_regular_script.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_regular_script.lua @@ -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 diff --git a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua index b4ab4d7..04eee69 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua @@ -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, diff --git a/luci-app-internet-detector/Makefile b/luci-app-internet-detector/Makefile index a62e150..c92be25 100644 --- a/luci-app-internet-detector/Makefile +++ b/luci-app-internet-detector/Makefile @@ -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 diff --git a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js index a9f7e8f..981f276 100644 --- a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js +++ b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js @@ -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';