Added selection of logging level.

This commit is contained in:
gSpot
2025-08-01 18:50:07 +03:00
parent fcd78c296c
commit eb93cd47b7
13 changed files with 131 additions and 102 deletions

View File

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

View File

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

View File

@@ -123,8 +123,8 @@ function Module:sendMessage(msg, textPattern)
-- Debug
if self.config.debug then
verboseArg = " -v"
self.debugOutput(string.format("--- %s ---", self.name))
end
self.debugOutput(string.format("--- %s ---", self.name))
local securityArgs = "-starttls -auth-login"
if self.mailSecurity == "ssl" then
@@ -140,10 +140,8 @@ function Module:sendMessage(msg, textPattern)
emailMsg)
-- Debug
if self.config.debug then
self.debugOutput(string.format("%s: %s", self.name, mtaCmd))
self.syslog("debug", string.format("%s: %s", self.name, mtaCmd))
end
self.debugOutput(string.format("%s: %s", self.name, mtaCmd))
self.syslog("debug", string.format("%s: %s", self.name, mtaCmd))
retVal = os.execute(mtaCmd)
if retVal == 0 then

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
config main 'config'
option mode '1'
option enable_logger '1'
option logging_level '6'
config instance 'internet'
option enabled '1'
@@ -22,13 +22,13 @@ config instance 'internet'
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_attempt_interval '15'
option mod_network_restart_attempt_interval '60'
option mod_network_restart_device_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_attempt_interval '15'
option mod_modem_restart_attempt_interval '60'
option mod_modem_restart_iface_timeout '0'
option mod_modem_restart_any_band '0'
option mod_public_ip_enabled '0'
@@ -52,11 +52,11 @@ config instance 'internet'
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_up_script_attempt_interval '15'
option mod_user_scripts_up_script_attempt_interval '60'
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_down_script_attempt_interval '15'
option mod_user_scripts_down_script_attempt_interval '60'
option mod_user_scripts_disconnected_at_startup '0'
option mod_regular_script_enabled '0'
option mod_regular_script_inet_state '2'

View File

@@ -13,7 +13,7 @@ local uci = require("uci")
local InternetDetector = {
mode = 0, -- 0: disabled, 1: Service, 2: UI detector
enableLogger = true,
loggingLevel = 6,
hostname = "OpenWrt",
appName = "internet-detector",
commonDir = "/tmp/run",
@@ -39,6 +39,16 @@ local InternetDetector = {
iface = nil,
instance = nil,
},
logLevels = {
emerg = { level = syslog.LOG_EMERG, num = 0 },
alert = { level = syslog.LOG_ALERT, num = 1 },
crit = { level = syslog.LOG_CRIT, num = 2 },
err = { level = syslog.LOG_ERR, num = 3 },
warning = { level = syslog.LOG_WARNING, num = 4 },
notice = { level = syslog.LOG_NOTICE, num = 5 },
info = { level = syslog.LOG_INFO, num = 6 },
debug = { level = syslog.LOG_DEBUG, num = 7 },
},
modules = {},
parsedHosts = {},
uiCounter = 0,
@@ -56,9 +66,9 @@ if mode ~= nil then
elseif err then
io.stderr:write(string.format("Error: %s\n", err))
end
local enableLogger, err = uciCursor:get(InternetDetector.appName, "config", "enable_logger")
if enableLogger ~= nil then
InternetDetector.enableLogger = (tonumber(enableLogger) ~= 0)
local loggingLevel, err = uciCursor:get(InternetDetector.appName, "config", "logging_level")
if loggingLevel ~= nil then
InternetDetector.loggingLevel = tonumber(loggingLevel)
elseif err then
io.stderr:write(string.format("Error: %s\n", err))
end
@@ -141,19 +151,12 @@ function InternetDetector:statusJson(inet, instance, t)
end
function InternetDetector:writeLogMessage(level, msg)
if self.enableLogger then
local levels = {
emerg = syslog.LOG_EMERG,
alert = syslog.LOG_ALERT,
crit = syslog.LOG_CRIT,
err = syslog.LOG_ERR,
warning = syslog.LOG_WARNING,
notice = syslog.LOG_NOTICE,
info = syslog.LOG_INFO,
debug = syslog.LOG_DEBUG,
}
syslog.syslog(levels[level] or syslog.LOG_INFO, string.format(
"%s: %s", self.serviceConfig.instance or "", msg))
local levelItem = self.logLevels[level]
local levelValue = (levelItem and levelItem.level) or self.logLevels["info"].level
local num = (levelItem and levelItem.num) or self.logLevels["info"].num
if num <= self.loggingLevel then
syslog.syslog(levelValue, string.format(
"%s: %s", self.serviceConfig.instance or "", msg))
end
end
@@ -246,6 +249,7 @@ function InternetDetector:TCPConnectionToHost(host, port)
"GETADDRINFO ERROR: %s, %s", errMsg, errNum))
else
local family = saTable[1].family
if family then
local sock, errMsg, errNum = socket.socket(family, socket.SOCK_STREAM, 0)
@@ -431,7 +435,6 @@ function InternetDetector:mainLoop()
self.uiCounter = self.uiCounter + 1
end
uiLastTime = uiTimeNow
if self.uiCounter >= self.uiRunTime then
self:breakMainLoop(signal.SIGTERM)
end
@@ -562,7 +565,7 @@ end
function InternetDetector:run()
local pidValue = unistd.getpid()
self:writeValueToFile(self.pidFile, pidValue)
if self.enableLogger then
if self.loggingLevel > 0 then
syslog.openlog(self.appName, syslog.LOG_PID, syslog.LOG_DAEMON)
end
self:writeLogMessage("info", "started")
@@ -610,7 +613,7 @@ function InternetDetector:run()
end
self:removeProcessFiles()
if self.enableLogger then
if self.loggingLevel > 0 then
self:writeLogMessage("info", "stoped")
syslog.closelog()
end
@@ -651,7 +654,7 @@ function InternetDetector:setServiceConfig(instance)
if self:loadUCIConfig("instance", instance) then
self:parseHosts()
if self.mode == 2 then
self.enableLogger = false
self.loggingLevel = 0
self.noModules = true
end
return true

View File

@@ -211,28 +211,26 @@ function Module:sendUDPMessage(message, server, port)
if data then
success = true
response = resp
elseif self.config.debug then
else
self.debugOutput(string.format(
"SOCKET RECV ERROR: %s, %s", tostring(resp), tostring(errNum)))
end
elseif self.config.debug then
else
self.debugOutput(string.format(
"SOCKET SEND ERROR: %s, %s", tostring(errMsg), tostring(errNum)))
end
if self.config.debug then
self.debugOutput(string.format(
"--- UDP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nserver = %s:%s\nsockname = %s:%s\nsuccess = %s",
os.time(),
self.timeout,
tostring(self.config.serviceConfig.iface),
server,
tostring(port),
tostring(response.addr),
tostring(response.port),
tostring(success))
)
end
self.debugOutput(string.format(
"--- UDP ---\ntime = %s\nconnection_timeout = %s\niface = %s\nserver = %s:%s\nsockname = %s:%s\nsuccess = %s",
os.time(),
self.timeout,
tostring(self.config.serviceConfig.iface),
server,
tostring(port),
tostring(response.addr),
tostring(response.port),
tostring(success))
)
unistd.close(sock)
retCode = success and 0 or 1

View File

@@ -5,8 +5,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-internet-detector
PKG_VERSION:=1.6.0
PKG_RELEASE:=2
PKG_VERSION:=1.6.1
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector
LUCI_PKGARCH:=all

View File

@@ -710,13 +710,19 @@ return view.extend({
if(this.currentAppMode !== '2') {
// enable_logger
o = s.option(form.Flag, 'enable_logger',
_('Enable logging'),
_('Write messages to the system log.')
// logging_level
o = s.option(form.ListValue, 'logging_level',
_('Logging'),
_('Log event level.')
);
o.value(-1, _('Disabled'));
o.value(3, _('Error'));
o.value(4, _('Warning'));
o.value(5, _('Notice'));
o.value(6, _('Info'));
o.value(7, _('Debug'));
o.rmempty = false;
o.default = '1';
o.default = '6';
};
s = m.section(form.GridSection, 'instance');
@@ -881,11 +887,11 @@ return view.extend({
// LED control
o = s.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('<abbr title="Light Emitting Diode">LED</abbr> indicates the Internet status.') +
'</div>';
o = s.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('<abbr title="Light Emitting Diode">LED</abbr> indicates the Internet status.') +
'</div>';
o.modalonly = true;
if(this.leds.length > 0) {
@@ -1521,11 +1527,11 @@ return view.extend({
// User scripts
o = s.taboption('user_scripts', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Shell commands to run when connected or disconnected from the Internet.') +
'</div>';
o = s.taboption('user_scripts', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Shell commands to run when connected or disconnected from the Internet.') +
'</div>';
o.modalonly = true;
// enabled
@@ -1600,11 +1606,11 @@ return view.extend({
// down-script tab
ss.tab('user_scripts_down_script', 'down-script');
o = ss.taboption('user_scripts_down_script', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Shell commands to run when disconnected from the Internet.') +
'</div>';
o = ss.taboption('user_scripts_down_script', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Shell commands to run when disconnected from the Internet.') +
'</div>';
o.modalonly = true;
// down_script edit

View File

@@ -98,6 +98,9 @@ msgstr "Интервал при отключении"
msgid "Dead period"
msgstr "Период после отключения"
msgid "Debug"
msgstr "Отладка"
msgid "Default port value for TCP connections."
msgstr "Стандартное значение порта для TCP-подключений."
@@ -152,9 +155,6 @@ msgstr "Email-адрес отправителя."
msgid "Enable"
msgstr "Включить"
msgid "Enable logging"
msgstr "Запись событий в лог"
msgid "Enable public-ip-script"
msgstr "Включить public-ip-script"
@@ -219,6 +219,9 @@ msgstr "Размер данных ICMP-пакета"
msgid "Incorrect bot token?"
msgstr "Неправильный токен бота?"
msgid "Info"
msgstr "Информация"
msgid "Instances"
msgstr "Экземпляры"
@@ -267,6 +270,12 @@ msgstr "Управление LED"
msgid "Loading"
msgstr "Загрузка"
msgid "Log event level."
msgstr "Уровень событий лога."
msgid "Logging"
msgstr "Запись событий в лог"
msgid "Mailsend is not available..."
msgstr "Mailsend недоступен..."
@@ -338,6 +347,9 @@ msgstr "Нет доступных сообщений. Напишите что-н
msgid "Not scheduled"
msgstr "Не запланирован"
msgid "Notice"
msgstr "Сообщение"
msgid "Number of attempts to request an IP address."
msgstr "Количество попыток запроса IP адреса"
@@ -582,6 +594,9 @@ msgstr ""
"Ожидание завершения перезагрузки перед выполнением принудительной "
"перезагрузки."
msgid "Warning"
msgstr "Внимание"
msgid "Web UI only (UI detector)"
msgstr "Только web-интерфейс (UI детектор)"
@@ -599,9 +614,6 @@ msgstr "Когда будет отправлено сообщение"
msgid "Windows: 32 bytes"
msgstr "Windows: 32 байта"
msgid "Write messages to the system log."
msgstr "Записывать сообщения в системный журнал."
msgid ""
"You need to register a new %sTelegram bot%s. Then get the bot's API token and paste it into the <code>Bot token</code> field. After that, open a chat with the bot, write something (in the Telegram app) and you will be able to get the chat ID using the <code>ID</code> button."
msgstr ""

View File

@@ -86,6 +86,9 @@ msgstr ""
msgid "Dead period"
msgstr ""
msgid "Debug"
msgstr ""
msgid "Default port value for TCP connections."
msgstr ""
@@ -140,9 +143,6 @@ msgstr ""
msgid "Enable"
msgstr ""
msgid "Enable logging"
msgstr ""
msgid "Enable public-ip-script"
msgstr ""
@@ -205,6 +205,9 @@ msgstr ""
msgid "Incorrect bot token?"
msgstr ""
msgid "Info"
msgstr ""
msgid "Instances"
msgstr ""
@@ -253,6 +256,12 @@ msgstr ""
msgid "Loading"
msgstr ""
msgid "Log event level."
msgstr ""
msgid "Logging"
msgstr ""
msgid "Mailsend is not available..."
msgstr ""
@@ -313,6 +322,9 @@ msgstr ""
msgid "Not scheduled"
msgstr ""
msgid "Notice"
msgstr ""
msgid "Number of attempts to request an IP address."
msgstr ""
@@ -552,6 +564,9 @@ msgstr ""
msgid "Waiting for a reboot to complete before performing a forced reboot."
msgstr ""
msgid "Warning"
msgstr ""
msgid "Web UI only (UI detector)"
msgstr ""
@@ -567,9 +582,6 @@ msgstr ""
msgid "Windows: 32 bytes"
msgstr ""
msgid "Write messages to the system log."
msgstr ""
msgid ""
"You need to register a new %sTelegram bot%s. Then get the bot's API token and paste it into the <code>Bot token</code> field. After that, open a chat with the bot, write something (in the Telegram app) and you will be able to get the chat ID using the <code>ID</code> button."
msgstr ""