diff --git a/README.md b/README.md index f51d806..95d1e12 100644 --- a/README.md +++ b/README.md @@ -15,22 +15,22 @@ Internet-detector is an application for checking the availability of the Interne ## Installation notes (OpenWrt >= 21.02) opkg update - wget --no-check-certificate -O /tmp/internet-detector_1.4.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.1-r1_all.ipk - opkg install /tmp/internet-detector_1.4.1-r1_all.ipk - rm /tmp/internet-detector_1.4.1-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector_1.4.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.2-r1_all.ipk + opkg install /tmp/internet-detector_1.4.2-r1_all.ipk + rm /tmp/internet-detector_1.4.2-r1_all.ipk /etc/init.d/internet-detector start /etc/init.d/internet-detector enable - wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.1-r1_all.ipk - opkg install /tmp/luci-app-internet-detector_1.4.1-r1_all.ipk - rm /tmp/luci-app-internet-detector_1.4.1-r1_all.ipk + wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.2-r1_all.ipk + opkg install /tmp/luci-app-internet-detector_1.4.2-r1_all.ipk + rm /tmp/luci-app-internet-detector_1.4.2-r1_all.ipk /etc/init.d/rpcd restart i18n-ru: - wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.1-r1_all.ipk - opkg install /tmp/luci-i18n-internet-detector-ru_1.4.1-r1_all.ipk - rm /tmp/luci-i18n-internet-detector-ru_1.4.1-r1_all.ipk + wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.2-r1_all.ipk + opkg install /tmp/luci-i18n-internet-detector-ru_1.4.2-r1_all.ipk + rm /tmp/luci-i18n-internet-detector-ru_1.4.2-r1_all.ipk ## Screenshots: @@ -42,9 +42,9 @@ i18n-ru: **Dependences:** modemmanager. - wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.1-r1_all.ipk - opkg install /tmp/internet-detector-mod-modem-restart_1.4.1-r1_all.ipk - rm /tmp/internet-detector-mod-modem-restart_1.4.1-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.2-r1_all.ipk + opkg install /tmp/internet-detector-mod-modem-restart_1.4.2-r1_all.ipk + rm /tmp/internet-detector-mod-modem-restart_1.4.2-r1_all.ipk /etc/init.d/internet-detector restart ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg) @@ -53,9 +53,9 @@ i18n-ru: **Dependences:** mailsend. - wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.1-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.1-r1_all.ipk - opkg install /tmp/internet-detector-mod-email_1.4.1-r1_all.ipk - rm /tmp/internet-detector-mod-email_1.4.1-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.2-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.2-r1_all.ipk + opkg install /tmp/internet-detector-mod-email_1.4.2-r1_all.ipk + rm /tmp/internet-detector-mod-email_1.4.2-r1_all.ipk /etc/init.d/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 6b06a59..7d045d0 100644 --- a/internet-detector-mod-email/Makefile +++ b/internet-detector-mod-email/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector-mod-email -PKG_VERSION:=1.4.1 +PKG_VERSION:=1.4.2 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector-mod-email/files/usr/lib/lua/internet-detector/mod_email.lua b/internet-detector-mod-email/files/usr/lib/lua/internet-detector/mod_email.lua index bda33e0..f924c55 100644 --- a/internet-detector-mod-email/files/usr/lib/lua/internet-detector/mod_email.lua +++ b/internet-detector-mod-email/files/usr/lib/lua/internet-detector/mod_email.lua @@ -5,41 +5,43 @@ local unistd = require("posix.unistd") local Module = { - name = "mod_email", - runPrio = 60, - config = { + name = "mod_email", + runPrio = 60, + config = { debug = false, }, - syslog = function(level, msg) return true end, - writeValue = function(filePath, str) return false end, - readValue = function(filePath) return nil end, - deadPeriod = 0, - alivePeriod = 0, - mode = 0, -- 0: connected, 1: disconnected, 2: both - hostAlias = "OpenWrt", - mta = "/usr/bin/mailsend", - mtaConnectTimeout = 5, -- default = 5 - mtaReadTimeout = 5, -- default = 5 - mailRecipient = nil, - mailSender = nil, - mailUser = nil, - mailPassword = nil, - mailSmtp = nil, - mailSmtpPort = nil, - mailSecurity = "tls", - msgTextPattern1 = "[%s]: %s: %s", -- Connected (host, instance, message) - msgTextPattern2 = "[%s]: %s: %s", -- Disconnected (host, instance, message) - msgSubPattern = "%s notification", -- Subject (host) - status = nil, - _enabled = false, - _deadCounter = 0, - _aliveCounter = 0, - _msgSentDisconnect = true, - _msgSentConnect = true, - _disconnected = true, - _lastDisconnection = nil, - _lastConnection = nil, - _message = {}, + syslog = function(level, msg) return true end, + writeValue = function(filePath, str) return false end, + readValue = function(filePath) return nil end, + deadPeriod = 0, + alivePeriod = 0, + mode = 0, -- 0: connected, 1: disconnected, 2: both + hostAlias = "OpenWrt", + mta = "/usr/bin/mailsend", + mtaConnectTimeout = 5, + mtaReadTimeout = 5, + mailRecipient = nil, + mailSender = nil, + mailUser = nil, + mailPassword = nil, + mailSmtp = nil, + mailSmtpPort = nil, + mailSecurity = "tls", + msgTextPattern = "[%s] (%s) | %s", -- Message (host, instance, message) + msgSubPattern = "%s notification", -- Subject (host) + msgConnectPattern = "Internet connected: %s", + msgDisconnectPattern = "Internet disconnected: %s", + msgSeparator = "; ", + msgMaxItems = 50, + status = nil, + _enabled = false, + _deadCounter = 0, + _aliveCounter = 0, + _msgSentDisconnect = true, + _disconnected = true, + _msgSentConnect = true, + _connected = true, + _msgBuffer = {}, } function Module:init(t) @@ -88,6 +90,17 @@ function Module:init(t) end end +function Module:appendNotice(str) + self._msgBuffer[#self._msgBuffer + 1] = str + if #self._msgBuffer > self.msgMaxItems then + local t = {} + for i = #self._msgBuffer - self.msgMaxItems + 1, #self._msgBuffer do + t[#t + 1] = self._msgBuffer[i] + end + self._msgBuffer = t + end +end + function Module:sendMessage(msg, textPattern) local verboseArg = "" local emailMsg = string.format( @@ -136,37 +149,37 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow) if currentStatus == 1 then self._aliveCounter = 0 self._msgSentConnect = false - self._lastConnection = nil + if not self._disconnected then self._disconnected = true - if not self._lastDisconnection then - self._lastDisconnection = os.date("%Y.%m.%d %H:%M:%S", os.time()) - end - self._message[#self._message + 1] = string.format( - "Internet disconnected: %s", self._lastDisconnection) + self:appendNotice(string.format( + self.msgDisconnectPattern, os.date("%Y.%m.%d %H:%M:%S", os.time()))) end + if not self._msgSentDisconnect and (self.mode == 1 or self.mode == 2) then if self._deadCounter >= self.deadPeriod then - self._lastDisconnection = nil - self:sendMessage(table.concat(self._message, "; "), self.msgTextPattern2) - self._message = {} + self:sendMessage(table.concat(self._msgBuffer, self.msgSeparator), self.msgTextPattern) + self._msgBuffer = {} self._msgSentDisconnect = true else self._deadCounter = self._deadCounter + timeDiff end end + self._connected = false else self._deadCounter = 0 self._msgSentDisconnect = false + + if not self._connected then + self._connected = true + self:appendNotice(string.format( + self.msgConnectPattern, os.date("%Y.%m.%d %H:%M:%S", os.time()))) + end + if not self._msgSentConnect and (self.mode == 0 or self.mode == 2) then - if not self._lastConnection then - self._lastConnection = os.date("%Y.%m.%d %H:%M:%S", os.time()) - end if self._aliveCounter >= self.alivePeriod then - self._message[#self._message + 1] = string.format( - "Internet connected: %s", self._lastConnection) - self:sendMessage(table.concat(self._message, "; "), self.msgTextPattern1) - self._message = {} + self:sendMessage(table.concat(self._msgBuffer, self.msgSeparator), self.msgTextPattern) + self._msgBuffer = {} self._msgSentConnect = true else self._aliveCounter = self._aliveCounter + timeDiff diff --git a/internet-detector-mod-modem-restart/Makefile b/internet-detector-mod-modem-restart/Makefile index 37907f0..9c52c1a 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.4.1 +PKG_VERSION:=1.4.2 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/mod_modem_restart.lua b/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/mod_modem_restart.lua index ed1dbbe..11e328d 100644 --- a/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/mod_modem_restart.lua +++ b/internet-detector-mod-modem-restart/files/usr/lib/lua/internet-detector/mod_modem_restart.lua @@ -19,7 +19,7 @@ local Module = { status = nil, _enabled = false, _deadCounter = 0, - _restarted = false, + _restarted = true, } function Module:toggleIface(flag) diff --git a/internet-detector/Makefile b/internet-detector/Makefile index c81bc23..287d29b 100644 --- a/internet-detector/Makefile +++ b/internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector -PKG_VERSION:=1.4.1 +PKG_VERSION:=1.4.2 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector/files/usr/lib/lua/internet-detector/mod_network_restart.lua b/internet-detector/files/usr/lib/lua/internet-detector/mod_network_restart.lua index 57e4ed5..1550709 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/mod_network_restart.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/mod_network_restart.lua @@ -2,19 +2,21 @@ local unistd = require("posix.unistd") local Module = { - name = "mod_network_restart", - runPrio = 30, - config = {}, - syslog = function(level, msg) return true end, - writeValue = function(filePath, str) return false end, - readValue = function(filePath) return nil end, - deadPeriod = 900, - attempts = 1, - iface = nil, - restartTimeout = 0, - status = nil, - _attemptsCounter = 0, - _deadCounter = 0, + name = "mod_network_restart", + runPrio = 30, + config = {}, + syslog = function(level, msg) return true end, + writeValue = function(filePath, str) return false end, + readValue = function(filePath) return nil end, + deadPeriod = 900, + attempts = 1, + iface = nil, + restartTimeout = 0, + status = nil, + _attemptsCounter = 0, + _deadCounter = 0, + _ifaceRestarting = false, + _ifaceRestartCounter = 0, } function Module:toggleFunc(flag) @@ -74,32 +76,47 @@ function Module:init(t) if t.restart_timeout ~= nil then self.restartTimeout = tonumber(t.restart_timeout) end + self._attemptsCounter = self.attempts end function Module:run(currentStatus, lastStatus, timeDiff, timeNow) - if currentStatus == 1 then - if self.attempts == 0 or self._attemptsCounter < self.attempts then - if self._deadCounter >= self.deadPeriod then - if self.iface then - self.syslog("info", string.format( - "%s: restarting network interface '%s'", self.name, self.iface)) - self:ifaceDown() - unistd.sleep(self.restartTimeout) - self:ifaceUp() - else - self.syslog("info", string.format( - "%s: restarting network", self.name)) - self:networkRestart() - end - self._deadCounter = 0 - self._attemptsCounter = self._attemptsCounter + 1 - else - self._deadCounter = self._deadCounter + timeDiff - end + if self._ifaceRestarting then + if self._ifaceRestartCounter >= self.restartTimeout then + self:ifaceUp() + self._ifaceRestarting = false + self._ifaceRestartCounter = 0 + else + self._ifaceRestartCounter = self._ifaceRestartCounter + timeDiff end else - self._attemptsCounter = 0 - self._deadCounter = 0 + if currentStatus == 1 then + if self._attemptsCounter < self.attempts then + if self._deadCounter >= self.deadPeriod then + if self.iface then + self.syslog("info", string.format( + "%s: restarting network interface '%s'", self.name, self.iface)) + self:ifaceDown() + if self.restartTimeout < 1 then + self:ifaceUp() + else + self._ifaceRestarting = true + end + else + self.syslog("info", string.format( + "%s: restarting network", self.name)) + self:networkRestart() + end + self._deadCounter = 0 + self._attemptsCounter = self._attemptsCounter + 1 + else + self._deadCounter = self._deadCounter + timeDiff + end + end + else + self._attemptsCounter = 0 + self._deadCounter = 0 + end + self._ifaceRestartCounter = 0 end end diff --git a/internet-detector/files/usr/lib/lua/internet-detector/mod_reboot.lua b/internet-detector/files/usr/lib/lua/internet-detector/mod_reboot.lua index 86fa28f..969e1ca 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/mod_reboot.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/mod_reboot.lua @@ -2,16 +2,18 @@ local unistd = require("posix.unistd") local Module = { - name = "mod_reboot", - runPrio = 20, - config = {}, - syslog = function(level, msg) return true end, - writeValue = function(filePath, str) return false end, - readValue = function(filePath) return nil end, - deadPeriod = 3600, - forceRebootDelay = 300, - status = nil, - _deadCounter = 0, + name = "mod_reboot", + runPrio = 20, + config = {}, + syslog = function(level, msg) return true end, + writeValue = function(filePath, str) return false end, + readValue = function(filePath) return nil end, + deadPeriod = 3600, + forceRebootDelay = 300, + antiBootloopDelay = 300, + status = nil, + _deadCounter = 0, + _rebooted = true, } function Module:rebootDevice() @@ -36,15 +38,17 @@ end function Module:run(currentStatus, lastStatus, timeDiff, timeNow) if currentStatus == 1 then - if self._deadCounter >= self.deadPeriod then - self:rebootDevice() - self._deadCounter = 0 - else - self._deadCounter = self._deadCounter + timeDiff + if not self._rebooted then + if timeNow >= self.antiBootloopDelay and self._deadCounter >= self.deadPeriod then + self:rebootDevice() + self._rebooted = true + else + self._deadCounter = self._deadCounter + timeDiff + end end - else self._deadCounter = 0 + self._rebooted = false end end diff --git a/internet-detector/files/usr/lib/lua/internet-detector/mod_user_scripts.lua b/internet-detector/files/usr/lib/lua/internet-detector/mod_user_scripts.lua index 355f1ab..3af696d 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/mod_user_scripts.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/mod_user_scripts.lua @@ -15,8 +15,8 @@ local Module = { status = nil, _deadCounter = 0, _aliveCounter = 0, - _upScriptExecuted = true, _downScriptExecuted = true, + _upScriptExecuted = true, } function Module:runExternalScript(scriptPath) @@ -42,23 +42,23 @@ end function Module:run(currentStatus, lastStatus, timeDiff, timeNow) if currentStatus == 1 then - self._aliveCounter = 0 - self._downScriptExecuted = false - if not self._upScriptExecuted then + self._aliveCounter = 0 + self._upScriptExecuted = false + if not self._downScriptExecuted then if self._deadCounter >= self.deadPeriod then self:runExternalScript(self.downScript) - self._upScriptExecuted = true + self._downScriptExecuted = true else self._deadCounter = self._deadCounter + timeDiff end end else - self._deadCounter = 0 - self._upScriptExecuted = false - if not self._downScriptExecuted then + self._deadCounter = 0 + self._downScriptExecuted = false + if not self._upScriptExecuted then if self._aliveCounter >= self.alivePeriod then self:runExternalScript(self.upScript) - self._downScriptExecuted = true + self._upScriptExecuted = true else self._aliveCounter = self._aliveCounter + timeDiff end diff --git a/luci-app-internet-detector/Makefile b/luci-app-internet-detector/Makefile index dc0ce2f..e0e18e0 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.4.1 +PKG_VERSION:=1.4.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 f4a1d6e..cfae490 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 @@ -873,7 +873,7 @@ return view.extend({ // dead_period o = s.taboption('restart_network', this.CBITimeInput, 'mod_network_restart_dead_period', _('Dead period'), - _('Period of time without Internet access before network restart.') + _('Period of time without Internet access before network restart or between restart attempts.') ); o.default = '900'; o.rmempty = false; diff --git a/luci-app-internet-detector/po/ru/internet-detector.po b/luci-app-internet-detector/po/ru/internet-detector.po index bf8b8c7..4e1a85c 100644 --- a/luci-app-internet-detector/po/ru/internet-detector.po +++ b/luci-app-internet-detector/po/ru/internet-detector.po @@ -309,8 +309,8 @@ msgstr "Период времени отсутствия доступа в Ин msgid "Period of time without Internet access before modem restart." msgstr "Период времени отсутствия доступа в Интренет перед перезапуском модема." -msgid "Period of time without Internet access before network restart." -msgstr "Период времени отсутствия доступа в Интренет перед перезапуском сети." +msgid "Period of time without Internet access before network restart or between restart attempts." +msgstr "Период времени отсутствия доступа в Интренет перед перезапуском сети или между попытками перезапуска." msgid "" "Period of time without Internet access until the device is rebooted." diff --git a/luci-app-internet-detector/po/templates/internet-detector.pot b/luci-app-internet-detector/po/templates/internet-detector.pot index b654798..2ccf138 100644 --- a/luci-app-internet-detector/po/templates/internet-detector.pot +++ b/luci-app-internet-detector/po/templates/internet-detector.pot @@ -285,7 +285,7 @@ msgstr "" msgid "Period of time without Internet access before modem restart." msgstr "" -msgid "Period of time without Internet access before network restart." +msgid "Period of time without Internet access before network restart or between restart attempts." msgstr "" msgid ""