Fixed mod_public_ip

This commit is contained in:
gSpot
2025-03-23 17:56:17 +03:00
parent 55802f750f
commit 5b669fe718
11 changed files with 151 additions and 78 deletions

View File

@@ -15,22 +15,22 @@ Internet-detector is an application for checking the availability of the Interne
## Installation notes (OpenWrt >= 21.02) ## Installation notes (OpenWrt >= 21.02)
opkg update opkg update
wget --no-check-certificate -O /tmp/internet-detector_1.4.3-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.3-r1_all.ipk wget --no-check-certificate -O /tmp/internet-detector_1.4.4-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.4-r1_all.ipk
opkg install /tmp/internet-detector_1.4.3-r1_all.ipk opkg install /tmp/internet-detector_1.4.4-r1_all.ipk
rm /tmp/internet-detector_1.4.3-r1_all.ipk rm /tmp/internet-detector_1.4.4-r1_all.ipk
service internet-detector start service internet-detector start
service internet-detector enable service internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.3-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.3-r1_all.ipk wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.4-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.4-r1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.4.3-r1_all.ipk opkg install /tmp/luci-app-internet-detector_1.4.4-r1_all.ipk
rm /tmp/luci-app-internet-detector_1.4.3-r1_all.ipk rm /tmp/luci-app-internet-detector_1.4.4-r1_all.ipk
service rpcd restart service rpcd restart
i18n-ru: i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.3-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.3-r1_all.ipk wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.4-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.4-r1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.4.3-r1_all.ipk opkg install /tmp/luci-i18n-internet-detector-ru_1.4.4-r1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.4.3-r1_all.ipk rm /tmp/luci-i18n-internet-detector-ru_1.4.4-r1_all.ipk
## Screenshots: ## Screenshots:
@@ -42,9 +42,9 @@ i18n-ru:
**Dependences:** modemmanager. **Dependences:** modemmanager.
wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.3-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.3-r1_all.ipk wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.4-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.4-r1_all.ipk
opkg install /tmp/internet-detector-mod-modem-restart_1.4.3-r1_all.ipk opkg install /tmp/internet-detector-mod-modem-restart_1.4.4-r1_all.ipk
rm /tmp/internet-detector-mod-modem-restart_1.4.3-r1_all.ipk rm /tmp/internet-detector-mod-modem-restart_1.4.4-r1_all.ipk
service internet-detector restart service internet-detector restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg) ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg)
@@ -53,9 +53,9 @@ i18n-ru:
**Dependences:** mailsend. **Dependences:** mailsend.
wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.3-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.3-r1_all.ipk wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.4-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.4-r1_all.ipk
opkg install /tmp/internet-detector-mod-email_1.4.3-r1_all.ipk opkg install /tmp/internet-detector-mod-email_1.4.4-r1_all.ipk
rm /tmp/internet-detector-mod-email_1.4.3-r1_all.ipk rm /tmp/internet-detector-mod-email_1.4.4-r1_all.ipk
service internet-detector restart service internet-detector restart
![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg) ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg)

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-email PKG_NAME:=internet-detector-mod-email
PKG_VERSION:=1.4.3 PKG_VERSION:=1.4.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector-mod-modem-restart PKG_NAME:=internet-detector-mod-modem-restart
PKG_VERSION:=1.4.3 PKG_VERSION:=1.4.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector PKG_NAME:=internet-detector
PKG_VERSION:=1.4.3 PKG_VERSION:=1.4.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>

View File

@@ -28,7 +28,9 @@ config instance 'internet'
option mod_public_ip_provider 'opendns1' option mod_public_ip_provider 'opendns1'
option mod_public_ip_qtype '0' option mod_public_ip_qtype '0'
option mod_public_ip_interval '600' option mod_public_ip_interval '600'
option mod_public_ip_timeout '3' option mod_public_ip_interval_failed '60'
option mod_public_ip_request_attempts '2'
option mod_public_ip_timeout '2'
option mod_public_ip_enable_ip_script '0' option mod_public_ip_enable_ip_script '0'
option mod_email_enabled '0' option mod_email_enabled '0'
option mod_email_mode '0' option mod_email_mode '0'

View File

@@ -76,11 +76,11 @@ function Module:init(t)
end end
end end
function Module:SetTriggerTimer(t) function Module:setTriggerTimer(t)
self.writeValue(t.ledTriggerFile, "timer") self.writeValue(t.ledTriggerFile, "timer")
end end
function Module:SetTriggerNone(t) function Module:setTriggerNone(t)
self.writeValue(t.ledTriggerFile, "none") self.writeValue(t.ledTriggerFile, "none")
end end
@@ -92,12 +92,12 @@ function Module:getCurrentTrigger(t)
end end
function Module:on(t) function Module:on(t)
self:SetTriggerNone(t) self:setTriggerNone(t)
self.writeValue(t.ledBrightnessFile, t.ledMaxBrightness) self.writeValue(t.ledBrightnessFile, t.ledMaxBrightness)
end end
function Module:off(t) function Module:off(t)
self:SetTriggerNone(t) self:setTriggerNone(t)
self.writeValue(t.ledBrightnessFile, 0) self.writeValue(t.ledBrightnessFile, 0)
end end
@@ -120,7 +120,7 @@ function Module:ledRunFunc(t, currentStatus)
end end
elseif t.ledAction1 == 3 then elseif t.ledAction1 == 3 then
if not self:getCurrentTrigger(t) then if not self:getCurrentTrigger(t) then
self:SetTriggerTimer(t) self:setTriggerTimer(t)
end end
end end
else else
@@ -134,7 +134,7 @@ function Module:ledRunFunc(t, currentStatus)
end end
elseif t.ledAction2 == 3 then elseif t.ledAction2 == 3 then
if not self:getCurrentTrigger(t) then if not self:getCurrentTrigger(t) then
self:SetTriggerTimer(t) self:setTriggerTimer(t)
end end
end end
end end

View File

@@ -4,23 +4,25 @@ local stdlib = require("posix.stdlib")
local unistd = require("posix.unistd") local unistd = require("posix.unistd")
local Module = { local Module = {
name = "mod_public_ip", name = "mod_public_ip",
runPrio = 50, runPrio = 50,
config = { config = {
noModules = false, noModules = false,
debug = false, debug = false,
serviceConfig = { serviceConfig = {
iface = nil, iface = nil,
}, },
}, },
syslog = function(level, msg) return true end, syslog = function(level, msg) return true end,
writeValue = function(filePath, str) return false end, writeValue = function(filePath, str) return false end,
readValue = function(filePath) return nil end, readValue = function(filePath) return nil end,
port = 53, port = 53,
runInterval = 600, runInterval = 600,
runIntervalFailed = 60, runIntervalFailed = 60,
timeout = 3, runIntervalDNSFailed = 1,
providers = { requestAttempts = 2,
timeout = 3,
providers = {
opendns1 = { opendns1 = {
name = "opendns1", host = "myip.opendns.com", name = "opendns1", host = "myip.opendns.com",
server = "208.67.222.222", server6 = "2620:119:35::35", server = "208.67.222.222", server6 = "2620:119:35::35",
@@ -52,16 +54,18 @@ local Module = {
port = 53, queryType = "TXT", queryType6 = "TXT", port = 53, queryType = "TXT", queryType6 = "TXT",
}, },
}, },
ipScript = "", ipScript = "",
enableIpScript = false, enableIpScript = false,
status = nil, status = nil,
_provider = nil, _provider = nil,
_qtype = false, _qtype = false,
_currentIp = nil, _currentIp = nil,
_enabled = false, _lastResolvedIp = nil,
_counter = 0, _enabled = false,
_interval = 600, _counter = 0,
_DNSPacket = nil, _DNSFalseCounter = 0,
_interval = 600,
_DNSPacket = nil,
} }
function Module:runIpScript() function Module:runIpScript()
@@ -306,7 +310,7 @@ function Module:decodeMessage(message)
return retTable return retTable
end end
function Module:resolveIP() function Module:requestIP()
local res local res
local qtype = self._qtype and self._provider.queryType6 or self._provider.queryType local qtype = self._qtype and self._provider.queryType6 or self._provider.queryType
local server = self._qtype and self._provider.server6 or self._provider.server local server = self._qtype and self._provider.server6 or self._provider.server
@@ -324,7 +328,7 @@ function Module:resolveIP()
end end
else else
self.syslog("warning", string.format( self.syslog("warning", string.format(
"%s: DNS error when requesting an IP address", self.name)) "%s: UDP error when requesting an IP address", self.name))
end end
return res return res
@@ -334,6 +338,12 @@ function Module:init(t)
if t.interval ~= nil then if t.interval ~= nil then
self.runInterval = tonumber(t.interval) self.runInterval = tonumber(t.interval)
end end
if t.interval_failed ~= nil then
self.runIntervalFailed = tonumber(t.interval_failed)
end
if t.request_attempts ~= nil then
self.requestAttempts = tonumber(t.request_attempts)
end
if t.timeout ~= nil then if t.timeout ~= nil then
self.timeout = tonumber(t.timeout) self.timeout = tonumber(t.timeout)
end end
@@ -352,10 +362,12 @@ function Module:init(t)
if t.qtype ~= nil then if t.qtype ~= nil then
self._qtype = (tonumber(t.qtype) ~= 0) self._qtype = (tonumber(t.qtype) ~= 0)
end end
self._currentIp = nil self._currentIp = nil
self._DNSPacket = nil self._lastResolvedIp = nil
self._interval = self.runInterval self._DNSPacket = nil
self._enabled = true self._interval = self.runInterval
self._DNSFalseCounter = 0
self._enabled = true
end end
function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked) function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
@@ -365,33 +377,44 @@ function Module:run(currentStatus, lastStatus, timeDiff, timeNow, inetChecked)
if currentStatus == 0 then if currentStatus == 0 then
if self._counter == 0 or self._counter >= self._interval or currentStatus ~= lastStatus then if self._counter == 0 or self._counter >= self._interval or currentStatus ~= lastStatus then
local ip = self:resolveIP() local ip = self:requestIP()
if not ip then if not ip then
ip = "" ip = ""
self._interval = self.runIntervalFailed self._DNSFalseCounter = self._DNSFalseCounter + 1
if self._DNSFalseCounter >= self.requestAttempts then
self._interval = self.runIntervalFailed
self._DNSFalseCounter = 0
else
self._interval = self.runIntervalDNSFailed
end
else else
self._interval = self.runInterval self._interval = self.runInterval
self._DNSFalseCounter = 0
end end
if ip ~= self._currentIp then if ip ~= self._currentIp then
self.status = ip self.status = ip
self.syslog( if ip ~= "" then
"notice", if self._counter > 0 and ip ~= self._lastResolvedIp then
string.format("%s: public IP address %s", self.name, (ip == "") and "Undefined" or ip) self.syslog(
) "notice",
if self._counter > 0 then string.format("%s: public IP address changed to %s", self.name, ip)
self:runIpScript() )
self:runIpScript()
end
self._lastResolvedIp = ip
end end
end end
self._currentIp = ip self._currentIp = ip
self._counter = 0 self._counter = 0
end end
else else
self._currentIp = nil self._currentIp = nil
self.status = self._currentIp self.status = self._currentIp
self._counter = 0 self._DNSFalseCounter = 0
self._interval = self.runInterval self._counter = 0
self._interval = self.runInterval
end end
self._counter = self._counter + timeDiff self._counter = self._counter + timeDiff
end end

View File

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

View File

@@ -1038,6 +1038,30 @@ return view.extend({
o.value(3600, '1' + ' ' + _('hour')); o.value(3600, '1' + ' ' + _('hour'));
o.value(10800, '3' + ' ' + _('hour')); o.value(10800, '3' + ' ' + _('hour'));
// interval_failed
o = s.taboption('public_ip', form.ListValue,
'mod_public_ip_interval_failed', _('Failed interval'),
_('Interval between IP address requests if the IP address is not defined.')
);
o.default = '60';
o.modalonly = true;
o.value(30, '30' + ' ' + _('sec'));
o.value(60, '1' + ' ' + _('min'));
o.value(180, '3' + ' ' + _('min'));
o.value(300, '5' + ' ' + _('min'));
o.value(600, '10' + ' ' + _('min'));
// request_attempts
o = s.taboption('public_ip', form.ListValue,
'mod_public_ip_request_attempts', _('Attempts'),
_('Number of attempts to request an IP address.')
);
o.default = '2'
o.modalonly = true;
for(let i = 1; i <= 3; i++) {
o.value(i);
};
// timeout // timeout
o = s.taboption('public_ip', form.ListValue, o = s.taboption('public_ip', form.ListValue,
'mod_public_ip_timeout', _('Server response timeout') 'mod_public_ip_timeout', _('Server response timeout')

View File

@@ -44,6 +44,9 @@ msgstr "Сообщение будет отправлено при подключ
msgid "An error has occurred" msgid "An error has occurred"
msgstr "Произошла ошибка" msgstr "Произошла ошибка"
msgid "Attempts"
msgstr "Попытки"
msgid "Big: 248 bytes" msgid "Big: 248 bytes"
msgstr "Большой: 248 байт" msgstr "Большой: 248 байт"
@@ -149,11 +152,8 @@ msgstr "Включен"
msgid "Expecting:" msgid "Expecting:"
msgstr "Ожидается:" msgstr "Ожидается:"
msgid "Public IP" msgid "Failed interval"
msgstr "Публичный IP" msgstr "Интервал при неудаче"
msgid "Public IP address"
msgstr "Публичный IP адрес"
msgid "Failed to get %s init status: %s" msgid "Failed to get %s init status: %s"
msgstr "Не удалось получить статус инициализации %s: %s" msgstr "Не удалось получить статус инициализации %s: %s"
@@ -216,6 +216,9 @@ msgstr "Статус Интернет"
msgid "Interval between IP address requests." msgid "Interval between IP address requests."
msgstr "Интервал между запросами IP адреса." msgstr "Интервал между запросами IP адреса."
msgid "Interval between IP address requests if the IP address is not defined."
msgstr "Интервал между запросами IP адреса, если IP адрес не определён."
msgid "Jumbo: 9000 bytes" msgid "Jumbo: 9000 bytes"
msgstr "Гигантский: 9000 байт" msgstr "Гигантский: 9000 байт"
@@ -282,6 +285,9 @@ msgstr "Нет доступных <abbr title=\"Светодиод\">LED</abbr>.
msgid "Not scheduled" msgid "Not scheduled"
msgstr "Не запланирован" msgstr "Не запланирован"
msgid "Number of attempts to request an IP address."
msgstr "Количество попыток запроса IP адреса"
msgid "Off" msgid "Off"
msgstr "Выключить" msgstr "Выключить"
@@ -332,6 +338,12 @@ msgstr "Регулярный скрипт"
msgid "Polling interval" msgid "Polling interval"
msgstr "Интервал опроса" msgstr "Интервал опроса"
msgid "Public IP"
msgstr "Публичный IP"
msgid "Public IP address"
msgstr "Публичный IP адрес"
msgid "Reboot device" msgid "Reboot device"
msgstr "Перезагрузка устройства" msgstr "Перезагрузка устройства"

View File

@@ -32,6 +32,9 @@ msgstr ""
msgid "An error has occurred" msgid "An error has occurred"
msgstr "" msgstr ""
msgid "Attempts"
msgstr ""
msgid "Big: 248 bytes" msgid "Big: 248 bytes"
msgstr "" msgstr ""
@@ -137,10 +140,7 @@ msgstr ""
msgid "Expecting:" msgid "Expecting:"
msgstr "" msgstr ""
msgid "Public IP" msgid "Failed interval"
msgstr ""
msgid "Public IP address"
msgstr "" msgstr ""
msgid "Failed to get %s init status: %s" msgid "Failed to get %s init status: %s"
@@ -202,6 +202,9 @@ msgstr ""
msgid "Interval between IP address requests." msgid "Interval between IP address requests."
msgstr "" msgstr ""
msgid "Interval between IP address requests if the IP address is not defined."
msgstr ""
msgid "Jumbo: 9000 bytes" msgid "Jumbo: 9000 bytes"
msgstr "" msgstr ""
@@ -260,6 +263,9 @@ msgstr ""
msgid "Not scheduled" msgid "Not scheduled"
msgstr "" msgstr ""
msgid "Number of attempts to request an IP address."
msgstr ""
msgid "Off" msgid "Off"
msgstr "" msgstr ""
@@ -307,6 +313,12 @@ msgstr ""
msgid "Polling interval" msgid "Polling interval"
msgstr "" msgstr ""
msgid "Public IP"
msgstr ""
msgid "Public IP address"
msgstr ""
msgid "Reboot device" msgid "Reboot device"
msgstr "" msgstr ""