mirror of
https://github.com/gSpotx2f/luci-app-internet-detector.git
synced 2025-12-09 21:17:00 +03:00
Compare commits
4 Commits
v0.6(depre
...
19.07
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f6a0fa1cc | ||
|
|
e8a3430571 | ||
|
|
a02e46cd19 | ||
|
|
dffaa94720 |
27
README.md
27
README.md
@@ -16,18 +16,17 @@ Internet-detector is an application for checking the availability of the Interne
|
||||
|
||||
## Installation notes
|
||||
|
||||
**OpenWrt >= 21.02:**
|
||||
**OpenWrt 19.07:**
|
||||
|
||||
opkg update
|
||||
wget --no-check-certificate -O /tmp/internet-detector_0.6-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_0.6-0_all.ipk
|
||||
opkg install /tmp/internet-detector_0.6-0_all.ipk
|
||||
rm /tmp/internet-detector_0.6-0_all.ipk
|
||||
wget --no-check-certificate -O /tmp/internet-detector_0.5-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/internet-detector_0.5-0_all.ipk
|
||||
opkg install /tmp/internet-detector_0.5-0_all.ipk
|
||||
rm /tmp/internet-detector_0.5-0_all.ipk
|
||||
/etc/init.d/internet-detector start
|
||||
/etc/init.d/internet-detector enable
|
||||
|
||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.6-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_0.6-1_all.ipk
|
||||
opkg install /tmp/luci-app-internet-detector_0.6-1_all.ipk
|
||||
rm /tmp/luci-app-internet-detector_0.6-1_all.ipk
|
||||
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.5-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-app-internet-detector_0.5-1_all.ipk
|
||||
opkg install /tmp/luci-app-internet-detector_0.5-1_all.ipk
|
||||
rm /tmp/luci-app-internet-detector_0.5-1_all.ipk
|
||||
/etc/init.d/rpcd restart
|
||||
|
||||
Email notification:
|
||||
@@ -36,13 +35,11 @@ Email notification:
|
||||
|
||||
i18n-ru:
|
||||
|
||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.6-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_0.6-1_all.ipk
|
||||
opkg install /tmp/luci-i18n-internet-detector-ru_0.6-1_all.ipk
|
||||
rm /tmp/luci-i18n-internet-detector-ru_0.6-1_all.ipk
|
||||
|
||||
**[OpenWrt 19.07](https://github.com/gSpotx2f/luci-app-internet-detector/tree/19.07)**
|
||||
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-i18n-internet-detector-ru_0.5-1_all.ipk
|
||||
opkg install /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk
|
||||
rm /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk
|
||||
|
||||
## Screenshots:
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=internet-detector
|
||||
PKG_VERSION:=0.6
|
||||
PKG_VERSION:=0.5
|
||||
PKG_RELEASE:=0
|
||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
|
||||
|
||||
@@ -48,7 +48,6 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_BIN) ./files/usr/bin/internet-detector $(1)/usr/bin/internet-detector
|
||||
$(INSTALL_DIR) $(1)/usr/lib/internet-detector
|
||||
$(INSTALL_DATA) ./files/usr/lib/internet-detector/mod_email.lua $(1)/usr/lib/internet-detector/mod_email.lua
|
||||
$(INSTALL_DATA) ./files/usr/lib/internet-detector/mod_public_ip.lua $(1)/usr/lib/internet-detector/mod_public_ip.lua
|
||||
$(INSTALL_DATA) ./files/usr/lib/internet-detector/mod_led_control.lua $(1)/usr/lib/internet-detector/mod_led_control.lua
|
||||
$(INSTALL_DATA) ./files/usr/lib/internet-detector/mod_modem_restart.lua $(1)/usr/lib/internet-detector/mod_modem_restart.lua
|
||||
$(INSTALL_DATA) ./files/usr/lib/internet-detector/mod_network_restart.lua $(1)/usr/lib/internet-detector/mod_network_restart.lua
|
||||
|
||||
@@ -33,12 +33,6 @@ config module 'mod_modem_restart'
|
||||
option dead_period '600'
|
||||
option any_band '0'
|
||||
|
||||
config module 'mod_public_ip'
|
||||
option enabled '0'
|
||||
option provider 'opendns1'
|
||||
option interval '600'
|
||||
option timeout '3'
|
||||
|
||||
config module 'mod_email'
|
||||
option enabled '0'
|
||||
option alive_period '0'
|
||||
|
||||
@@ -132,16 +132,6 @@ local function readValueFromFile(filePath)
|
||||
return retValue
|
||||
end
|
||||
|
||||
local function statusJson(inet, t)
|
||||
local lines = { [1] = string.format('"inet":%d', inet) }
|
||||
if t then
|
||||
for k, v in pairs(t) do
|
||||
lines[#lines + 1] = string.format('"%s":"%s"', k, v)
|
||||
end
|
||||
end
|
||||
return "{" .. table.concat(lines, ",") .. "}"
|
||||
end
|
||||
|
||||
local function writeLogMessage(level, msg)
|
||||
if Config.enableLogger then
|
||||
nixio.syslog(level, msg)
|
||||
@@ -213,7 +203,7 @@ local function TCPConnectionToHost(host, port)
|
||||
if addrInfo then
|
||||
local family = addrInfo[1].family
|
||||
if family then
|
||||
local socket = nixio.socket(family, "stream")
|
||||
local socket = nixio.socket(family, "stream")
|
||||
socket:setopt("socket", "sndtimeo", Config.connectionTimeout)
|
||||
socket:setopt("socket", "rcvtimeo", Config.connectionTimeout)
|
||||
if Config.iface then
|
||||
@@ -274,22 +264,23 @@ local function main()
|
||||
if counter == 0 or counter >= interval then
|
||||
currentStatus = checkHosts()
|
||||
if not nixio.fs.access(Config.statusFile, "r") then
|
||||
writeValueToFile(Config.statusFile, statusJson(currentStatus))
|
||||
writeValueToFile(Config.statusFile, currentStatus)
|
||||
end
|
||||
|
||||
if currentStatus == 0 then
|
||||
interval = Config.intervalUp
|
||||
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
||||
writeValueToFile(Config.statusFile, statusJson(currentStatus))
|
||||
writeValueToFile(Config.statusFile, currentStatus)
|
||||
writeLogMessage("notice", "Internet connected")
|
||||
end
|
||||
else
|
||||
interval = Config.intervalDown
|
||||
if lastStatus ~= nil and currentStatus ~= lastStatus then
|
||||
writeValueToFile(Config.statusFile, statusJson(currentStatus))
|
||||
writeValueToFile(Config.statusFile, currentStatus)
|
||||
writeLogMessage("notice", "Internet disconnected")
|
||||
end
|
||||
end
|
||||
|
||||
counter = 0
|
||||
end
|
||||
|
||||
@@ -304,17 +295,6 @@ local function main()
|
||||
lastTime = timeNow
|
||||
e:run(currentStatus, lastStatus, timeDiff)
|
||||
end
|
||||
|
||||
local modulesStatus = {}
|
||||
for k, v in ipairs(Config.modules) do
|
||||
if v.status ~= nil then
|
||||
modulesStatus[v.name] = v.status
|
||||
end
|
||||
end
|
||||
if next(modulesStatus) then
|
||||
writeValueToFile(Config.statusFile, statusJson(currentStatus, modulesStatus))
|
||||
end
|
||||
|
||||
lastStatus = currentStatus
|
||||
nixio.nanosleep(1)
|
||||
counter = counter + 1
|
||||
@@ -346,29 +326,24 @@ local function poll(attempts, timeout)
|
||||
Config.connectionTimeout = timeout
|
||||
end
|
||||
if checkHosts() == 0 then
|
||||
return statusJson(0)
|
||||
return "up"
|
||||
else
|
||||
return statusJson(1)
|
||||
return "down"
|
||||
end
|
||||
end
|
||||
|
||||
local function inetStatus(json)
|
||||
local inetStat = 1
|
||||
local function inetStatus()
|
||||
local inetStat = "down"
|
||||
if nixio.fs.access(Config.statusFile, "r") then
|
||||
local inetStatVal = readValueFromFile(Config.statusFile)
|
||||
inetStat = inetStatVal
|
||||
if inetStatVal ~= nil and tonumber(inetStatVal) == 0 then
|
||||
inetStat = "up"
|
||||
end
|
||||
elseif Config.mode == 1 then
|
||||
inetStat = poll()
|
||||
else
|
||||
os.exit(126)
|
||||
end
|
||||
if not json then
|
||||
local sVal = inetStat:match('"inet":[0-9]')
|
||||
if sVal then
|
||||
sVal = sVal:match("[0-9]")
|
||||
inetStat = (tonumber(sVal) == 0) and "up" or "down"
|
||||
end
|
||||
end
|
||||
return inetStat
|
||||
end
|
||||
|
||||
@@ -514,7 +489,7 @@ parseHosts()
|
||||
|
||||
local function help()
|
||||
return string.format(
|
||||
"Usage: %s [start|stop|restart|no-daemon|debug|status|inet-status|inet-status-json|poll [<attempts num>] [<timeout sec>]|--help]",
|
||||
"Usage: %s [start|stop|restart|no-daemon|debug|status|inet-status|poll [<attempts num>] [<timeout sec>]|--help]",
|
||||
arg[0]
|
||||
)
|
||||
end
|
||||
@@ -534,8 +509,6 @@ elseif arg[1] == "status" then
|
||||
print(status())
|
||||
elseif arg[1] == "inet-status" then
|
||||
print(inetStatus())
|
||||
elseif arg[1] == "inet-status-json" then
|
||||
print(inetStatus(true))
|
||||
elseif arg[1] == "poll" then
|
||||
local attempts, timeout
|
||||
if arg[2] and arg[2]:match("[0-9]+") then
|
||||
|
||||
@@ -20,7 +20,6 @@ local Module = {
|
||||
mailSmtp = "smtp.gmail.com",
|
||||
mailSmtpPort = '587',
|
||||
mailSecurity = "tls",
|
||||
status = nil,
|
||||
_enabled = false,
|
||||
_aliveCounter = 0,
|
||||
_msgSent = true,
|
||||
|
||||
@@ -10,7 +10,6 @@ local Module = {
|
||||
runInterval = 5,
|
||||
sysLedsDir = "/sys/class/leds",
|
||||
ledName = nil,
|
||||
status = nil,
|
||||
_enabled = false,
|
||||
_ledDir = nil,
|
||||
_ledMaxBrightnessFile = nil,
|
||||
|
||||
@@ -15,7 +15,6 @@ local Module = {
|
||||
deadPeriod = 0,
|
||||
iface = nil,
|
||||
anyBand = false,
|
||||
status = nil,
|
||||
_enabled = false,
|
||||
_deadCounter = 0,
|
||||
_restarted = false,
|
||||
|
||||
@@ -11,7 +11,6 @@ local Module = {
|
||||
attempts = 0,
|
||||
deadPeriod = 0,
|
||||
restartTimeout = 0,
|
||||
status = nil,
|
||||
_attemptsCounter = 0,
|
||||
_deadCounter = 0,
|
||||
}
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
|
||||
local nixio = require("nixio")
|
||||
|
||||
local Module = {
|
||||
name = "mod_public_ip",
|
||||
config = {},
|
||||
syslog = function(level, msg) return true end,
|
||||
writeValue = function(filePath, str) return false end,
|
||||
readValue = function(filePath) return nil end,
|
||||
runInterval = 600,
|
||||
nslookup = "/usr/bin/nslookup",
|
||||
timeout = 3,
|
||||
providers = {
|
||||
opendns1 = {
|
||||
name = "opendns1", server = "208.67.222.222",
|
||||
host = "myip.opendns.com", queryType = "a"
|
||||
},
|
||||
opendns2 = {
|
||||
name = "opendns2", server = "208.67.220.220",
|
||||
host = "myip.opendns.com", queryType = "a"
|
||||
},
|
||||
opendns3 = {
|
||||
name = "opendns3", server = "208.67.222.220",
|
||||
host = "myip.opendns.com", queryType = "a"
|
||||
},
|
||||
opendns4 = {
|
||||
name = "opendns4", server = "208.67.220.222",
|
||||
host = "myip.opendns.com", queryType = "a"
|
||||
},
|
||||
akamai = {
|
||||
name = "akamai", server = "ns1-1.akamaitech.net",
|
||||
host = "whoami.akamai.net", queryType = "a"
|
||||
},
|
||||
google = {
|
||||
name = "google", server = "ns1.google.com",
|
||||
host = "o-o.myaddr.l.google.com", queryType = "txt"
|
||||
},
|
||||
},
|
||||
status = nil,
|
||||
_provider = nil,
|
||||
_nslookupCmd = nil,
|
||||
_currentIp = nil,
|
||||
_enabled = false,
|
||||
_counter = 0,
|
||||
}
|
||||
|
||||
function Module:parseA(str)
|
||||
res = str:match("Name:%s+" .. self._provider.host .. "\nAddress:%s+[%w.:]+")
|
||||
if res then
|
||||
return res:match("[%w.:]+$")
|
||||
end
|
||||
end
|
||||
|
||||
function Module:parseGoogle(str)
|
||||
res = str:match(self._provider.host .. '%s+text%s+=%s+"[%w.:]+"')
|
||||
if res then
|
||||
return res:gsub('"', ''):match("[%w.:]+$")
|
||||
end
|
||||
end
|
||||
|
||||
function Module:resolveIP()
|
||||
local res
|
||||
local fh = io.popen(self._nslookupCmd, "r")
|
||||
if fh then
|
||||
output = fh:read("*a")
|
||||
fh:close()
|
||||
if self._provider.name == "google" then
|
||||
res = self:parseGoogle(output)
|
||||
else
|
||||
res = self:parseA(output)
|
||||
end
|
||||
else
|
||||
self.syslog("err", string.format(
|
||||
"%s: Nslookup call failed (%s)", self.name, self.nslookup))
|
||||
end
|
||||
return res or "Undefined"
|
||||
end
|
||||
|
||||
function Module:init(t)
|
||||
if t.interval then
|
||||
self.runInterval = tonumber(t.interval)
|
||||
end
|
||||
if t.timeout then
|
||||
self.timeout = tonumber(t.timeout)
|
||||
end
|
||||
if t.provider then
|
||||
self._provider = self.providers[t.provider]
|
||||
else
|
||||
self._provider = self.providers.opendns1
|
||||
end
|
||||
if not nixio.fs.access(self.nslookup, "x") then
|
||||
self._enabled = false
|
||||
self.syslog(
|
||||
"warning",
|
||||
string.format("%s: '%s' does not exists", self.name, self.nslookup)
|
||||
)
|
||||
else
|
||||
self._enabled = true
|
||||
self._nslookupCmd = string.format(
|
||||
"%s -type=%s -timeout=%d %s %s",
|
||||
self.nslookup,
|
||||
self._provider.queryType,
|
||||
self.timeout,
|
||||
self._provider.host,
|
||||
self._provider.server
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function Module:run(currentStatus, lastStatus, timeDiff)
|
||||
if not self._enabled then
|
||||
return
|
||||
end
|
||||
if currentStatus == 0 then
|
||||
if self._counter == 0 or self._counter >= self.runInterval or currentStatus ~= lastStatus then
|
||||
local ip = self:resolveIP()
|
||||
if ip ~= self._currentIp then
|
||||
self.status = ip
|
||||
self.syslog(
|
||||
"notice",
|
||||
string.format("%s: public IP address %s", self.name, ip)
|
||||
)
|
||||
else
|
||||
self.status = nil
|
||||
end
|
||||
self._currentIp = ip
|
||||
self._counter = 0
|
||||
else
|
||||
self.status = nil
|
||||
end
|
||||
else
|
||||
self.status = nil
|
||||
self._currentIp = nil
|
||||
self._counter = 0
|
||||
end
|
||||
self._counter = self._counter + timeDiff
|
||||
end
|
||||
|
||||
return Module
|
||||
@@ -9,7 +9,6 @@ local Module = {
|
||||
readValue = function(filePath) return nil end,
|
||||
deadPeriod = 0,
|
||||
forceRebootDelay = 0,
|
||||
status = nil,
|
||||
_deadCounter = 0,
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ local Module = {
|
||||
alivePeriod = 0,
|
||||
upScript = "",
|
||||
downScript = "",
|
||||
status = nil,
|
||||
_deadCounter = 0,
|
||||
_aliveCounter = 0,
|
||||
_upScriptExecuted = true,
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_VERSION:=0.6-1
|
||||
PKG_VERSION:=0.5
|
||||
PKG_RELEASE:=1
|
||||
LUCI_TITLE:=LuCI support for internet-detector
|
||||
LUCI_DEPENDS:=+internet-detector
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
@@ -1,41 +1,11 @@
|
||||
'use strict';
|
||||
'require baseclass';
|
||||
'require form';
|
||||
'require fs';
|
||||
'require poll';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require ui';
|
||||
'require view';
|
||||
'require tools.widgets as widgets'
|
||||
|
||||
document.head.append(E('style', {'type': 'text/css'},
|
||||
`
|
||||
:root {
|
||||
--app-id-font-color: #fff;
|
||||
--app-id-connected-color: #2ea256;
|
||||
--app-id-disconnected-color: #ff4e54;
|
||||
--app-id-undefined-color: #8a8a8a;
|
||||
}
|
||||
:root[data-darkmode="true"] {
|
||||
--app-id-connected-color: #005F20;
|
||||
--app-id-disconnected-color: #a93734;
|
||||
--app-id-undefined-color: #4d4d4d;
|
||||
}
|
||||
.id-connected {
|
||||
background-color: var(--app-id-connected-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
.id-disconnected {
|
||||
background-color: var(--app-id-disconnected-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
.id-undefined {
|
||||
background-color: var(--app-id-undefined-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
`));
|
||||
|
||||
const btnStyleEnabled = 'btn cbi-button-save';
|
||||
const btnStyleDisabled = 'btn cbi-button-reset';
|
||||
const btnStyleApply = 'btn cbi-button-apply';
|
||||
@@ -104,7 +74,7 @@ var Timefield = ui.Textfield.extend({
|
||||
},
|
||||
});
|
||||
|
||||
return view.extend({
|
||||
return L.view.extend({
|
||||
appName : 'internet-detector',
|
||||
execPath : '/usr/bin/internet-detector',
|
||||
upScriptPath : '/etc/internet-detector/up-script',
|
||||
@@ -115,10 +85,9 @@ return view.extend({
|
||||
appStatus : 'stoped',
|
||||
initStatus : null,
|
||||
inetStatus : null,
|
||||
publicIp : null,
|
||||
inetStatusLabel : E('span', { 'class': 'label', 'id': 'inetStatusLabel' }),
|
||||
inetStatusLabel : E('span', { 'class': 'label' }),
|
||||
inetStatusSpinner : E('span', { 'style': 'margin-top:1em' }, ' '),
|
||||
serviceStatusLabel : E('em', { 'id': 'serviceStatusLabel' }),
|
||||
serviceStatusLabel : E('em'),
|
||||
initButton : null,
|
||||
uiPollCounter : 0,
|
||||
uiPollState : null,
|
||||
@@ -177,19 +146,22 @@ return view.extend({
|
||||
},
|
||||
|
||||
setInternetStatus: function() {
|
||||
if(this.inetStatus === 0) {
|
||||
this.inetStatusLabel.textContent = _('Connected') + (this.publicIp ? ' | %s: %s'.format(_('Public IP'), _(this.publicIp)) : '');
|
||||
this.inetStatusLabel.className = "label id-connected";
|
||||
if(this.inetStatus === 'up') {
|
||||
this.inetStatusLabel.style.background = '#46a546';
|
||||
this.inetStatusLabel.textContent = _('Connected');
|
||||
this.inetStatusLabel.style.color = '#ffffff';
|
||||
this.unsetInetStatusSpinner();
|
||||
}
|
||||
else if(this.inetStatus === 1) {
|
||||
else if(this.inetStatus === 'down') {
|
||||
this.inetStatusLabel.textContent = _('Disconnected');
|
||||
this.inetStatusLabel.className = "label id-disconnected";
|
||||
this.inetStatusLabel.style.background = '#ff4953';
|
||||
this.inetStatusLabel.style.color = '#ffffff';
|
||||
this.unsetInetStatusSpinner();
|
||||
}
|
||||
else {
|
||||
this.inetStatusLabel.textContent = _('Undefined');
|
||||
this.inetStatusLabel.className = "label id-undefined";
|
||||
this.inetStatusLabel.style.background = '#9b9b9b';
|
||||
this.inetStatusLabel.style.color = '#ffffff';
|
||||
|
||||
if(this.currentAppMode !== '0' && this.appStatus !== 'stoped') {
|
||||
this.setInetStatusSpinner();
|
||||
@@ -203,37 +175,22 @@ return view.extend({
|
||||
};
|
||||
},
|
||||
|
||||
inetStatusFromJson: function(res) {
|
||||
let curInetStatus = null;
|
||||
let curPubIp = null;
|
||||
if(res.code === 0) {
|
||||
try {
|
||||
let json = JSON.parse(res.stdout.trim());
|
||||
curInetStatus = json.inet;
|
||||
curPubIp = json.mod_public_ip;
|
||||
} catch(e) {};
|
||||
};
|
||||
return [ curInetStatus, curPubIp ];
|
||||
},
|
||||
|
||||
servicePoll: function() {
|
||||
return Promise.all([
|
||||
fs.exec(this.execPath, [ 'status' ]),
|
||||
fs.exec(this.execPath, [ 'inet-status-json' ]),
|
||||
fs.exec(this.execPath, [ 'inet-status' ]),
|
||||
]).then(stat => {
|
||||
let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null;
|
||||
let [ curInetStatus, curPubIp ] = this.inetStatusFromJson(stat[1]);
|
||||
if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus && this.publicIp === curPubIp) {
|
||||
let curInetStatus = (stat[1].code === 0) ? stat[1].stdout.trim() : null;
|
||||
if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus) {
|
||||
return;
|
||||
};
|
||||
this.appStatus = curAppStatus;
|
||||
this.inetStatus = curInetStatus;
|
||||
this.publicIp = curPubIp;
|
||||
this.setInternetStatus();
|
||||
}).catch(e => {
|
||||
this.appStatus = 'stoped';
|
||||
this.inetStatus = null;
|
||||
this.publicIp = null
|
||||
});
|
||||
},
|
||||
|
||||
@@ -248,22 +205,27 @@ return view.extend({
|
||||
|
||||
this.uiPollCounter = 0;
|
||||
|
||||
return fs.exec(this.execPath, [ 'inet-status-json' ]).then(res => {
|
||||
let curPubIp;
|
||||
[ this.uiPollState, curPubIp ] = this.inetStatusFromJson(res);
|
||||
if(this.inetStatus !== this.uiPollState || this.publicIp !== curPubIp) {
|
||||
this.inetStatus = (this.currentAppMode === '0') ? null : this.uiPollState;
|
||||
this.publicIp = (this.currentAppMode === '0') ? null : curPubIp;
|
||||
return fs.exec(this.execPath, [ 'inet-status' ]).then(res => {
|
||||
this.uiPollState = (res.code === 0 && res.stdout.trim() === 'up') ? 0 : 1;
|
||||
|
||||
if(this.uiPollState === 0) {
|
||||
curInetStatus = 'up';
|
||||
} else {
|
||||
curInetStatus = 'down';
|
||||
};
|
||||
|
||||
if(this.inetStatus !== curInetStatus) {
|
||||
this.inetStatus = (this.currentAppMode === '0') ? null : curInetStatus;
|
||||
this.setInternetStatus();
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
serviceRestart: function(ev) {
|
||||
poll.stop();
|
||||
L.Poll.stop();
|
||||
return this.handleServiceAction('restart').then(() => {
|
||||
window.setTimeout(() => this.servicePoll(), 1000);
|
||||
poll.start();
|
||||
L.Poll.start();
|
||||
});
|
||||
},
|
||||
|
||||
@@ -306,7 +268,7 @@ return view.extend({
|
||||
this.ctx.setInternetStatus();
|
||||
|
||||
return E([
|
||||
E('label', { 'class': 'cbi-value-title', 'for': 'inetStatusLabel' },
|
||||
E('label', { 'class': 'cbi-value-title' },
|
||||
_('Internet status')
|
||||
),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
@@ -330,7 +292,7 @@ return view.extend({
|
||||
|
||||
renderWidget: function(section_id, option_index, cfgvalue) {
|
||||
return E([
|
||||
E('label', { 'class': 'cbi-value-title', 'for': 'serviceStatusLabel' },
|
||||
E('label', { 'class': 'cbi-value-title' },
|
||||
_('Service')
|
||||
),
|
||||
E('div', { 'class': 'cbi-value-field' },
|
||||
@@ -376,21 +338,17 @@ return view.extend({
|
||||
}, (!this.ctx.initStatus) ? _('Disabled') : _('Enabled'));
|
||||
|
||||
return E( [
|
||||
E('label', { 'class': 'cbi-value-title', 'for': 'initButton' },
|
||||
E('label', { 'class': 'cbi-value-title' },
|
||||
_('Run service at startup')
|
||||
),
|
||||
E('div', { 'class': 'cbi-value-field' }, [
|
||||
E('div', {}, this.ctx.initButton),
|
||||
E('input', {
|
||||
'id' : 'initButton',
|
||||
'type': 'hidden',
|
||||
}),
|
||||
]),
|
||||
E('div', { 'class': 'cbi-value-field' },
|
||||
this.ctx.initButton
|
||||
),
|
||||
]);
|
||||
},
|
||||
}),
|
||||
|
||||
fileEditDialog: baseclass.extend({
|
||||
fileEditDialog: L.Class.extend({
|
||||
__init__: function(file, title, description, callback, fileExists=false) {
|
||||
this.file = file;
|
||||
this.title = title;
|
||||
@@ -520,7 +478,7 @@ return view.extend({
|
||||
|
||||
let s, o, ss;
|
||||
let m = new form.Map(this.appName,
|
||||
_('Internet Detector'),
|
||||
_('Internet detector'),
|
||||
_('Checking Internet availability.'));
|
||||
|
||||
|
||||
@@ -910,58 +868,6 @@ return view.extend({
|
||||
'</em></div>';
|
||||
};
|
||||
|
||||
// Public IP address
|
||||
|
||||
s.tab('public_ip', _('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.SectionValue, 'mod_public_ip', form.NamedSection,
|
||||
'mod_public_ip', 'mod_public_ip'
|
||||
);
|
||||
ss = o.subsection;
|
||||
|
||||
// enabled
|
||||
o = ss.option(form.Flag, 'enabled',
|
||||
_('Enable'));
|
||||
o.rmempty = false;
|
||||
|
||||
// provider
|
||||
o = ss.option(form.ListValue,
|
||||
'provider', _('DNS provider'),
|
||||
_('Service for determining the public IP address through DNS.')
|
||||
);
|
||||
o.value('opendns1');
|
||||
o.value('opendns2');
|
||||
o.value('opendns3');
|
||||
o.value('opendns4');
|
||||
o.value('akamai');
|
||||
o.value('google');
|
||||
|
||||
// interval
|
||||
o = ss.option(form.ListValue,
|
||||
'interval', _('Polling interval'),
|
||||
_('Interval between IP address requests.')
|
||||
);
|
||||
o.value(60, '1' + ' ' + _('min'));
|
||||
o.value(300, '5' + ' ' + _('min'));
|
||||
o.value(600, '10' + ' ' + _('min'));
|
||||
o.value(1800, '30' + ' ' + _('min'));
|
||||
o.value(3600, '1' + ' ' + _('hour'));
|
||||
o.value(10800, '3' + ' ' + _('hour'));
|
||||
|
||||
// timeout
|
||||
o = ss.option(form.ListValue,
|
||||
'timeout', _('Server response timeout')
|
||||
);
|
||||
for(let i=1; i<=5; i++) {
|
||||
o.value(i, i + ' ' + _('sec'));
|
||||
};
|
||||
|
||||
// Email notification
|
||||
|
||||
s.tab('email', _('Email notification'));
|
||||
@@ -1114,7 +1020,7 @@ return view.extend({
|
||||
|
||||
|
||||
if(this.currentAppMode !== '0') {
|
||||
poll.add(
|
||||
L.Poll.add(
|
||||
L.bind((this.currentAppMode === '2') ? this.servicePoll : this.uiPoll, this),
|
||||
this.pollInterval
|
||||
);
|
||||
|
||||
@@ -1,54 +1,12 @@
|
||||
'use strict';
|
||||
'require baseclass';
|
||||
'require fs';
|
||||
'require uci';
|
||||
|
||||
document.head.append(E('style', {'type': 'text/css'},
|
||||
`
|
||||
:root {
|
||||
--app-id-font-color: #fff;
|
||||
--app-id-connected-color: #2ea256;
|
||||
--app-id-disconnected-color: #ff4e54;
|
||||
--app-id-undefined-color: #8a8a8a;
|
||||
}
|
||||
:root[data-darkmode="true"] {
|
||||
--app-id-connected-color: #005F20;
|
||||
--app-id-disconnected-color: #a93734;
|
||||
--app-id-undefined-color: #4d4d4d;
|
||||
}
|
||||
.id-connected {
|
||||
background-color: var(--app-id-connected-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
.id-disconnected {
|
||||
background-color: var(--app-id-disconnected-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
.id-undefined {
|
||||
background-color: var(--app-id-undefined-color) !important;
|
||||
color: var(--app-id-font-color) !important;
|
||||
}
|
||||
`));
|
||||
|
||||
return baseclass.extend({
|
||||
return L.Class.extend({
|
||||
title : _('Internet'),
|
||||
appName : 'internet-detector',
|
||||
execPath : '/usr/bin/internet-detector',
|
||||
inetStatus : null,
|
||||
publicIp : null,
|
||||
|
||||
inetStatusFromJson: function(res) {
|
||||
let curInetStatus = null;
|
||||
let curPubIp = null;
|
||||
if(res.code === 0) {
|
||||
try {
|
||||
let json = JSON.parse(res.stdout.trim());
|
||||
curInetStatus = json.inet;
|
||||
curPubIp = json.mod_public_ip;
|
||||
} catch(e) {};
|
||||
};
|
||||
return [ curInetStatus, curPubIp ];
|
||||
},
|
||||
|
||||
load: async function() {
|
||||
if(!(
|
||||
@@ -79,7 +37,7 @@ return baseclass.extend({
|
||||
};
|
||||
|
||||
window.internetDetectorCounter = 0;
|
||||
return L.resolveDefault(fs.exec(this.execPath, [ 'inet-status-json' ]), null);
|
||||
return L.resolveDefault(fs.exec(this.execPath, [ 'inet-status' ]), null);
|
||||
}
|
||||
else {
|
||||
window.internetDetectorState = 2;
|
||||
@@ -92,22 +50,34 @@ return baseclass.extend({
|
||||
};
|
||||
|
||||
if(data) {
|
||||
[ window.internetDetectorState, this.publicIp ] = this.inetStatusFromJson(data);
|
||||
this.inetStatus = (data.code === 0) ? data.stdout.trim() : null;
|
||||
if(this.inetStatus === 'up') {
|
||||
window.internetDetectorState = 0;
|
||||
}
|
||||
else if(this.inetStatus === 'down') {
|
||||
window.internetDetectorState = 1;
|
||||
}
|
||||
else {
|
||||
window.internetDetectorState = 2;
|
||||
};
|
||||
};
|
||||
|
||||
let internetStatus = E('span', { 'class': 'label' });
|
||||
|
||||
if(window.internetDetectorState === 0) {
|
||||
internetStatus.textContent = _('Connected') + (this.publicIp ? ' | %s: %s'.format(_('Public IP'), _(this.publicIp)) : '');
|
||||
internetStatus.className = "label id-connected";
|
||||
internetStatus.textContent = _('Connected');
|
||||
internetStatus.style.background = '#46a546';
|
||||
internetStatus.style.color = '#ffffff';
|
||||
}
|
||||
else if(window.internetDetectorState === 1) {
|
||||
internetStatus.textContent = _('Disconnected');
|
||||
internetStatus.className = "label id-disconnected";
|
||||
internetStatus.style.background = '#ff4953';
|
||||
internetStatus.style.color = '#ffffff';
|
||||
}
|
||||
else {
|
||||
internetStatus.textContent = _('Undefined');
|
||||
internetStatus.className = "label id-undefined";
|
||||
internetStatus.style.background = '#9b9b9b';
|
||||
internetStatus.style.color = '#ffffff';
|
||||
};
|
||||
|
||||
return E('div', {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
module('luci.controller.internet-detector', package.seeall)
|
||||
|
||||
function index()
|
||||
if nixio.fs.access('/usr/bin/internet-detector', 'x') then
|
||||
entry({'admin', 'services', 'internet-detector'}, view('internet-detector'), _('Internet detector'), 80).acl_depends = { 'luci-app-internet-detector' }
|
||||
end
|
||||
end
|
||||
@@ -47,9 +47,6 @@ msgstr "Тип проверки"
|
||||
msgid "Checking Internet availability."
|
||||
msgstr "Проверка доступности Интернет."
|
||||
|
||||
msgid "Checking the real public IP address."
|
||||
msgstr "Проверка реального публичного IP адреса."
|
||||
|
||||
msgid "Command failed"
|
||||
msgstr "Команда не выполнена"
|
||||
|
||||
@@ -92,9 +89,6 @@ msgstr "Отключен"
|
||||
msgid "Dismiss"
|
||||
msgstr "Закрыть"
|
||||
|
||||
msgid "DNS provider"
|
||||
msgstr "DNS провайдер"
|
||||
|
||||
msgid "Edit"
|
||||
msgstr "Изменить"
|
||||
|
||||
@@ -125,12 +119,6 @@ msgstr "Включен"
|
||||
msgid "Expecting:"
|
||||
msgstr "Ожидается:"
|
||||
|
||||
msgid "Public IP"
|
||||
msgstr "Публичный IP"
|
||||
|
||||
msgid "Public IP address"
|
||||
msgstr "Публичный IP адрес"
|
||||
|
||||
msgid "Failed to get %s init status: %s"
|
||||
msgstr "Не удалось получить статус инициализации %s: %s"
|
||||
|
||||
@@ -174,7 +162,7 @@ msgstr "Интерфейс"
|
||||
msgid "Internet"
|
||||
msgstr "Интернет"
|
||||
|
||||
msgid "Internet Detector"
|
||||
msgid "Internet detector"
|
||||
msgstr "Интернет-детектор"
|
||||
|
||||
msgid "Internet detector mode"
|
||||
@@ -183,9 +171,6 @@ msgstr "Режим интернет-детектора"
|
||||
msgid "Internet status"
|
||||
msgstr "Статус Интернет"
|
||||
|
||||
msgid "Interval between IP address requests."
|
||||
msgstr "Интервал между запросами IP адреса."
|
||||
|
||||
msgid "Jumbo: 9000 bytes"
|
||||
msgstr "Гигантский: 9000 байт"
|
||||
|
||||
@@ -301,9 +286,6 @@ msgstr "Пинг хоста"
|
||||
msgid "Ping packet size"
|
||||
msgstr "Размер пакета Ping"
|
||||
|
||||
msgid "Polling interval"
|
||||
msgstr "Интервал опроса"
|
||||
|
||||
msgid "Reboot device"
|
||||
msgstr "Перезагрузка устройства"
|
||||
|
||||
@@ -352,9 +334,6 @@ msgstr "Безопасность"
|
||||
msgid "Sender"
|
||||
msgstr "Отправитель"
|
||||
|
||||
msgid "Server response timeout"
|
||||
msgstr "Таймаут ответа сервера"
|
||||
|
||||
msgid "Service"
|
||||
msgstr "Служба"
|
||||
|
||||
@@ -364,9 +343,6 @@ msgstr "Не удалось выполнить действие службы \"%
|
||||
msgid "Service configuration"
|
||||
msgstr "Конфигурация службы"
|
||||
|
||||
msgid "Service for determining the public IP address through DNS."
|
||||
msgstr "Сервис для определения публичного IP адреса через DNS."
|
||||
|
||||
msgid "Service modules"
|
||||
msgstr "Модули службы"
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ msgstr ""
|
||||
msgid "Checking Internet availability."
|
||||
msgstr ""
|
||||
|
||||
msgid "Checking the real public IP address."
|
||||
msgstr ""
|
||||
|
||||
msgid "Command failed"
|
||||
msgstr ""
|
||||
|
||||
@@ -80,9 +77,6 @@ msgstr ""
|
||||
msgid "Dismiss"
|
||||
msgstr ""
|
||||
|
||||
msgid "DNS provider"
|
||||
msgstr ""
|
||||
|
||||
msgid "Edit"
|
||||
msgstr ""
|
||||
|
||||
@@ -113,12 +107,6 @@ msgstr ""
|
||||
msgid "Expecting:"
|
||||
msgstr ""
|
||||
|
||||
msgid "Public IP"
|
||||
msgstr ""
|
||||
|
||||
msgid "Public IP address"
|
||||
msgstr ""
|
||||
|
||||
msgid "Failed to get %s init status: %s"
|
||||
msgstr ""
|
||||
|
||||
@@ -160,7 +148,7 @@ msgstr ""
|
||||
msgid "Internet"
|
||||
msgstr ""
|
||||
|
||||
msgid "Internet Detector"
|
||||
msgid "Internet detector"
|
||||
msgstr ""
|
||||
|
||||
msgid "Internet detector mode"
|
||||
@@ -169,9 +157,6 @@ msgstr ""
|
||||
msgid "Internet status"
|
||||
msgstr ""
|
||||
|
||||
msgid "Interval between IP address requests."
|
||||
msgstr ""
|
||||
|
||||
msgid "Jumbo: 9000 bytes"
|
||||
msgstr ""
|
||||
|
||||
@@ -269,9 +254,6 @@ msgstr ""
|
||||
msgid "Ping packet size"
|
||||
msgstr ""
|
||||
|
||||
msgid "Polling interval"
|
||||
msgstr ""
|
||||
|
||||
msgid "Reboot device"
|
||||
msgstr ""
|
||||
|
||||
@@ -320,9 +302,6 @@ msgstr ""
|
||||
msgid "Sender"
|
||||
msgstr ""
|
||||
|
||||
msgid "Server response timeout"
|
||||
msgstr ""
|
||||
|
||||
msgid "Service"
|
||||
msgstr ""
|
||||
|
||||
@@ -332,9 +311,6 @@ msgstr ""
|
||||
msgid "Service configuration"
|
||||
msgstr ""
|
||||
|
||||
msgid "Service for determining the public IP address through DNS."
|
||||
msgstr ""
|
||||
|
||||
msgid "Service modules"
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"admin/services/internet-detector": {
|
||||
"title": "Internet Detector",
|
||||
"title": "Internet detector",
|
||||
"order": 80,
|
||||
"action": {
|
||||
"type": "view",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 233 KiB After Width: | Height: | Size: 176 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 196 KiB |
Reference in New Issue
Block a user