v1.5. Some new options. New package structure.

This commit is contained in:
gSpot
2025-06-05 01:00:21 +03:00
parent d0c1f03ce5
commit 9803fe0ab4
22 changed files with 590 additions and 271 deletions

View File

@@ -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.4.6-r2_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.6-r2_all.ipk
opkg install /tmp/internet-detector_1.4.6-r2_all.ipk
rm /tmp/internet-detector_1.4.6-r2_all.ipk
wget --no-check-certificate -O /tmp/internet-detector_1.5.0-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.5.0-r1_all.ipk
opkg install /tmp/internet-detector_1.5.0-r1_all.ipk
rm /tmp/internet-detector_1.5.0-r1_all.ipk
service internet-detector start
service internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.6-r1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk
rm /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.5.0-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.5.0-r1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.5.0-r1_all.ipk
rm /tmp/luci-app-internet-detector_1.5.0-r1_all.ipk
service rpcd restart
i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.5.0-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.5.0-r1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.5.0-r1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.5.0-r1_all.ipk
## Screenshots:
@@ -44,9 +44,9 @@ i18n-ru:
**Dependences:** modemmanager.
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk
opkg install /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk
rm /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.5.0-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.5.0-r1_all.ipk
opkg install /tmp/internet-detector-mod-modem-restart_1.5.0-r1_all.ipk
rm /tmp/internet-detector-mod-modem-restart_1.5.0-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.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.6-r1_all.ipk
opkg install /tmp/internet-detector-mod-email_1.4.6-r1_all.ipk
rm /tmp/internet-detector-mod-email_1.4.6-r1_all.ipk
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.5.0-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.5.0-r1_all.ipk
opkg install /tmp/internet-detector-mod-email_1.5.0-r1_all.ipk
rm /tmp/internet-detector-mod-email_1.5.0-r1_all.ipk
service internet-detector restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg)

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-email
PKG_VERSION:=1.4.6
PKG_VERSION:=1.5.0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
@@ -34,8 +34,8 @@ define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_email.lua $(1)/usr/lib/lua/internet-detector/mod_email.lua
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector/modules
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_email.lua $(1)/usr/lib/lua/internet-detector/modules/mod_email.lua
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@@ -70,6 +70,12 @@ function Module:init(t)
if t.mail_security ~= nil then
self.mailSecurity = t.mail_security
end
if tonumber(t.message_at_startup) == 1 then
self._msgSentDisconnect = false
self._disconnected = false
self._msgSentConnect = false
self._connected = false
end
if unistd.access(self.mta, "x") then
self._enabled = true
@@ -142,7 +148,7 @@ function Module:sendMessage(msg, textPattern)
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
if not self._enabled then
return
end

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-modem-restart
PKG_VERSION:=1.4.6
PKG_VERSION:=1.5.0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
@@ -34,8 +34,8 @@ define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_modem_restart.lua $(1)/usr/lib/lua/internet-detector/mod_modem_restart.lua
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector/modules
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua $(1)/usr/lib/lua/internet-detector/modules/mod_modem_restart.lua
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@@ -1,106 +0,0 @@
--[[
Dependences:
modemmanager
--]]
local unistd = require("posix.unistd")
local Module = {
name = "mod_modem_restart",
runPrio = 40,
config = {},
syslog = function(level, msg) return true end,
writeValue = function(filePath, str) return false end,
readValue = function(filePath) return nil end,
mmcli = "/usr/bin/mmcli",
mmInit = "/etc/init.d/modemmanager",
deadPeriod = 600,
iface = nil,
anyBand = false,
status = nil,
_enabled = false,
_deadCounter = 0,
_restarted = true,
}
function Module:toggleIface(flag)
if not self.iface then
return
end
return os.execute(
string.format("%s %s", (flag and "/sbin/ifup" or "/sbin/ifdown"), self.iface)
)
end
function Module:restartMM()
if os.execute(string.format("%s enabled", self.mmInit)) ~= 0 then
self.syslog("warning", string.format(
"%s: modemmanager service is disabled", self.name))
return
end
if self.anyBand then
self.syslog("info", string.format(
"%s: resetting current-bands to 'any'", self.name))
os.execute(string.format("%s -m any --set-current-bands=any", self.mmcli))
end
self.syslog("info", string.format("%s: reconnecting modem", self.name))
os.execute(string.format("%s restart", self.mmInit))
if self.iface then
self.syslog("info", string.format(
"%s: restarting network interface '%s'", self.name, self.iface))
self:toggleIface(false)
self:toggleIface(true)
end
end
function Module:init(t)
if t.dead_period ~= nil then
self.deadPeriod = tonumber(t.dead_period)
end
if t.iface ~= nil then
self.iface = t.iface
end
if t.any_band ~= nil then
self.anyBand = (tonumber(t.any_band) ~= 0)
end
if not unistd.access(self.mmcli, "x") then
self.anyBand = false
end
if (unistd.access(self.mmInit, "x")
and os.execute(string.format("%s enabled", self.mmInit)) == 0) then
self._enabled = true
else
self._enabled = false
self.syslog("warning", string.format(
"%s: modemmanager service is not available", self.name))
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
if not self._enabled then
return
end
if currentStatus == 1 then
if not self._restarted then
if self._deadCounter >= self.deadPeriod then
self:restartMM()
self._restarted = true
else
self._deadCounter = self._deadCounter + timeDiff
end
end
else
self._deadCounter = 0
self._restarted = false
end
end
function Module:onExit()
return true
end
return Module

View File

@@ -0,0 +1,145 @@
--[[
Dependences:
modemmanager
--]]
local unistd = require("posix.unistd")
local Module = {
name = "mod_modem_restart",
runPrio = 40,
config = {},
syslog = function(level, msg) return true end,
writeValue = function(filePath, str) return false end,
readValue = function(filePath) return nil end,
mmcli = "/usr/bin/mmcli",
mmInit = "/etc/init.d/modemmanager",
deadPeriod = 600,
attempts = 1,
ifaceTimeout = 0,
iface = nil,
anyBand = false,
status = nil,
_enabled = false,
_attemptsCounter = 0,
_deadCounter = 0,
_modemRestarted = false,
_ifaceRestarting = false,
_ifaceRestartCounter = 0,
_disconnectedAtStartup = false,
}
function Module:toggleIface(flag)
if not self.iface then
return
end
return os.execute(
string.format("%s %s", (flag and "/sbin/ifup" or "/sbin/ifdown"), self.iface)
)
end
function Module:init(t)
if t.attempts ~= nil then
self.attempts = tonumber(t.attempts)
end
if t.dead_period ~= nil then
self.deadPeriod = tonumber(t.dead_period)
end
if t.iface ~= nil then
self.iface = t.iface
end
if t.iface_timeout ~= nil then
self.ifaceTimeout = tonumber(t.iface_timeout)
end
if t.any_band ~= nil then
self.anyBand = (tonumber(t.any_band) ~= 0)
end
if tonumber(t.disconnected_at_startup) == 1 then
self._disconnectedAtStartup = true
end
if not unistd.access(self.mmcli, "x") then
self.anyBand = false
end
if (unistd.access(self.mmInit, "x")
and os.execute(string.format("%s enabled", self.mmInit)) == 0) then
self._enabled = true
else
self._enabled = false
self.syslog("warning", string.format(
"%s: modemmanager service is not available", self.name))
end
end
function Module:restartMM()
if os.execute(string.format("%s enabled", self.mmInit)) == 0 then
if self.anyBand then
self.syslog("info", string.format(
"%s: resetting current-bands to 'any'", self.name))
os.execute(string.format("%s -m any --set-current-bands=any", self.mmcli))
end
self.syslog("info", string.format("%s: reconnecting modem", self.name))
os.execute(string.format("%s restart", self.mmInit))
if self.iface then
self.syslog("info", string.format(
"%s: restarting network interface '%s'", self.name, self.iface))
self:toggleIface(false)
if self.ifaceTimeout < 1 then
self:toggleIface(true)
else
self._ifaceRestarting = true
end
end
else
self.syslog("warning", string.format(
"%s: modemmanager service is disabled", self.name))
end
if self.attempts > 0 then
self._attemptsCounter = self._attemptsCounter + 1
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
if not self._enabled then
return
end
if self.iface and self._ifaceRestarting then
if self._ifaceRestartCounter >= self.ifaceTimeout then
self:toggleIface(true)
self._ifaceRestarting = false
self._ifaceRestartCounter = 0
else
self._ifaceRestartCounter = self._ifaceRestartCounter + timeDiff
end
else
if currentStatus == 1 then
if not self._modemRestarted then
if self._disconnectedAtStartup and (self.attempts == 0 or self._attemptsCounter < self.attempts) then
if self._deadCounter >= self.deadPeriod then
self:restartMM()
self._modemRestarted = true
self._deadCounter = 0
else
self._deadCounter = self._deadCounter + timeDiff
end
end
elseif inetChecked and (self.attempts == 0 or self._attemptsCounter < self.attempts) then
self:restartMM()
end
else
self._attemptsCounter = 0
self._deadCounter = 0
self._disconnectedAtStartup = true
self._modemRestarted = false
end
self._ifaceRestartCounter = 0
end
end
function Module:onExit()
return true
end
return Module

View File

@@ -5,8 +5,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector
PKG_VERSION:=1.4.6
PKG_RELEASE:=2
PKG_VERSION:=1.5.0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
include $(INCLUDE_DIR)/package.mk
@@ -54,12 +54,14 @@ define Package/$(PKG_NAME)/install
$(INSTALL_BIN) ./files/usr/bin/internet-detector $(1)/usr/bin/internet-detector
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/main.lua $(1)/usr/lib/lua/internet-detector/main.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_led_control.lua $(1)/usr/lib/lua/internet-detector/mod_led_control.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_reboot.lua $(1)/usr/lib/lua/internet-detector/mod_reboot.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_network_restart.lua $(1)/usr/lib/lua/internet-detector/mod_network_restart.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_public_ip.lua $(1)/usr/lib/lua/internet-detector/mod_public_ip.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_user_scripts.lua $(1)/usr/lib/lua/internet-detector/mod_user_scripts.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/mod_regular_script.lua $(1)/usr/lib/lua/internet-detector/mod_regular_script.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/init.lua $(1)/usr/lib/lua/internet-detector/init.lua
$(INSTALL_DIR) $(1)/usr/lib/lua/internet-detector/modules
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_led_control.lua $(1)/usr/lib/lua/internet-detector/modules/mod_led_control.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_reboot.lua $(1)/usr/lib/lua/internet-detector/modules/mod_reboot.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_network_restart.lua $(1)/usr/lib/lua/internet-detector/modules/mod_network_restart.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_public_ip.lua $(1)/usr/lib/lua/internet-detector/modules/mod_public_ip.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua $(1)/usr/lib/lua/internet-detector/modules/mod_user_scripts.lua
$(INSTALL_DATA) ./files/usr/lib/lua/internet-detector/modules/mod_regular_script.lua $(1)/usr/lib/lua/internet-detector/modules/mod_regular_script.lua
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@@ -15,14 +15,19 @@ config instance 'internet'
option connection_timeout '2'
option mod_led_control_enabled '0'
option mod_reboot_enabled '0'
option mod_reboot_disconnected_at_startup '0'
option mod_reboot_dead_period '3600'
option mod_reboot_force_reboot_delay '300'
option mod_network_restart_enabled '0'
option mod_network_restart_disconnected_at_startup '0'
option mod_network_restart_dead_period '900'
option mod_network_restart_attempts '1'
option mod_network_restart_restart_timeout '0'
option mod_modem_restart_enabled '0'
option mod_modem_restart_disconnected_at_startup '0'
option mod_modem_restart_dead_period '600'
option mod_modem_restart_attempts '1'
option mod_modem_restart_iface_timeout '0'
option mod_modem_restart_any_band '0'
option mod_public_ip_enabled '0'
option mod_public_ip_provider 'opendns1'
@@ -33,12 +38,17 @@ config instance 'internet'
option mod_public_ip_timeout '2'
option mod_public_ip_enable_ip_script '0'
option mod_email_enabled '0'
option mod_email_message_at_startup '0'
option mod_email_mode '0'
option mod_email_alive_period '0'
option mod_email_mail_security 'tls'
option mod_user_scripts_enabled '0'
option mod_user_scripts_alive_period '0'
option mod_user_scripts_up_script_attempts '1'
option mod_user_scripts_connected_at_startup '0'
option mod_user_scripts_dead_period '0'
option mod_user_scripts_down_script_attempts '1'
option mod_user_scripts_disconnected_at_startup '0'
option mod_regular_script_enabled '0'
option mod_regular_script_inet_state '2'
option mod_regular_script_interval '3600'

View File

@@ -0,0 +1 @@
return require("internet-detector.main")

View File

@@ -45,7 +45,7 @@ local InternetDetector = {
}
InternetDetector.configDir = string.format("/etc/%s", InternetDetector.appName)
InternetDetector.modulesDir = string.format(
"%s/%s", InternetDetector.libDir, InternetDetector.appName)
"%s/%s/modules", InternetDetector.libDir, InternetDetector.appName)
-- Loading settings from UCI
@@ -175,9 +175,9 @@ function InternetDetector:loadModules()
if modConfig.enabled == 1 then
local m
if self.debug then
m = require(string.format("%s.%s", self.appName, modName))
m = require(string.format("%s.modules.%s", self.appName, modName))
else
m = self:prequire(string.format("%s.%s", self.appName, modName))
m = self:prequire(string.format("%s.modules.%s", self.appName, modName))
end
if m then
m.config = self
@@ -244,6 +244,7 @@ function InternetDetector:TCPConnectionToHost(host, port)
end
else
local family = saTable[1].family
if family then
local sock, errMsg, errNum = socket.socket(family, socket.SOCK_STREAM, 0)
@@ -351,7 +352,6 @@ function InternetDetector:mainLoop()
local interval = self.serviceConfig.interval_up
local modulesStatus = {}
local counter = 0
local onStart = true
local inetChecked = false
_RUNNING = true
while _RUNNING do
@@ -366,27 +366,27 @@ function InternetDetector:mainLoop()
self:writeLogMessage("err", "Unknown error while checking host!")
end
end
if onStart or not stat.stat(self.statusFile) then
if not stat.stat(self.statusFile) then
self:writeValueToFile(self.statusFile, self:statusJson(
currentStatus, self.serviceConfig.instance))
onStart = false
end
if currentStatus == 0 then
interval = self.serviceConfig.interval_up
if lastStatus ~= nil and currentStatus ~= lastStatus then
if currentStatus ~= lastStatus then
self:writeValueToFile(self.statusFile, self:statusJson(
currentStatus, self.serviceConfig.instance))
self:writeLogMessage("notice", "Connected")
end
else
interval = self.serviceConfig.interval_down
if lastStatus ~= nil and currentStatus ~= lastStatus then
if currentStatus ~= lastStatus then
self:writeValueToFile(self.statusFile, self:statusJson(
currentStatus, self.serviceConfig.instance))
self:writeLogMessage("notice", "Disconnected")
end
end
counter = 0
end
@@ -423,6 +423,7 @@ function InternetDetector:mainLoop()
end
lastStatus = currentStatus
unistd.sleep(1)
counter = counter + 1

View File

@@ -1,73 +0,0 @@
local unistd = require("posix.unistd")
local Module = {
name = "mod_user_scripts",
runPrio = 80,
config = {},
syslog = function(level, msg) return true end,
writeValue = function(filePath, str) return false end,
readValue = function(filePath) return nil end,
deadPeriod = 0,
alivePeriod = 0,
upScript = "",
downScript = "",
status = nil,
_deadCounter = 0,
_aliveCounter = 0,
_downScriptExecuted = true,
_upScriptExecuted = true,
}
function Module:runExternalScript(scriptPath)
if unistd.access(scriptPath, "r") then
os.execute(string.format('/bin/sh "%s" &', scriptPath))
end
end
function Module:init(t)
if t.dead_period ~= nil then
self.deadPeriod = tonumber(t.dead_period)
end
if t.alive_period ~= nil then
self.alivePeriod = tonumber(t.alive_period)
end
if self.config.configDir then
self.upScript = string.format(
"%s/up-script.%s", self.config.configDir, self.config.serviceConfig.instance)
self.downScript = string.format(
"%s/down-script.%s", self.config.configDir, self.config.serviceConfig.instance)
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
if currentStatus == 1 then
self._aliveCounter = 0
self._upScriptExecuted = false
if not self._downScriptExecuted then
if self._deadCounter >= self.deadPeriod then
self:runExternalScript(self.downScript)
self._downScriptExecuted = true
else
self._deadCounter = self._deadCounter + timeDiff
end
end
else
self._deadCounter = 0
self._downScriptExecuted = false
if not self._upScriptExecuted then
if self._aliveCounter >= self.alivePeriod then
self:runExternalScript(self.upScript)
self._upScriptExecuted = true
else
self._aliveCounter = self._aliveCounter + timeDiff
end
end
end
end
function Module:onExit()
return true
end
return Module

View File

@@ -2,24 +2,25 @@
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,
restartTimeout = 0,
status = nil,
_attemptsCounter = 0,
_deadCounter = 0,
_networkRestarted = false,
_ifaceRestarting = false,
_ifaceRestartCounter = 0,
_netIfaces = {},
_netDevices = {},
_netItemsNum = 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,
restartTimeout = 0,
status = nil,
_attemptsCounter = 0,
_deadCounter = 0,
_networkRestarted = false,
_ifaceRestarting = false,
_ifaceRestartCounter = 0,
_netIfaces = {},
_netDevices = {},
_netItemsNum = 0,
_disconnectedAtStartup = false,
}
function Module:toggleDevices(flag)
@@ -81,7 +82,9 @@ function Module:init(t)
if t.restart_timeout ~= nil then
self.restartTimeout = tonumber(t.restart_timeout)
end
self._attemptsCounter = self.attempts
if tonumber(t.disconnected_at_startup) == 1 then
self._disconnectedAtStartup = true
end
end
function Module:networkRestartFunc()
@@ -105,7 +108,9 @@ function Module:networkRestartFunc()
"%s: restarting network", self.name))
self:restartNetworkService()
end
self._attemptsCounter = self._attemptsCounter + 1
if self.attempts > 0 then
self._attemptsCounter = self._attemptsCounter + 1
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
@@ -120,7 +125,7 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
else
if currentStatus == 1 then
if not self._networkRestarted then
if self._attemptsCounter < self.attempts then
if self._disconnectedAtStartup and (self.attempts == 0 or self._attemptsCounter < self.attempts) then
if self._deadCounter >= self.deadPeriod then
self:networkRestartFunc()
self._networkRestarted = true
@@ -129,13 +134,14 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
self._deadCounter = self._deadCounter + timeDiff
end
end
elseif inetChecked and self._attemptsCounter < self.attempts then
elseif inetChecked and (self.attempts == 0 or self._attemptsCounter < self.attempts) then
self:networkRestartFunc()
end
else
self._attemptsCounter = 0
self._deadCounter = 0
self._networkRestarted = false
self._attemptsCounter = 0
self._deadCounter = 0
self._disconnectedAtStartup = true
self._networkRestarted = false
end
self._ifaceRestartCounter = 0
end

View File

@@ -34,6 +34,9 @@ function Module:init(t)
if t.force_reboot_delay ~= nil then
self.forceRebootDelay = tonumber(t.force_reboot_delay)
end
if tonumber(t.disconnected_at_startup) == 1 then
self._rebooted = false
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)

View File

@@ -0,0 +1,120 @@
local unistd = require("posix.unistd")
local Module = {
name = "mod_user_scripts",
runPrio = 80,
config = {},
syslog = function(level, msg) return true end,
writeValue = function(filePath, str) return false end,
readValue = function(filePath) return nil end,
deadPeriod = 0,
alivePeriod = 0,
upScript = "",
downScript = "",
upScriptAttempts = 1,
downScriptAttempts = 1,
status = nil,
_deadCounter = 0,
_aliveCounter = 0,
_upScriptAttemptsCounter = 0,
_downScriptAttemptsCounter = 0,
_upScriptExecuted = false,
_downScriptExecuted = false,
_disconnectedAtStartup = false,
_connectedAtStartup = false,
}
function Module:runExternalScript(scriptPath)
if unistd.access(scriptPath, "r") then
os.execute(string.format('/bin/sh "%s" &', scriptPath))
end
end
function Module:init(t)
if t.dead_period ~= nil then
self.deadPeriod = tonumber(t.dead_period)
end
if t.alive_period ~= nil then
self.alivePeriod = tonumber(t.alive_period)
end
if t.up_script_attempts ~= nil then
self.upScriptAttempts = tonumber(t.up_script_attempts)
end
if t.down_script_attempts ~= nil then
self.downScriptAttempts = tonumber(t.down_script_attempts)
end
if self.config.configDir then
self.upScript = string.format(
"%s/up-script.%s", self.config.configDir, self.config.serviceConfig.instance)
self.downScript = string.format(
"%s/down-script.%s", self.config.configDir, self.config.serviceConfig.instance)
end
if tonumber(t.connected_at_startup) == 1 then
self._connectedAtStartup = true
end
if tonumber(t.disconnected_at_startup) == 1 then
self._disconnectedAtStartup = true
end
end
function Module:runUpScriptFunc()
self:runExternalScript(self.upScript)
if self.upScriptAttempts > 0 then
self._upScriptAttemptsCounter = self._upScriptAttemptsCounter + 1
end
end
function Module:runDownScriptFunc()
self:runExternalScript(self.downScript)
if self.downScriptAttempts > 0 then
self._downScriptAttemptsCounter = self._downScriptAttemptsCounter + 1
end
end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
if currentStatus == 1 then
self._upScriptAttemptsCounter = 0
self._aliveCounter = 0
self._connectedAtStartup = true
self._upScriptExecuted = false
if not self._downScriptExecuted then
if self._disconnectedAtStartup and (self.downScriptAttempts == 0 or self._downScriptAttemptsCounter < self.downScriptAttempts) then
if self._deadCounter >= self.deadPeriod then
self:runDownScriptFunc()
self._downScriptExecuted = true
self._deadCounter = 0
else
self._deadCounter = self._deadCounter + timeDiff
end
end
elseif inetChecked and (self.downScriptAttempts == 0 or self._downScriptAttemptsCounter < self.downScriptAttempts) then
self:runDownScriptFunc()
end
elseif currentStatus == 0 then
self._downScriptAttemptsCounter = 0
self._deadCounter = 0
self._disconnectedAtStartup = true
self._downScriptExecuted = false
if not self._upScriptExecuted then
if self._connectedAtStartup and (self.upScriptAttempts == 0 or self._upScriptAttemptsCounter < self.upScriptAttempts) then
if self._aliveCounter >= self.alivePeriod then
self:runUpScriptFunc()
self._upScriptExecuted = true
self._aliveCounter = 0
else
self._aliveCounter = self._aliveCounter + timeDiff
end
end
elseif inetChecked and (self.upScriptAttempts == 0 or self._upScriptAttemptsCounter < self.upScriptAttempts) then
self:runUpScriptFunc()
end
end
end
function Module:onExit()
return true
end
return Module

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-internet-detector
PKG_VERSION:=1.4.6
PKG_VERSION:=1.5.0
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector

View File

@@ -867,6 +867,14 @@ return view.extend({
o.value(3600, '1 ' + _('hour'));
o.default = '300';
// disconnected_at_startup
o = s.taboption('reboot_device', form.Flag, 'mod_reboot_disconnected_at_startup',
_('On startup'),
_('Reboot device if the Internet is disconnected at service startup.')
);
o.rmempty = false;
o.modalonly = true;
// Restart network
o = s.taboption('restart_network', form.DummyValue, '_dummy');
@@ -891,6 +899,14 @@ return view.extend({
o.rmempty = false;
o.modalonly = true;
// ifaces
o = s.taboption('restart_network', widgets.DeviceSelect, 'mod_network_restart_ifaces',
_('Device'),
_('Network device or interface to restart. If not specified, then the network service is restarted.')
);
o.modalonly = true;
o.multiple = true;
// attempts
o = s.taboption('restart_network', form.ListValue,
'mod_network_restart_attempts', _('Restart attempts'),
@@ -902,16 +918,9 @@ return view.extend({
o.value(3);
o.value(4);
o.value(5);
o.value(0, _('infinitely'));
o.default = '1';
// ifaces
o = s.taboption('restart_network', widgets.DeviceSelect, 'mod_network_restart_ifaces',
_('Device'),
_('Network device or interface to restart. If not specified, then the network service is restarted.')
);
o.modalonly = true;
o.multiple = true;
// restart_timeout
o = s.taboption('restart_network', form.ListValue,
'mod_network_restart_restart_timeout', _('Restart timeout'),
@@ -931,15 +940,23 @@ return view.extend({
o.value(10, '10 ' + _('sec'));
o.default = '0';
// disconnected_at_startup
o = s.taboption('restart_network', form.Flag, 'mod_network_restart_disconnected_at_startup',
_('On startup'),
_('Restart network if the Internet is disconnected at service startup.')
);
o.rmempty = false;
o.modalonly = true;
// Restart modem
if(this.mm) {
if(this.mmInit) {
o = s.taboption('restart_modem', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Modem will be restarted when the Internet is disconnected.') +
'</div>';
o = s.taboption('restart_modem', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Modem will be restarted when the Internet is disconnected.') +
'</div>';
o.modalonly = true;
// enabled
@@ -966,6 +983,21 @@ return view.extend({
o.rmempty = false;
o.modalonly = true;
// attempts
o = s.taboption('restart_modem', form.ListValue,
'mod_modem_restart_attempts', _('Restart attempts'),
_('Maximum number of modem restart attempts before Internet access is available.')
);
o.modalonly = true;
o.value(1);
o.value(2);
o.value(3);
o.value(4);
o.value(5);
o.value(10);
o.value(0, _('infinitely'));
o.default = '1';
// iface
o = s.taboption('restart_modem', widgets.NetworkSelect, 'mod_modem_restart_iface',
_('Interface'),
@@ -974,6 +1006,33 @@ return view.extend({
o.multiple = false;
o.nocreate = true;
o.modalonly = true;
// iface_timeout
o = s.taboption('restart_modem', form.ListValue,
'mod_modem_restart_iface_timeout', _('Interface timeout'),
_('Timeout between stopping and starting a ModemManger interface.')
);
o.modalonly = true;
o.value(0, '0 ' + _('sec'));
o.value(1, '1 ' + _('sec'));
o.value(2, '2 ' + _('sec'));
o.value(3, '3 ' + _('sec'));
o.value(4, '4 ' + _('sec'));
o.value(5, '5 ' + _('sec'));
o.value(6, '6 ' + _('sec'));
o.value(7, '7 ' + _('sec'));
o.value(8, '8 ' + _('sec'));
o.value(9, '9 ' + _('sec'));
o.value(10, '10 ' + _('sec'));
o.default = '0';
// disconnected_at_startup
o = s.taboption('restart_modem', form.Flag, 'mod_modem_restart_disconnected_at_startup',
_('On startup'),
_('Restart modem if the Internet is disconnected at service startup.')
);
o.rmempty = false;
o.modalonly = true;
} else {
o = s.taboption('restart_modem', form.DummyValue, '_dummy');
o.rawhtml = true;
@@ -987,11 +1046,11 @@ return view.extend({
// Public IP address
o = s.taboption('public_ip', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Checking the real public IP address.') +
'</div>';
o = s.taboption('public_ip', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Checking the real public IP address.') +
'</div>';
o.modalonly = true;
// enabled
@@ -1193,6 +1252,14 @@ return view.extend({
o.value('ssl', 'SSL');
o.default = 'tls';
o.modalonly = true;
// message_at_startup
o = s.taboption('email', form.Flag, 'mod_email_message_at_startup',
_('On startup'),
_('Send message on service startup.')
);
o.rmempty = false;
o.modalonly = true;
} else {
o = s.taboption('email', form.DummyValue, '_dummy');
o.rawhtml = true;
@@ -1230,12 +1297,35 @@ return view.extend({
// alive_period
o = s.taboption('user_scripts', this.CBITimeInput,
'mod_user_scripts_alive_period', _('Alive period'),
_('Period of time after connecting to Internet before "up-script" runs.')
_('Period of time after connecting to Internet before up-script runs.')
);
o.default = '0';
o.rmempty = false;
o.modalonly = true;
// up_script_attempts
o = s.taboption('user_scripts', form.ListValue,
'mod_user_scripts_up_script_attempts', _('up-script attempts'),
_('Maximum number of up-script run attempts when connected to the Internet.')
);
o.modalonly = true;
o.value(1);
o.value(2);
o.value(3);
o.value(4);
o.value(5);
o.value(10);
o.value(0, _('infinitely'));
o.default = '1';
// connected_at_startup
o = s.taboption('user_scripts', form.Flag, 'mod_user_scripts_connected_at_startup',
_('On startup'),
_('Run up-script if the Internet is connected at service startup.')
);
o.rmempty = false;
o.modalonly = true;
// down_script edit
o = s.taboption('user_scripts', this.CBIBlockFileEdit, this,
'down_script',
@@ -1248,12 +1338,35 @@ return view.extend({
// dead_period
o = s.taboption('user_scripts', this.CBITimeInput,
'mod_user_scripts_dead_period', _('Dead period'),
_('Period of time after disconnecting from Internet before "down-script" runs.')
_('Period of time after disconnecting from Internet before down-script runs.')
);
o.default = '0';
o.rmempty = false;
o.modalonly = true;
// down_script_attempts
o = s.taboption('user_scripts', form.ListValue,
'mod_user_scripts_down_script_attempts', _('down-script attempts'),
_('Maximum number of down-script run attempts before Internet access is available.')
);
o.modalonly = true;
o.value(1);
o.value(2);
o.value(3);
o.value(4);
o.value(5);
o.value(10);
o.value(0, _('infinitely'));
o.default = '1';
// disconnected_at_startup
o = s.taboption('user_scripts', form.Flag, 'mod_user_scripts_disconnected_at_startup',
_('On startup'),
_('Run down-script if the Internet is disconnected at service startup.')
);
o.rmempty = false;
o.modalonly = true;
// Regular script
o = s.taboption('regular_script', form.DummyValue, '_dummy');

View File

@@ -201,6 +201,9 @@ msgstr "Размер данных ICMP-пакета"
msgid "Interface"
msgstr "Интерфейс"
msgid "Interface timeout"
msgstr "Таймаут интерфейса"
msgid "Internet"
msgstr "Интернет"
@@ -244,6 +247,17 @@ msgstr ""
"Максимальное количество попыток перезапуска сети до появления доступа в "
"Интренет."
msgid ""
"Maximum number of up-script run attempts when connected to the Internet."
msgstr ""
"Максимальное количество попыток запуска up-script при подключении к Интренет."
msgid ""
"Maximum number of down-script run attempts before Internet access is available."
msgstr ""
"Максимальное количество попыток запуска down-script до появления доступа в "
"Интренет."
msgid "Maximum timeout for waiting for a response from the host."
msgstr "Максимальный таймаут ожидания ответа от хоста."
@@ -294,6 +308,9 @@ msgstr "Выключить"
msgid "On"
msgstr "Включить"
msgid "On startup"
msgstr "При запуске"
msgid "One of the following:"
msgstr "Одно из следующих значений:"
@@ -304,18 +321,18 @@ msgid "Password for SMTP authentication."
msgstr "Пароль для SMTP-аутентификации."
msgid ""
"Period of time after connecting to Internet before \"up-script\" runs."
"Period of time after connecting to Internet before up-script runs."
msgstr ""
"Период времени после подключения к Интернет перед запуском \"up-script\"."
"Период времени после подключения к Интернет перед запуском up-script."
msgid ""
"Period of time after connecting to the Internet before sending a message."
msgstr "Период времени после подключения к Интернет перед отправкой сообщения."
msgid ""
"Period of time after disconnecting from Internet before \"down-script\" runs."
"Period of time after disconnecting from Internet before down-script runs."
msgstr ""
"Период времени после отключения от Интернет перед запуском \"down-script\"."
"Период времени после отключения от Интернет перед запуском down-script."
msgid ""
"Period of time after disconnecting from Internet before sending a message."
@@ -347,6 +364,9 @@ msgstr "Публичный IP адрес"
msgid "Reboot device"
msgstr "Перезагрузка устройства"
msgid "Reboot device if the Internet is disconnected at service startup."
msgstr "Перезагрузка устройства если Интренет отключен при запуске службы."
msgid "Recipient"
msgstr "Получатель"
@@ -359,9 +379,15 @@ msgstr "Попытки перезапуска"
msgid "Restart modem"
msgstr "Перезапуск модема"
msgid "Restart modem if the Internet is disconnected at service startup."
msgstr "Перезапуск модема если Интренет отключен при запуске службы."
msgid "Restart network"
msgstr "Перезапуск сети"
msgid "Restart network if the Internet is disconnected at service startup."
msgstr "Перезапуск сети если Интренет отключен при запуске службы."
msgid "Restart service"
msgstr "Перезапуск службы"
@@ -377,6 +403,12 @@ msgstr "Выполнять если статус Интернет"
msgid "Run service at startup"
msgstr "Запуск службы при старте"
msgid "Run down-script if the Internet is disconnected at service startup."
msgstr "Выполнить down-script если Интренет отключен при запуске службы."
msgid "Run up-script if the Internet is connected at service startup."
msgstr "Выполнить up-script если Интренет подключен при запуске службы."
msgid "Running"
msgstr "Выполняется"
@@ -395,6 +427,9 @@ msgstr "Сохранить"
msgid "Security"
msgstr "Безопасность"
msgid "Send message on service startup."
msgstr "Отправлять сообщение при запуске службы."
msgid "Sender"
msgstr "Отправитель"
@@ -464,6 +499,9 @@ msgstr "TLS: использовать STARTTLS если сервер подде
msgid "Timeout between stopping and starting a network device."
msgstr "Таймаут между остановкой и запуском сетевого устройства."
msgid "Timeout between stopping and starting a ModemManger interface."
msgstr "Таймаут между остановкой и запуском интерфейса ModemManger."
msgid "Type a time string"
msgstr "Введите строку времени"
@@ -537,6 +575,9 @@ msgstr "down-script"
msgid "hour"
msgstr "час"
msgid "infinitely"
msgstr "бесконечно"
msgid "hours"
msgstr "часы"
@@ -554,3 +595,9 @@ msgstr "секунды"
msgid "up-script"
msgstr "up-script"
msgid "down-script attempts"
msgstr "Попытки down-script"
msgid "up-script attempts"
msgstr "Попытки up-script"

View File

@@ -187,6 +187,9 @@ msgstr ""
msgid "Interface"
msgstr ""
msgid "Interface timeout"
msgstr ""
msgid "Internet"
msgstr ""
@@ -228,6 +231,14 @@ msgid ""
"available."
msgstr ""
msgid ""
"Maximum number of up-script run attempts when connected to the Internet."
msgstr ""
msgid ""
"Maximum number of down-script run attempts before Internet access is available."
msgstr ""
msgid "Maximum timeout for waiting for a response from the host."
msgstr ""
@@ -272,6 +283,9 @@ msgstr ""
msgid "On"
msgstr ""
msgid "On startup"
msgstr ""
msgid "One of the following:"
msgstr ""
@@ -282,7 +296,7 @@ msgid "Password for SMTP authentication."
msgstr ""
msgid ""
"Period of time after connecting to Internet before \"up-script\" runs."
"Period of time after connecting to Internet before up-script runs."
msgstr ""
msgid ""
@@ -290,7 +304,7 @@ msgid ""
msgstr ""
msgid ""
"Period of time after disconnecting from Internet before \"down-script\" runs."
"Period of time after disconnecting from Internet before down-script runs."
msgstr ""
msgid ""
@@ -322,6 +336,9 @@ msgstr ""
msgid "Reboot device"
msgstr ""
msgid "Reboot device if the Internet is disconnected at service startup."
msgstr ""
msgid "Recipient"
msgstr ""
@@ -334,9 +351,15 @@ msgstr ""
msgid "Restart modem"
msgstr ""
msgid "Restart modem if the Internet is disconnected at service startup."
msgstr ""
msgid "Restart network"
msgstr ""
msgid "Restart network if the Internet is disconnected at service startup."
msgstr ""
msgid "Restart service"
msgstr ""
@@ -352,6 +375,12 @@ msgstr ""
msgid "Run service at startup"
msgstr ""
msgid "Run down-script if the Internet is disconnected at service startup."
msgstr ""
msgid "Run up-script if the Internet is connected at service startup."
msgstr ""
msgid "Running"
msgstr ""
@@ -370,6 +399,9 @@ msgstr ""
msgid "Security"
msgstr ""
msgid "Send message on service startup."
msgstr ""
msgid "Sender"
msgstr ""
@@ -439,6 +471,9 @@ msgstr ""
msgid "Timeout between stopping and starting a network device."
msgstr ""
msgid "Timeout between stopping and starting a ModemManger interface."
msgstr ""
msgid "Type a time string"
msgstr ""
@@ -508,6 +543,9 @@ msgstr ""
msgid "hours"
msgstr ""
msgid "infinitely"
msgstr ""
msgid "min"
msgstr ""
@@ -522,3 +560,9 @@ msgstr ""
msgid "up-script"
msgstr ""
msgid "down-script attempts"
msgstr ""
msgid "up-script attempts"
msgstr ""

View File

@@ -16,7 +16,7 @@ end
local function init()
local lines = {}
if prequire(appName .. ".mod_modem_restart") then
if prequire(appName .. ".modules.mod_modem_restart") then
lines[#lines + 1] = '"mm_mod":true'
if (unistd.access(modemManagerInit, "x") and
os.execute(modemManagerInit .. " enabled") == 0) then
@@ -27,7 +27,7 @@ local function init()
else
lines[#lines + 1] = '"mm_mod":false'
end
if prequire(appName .. ".mod_email") then
if prequire(appName .. ".modules.mod_email") then
lines[#lines + 1] = '"email_mod":true'
if unistd.access(mailsendExec, "x") then
lines[#lines + 1] = '"email_exec":true'