From 617908f5b8813ce74ad0a649e53fd443e719eb1f Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Mon, 24 Mar 2025 00:24:10 +0800 Subject: [PATCH] update 2025-03-24 00:24:10 --- luci-app-internet-detector/README.md | 30 ++--- .../internet-detector-mod-email/Makefile | 2 +- .../Makefile | 2 +- .../internet-detector/Makefile | 2 +- .../files/etc/config/internet-detector | 4 +- .../lua/internet-detector/mod_led_control.lua | 12 +- .../lua/internet-detector/mod_public_ip.lua | 109 +++++++++++------- .../luci-app-internet-detector/Makefile | 2 +- .../resources/view/internet-detector.js | 24 ++++ .../po/ru/internet-detector.po | 22 +++- .../po/templates/internet-detector.pot | 20 +++- .../luasrc/controller/shadowsocksr.lua | 2 +- .../model/cbi/shadowsocksr/advanced.lua | 6 +- .../model/cbi/shadowsocksr/client-config.lua | 67 +++++++++-- .../luasrc/model/cbi/shadowsocksr/client.lua | 4 +- .../luasrc/model/cbi/shadowsocksr/server.lua | 12 +- .../luasrc/model/cbi/shadowsocksr/servers.lua | 57 ++++++++- .../luasrc/model/cbi/shadowsocksr/status.lua | 2 +- .../luasrc/view/shadowsocksr/server_list.htm | 20 +++- .../luasrc/view/shadowsocksr/ssrurl.htm | 42 +++++-- luci-app-ssr-plus/po/zh_Hans/ssr-plus.po | 15 ++- .../root/etc/init.d/shadowsocksr | 100 ++++++++++++++-- .../root/usr/share/shadowsocksr/subscribe.lua | 19 ++- .../root/usr/share/shadowsocksr/update.lua | 2 +- 24 files changed, 430 insertions(+), 147 deletions(-) diff --git a/luci-app-internet-detector/README.md b/luci-app-internet-detector/README.md index b5c978ea2..73e233bdf 100644 --- a/luci-app-internet-detector/README.md +++ b/luci-app-internet-detector/README.md @@ -15,22 +15,22 @@ Internet-detector is an application for checking the availability of the Interne ## Installation notes (OpenWrt >= 21.02) 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 - opkg install /tmp/internet-detector_1.4.3-r1_all.ipk - rm /tmp/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.4-r1_all.ipk + rm /tmp/internet-detector_1.4.4-r1_all.ipk service internet-detector start 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 - opkg install /tmp/luci-app-internet-detector_1.4.3-r1_all.ipk - rm /tmp/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.4-r1_all.ipk + rm /tmp/luci-app-internet-detector_1.4.4-r1_all.ipk service rpcd restart 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 - opkg install /tmp/luci-i18n-internet-detector-ru_1.4.3-r1_all.ipk - rm /tmp/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.4-r1_all.ipk + rm /tmp/luci-i18n-internet-detector-ru_1.4.4-r1_all.ipk ## Screenshots: @@ -42,9 +42,9 @@ i18n-ru: **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 - opkg install /tmp/internet-detector-mod-modem-restart_1.4.3-r1_all.ipk - rm /tmp/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.4-r1_all.ipk + rm /tmp/internet-detector-mod-modem-restart_1.4.4-r1_all.ipk service internet-detector restart ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/04.jpg) @@ -53,9 +53,9 @@ i18n-ru: **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 - opkg install /tmp/internet-detector-mod-email_1.4.3-r1_all.ipk - rm /tmp/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.4-r1_all.ipk + rm /tmp/internet-detector-mod-email_1.4.4-r1_all.ipk service internet-detector restart ![](https://github.com/gSpotx2f/luci-app-internet-detector/blob/master/screenshots/05.jpg) diff --git a/luci-app-internet-detector/internet-detector-mod-email/Makefile b/luci-app-internet-detector/internet-detector-mod-email/Makefile index af889efd1..5efd4376a 100644 --- a/luci-app-internet-detector/internet-detector-mod-email/Makefile +++ b/luci-app-internet-detector/internet-detector-mod-email/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector-mod-email -PKG_VERSION:=1.4.3 +PKG_VERSION:=1.4.4 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/luci-app-internet-detector/internet-detector-mod-modem-restart/Makefile b/luci-app-internet-detector/internet-detector-mod-modem-restart/Makefile index 3facca500..27a2eda1a 100644 --- a/luci-app-internet-detector/internet-detector-mod-modem-restart/Makefile +++ b/luci-app-internet-detector/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.3 +PKG_VERSION:=1.4.4 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/luci-app-internet-detector/internet-detector/Makefile b/luci-app-internet-detector/internet-detector/Makefile index 505a56771..7d3d7e206 100644 --- a/luci-app-internet-detector/internet-detector/Makefile +++ b/luci-app-internet-detector/internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=internet-detector -PKG_VERSION:=1.4.3 +PKG_VERSION:=1.4.4 PKG_RELEASE:=1 PKG_MAINTAINER:=gSpot diff --git a/luci-app-internet-detector/internet-detector/files/etc/config/internet-detector b/luci-app-internet-detector/internet-detector/files/etc/config/internet-detector index 720aa5804..42f70dbf0 100644 --- a/luci-app-internet-detector/internet-detector/files/etc/config/internet-detector +++ b/luci-app-internet-detector/internet-detector/files/etc/config/internet-detector @@ -28,7 +28,9 @@ config instance 'internet' option mod_public_ip_provider 'opendns1' option mod_public_ip_qtype '0' 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_email_enabled '0' option mod_email_mode '0' diff --git a/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_led_control.lua b/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_led_control.lua index 88454d86a..c9c8b8996 100644 --- a/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_led_control.lua +++ b/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_led_control.lua @@ -76,11 +76,11 @@ function Module:init(t) end end -function Module:SetTriggerTimer(t) +function Module:setTriggerTimer(t) self.writeValue(t.ledTriggerFile, "timer") end -function Module:SetTriggerNone(t) +function Module:setTriggerNone(t) self.writeValue(t.ledTriggerFile, "none") end @@ -92,12 +92,12 @@ function Module:getCurrentTrigger(t) end function Module:on(t) - self:SetTriggerNone(t) + self:setTriggerNone(t) self.writeValue(t.ledBrightnessFile, t.ledMaxBrightness) end function Module:off(t) - self:SetTriggerNone(t) + self:setTriggerNone(t) self.writeValue(t.ledBrightnessFile, 0) end @@ -120,7 +120,7 @@ function Module:ledRunFunc(t, currentStatus) end elseif t.ledAction1 == 3 then if not self:getCurrentTrigger(t) then - self:SetTriggerTimer(t) + self:setTriggerTimer(t) end end else @@ -134,7 +134,7 @@ function Module:ledRunFunc(t, currentStatus) end elseif t.ledAction2 == 3 then if not self:getCurrentTrigger(t) then - self:SetTriggerTimer(t) + self:setTriggerTimer(t) end end end diff --git a/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua b/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua index a62d0c0af..be374b4e1 100644 --- a/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua +++ b/luci-app-internet-detector/internet-detector/files/usr/lib/lua/internet-detector/mod_public_ip.lua @@ -4,23 +4,25 @@ local stdlib = require("posix.stdlib") local unistd = require("posix.unistd") local Module = { - name = "mod_public_ip", - runPrio = 50, - config = { - noModules = false, - debug = false, + name = "mod_public_ip", + runPrio = 50, + config = { + noModules = false, + debug = false, serviceConfig = { iface = nil, }, }, - syslog = function(level, msg) return true end, - writeValue = function(filePath, str) return false end, - readValue = function(filePath) return nil end, - port = 53, - runInterval = 600, - runIntervalFailed = 60, - timeout = 3, - providers = { + syslog = function(level, msg) return true end, + writeValue = function(filePath, str) return false end, + readValue = function(filePath) return nil end, + port = 53, + runInterval = 600, + runIntervalFailed = 60, + runIntervalDNSFailed = 1, + requestAttempts = 2, + timeout = 3, + providers = { opendns1 = { name = "opendns1", host = "myip.opendns.com", server = "208.67.222.222", server6 = "2620:119:35::35", @@ -52,16 +54,18 @@ local Module = { port = 53, queryType = "TXT", queryType6 = "TXT", }, }, - ipScript = "", - enableIpScript = false, - status = nil, - _provider = nil, - _qtype = false, - _currentIp = nil, - _enabled = false, - _counter = 0, - _interval = 600, - _DNSPacket = nil, + ipScript = "", + enableIpScript = false, + status = nil, + _provider = nil, + _qtype = false, + _currentIp = nil, + _lastResolvedIp = nil, + _enabled = false, + _counter = 0, + _DNSFalseCounter = 0, + _interval = 600, + _DNSPacket = nil, } function Module:runIpScript() @@ -306,7 +310,7 @@ function Module:decodeMessage(message) return retTable end -function Module:resolveIP() +function Module:requestIP() local res local qtype = self._qtype and self._provider.queryType6 or self._provider.queryType local server = self._qtype and self._provider.server6 or self._provider.server @@ -324,7 +328,7 @@ function Module:resolveIP() end else 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 return res @@ -334,6 +338,12 @@ function Module:init(t) if t.interval ~= nil then self.runInterval = tonumber(t.interval) 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 self.timeout = tonumber(t.timeout) end @@ -352,10 +362,12 @@ function Module:init(t) if t.qtype ~= nil then self._qtype = (tonumber(t.qtype) ~= 0) end - self._currentIp = nil - self._DNSPacket = nil - self._interval = self.runInterval - self._enabled = true + self._currentIp = nil + self._lastResolvedIp = nil + self._DNSPacket = nil + self._interval = self.runInterval + self._DNSFalseCounter = 0 + self._enabled = true end 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 self._counter == 0 or self._counter >= self._interval or currentStatus ~= lastStatus then - local ip = self:resolveIP() + local ip = self:requestIP() if not ip then - ip = "" - self._interval = self.runIntervalFailed + ip = "" + 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 - self._interval = self.runInterval + self._interval = self.runInterval + self._DNSFalseCounter = 0 end if ip ~= self._currentIp then self.status = ip - self.syslog( - "notice", - string.format("%s: public IP address %s", self.name, (ip == "") and "Undefined" or ip) - ) - if self._counter > 0 then - self:runIpScript() + if ip ~= "" then + if self._counter > 0 and ip ~= self._lastResolvedIp then + self.syslog( + "notice", + string.format("%s: public IP address changed to %s", self.name, ip) + ) + self:runIpScript() + end + self._lastResolvedIp = ip end end self._currentIp = ip self._counter = 0 end else - self._currentIp = nil - self.status = self._currentIp - self._counter = 0 - self._interval = self.runInterval + self._currentIp = nil + self.status = self._currentIp + self._DNSFalseCounter = 0 + self._counter = 0 + self._interval = self.runInterval end self._counter = self._counter + timeDiff end diff --git a/luci-app-internet-detector/luci-app-internet-detector/Makefile b/luci-app-internet-detector/luci-app-internet-detector/Makefile index b46eb3ca9..705359914 100644 --- a/luci-app-internet-detector/luci-app-internet-detector/Makefile +++ b/luci-app-internet-detector/luci-app-internet-detector/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-internet-detector -PKG_VERSION:=1.4.3 +PKG_VERSION:=1.4.4 PKG_RELEASE:=1 LUCI_TITLE:=LuCI support for internet-detector LUCI_DEPENDS:=+internet-detector diff --git a/luci-app-internet-detector/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js b/luci-app-internet-detector/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js index 0bd4e6c62..a2cc34a50 100644 --- a/luci-app-internet-detector/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js +++ b/luci-app-internet-detector/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js @@ -1038,6 +1038,30 @@ return view.extend({ o.value(3600, '1' + ' ' + _('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 o = s.taboption('public_ip', form.ListValue, 'mod_public_ip_timeout', _('Server response timeout') diff --git a/luci-app-internet-detector/luci-app-internet-detector/po/ru/internet-detector.po b/luci-app-internet-detector/luci-app-internet-detector/po/ru/internet-detector.po index 62e07593b..3a926e156 100644 --- a/luci-app-internet-detector/luci-app-internet-detector/po/ru/internet-detector.po +++ b/luci-app-internet-detector/luci-app-internet-detector/po/ru/internet-detector.po @@ -44,6 +44,9 @@ msgstr "Сообщение будет отправлено при подключ msgid "An error has occurred" msgstr "Произошла ошибка" +msgid "Attempts" +msgstr "Попытки" + msgid "Big: 248 bytes" msgstr "Большой: 248 байт" @@ -149,11 +152,8 @@ msgstr "Включен" msgid "Expecting:" msgstr "Ожидается:" -msgid "Public IP" -msgstr "Публичный IP" - -msgid "Public IP address" -msgstr "Публичный IP адрес" +msgid "Failed interval" +msgstr "Интервал при неудаче" msgid "Failed to get %s init status: %s" msgstr "Не удалось получить статус инициализации %s: %s" @@ -216,6 +216,9 @@ msgstr "Статус Интернет" msgid "Interval between IP address requests." msgstr "Интервал между запросами IP адреса." +msgid "Interval between IP address requests if the IP address is not defined." +msgstr "Интервал между запросами IP адреса, если IP адрес не определён." + msgid "Jumbo: 9000 bytes" msgstr "Гигантский: 9000 байт" @@ -282,6 +285,9 @@ msgstr "Нет доступных LED. msgid "Not scheduled" msgstr "Не запланирован" +msgid "Number of attempts to request an IP address." +msgstr "Количество попыток запроса IP адреса" + msgid "Off" msgstr "Выключить" @@ -332,6 +338,12 @@ msgstr "Регулярный скрипт" msgid "Polling interval" msgstr "Интервал опроса" +msgid "Public IP" +msgstr "Публичный IP" + +msgid "Public IP address" +msgstr "Публичный IP адрес" + msgid "Reboot device" msgstr "Перезагрузка устройства" diff --git a/luci-app-internet-detector/luci-app-internet-detector/po/templates/internet-detector.pot b/luci-app-internet-detector/luci-app-internet-detector/po/templates/internet-detector.pot index 5572b8886..eee4aba14 100644 --- a/luci-app-internet-detector/luci-app-internet-detector/po/templates/internet-detector.pot +++ b/luci-app-internet-detector/luci-app-internet-detector/po/templates/internet-detector.pot @@ -32,6 +32,9 @@ msgstr "" msgid "An error has occurred" msgstr "" +msgid "Attempts" +msgstr "" + msgid "Big: 248 bytes" msgstr "" @@ -137,10 +140,7 @@ msgstr "" msgid "Expecting:" msgstr "" -msgid "Public IP" -msgstr "" - -msgid "Public IP address" +msgid "Failed interval" msgstr "" msgid "Failed to get %s init status: %s" @@ -202,6 +202,9 @@ msgstr "" msgid "Interval between IP address requests." msgstr "" +msgid "Interval between IP address requests if the IP address is not defined." +msgstr "" + msgid "Jumbo: 9000 bytes" msgstr "" @@ -260,6 +263,9 @@ msgstr "" msgid "Not scheduled" msgstr "" +msgid "Number of attempts to request an IP address." +msgstr "" + msgid "Off" msgstr "" @@ -307,6 +313,12 @@ msgstr "" msgid "Polling interval" msgstr "" +msgid "Public IP" +msgstr "" + +msgid "Public IP address" +msgstr "" + msgid "Reboot device" msgstr "" diff --git a/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua b/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua index 31989b01a..4ba5d0684 100644 --- a/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua +++ b/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua @@ -96,7 +96,7 @@ function check_port() local retstring = "

" local s local server_name = "" - local uci = luci.model.uci.cursor() + local uci = require "luci.model.uci".cursor() local iret = 1 uci:foreach("shadowsocksr", "servers", function(s) if s.alias then diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua index 0cb47f0af..593d8f2dd 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua @@ -1,9 +1,9 @@ local m, s, o -local uci = luci.model.uci.cursor() +local uci = require "luci.model.uci".cursor() local server_table = {} local type_table = {} local function is_finded(e) - return luci.sys.exec('type -t -p "%s"' % e) ~= "" and true or false + return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= "" end uci:foreach("shadowsocksr", "servers", function(s) @@ -203,6 +203,7 @@ for key, server_type in pairs(type_table) do o:depends("server", key) end end +o:depends({server = "same", disable = true}) -- Socks User o = s:option(Value, "socks5_user", translate("Socks5 User"), translate("Only when Socks5 Auth Mode is password valid, Mandatory.")) @@ -225,6 +226,7 @@ for key, server_type in pairs(type_table) do o:depends("server", key) end end +o:depends({server = "same", disable = true}) end -- Local Port diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index d3e668f8a..7f4768625 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -6,19 +6,29 @@ require "luci.sys" require "luci.http" require "luci.jsonc" require "luci.model.ipkg" +require "luci.model.uci" +local uci = require "luci.model.uci".cursor() local m, s, o + local sid = arg[1] local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid") +-- 确保正确判断程序是否存在 local function is_finded(e) - return luci.sys.exec('type -t -p "%s"' % e) ~= "" and true or false + return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= "" end local function is_installed(e) return luci.model.ipkg.installed(e) end +local has_ss_rust = is_finded("sslocal") or is_finded("ssserver") +local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local") + +-- 读取当前存储的 ss_type +local ss_type = uci:get_first("shadowsocksr", "server_subscribe", "ss_type") + local server_table = {} local encrypt_methods = { -- ssr @@ -79,7 +89,7 @@ local encrypt_methods_ss = { "camellia-256-cfb", "salsa20", "chacha20", - "chacha20-ietf" ]] + "chacha20-ietf" ]]-- } local protocol = { @@ -146,8 +156,8 @@ end if is_finded("ssr-redir") then o:value("ssr", translate("ShadowsocksR")) end -if is_finded("ss-local") or is_finded("ss-redir") or is_finded("sslocal") or is_finded("ssmanager") then - o:value("ss", translate("Shadowsocks")) +if has_ss_rust or has_ss_libev then + o:value("ss", translate("ShadowSocks")) end if is_finded("trojan") then o:value("trojan", translate("Trojan")) @@ -185,16 +195,44 @@ o:depends("type", "tun") o.description = translate("Redirect traffic to this network interface") -- 新增一个选择框,用于选择 Shadowsocks 版本 -o = s:option(ListValue, "ss_variant", translate("Shadowsocks Variant")) -local isSSRust = is_finded("sslocal") or is_finded("ssmanager") -local isSSLibev = is_finded("ss-local") or is_finded("ss-redir") -if isSSRust then - o:value("isSSRust", translate("Shadowsocks-rust Version")) +o = s:option(ListValue, "has_ss_type", string.format("%s", translate("ShadowSocks Node Use Version"))) +o.description = translate("Selection ShadowSocks Node Use Version.") +-- 设置默认 Shadowsocks 版本 +-- 动态添加选项 +if has_ss_rust then + o:value("ss-rust", translate("ShadowSocks-rust Version")) end -if isSSLibev then - o:value("isSSLibev", translate("Shadowsocks-libev Version")) +if has_ss_libev then + o:value("ss-libev", translate("ShadowSocks-libev Version")) +end +-- 设置默认值 +if ss_type == "ss-rust" then + o.default = "ss-rust" +elseif ss_type == "ss-libev" then + o.default = "ss-libev" end o:depends("type", "ss") +o.write = function(self, section, value) + -- 更新 Shadowsocks 节点的 has_ss_type + uci:foreach("shadowsocksr", "servers", function(s) + local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型 + if node_type == "ss" then -- 仅修改 Shadowsocks 节点 + local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type") + if old_value ~= value then + uci:set("shadowsocksr", s[".name"], "has_ss_type", value) + end + end + end) + + -- 更新 server_subscribe 的 ss_type + local old_value = uci:get("shadowsocksr", "server_subscribe", "ss_type") + if old_value ~= value then + uci:set("shadowsocksr", "@server_subscribe[0]", "ss_type", value) + end + + -- 更新当前 section 的 has_ss_type + Value.write(self, section, value) +end o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol")) o:value("vless", translate("VLESS")) @@ -271,7 +309,12 @@ o:depends("type", "ssr") o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method")) for _, v in ipairs(encrypt_methods_ss) do - o:value(v) + if v == "none" then + o.default = "none" + o:value("none", translate("none")) + else + o:value(v, translate(v)) + end end o.rmempty = true o:depends("type", "ss") diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client.lua index 26de9baa4..6e209e1a9 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client.lua @@ -3,11 +3,11 @@ -- Licensed to the public under the GNU General Public License v3. local m, s, sec, o -local uci = luci.model.uci.cursor() +local uci = require "luci.model.uci".cursor() local validation = require "luci.cbi.datatypes" local function is_finded(e) - return luci.sys.exec('type -t -p "%s"' % e) ~= "" and true or false + return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= "" end m = Map("shadowsocksr", translate("ShadowSocksR Plus+ Settings"), translate("

Support SS/SSR/V2RAY/XRAY/TROJAN/NAIVEPROXY/SOCKS5/TUN etc.

")) diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/server.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/server.lua index 6ef44c080..db3160ab4 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/server.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/server.lua @@ -120,15 +120,9 @@ function o.cfgvalue(...) end o = sec:option(DummyValue, "encrypt_method", translate("Encrypt Method")) -function o.cfgvalue(...) - local v = Value.cfgvalue(...) - return v and v:upper() or "-" -end - -o = sec:option(DummyValue, "encrypt_method_ss", translate("Encrypt Method")) -function o.cfgvalue(...) - local v = Value.cfgvalue(...) - return v and v:upper() or "-" +function o.cfgvalue(self, section) + local method = self.map:get(section, "encrypt_method") or self.map:get(section, "encrypt_method_ss") + return method and method:upper() or "-" end o = sec:option(DummyValue, "protocol", translate("Protocol")) diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua index 991884858..ac1bbc6f2 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua @@ -1,10 +1,39 @@ -- Licensed to the public under the GNU General Public License v3. require "luci.http" +require "luci.sys" require "luci.dispatcher" require "luci.model.uci" -local m, s, o -local uci = luci.model.uci.cursor() +local uci = require "luci.model.uci".cursor() + +local m, s, o, node local server_count = 0 + +-- 确保正确判断程序是否存在 +local function is_finded(e) + return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= "" +end + +local has_ss_rust = is_finded("sslocal") or is_finded("ssserver") +local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local") + +local ss_type_list = {} + +if has_ss_rust then + table.insert(ss_type_list, { id = "ss-rust", name = translate("ShadowSocks-rust Version") }) +end +if has_ss_libev then + table.insert(ss_type_list, { id = "ss-libev", name = translate("ShadowSocks-libev Version") }) +end + +-- 如果用户没有手动设置,则自动选择 +if ss_type == "" then + if has_ss_rust then + ss_type = "ss-rust" + elseif has_ss_libev then + ss_type = "ss-libev" + end +end + uci:foreach("shadowsocksr", "servers", function(s) server_count = server_count + 1 end) @@ -48,6 +77,30 @@ o.default = 30 o.rmempty = true o:depends("auto_update", "1") +-- 确保 ss_type_list 不为空 +if #ss_type_list > 0 then + o = s:option(ListValue, "ss_type", string.format("%s", translate("ShadowSocks Node Use Version"))) + o.description = translate("Selection ShadowSocks Node Use Version.") + for _, v in ipairs(ss_type_list) do + o:value(v.id, v.name) -- 存储 "ss-libev" / "ss-rust",但 UI 显示完整名称 + end + o.default = ss_type -- 设置默认值 + o.write = function(self, section, value) + -- 更新 Shadowsocks 节点的 has_ss_type + uci:foreach("shadowsocksr", "servers", function(s) + local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型 + if node_type == "ss" then -- 仅修改 Shadowsocks 节点 + local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type") + if old_value ~= value then + uci:set("shadowsocksr", s[".name"], "has_ss_type", value) + end + end + end) + -- 更新当前 section 的 ss_type + Value.write(self, section, value) + end +end + o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL")) o.rmempty = true diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/status.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/status.lua index c7e84ec69..21b7c70d6 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/status.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/status.lua @@ -15,7 +15,7 @@ local ad_count = 0 local ip_count = 0 local nfip_count = 0 local Process_list = luci.sys.exec("busybox ps -w") -local uci = luci.model.uci.cursor() +local uci = require "luci.model.uci".cursor() -- html constants font_blue = [[]] style_blue = [[]] diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm index f9befe53f..2ba1be910 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm @@ -87,8 +87,18 @@ } // set tr draggable - function enableDragForTable(table_selecter, store) { - var trs = document.querySelectorAll(table_selecter + " tr"); + function enableDragForTable(table_selector, store) { + // 添加 CSS 样式 + const style = document.createElement("style"); + style.textContent = ` + tr[draggable="true"] { + cursor: move; + user-select: none; + } + `; + document.head.appendChild(style); + + var trs = document.querySelectorAll(table_selector + " tr"); if (!trs || trs.length.length < 3) { return; } @@ -104,12 +114,12 @@ ev.dataTransfer.dropEffect = "move"; } function moveToTop(id) { - var top = document.querySelectorAll(table_selecter + " tr")[2]; + var top = document.querySelectorAll(table_selector + " tr")[2]; cbi_row_drop(id, top.id, store); } function moveToBottom(id) { - console.log('moveToBottom:', id); - var trList = document.querySelectorAll(table_selecter + " tr"); + //console.log('moveToBottom:', id); + var trList = document.querySelectorAll(table_selector + " tr"); var bottom = trList[trList.length - 1]; cbi_row_drop(id, bottom.id, store, true); } diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm index d38d2121e..72170dd5b 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm @@ -1,6 +1,12 @@ <%+cbi/valueheader%> +<% +local map = self.map +local ss_type = map:get("@server_subscribe[0]", "ss_type") +-%>