mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2026-01-02 22:58:56 +03:00
v1.4. New module: mod_regular_script
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=internet-detector
|
||||
PKG_VERSION:=1.3.3
|
||||
PKG_VERSION:=1.4.0
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
@@ -31,6 +31,7 @@ define Package/$(PKG_NAME)/conffiles
|
||||
/etc/internet-detector/down-script.internet
|
||||
/etc/internet-detector/up-script.internet
|
||||
/etc/internet-detector/public-ip-script.internet
|
||||
/etc/internet-detector/regular-script.internet
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
@@ -46,6 +47,7 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DATA) ./files/etc/internet-detector/down-script.internet $(1)/etc/internet-detector/down-script.internet
|
||||
$(INSTALL_DATA) ./files/etc/internet-detector/up-script.internet $(1)/etc/internet-detector/up-script.internet
|
||||
$(INSTALL_DATA) ./files/etc/internet-detector/public-ip-script.internet $(1)/etc/internet-detector/public-ip-script.internet
|
||||
$(INSTALL_DATA) ./files/etc/internet-detector/regular-script.internet $(1)/etc/internet-detector/regular-script.internet
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/etc/init.d/internet-detector $(1)/etc/init.d/internet-detector
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
@@ -57,6 +59,7 @@ define Package/$(PKG_NAME)/install
|
||||
$(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
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
|
||||
@@ -36,3 +36,6 @@ config instance 'internet'
|
||||
option mod_user_scripts_enabled '0'
|
||||
option mod_user_scripts_alive_period '0'
|
||||
option mod_user_scripts_dead_period '0'
|
||||
option mod_regular_script_enabled '0'
|
||||
option mod_regular_script_inet_state '2'
|
||||
option mod_regular_script_interval '3600'
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# Shell commands that are run regularly
|
||||
@@ -390,7 +390,7 @@ function InternetDetector:mainLoop()
|
||||
mTimeDiff = 1
|
||||
end
|
||||
mLastTime = mTimeNow
|
||||
e:run(currentStatus, lastStatus, mTimeDiff)
|
||||
e:run(currentStatus, lastStatus, mTimeDiff, mTimeNow)
|
||||
end
|
||||
|
||||
local modulesStatus = {}
|
||||
|
||||
@@ -100,7 +100,7 @@ function Module:getCurrentState()
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
|
||||
if not self._enabled then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -76,7 +76,7 @@ function Module:init(t)
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
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
|
||||
|
||||
@@ -359,7 +359,7 @@ function Module:init(t)
|
||||
self._enabled = true
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
|
||||
if not self._enabled then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ function Module:init(t)
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
|
||||
if currentStatus == 1 then
|
||||
if self._deadCounter >= self.deadPeriod then
|
||||
self:rebootDevice()
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
local stdlib = require("posix.stdlib")
|
||||
local unistd = require("posix.unistd")
|
||||
|
||||
local Module = {
|
||||
name = "mod_regular_script",
|
||||
runPrio = 90,
|
||||
config = {},
|
||||
syslog = function(level, 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
|
||||
interval = 3600,
|
||||
script = "",
|
||||
status = nil,
|
||||
_nextTime = nil,
|
||||
}
|
||||
|
||||
function Module:runExternalScript(scriptPath, currentStatus)
|
||||
if unistd.access(scriptPath, "r") then
|
||||
stdlib.setenv("INET_STATE", currentStatus)
|
||||
os.execute(string.format('/bin/sh "%s" &', scriptPath))
|
||||
end
|
||||
end
|
||||
|
||||
function Module:init(t)
|
||||
if t.inet_state ~= nil then
|
||||
self.inetState = tonumber(t.inet_state)
|
||||
end
|
||||
if t.interval ~= nil then
|
||||
self.interval = tonumber(t.interval)
|
||||
end
|
||||
if self.config.configDir then
|
||||
self.script = string.format(
|
||||
"%s/regular-script.%s", self.config.configDir, self.config.serviceConfig.instance)
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
|
||||
if not self._nextTime then
|
||||
if timeNow < self.interval then
|
||||
self._nextTime = self.interval
|
||||
else
|
||||
self._nextTime = timeNow - (timeNow % self.interval) + self.interval
|
||||
end
|
||||
end
|
||||
if timeNow >= self._nextTime then
|
||||
if self.inetState == 2 or (self.inetState == 0 and currentStatus == 0) or (self.inetState == 1 and currentStatus == 1) then
|
||||
self:runExternalScript(self.script, currentStatus)
|
||||
end
|
||||
self._nextTime = self._nextTime + self.interval
|
||||
end
|
||||
end
|
||||
|
||||
return Module
|
||||
@@ -40,7 +40,7 @@ function Module:init(t)
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
function Module:run(currentStatus, lastStatus, timeDiff, timeNow)
|
||||
if currentStatus == 1 then
|
||||
self._aliveCounter = 0
|
||||
self._downScriptExecuted = false
|
||||
|
||||
Reference in New Issue
Block a user