From 63ddfa1ed0b6aac0305151d63855f4b1e1985f58 Mon Sep 17 00:00:00 2001 From: gSpot Date: Tue, 27 May 2025 16:11:57 +0300 Subject: [PATCH] Running modules with pcall(). --- README.md | 30 +++++++++---------- internet-detector-mod-email/Makefile | 2 +- internet-detector-mod-modem-restart/Makefile | 2 +- internet-detector/Makefile | 2 +- .../usr/lib/lua/internet-detector/main.lua | 20 +++++++++++-- .../lua/internet-detector/mod_public_ip.lua | 2 +- luci-app-internet-detector/Makefile | 2 +- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 89a4d2a..80b2742 100644 --- a/README.md +++ b/README.md @@ -17,22 +17,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.4.5-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.5-r1_all.ipk - opkg install /tmp/internet-detector_1.4.5-r1_all.ipk - rm /tmp/internet-detector_1.4.5-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.4.6-r1_all.ipk + opkg install /tmp/internet-detector_1.4.6-r1_all.ipk + rm /tmp/internet-detector_1.4.6-r1_all.ipk service internet-detector start service internet-detector enable - wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.5-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.5-r1_all.ipk - opkg install /tmp/luci-app-internet-detector_1.4.5-r1_all.ipk - rm /tmp/luci-app-internet-detector_1.4.5-r1_all.ipk + wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.4.6-r1_all.ipk + opkg install /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk + rm /tmp/luci-app-internet-detector_1.4.6-r1_all.ipk service rpcd restart i18n-ru: - wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.5-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.5-r1_all.ipk - opkg install /tmp/luci-i18n-internet-detector-ru_1.4.5-r1_all.ipk - rm /tmp/luci-i18n-internet-detector-ru_1.4.5-r1_all.ipk + wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk + opkg install /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk + rm /tmp/luci-i18n-internet-detector-ru_1.4.6-r1_all.ipk ## Screenshots: @@ -44,9 +44,9 @@ i18n-ru: **Dependences:** modemmanager. - wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.5-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.5-r1_all.ipk - opkg install /tmp/internet-detector-mod-modem-restart_1.4.5-r1_all.ipk - rm /tmp/internet-detector-mod-modem-restart_1.4.5-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk + opkg install /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk + rm /tmp/internet-detector-mod-modem-restart_1.4.6-r1_all.ipk service internet-detector restart ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg) @@ -55,9 +55,9 @@ i18n-ru: **Dependences:** mailsend. - wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.5-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.5-r1_all.ipk - opkg install /tmp/internet-detector-mod-email_1.4.5-r1_all.ipk - rm /tmp/internet-detector-mod-email_1.4.5-r1_all.ipk + wget --no-check-certificate -O /tmp/internet-detector-mod-email_1.4.6-r1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector-mod-email_1.4.6-r1_all.ipk + opkg install /tmp/internet-detector-mod-email_1.4.6-r1_all.ipk + rm /tmp/internet-detector-mod-email_1.4.6-r1_all.ipk service internet-detector restart ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg) diff --git a/internet-detector-mod-email/Makefile b/internet-detector-mod-email/Makefile index 6b4a91a..66216a4 100644 --- a/internet-detector-mod-email/Makefile +++ b/internet-detector-mod-email/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector-mod-email -PKG_VERSION:=1.4.5 +PKG_VERSION:=1.4.6 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector-mod-modem-restart/Makefile b/internet-detector-mod-modem-restart/Makefile index ca401ec..1002087 100644 --- a/internet-detector-mod-modem-restart/Makefile +++ b/internet-detector-mod-modem-restart/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector-mod-modem-restart -PKG_VERSION:=1.4.5 +PKG_VERSION:=1.4.6 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector/Makefile b/internet-detector/Makefile index 0d9d312..c3f288a 100644 --- a/internet-detector/Makefile +++ b/internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector -PKG_VERSION:=1.4.5 +PKG_VERSION:=1.4.6 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/internet-detector/files/usr/lib/lua/internet-detector/main.lua b/internet-detector/files/usr/lib/lua/internet-detector/main.lua index ecdf64e..4ee5461 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/main.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/main.lua @@ -356,7 +356,16 @@ function InternetDetector:mainLoop() _RUNNING = true while _RUNNING do if counter == 0 or counter >= interval then - currentStatus = self:checkHosts() + if self.debug then + currentStatus = self:checkHosts() + else + local ret, status = pcall(self.checkHosts, self, currentStatus) + if ret then + currentStatus = status + else + self:writeLogMessage("err", "Unknown error while checking host!") + end + end if onStart or not stat.stat(self.statusFile) then self:writeValueToFile(self.statusFile, self:statusJson( currentStatus, self.serviceConfig.instance)) @@ -391,7 +400,14 @@ function InternetDetector:mainLoop() mTimeDiff = 1 end mLastTime = mTimeNow - e:run(currentStatus, lastStatus, mTimeDiff, mTimeNow, inetChecked) + if self.debug then + e:run(currentStatus, lastStatus, mTimeDiff, mTimeNow, inetChecked) + else + local ret = pcall(e.run, e, currentStatus, lastStatus, mTimeDiff, mTimeNow, inetChecked) + if not ret then + self:writeLogMessage("err", string.format("%s: Unknown error!", e.name)) + end + end end local modStatusChanged = false diff --git a/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua b/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua index ac5110c..20fc635 100644 --- a/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua +++ b/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua @@ -321,7 +321,7 @@ function Module:requestIP() end local retCode, response = self:sendUDPMessage(self._DNSPacket, server, port) - if retCode == 0 then + if retCode == 0 and response then local retTable = self:decodeMessage(response) if #retTable > 0 then res = table.concat(retTable, ", ") diff --git a/luci-app-internet-detector/Makefile b/luci-app-internet-detector/Makefile index 5a4b503..2cd9ec8 100644 --- a/luci-app-internet-detector/Makefile +++ b/luci-app-internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-internet-detector -PKG_VERSION:=1.4.5 +PKG_VERSION:=1.4.6 PKG_RELEASE:=1 LUCI_TITLE:=LuCI support for internet-detector LUCI_DEPENDS:=+internet-detector