v1.2. UI detector refactoring
19
README.md
@@ -19,15 +19,15 @@ Internet-detector is an application for checking the availability of the Interne
|
|||||||
**OpenWrt >= 21.02:**
|
**OpenWrt >= 21.02:**
|
||||||
|
|
||||||
opkg update
|
opkg update
|
||||||
wget --no-check-certificate -O /tmp/internet-detector_1.1-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.1-0_all.ipk
|
wget --no-check-certificate -O /tmp/internet-detector_1.2-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.2-0_all.ipk
|
||||||
opkg install /tmp/internet-detector_1.1-0_all.ipk
|
opkg install /tmp/internet-detector_1.2-0_all.ipk
|
||||||
rm /tmp/internet-detector_1.1-0_all.ipk
|
rm /tmp/internet-detector_1.2-0_all.ipk
|
||||||
/etc/init.d/internet-detector start
|
/etc/init.d/internet-detector start
|
||||||
/etc/init.d/internet-detector enable
|
/etc/init.d/internet-detector enable
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.1-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.1-0_all.ipk
|
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.2-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.2-0_all.ipk
|
||||||
opkg install /tmp/luci-app-internet-detector_1.1-0_all.ipk
|
opkg install /tmp/luci-app-internet-detector_1.2-0_all.ipk
|
||||||
rm /tmp/luci-app-internet-detector_1.1-0_all.ipk
|
rm /tmp/luci-app-internet-detector_1.2-0_all.ipk
|
||||||
/etc/init.d/rpcd restart
|
/etc/init.d/rpcd restart
|
||||||
|
|
||||||
Email notification:
|
Email notification:
|
||||||
@@ -36,9 +36,9 @@ Email notification:
|
|||||||
|
|
||||||
i18n-ru:
|
i18n-ru:
|
||||||
|
|
||||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.1-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.1-0_all.ipk
|
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.2-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.2-0_all.ipk
|
||||||
opkg install /tmp/luci-i18n-internet-detector-ru_1.1-0_all.ipk
|
opkg install /tmp/luci-i18n-internet-detector-ru_1.2-0_all.ipk
|
||||||
rm /tmp/luci-i18n-internet-detector-ru_1.1-0_all.ipk
|
rm /tmp/luci-i18n-internet-detector-ru_1.2-0_all.ipk
|
||||||
|
|
||||||
**[OpenWrt 19.07](https://github.com/gSpotx2f/luci-app-internet-detector/tree/19.07)**
|
**[OpenWrt 19.07](https://github.com/gSpotx2f/luci-app-internet-detector/tree/19.07)**
|
||||||
|
|
||||||
@@ -47,4 +47,3 @@ i18n-ru:
|
|||||||

|

|
||||||

|

|
||||||

|

|
||||||

|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#
|
#
|
||||||
# (с) 2023 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
# (с) 2024 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
||||||
#
|
#
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=internet-detector
|
PKG_NAME:=internet-detector
|
||||||
PKG_VERSION:=1.1
|
PKG_VERSION:=1.2
|
||||||
PKG_RELEASE:=0
|
PKG_RELEASE:=0
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,6 @@ config main 'config'
|
|||||||
option mode '1'
|
option mode '1'
|
||||||
option enable_logger '1'
|
option enable_logger '1'
|
||||||
|
|
||||||
config ui 'ui'
|
|
||||||
list hosts '8.8.8.8'
|
|
||||||
list hosts '1.1.1.1'
|
|
||||||
option check_type '0'
|
|
||||||
option tcp_port '53'
|
|
||||||
option interval_up '6'
|
|
||||||
option interval_down '1'
|
|
||||||
option connection_attempts '1'
|
|
||||||
option connection_timeout '1'
|
|
||||||
|
|
||||||
config instance 'internet'
|
config instance 'internet'
|
||||||
option enabled '1'
|
option enabled '1'
|
||||||
list hosts '8.8.8.8'
|
list hosts '8.8.8.8'
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
START=97
|
START=97
|
||||||
STOP=01
|
STOP=01
|
||||||
|
|
||||||
PROG=/usr/bin/internet-detector
|
PROG="/usr/bin/internet-detector"
|
||||||
|
|
||||||
config_app() {
|
run_instance() {
|
||||||
config_get enabled "$1" enabled "0"
|
config_get enabled "$1" enabled "0"
|
||||||
if [ $enabled = "1" ]; then
|
if [ $enabled = "1" ]; then
|
||||||
$PROG service "$1"
|
$PROG service "$1"
|
||||||
@@ -16,7 +16,7 @@ start() {
|
|||||||
config_load internet-detector
|
config_load internet-detector
|
||||||
config_get mode "config" mode "0"
|
config_get mode "config" mode "0"
|
||||||
if [ $mode = "1" ]; then
|
if [ $mode = "1" ]; then
|
||||||
config_foreach config_app "instance"
|
config_foreach run_instance "instance"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
luaposix
|
luaposix
|
||||||
libuci-lua
|
libuci-lua
|
||||||
|
|
||||||
(с) 2023 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
(с) 2024 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
-- Importing packages
|
-- Importing packages
|
||||||
@@ -26,15 +26,18 @@ local uci = require("uci")
|
|||||||
-- Default settings
|
-- Default settings
|
||||||
|
|
||||||
local InternetDetector = {
|
local InternetDetector = {
|
||||||
mode = 0,
|
mode = 0, -- 0: disabled, 1: Service, 2: UI detector
|
||||||
enableLogger = true,
|
enableLogger = true,
|
||||||
hostname = "OpenWrt",
|
hostname = "OpenWrt",
|
||||||
appName = "internet-detector",
|
appName = "internet-detector",
|
||||||
commonDir = "/tmp/run",
|
commonDir = "/tmp/run",
|
||||||
pingCmd = "/bin/ping",
|
pingCmd = "/bin/ping",
|
||||||
pingParams = "-c 1",
|
pingParams = "-c 1",
|
||||||
debug = false,
|
uiRunTime = 30,
|
||||||
serviceConfig = {
|
noModules = false,
|
||||||
|
uiAvailModules = { mod_public_ip = true },
|
||||||
|
debug = false,
|
||||||
|
serviceConfig = {
|
||||||
hosts = {
|
hosts = {
|
||||||
[1] = "8.8.8.8",
|
[1] = "8.8.8.8",
|
||||||
[2] = "1.1.1.1",
|
[2] = "1.1.1.1",
|
||||||
@@ -49,13 +52,15 @@ local InternetDetector = {
|
|||||||
iface = nil,
|
iface = nil,
|
||||||
instance = nil,
|
instance = nil,
|
||||||
},
|
},
|
||||||
modules = {},
|
modules = {},
|
||||||
parsedHosts = {},
|
parsedHosts = {},
|
||||||
|
uiCounter = 0,
|
||||||
}
|
}
|
||||||
InternetDetector.configDir = string.format("/etc/%s", InternetDetector.appName)
|
InternetDetector.configDir = string.format("/etc/%s", InternetDetector.appName)
|
||||||
InternetDetector.modulesDir = string.format("/usr/lib/%s", InternetDetector.appName)
|
InternetDetector.modulesDir = string.format("/usr/lib/%s", InternetDetector.appName)
|
||||||
|
|
||||||
-- Loading settings from UCI
|
-- Loading settings from UCI
|
||||||
|
|
||||||
local uciCursor = uci.cursor()
|
local uciCursor = uci.cursor()
|
||||||
InternetDetector.mode = tonumber(
|
InternetDetector.mode = tonumber(
|
||||||
uciCursor:get(InternetDetector.appName, "config", "mode"))
|
uciCursor:get(InternetDetector.appName, "config", "mode"))
|
||||||
@@ -161,22 +166,25 @@ function InternetDetector:loadModules()
|
|||||||
if ok then
|
if ok then
|
||||||
for item in modulesDir do
|
for item in modulesDir do
|
||||||
if item:match("^mod_") then
|
if item:match("^mod_") then
|
||||||
local modName = item:gsub("%.lua$", "")
|
local modName = item:gsub("%.lua$", "")
|
||||||
local modConfig = {}
|
if self.noModules and not self.uiAvailModules[modName] then
|
||||||
for k, v in pairs(self.serviceConfig) do
|
else
|
||||||
if k:match("^" .. modName) then
|
local modConfig = {}
|
||||||
modConfig[k:gsub("^" .. modName .. "_", "")] = v
|
for k, v in pairs(self.serviceConfig) do
|
||||||
|
if k:match("^" .. modName) then
|
||||||
|
modConfig[k:gsub("^" .. modName .. "_", "")] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
if modConfig.enabled == 1 then
|
||||||
if modConfig.enabled == 1 then
|
local m = self:prequire(modName)
|
||||||
local m = self:prequire(modName)
|
if m then
|
||||||
if m then
|
m.config = self
|
||||||
m.config = self
|
m.syslog = function(level, msg) self:writeLogMessage(level, msg) end
|
||||||
m.syslog = function(level, msg) self:writeLogMessage(level, msg) end
|
m.writeValue = function(filePath, str) return self:writeValueToFile(filePath, str) end
|
||||||
m.writeValue = function(filePath, str) return self:writeValueToFile(filePath, str) end
|
m.readValue = function(filePath) return self:readValueFromFile(filePath) end
|
||||||
m.readValue = function(filePath) return self:readValueFromFile(filePath) end
|
m:init(modConfig)
|
||||||
m:init(modConfig)
|
self.modules[#self.modules + 1] = m
|
||||||
self.modules[#self.modules + 1] = m
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -213,7 +221,6 @@ function InternetDetector:pingHost(host)
|
|||||||
)
|
)
|
||||||
local retCode = os.execute(ping)
|
local retCode = os.execute(ping)
|
||||||
|
|
||||||
-- Debug
|
|
||||||
if self.debug then
|
if self.debug then
|
||||||
io.stdout:write(string.format(
|
io.stdout:write(string.format(
|
||||||
"--- Ping ---\ntime = %s\n%s\nretCode = %s\n", os.time(), ping, retCode)
|
"--- Ping ---\ntime = %s\n%s\nretCode = %s\n", os.time(), ping, retCode)
|
||||||
@@ -329,15 +336,20 @@ function InternetDetector:breakMain(signo)
|
|||||||
RUNNING = false
|
RUNNING = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function InternetDetector:resetUiCounter(signo)
|
||||||
|
self.uiCounter = 0
|
||||||
|
end
|
||||||
|
|
||||||
function InternetDetector:main()
|
function InternetDetector:main()
|
||||||
signal.signal(signal.SIGTERM, function(signo) self:breakMain(signo) end)
|
signal.signal(signal.SIGTERM, function(signo) self:breakMain(signo) end)
|
||||||
signal.signal(signal.SIGINT, function(signo) self:breakMain(signo) end)
|
signal.signal(signal.SIGINT, function(signo) self:breakMain(signo) end)
|
||||||
signal.signal(signal.SIGQUIT, function(signo) self:breakMain(signo) end)
|
signal.signal(signal.SIGQUIT, function(signo) self:breakMain(signo) end)
|
||||||
|
signal.signal(signal.SIGUSR1, function(signo) self:resetUiCounter(signo) end)
|
||||||
|
|
||||||
local lastStatus, currentStatus, timeNow, timeDiff, lastTime
|
local lastStatus, currentStatus, mTimeNow, mTimeDiff, mLastTime, uiTimeNow, uiLastTime
|
||||||
local interval = self.serviceConfig.interval_up
|
local interval = self.serviceConfig.interval_up
|
||||||
local counter = 0
|
local counter = 0
|
||||||
local onStart = true
|
local onStart = true
|
||||||
RUNNING = true
|
RUNNING = true
|
||||||
while RUNNING do
|
while RUNNING do
|
||||||
if counter == 0 or counter >= interval then
|
if counter == 0 or counter >= interval then
|
||||||
@@ -367,16 +379,16 @@ function InternetDetector:main()
|
|||||||
counter = 0
|
counter = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
timeDiff = 0
|
mTimeDiff = 0
|
||||||
for _, e in ipairs(self.modules) do
|
for _, e in ipairs(self.modules) do
|
||||||
timeNow = time.clock_gettime(time.CLOCK_MONOTONIC).tv_sec
|
mTimeNow = time.clock_gettime(time.CLOCK_MONOTONIC).tv_sec
|
||||||
if lastTime then
|
if mLastTime then
|
||||||
timeDiff = timeDiff + timeNow - lastTime
|
mTimeDiff = mTimeDiff + mTimeNow - mLastTime
|
||||||
else
|
else
|
||||||
timeDiff = 1
|
mTimeDiff = 1
|
||||||
end
|
end
|
||||||
lastTime = timeNow
|
mLastTime = mTimeNow
|
||||||
e:run(currentStatus, lastStatus, timeDiff)
|
e:run(currentStatus, lastStatus, mTimeDiff)
|
||||||
end
|
end
|
||||||
|
|
||||||
local modulesStatus = {}
|
local modulesStatus = {}
|
||||||
@@ -392,7 +404,20 @@ function InternetDetector:main()
|
|||||||
|
|
||||||
lastStatus = currentStatus
|
lastStatus = currentStatus
|
||||||
unistd.sleep(1)
|
unistd.sleep(1)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
|
|
||||||
|
if self.mode == 2 then
|
||||||
|
uiTimeNow = time.clock_gettime(time.CLOCK_MONOTONIC).tv_sec
|
||||||
|
if uiLastTime then
|
||||||
|
self.uiCounter = self.uiCounter + uiTimeNow - uiLastTime
|
||||||
|
else
|
||||||
|
self.uiCounter = self.uiCounter + 1
|
||||||
|
end
|
||||||
|
uiLastTime = uiTimeNow
|
||||||
|
if self.uiCounter >= self.uiRunTime then
|
||||||
|
self:breakMain(signal.SIGTERM)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -490,13 +515,27 @@ function InternetDetector:stop()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function InternetDetector:setSIGUSR()
|
||||||
|
local appName = self.appName:gsub("-", "%%-")
|
||||||
|
local ok, commonDir = pcall(dirent.files, self.commonDir)
|
||||||
|
if ok then
|
||||||
|
for item in commonDir do
|
||||||
|
if item:match("^" .. appName .. ".-%.pid$") then
|
||||||
|
pidValue = self:readValueFromFile(string.format("%s/%s", self.commonDir, item))
|
||||||
|
if pidValue then
|
||||||
|
signal.kill(tonumber(pidValue), signal.SIGUSR1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function InternetDetector:preRun()
|
function InternetDetector:preRun()
|
||||||
-- Exit if internet-detector mode != 1(Service)
|
-- Exit if internet-detector mode != (1 or 2)
|
||||||
if self.mode ~= 1 then
|
if self.mode ~= 1 and self.mode ~= 2 then
|
||||||
io.stderr:write(string.format('Start failed, mode != 1\n', self.appName))
|
io.stderr:write(string.format('Start failed, mode != (1 or 2)\n', self.appName))
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end
|
end
|
||||||
if stat.stat(self.pidFile) then
|
if stat.stat(self.pidFile) then
|
||||||
@@ -528,7 +567,6 @@ function InternetDetector:run()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debug
|
|
||||||
if self.debug then
|
if self.debug then
|
||||||
local function inspectTable()
|
local function inspectTable()
|
||||||
local tables = {}, f
|
local tables = {}, f
|
||||||
@@ -597,6 +635,10 @@ end
|
|||||||
function InternetDetector:setServiceConfig(instance)
|
function InternetDetector:setServiceConfig(instance)
|
||||||
if self:loadUCIConfig("instance", instance) then
|
if self:loadUCIConfig("instance", instance) then
|
||||||
self:parseHosts()
|
self:parseHosts()
|
||||||
|
if self.mode == 2 then
|
||||||
|
self.enableLogger = false
|
||||||
|
self.noModules = true
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -605,12 +647,12 @@ end
|
|||||||
|
|
||||||
local function help()
|
local function help()
|
||||||
return string.format(
|
return string.format(
|
||||||
"Usage: %s service <UCI instance> | nodaemon <UCI instance> | debug <UCI instance> | stop | status | inet-status | poll [<attempts num>] [<timeout sec>] | --help",
|
"Usage: %s service <UCI instance> | nodaemon <UCI instance> | debug <UCI instance> | stop | status | inet-status | uipoll | --help",
|
||||||
arg[0]
|
arg[0]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local helpArgs = { ["-h"] = true, ["--help"] = true, ["help"] = true }
|
local helpArgs = { ["-h"] = true, ["--help"] = true, help = true }
|
||||||
if arg[1] == "service" then
|
if arg[1] == "service" then
|
||||||
if arg[2] then
|
if arg[2] then
|
||||||
if InternetDetector:setServiceConfig(arg[2]) then
|
if InternetDetector:setServiceConfig(arg[2]) then
|
||||||
@@ -651,20 +693,12 @@ elseif arg[1] == "status" then
|
|||||||
print(InternetDetector:status())
|
print(InternetDetector:status())
|
||||||
elseif arg[1] == "inet-status" then
|
elseif arg[1] == "inet-status" then
|
||||||
print(InternetDetector:inetStatus())
|
print(InternetDetector:inetStatus())
|
||||||
elseif arg[1] == "poll" then
|
elseif arg[1] == "uipoll" then
|
||||||
if InternetDetector:loadUCIConfig("ui", "ui") then
|
if InternetDetector:status() == "stoped" then
|
||||||
InternetDetector:parseHosts()
|
|
||||||
|
|
||||||
if arg[2] and arg[2]:match("[0-9]+") then
|
|
||||||
InternetDetector.serviceConfig.connection_attempts = tonumber(arg[2])
|
|
||||||
if arg[3] and arg[3]:match("[0-9]+") then
|
|
||||||
InternetDetector.serviceConfig.connection_timeout = tonumber(arg[3])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print(InternetDetector:poll())
|
|
||||||
else
|
|
||||||
os.exit(126)
|
os.exit(126)
|
||||||
|
else
|
||||||
|
InternetDetector:setSIGUSR()
|
||||||
|
print(InternetDetector:inetStatus())
|
||||||
end
|
end
|
||||||
elseif helpArgs[arg[1]] then
|
elseif helpArgs[arg[1]] then
|
||||||
print(help())
|
print(help())
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ local Module = {
|
|||||||
runInterval = 5,
|
runInterval = 5,
|
||||||
sysLedsDir = "/sys/class/leds",
|
sysLedsDir = "/sys/class/leds",
|
||||||
ledName = nil,
|
ledName = nil,
|
||||||
ledAction1 = 2,
|
ledAction1 = 2, -- 1: off, 2: on, 3: blink
|
||||||
ledAction2 = 1,
|
ledAction2 = 1, -- 1: off, 2: on, 3: blink
|
||||||
status = nil,
|
status = nil,
|
||||||
_enabled = false,
|
_enabled = false,
|
||||||
_ledDir = nil,
|
_ledDir = nil,
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ local Module = {
|
|||||||
name = "mod_public_ip",
|
name = "mod_public_ip",
|
||||||
runPrio = 50,
|
runPrio = 50,
|
||||||
config = {
|
config = {
|
||||||
debug = false,
|
noModules = false,
|
||||||
|
debug = false,
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
iface = nil,
|
iface = nil,
|
||||||
},
|
},
|
||||||
@@ -65,7 +66,7 @@ local Module = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Module:runIpScript()
|
function Module:runIpScript()
|
||||||
if self.enableIpScript and unistd.access(self.ipScript, "r") then
|
if not self.config.noModules and self.enableIpScript and unistd.access(self.ipScript, "r") then
|
||||||
stdlib.setenv("PUBLIC_IP", self.status)
|
stdlib.setenv("PUBLIC_IP", self.status)
|
||||||
os.execute(string.format('/bin/sh "%s" &', self.ipScript))
|
os.execute(string.format('/bin/sh "%s" &', self.ipScript))
|
||||||
end
|
end
|
||||||
@@ -247,8 +248,8 @@ function Module:decodeMessage(message)
|
|||||||
|
|
||||||
local questionSectionStarts = 25
|
local questionSectionStarts = 25
|
||||||
local questionParts = self:parseParts(message, questionSectionStarts, {})
|
local questionParts = self:parseParts(message, questionSectionStarts, {})
|
||||||
local qtypeStarts = questionSectionStarts + (#table.concat(questionParts)) + (#questionParts * 2) + 1
|
local qtypeStarts = questionSectionStarts + (#table.concat(questionParts)) + (#questionParts * 2) + 1
|
||||||
local qclassStarts = qtypeStarts + 4
|
local qclassStarts = qtypeStarts + 4
|
||||||
|
|
||||||
local answerSectionStarts = qclassStarts + 4
|
local answerSectionStarts = qclassStarts + 4
|
||||||
local numAnswers = math.max(
|
local numAnswers = math.max(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#
|
#
|
||||||
# (с) 2023 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
# (с) 2024 gSpot (https://github.com/gSpotx2f/luci-app-internet-detector)
|
||||||
#
|
#
|
||||||
|
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_VERSION:=1.1-0
|
PKG_VERSION:=1.2-0
|
||||||
LUCI_TITLE:=LuCI support for internet-detector
|
LUCI_TITLE:=LuCI support for internet-detector
|
||||||
LUCI_DEPENDS:=+internet-detector
|
LUCI_DEPENDS:=+internet-detector
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
'require baseclass';
|
'require baseclass';
|
||||||
'require fs';
|
'require fs';
|
||||||
|
'require rpc';
|
||||||
'require uci';
|
'require uci';
|
||||||
|
|
||||||
document.head.append(E('style', {'type': 'text/css'},
|
document.head.append(E('style', {'type': 'text/css'},
|
||||||
@@ -57,14 +58,22 @@ return baseclass.extend({
|
|||||||
title : _('Internet'),
|
title : _('Internet'),
|
||||||
appName : 'internet-detector',
|
appName : 'internet-detector',
|
||||||
execPath : '/usr/bin/internet-detector',
|
execPath : '/usr/bin/internet-detector',
|
||||||
uiCheckIntervalUp : null,
|
|
||||||
uiCheckIntervalDown : null,
|
|
||||||
currentAppMode : null,
|
currentAppMode : null,
|
||||||
inetStatus : null,
|
inetStatus : null,
|
||||||
uiState : null,
|
|
||||||
counter : 0,
|
|
||||||
|
|
||||||
inetStatusFromJson : function(res) {
|
callUIPoll: rpc.declare({
|
||||||
|
object: 'luci.internet-detector',
|
||||||
|
method: 'UIPoll',
|
||||||
|
expect: { '': {} }
|
||||||
|
}),
|
||||||
|
|
||||||
|
getUIPoll() {
|
||||||
|
return this.callUIPoll().then(data => {
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
inetStatusFromJson(res) {
|
||||||
let inetStatData = null;
|
let inetStatData = null;
|
||||||
if(res.code === 0) {
|
if(res.code === 0) {
|
||||||
try {
|
try {
|
||||||
@@ -74,50 +83,38 @@ return baseclass.extend({
|
|||||||
return inetStatData;
|
return inetStatData;
|
||||||
},
|
},
|
||||||
|
|
||||||
load: async function() {
|
async load() {
|
||||||
if(!(this.uiCheckIntervalUp && this.uiCheckIntervalDown && this.currentAppMode)) {
|
if(!this.currentAppMode) {
|
||||||
await uci.load(this.appName).then(data => {
|
await uci.load(this.appName).then(data => {
|
||||||
this.uiCheckIntervalUp = Number(uci.get(this.appName, 'ui', 'interval_up'));
|
this.currentAppMode = uci.get(this.appName, 'config', 'mode');
|
||||||
this.uiCheckIntervalDown = Number(uci.get(this.appName, 'ui', 'interval_down'));
|
|
||||||
this.currentAppMode = uci.get(this.appName, 'config', 'mode');
|
|
||||||
}).catch(e => {});
|
}).catch(e => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
if(this.currentAppMode === '2') {
|
if(this.currentAppMode === '2') {
|
||||||
this.counter++;
|
return this.getUIPoll();
|
||||||
|
|
||||||
if((this.uiState === 0 && this.counter % this.uiCheckIntervalUp) ||
|
|
||||||
(this.uiState === 1 && this.counter % this.uiCheckIntervalDown)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.counter = 0;
|
|
||||||
return L.resolveDefault(fs.exec(this.execPath, [ 'poll' ]), null);
|
|
||||||
}
|
}
|
||||||
else if(this.currentAppMode === '1') {
|
else if(this.currentAppMode === '1') {
|
||||||
return L.resolveDefault(fs.exec(this.execPath, [ 'inet-status' ]), null);
|
return L.resolveDefault(fs.exec(this.execPath, [ 'inet-status' ]), null);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(data) {
|
render(data) {
|
||||||
if(this.currentAppMode === '0') {
|
if(this.currentAppMode === '0') {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
else if(this.currentAppMode === '1' && data) {
|
||||||
|
data = this.inetStatusFromJson(data);
|
||||||
};
|
};
|
||||||
|
this.inetStatus = data;
|
||||||
if(data) {
|
|
||||||
this.inetStatus = this.inetStatusFromJson(data);
|
|
||||||
if(this.currentAppMode === '2') {
|
|
||||||
this.uiState = this.inetStatus.instances[0].inet;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
let inetStatusArea = E('div', {});
|
let inetStatusArea = E('div', {});
|
||||||
|
|
||||||
if(!this.inetStatus || !this.inetStatus.instances || this.inetStatus.instances.length === 0) {
|
if(!this.inetStatus || !this.inetStatus.instances || this.inetStatus.instances.length === 0) {
|
||||||
inetStatusArea.append(
|
let label = E('span', { 'class': 'id-label-status id-undefined' }, _('Undefined'));
|
||||||
E('span', { 'class': 'id-label-status id-undefined' }, _('Undefined'))
|
if(this.currentAppMode === '2') {
|
||||||
);
|
label.classList.add('spinning');
|
||||||
|
};
|
||||||
|
inetStatusArea.append(label);
|
||||||
} else {
|
} else {
|
||||||
this.inetStatus.instances.sort((a, b) => a.num > b.num);
|
this.inetStatus.instances.sort((a, b) => a.num > b.num);
|
||||||
|
|
||||||
@@ -139,8 +136,7 @@ return baseclass.extend({
|
|||||||
|
|
||||||
inetStatusArea.append(
|
inetStatusArea.append(
|
||||||
E('span', { 'class': className }, '%s%s%s'.format(
|
E('span', { 'class': className }, '%s%s%s'.format(
|
||||||
(this.currentAppMode === '1') ? i.instance + ': ' : '',
|
i.instance + ': ', status, publicIp)
|
||||||
status, publicIp)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -434,9 +434,6 @@ msgstr "Таймаут между остановкой и запуском ин
|
|||||||
msgid "Type a time string"
|
msgid "Type a time string"
|
||||||
msgstr "Введите строку времени"
|
msgstr "Введите строку времени"
|
||||||
|
|
||||||
msgid "UI detector configuration"
|
|
||||||
msgstr "Конфигурация UI детектора"
|
|
||||||
|
|
||||||
msgid "Unable to read the contents"
|
msgid "Unable to read the contents"
|
||||||
msgstr "Невозможно прочитать содержимое"
|
msgstr "Невозможно прочитать содержимое"
|
||||||
|
|
||||||
|
|||||||
@@ -404,9 +404,6 @@ msgstr ""
|
|||||||
msgid "Type a time string"
|
msgid "Type a time string"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "UI detector configuration"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgid "Unable to read the contents"
|
msgid "Unable to read the contents"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
46
luci-app-internet-detector/root/usr/libexec/rpcd/luci.internet-detector
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
|
readonly ID_EXEC="/usr/bin/internet-detector"
|
||||||
|
|
||||||
|
run_instance() {
|
||||||
|
config_get enabled "$1" enabled "0"
|
||||||
|
if [ $enabled = "1" ]; then
|
||||||
|
$ID_EXEC service "$1" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
start_ui_instances() {
|
||||||
|
config_load internet-detector
|
||||||
|
config_get mode "config" mode "0"
|
||||||
|
if [ $mode = "2" ]; then
|
||||||
|
config_foreach run_instance "instance"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_poll() {
|
||||||
|
$ID_EXEC uipoll
|
||||||
|
if [ $? -eq 126 ]; then
|
||||||
|
start_ui_instances
|
||||||
|
$ID_EXEC inet-status
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
list)
|
||||||
|
json_init
|
||||||
|
json_add_object "UIPoll"
|
||||||
|
json_close_object
|
||||||
|
json_dump
|
||||||
|
json_cleanup
|
||||||
|
;;
|
||||||
|
call)
|
||||||
|
case "$2" in
|
||||||
|
UIPoll)
|
||||||
|
ui_poll
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -12,7 +12,8 @@
|
|||||||
},
|
},
|
||||||
"uci": [ "internet-detector" ],
|
"uci": [ "internet-detector" ],
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"luci": [ "getInitList", "setInitAction" ]
|
"luci": [ "getInitList", "setInitAction" ],
|
||||||
|
"luci.internet-detector": [ "UIPoll" ]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"write": {
|
"write": {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 137 KiB |
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 44 KiB |