diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile index 07f4ea617..5fff07799 100644 --- a/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile @@ -34,7 +34,7 @@ PKG_CONFIG_DEPENDS:= \ LUCI_TITLE:=LuCI support for PassWall LUCI_PKGARCH:=all LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \ - +chinadns-ng +dns2socks +dns2tcp +dnsmasq-full +ip-full \ + +chinadns-ng +dns2socks +dnsmasq-full +ip-full \ +libuci-lua +lua +luci-compat +luci-lib-jsonc \ +microsocks +resolveip +tcping diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 446186edf..ba84fc9b9 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -5,10 +5,10 @@ module("luci.controller.passwall", package.seeall) local api = require "luci.passwall.api" local appname = "passwall" -- not available local uci = api.libuci -- in funtion index() +local fs = api.fs local http = require "luci.http" local util = require "luci.util" local i18n = require "luci.i18n" -local fs = require "nixio.fs" function index() if not nixio.fs.access("/etc/config/passwall") then @@ -19,6 +19,7 @@ function index() local api = require "luci.passwall.api" local appname = "passwall" -- global definitions not available local uci = api.libuci -- in function index() + local fs = api.fs entry({"admin", "services", appname}).dependent = true entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true @@ -36,7 +37,7 @@ function index() entry({"admin", "services", appname, "node_list"}, cbi(appname .. "/client/node_list"), _("Node List"), 2).dependent = true entry({"admin", "services", appname, "node_subscribe"}, cbi(appname .. "/client/node_subscribe"), _("Node Subscribe"), 3).dependent = true entry({"admin", "services", appname, "other"}, cbi(appname .. "/client/other", {autoapply = true}), _("Other Settings"), 92).leaf = true - if nixio.fs.access("/usr/sbin/haproxy") then + if fs.access("/usr/sbin/haproxy") then entry({"admin", "services", appname, "haproxy"}, cbi(appname .. "/client/haproxy"), _("Load Balancing"), 93).leaf = true end entry({"admin", "services", appname, "app_update"}, cbi(appname .. "/client/app_update"), _("App Update"), 95).leaf = true @@ -186,10 +187,10 @@ function get_redir_log() local proto = luci.http.formvalue("proto") local path = "/tmp/etc/passwall/acl/" .. name proto = proto:upper() - if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not nixio.fs.access(path .. "/" .. proto .. ".log") then + if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not fs.access(path .. "/" .. proto .. ".log") then proto = "TCP" end - if nixio.fs.access(path .. "/" .. proto .. ".log") then + if fs.access(path .. "/" .. proto .. ".log") then local content = luci.sys.exec("cat ".. path .. "/" .. proto .. ".log") content = content:gsub("\n", "
") luci.http.write(content) @@ -201,7 +202,7 @@ end function get_socks_log() local name = luci.http.formvalue("name") local path = "/tmp/etc/passwall/SOCKS_" .. name .. ".log" - if nixio.fs.access(path) then + if fs.access(path) then local content = luci.sys.exec("cat ".. path) content = content:gsub("\n", "
") luci.http.write(content) @@ -453,7 +454,7 @@ end function server_user_log() local id = luci.http.formvalue("id") - if nixio.fs.access("/tmp/etc/passwall_server/" .. id .. ".log") then + if fs.access("/tmp/etc/passwall_server/" .. id .. ".log") then local content = luci.sys.exec("cat /tmp/etc/passwall_server/" .. id .. ".log") content = content:gsub("\n", "
") luci.http.write(content) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua index 6ca0a9422..5bc253108 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua @@ -1,6 +1,6 @@ local api = require "luci.passwall.api" local appname = "passwall" -local uci = api.uci +local uci = api.libuci local sys = api.sys local has_singbox = api.finded_com("singbox") local has_xray = api.finded_com("xray") diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua index 1715cccb3..7bd9fb349 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua @@ -1,6 +1,6 @@ local api = require "luci.passwall.api" local appname = "passwall" -local uci = api.uci +local uci = api.libuci local datatypes = api.datatypes local has_singbox = api.finded_com("singbox") local has_xray = api.finded_com("xray") diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua index 98504b8b2..2a21f9b3f 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua @@ -1,7 +1,7 @@ local api = require "luci.passwall.api" local appname = "passwall" -local uci = api.uci -local fs = require "nixio.fs" +local uci = api.libuci +local fs = api.fs local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/client/type/" if not arg[1] or not uci:get(appname, arg[1]) then diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua index 793cab032..b7afc57f1 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/socks_config.lua @@ -1,6 +1,6 @@ local api = require "luci.passwall.api" local appname = "passwall" -local uci = api.uci +local uci = api.libuci local has_singbox = api.finded_com("singbox") local has_xray = api.finded_com("xray") diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua index 6daff99db..9fb19305b 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua @@ -8,7 +8,7 @@ end local appname = "passwall" local jsonc = api.jsonc -local uci = api.uci +local uci = api.libuci local type_name = "Xray" diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua index d5eb0ed40..40eb13ce4 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua @@ -11,7 +11,7 @@ end local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'") local appname = "passwall" -local uci = api.uci +local uci = api.libuci local type_name = "sing-box" diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua index 81c8c3fcc..23a3eaee4 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua @@ -6,6 +6,8 @@ if not api.finded_com("hysteria") then return end +local fs = api.fs + local type_name = "Hysteria2" local option_prefix = "hysteria2_" @@ -46,7 +48,7 @@ o = s:option(FileUpload, _n("tls_certificateFile"), translate("Public key absolu o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem" o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value @@ -59,7 +61,7 @@ o = s:option(FileUpload, _n("tls_keyFile"), translate("Private key absolute path o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key" o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua index e29673fd7..ed1367e4d 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua @@ -6,6 +6,8 @@ if not api.finded_com("xray") then return end +local fs = api.fs + local type_name = "Xray" local option_prefix = "xray_" @@ -174,7 +176,7 @@ o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg o:depends({ [_n("tls")] = true, [_n("reality")] = false }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value @@ -188,7 +190,7 @@ o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. " o:depends({ [_n("tls")] = true, [_n("reality")] = false }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua index 61856ca1e..054848d93 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua @@ -8,6 +8,8 @@ if not singbox_bin then return end +local fs = api.fs + local singbox_tags = luci.sys.exec(singbox_bin .. " version | grep 'Tags:' | awk '{print $2}'") local type_name = "sing-box" @@ -255,7 +257,7 @@ o:depends({ [_n("protocol")] = "tuic" }) o:depends({ [_n("protocol")] = "hysteria2" }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value @@ -273,7 +275,7 @@ o:depends({ [_n("protocol")] = "tuic" }) o:depends({ [_n("protocol")] = "hysteria2" }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/trojan-plus.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/trojan-plus.lua index 21bbad114..9581a7a6a 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/trojan-plus.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/trojan-plus.lua @@ -6,6 +6,8 @@ if not api.is_finded("trojan-plus") then return end +local fs = api.fs + local type_name = "Trojan-Plus" local option_prefix = "trojan_plus_" @@ -50,7 +52,7 @@ o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg o:depends({ [_n("tls")] = true }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value @@ -64,7 +66,7 @@ o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. " o:depends({ [_n("tls")] = true }) o.validate = function(self, value, t) if value and value ~= "" then - if not nixio.fs.access(value) then + if not fs.access(value) then return nil, translate("Can't find this file!") else return value diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua index b4371db33..6affd2c7d 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua @@ -1,5 +1,5 @@ local api = require "luci.passwall.api" -local fs = require "nixio.fs" +local fs = api.fs local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/server/type/" m = Map("passwall_server", translate("Server Config")) diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index cc1d6debc..c866607ce 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -4,7 +4,6 @@ bin = require "nixio".bin fs = require "nixio.fs" sys = require "luci.sys" libuci = require "uci".cursor() -uci = require"luci.model.uci".cursor() util = require "luci.util" datatypes = require "luci.cbi.datatypes" jsonc = require "luci.jsonc" @@ -176,7 +175,7 @@ end function curl_direct(url, file, args) --直连访问 - local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct" + local chn_list = libuci:get(appname, "@global[0]", "chn_list") or "direct" local Dns = (chn_list == "proxy") and "1.1.1.1" or "223.5.5.5" if not args then args = {} end local tmp_args = clone(args) @@ -425,7 +424,7 @@ function get_node_name(node_id) if type(node_id) == "table" then e = node_id else - e = uci:get_all(appname, node_id) + e = libuci:get_all(appname, node_id) end if e then if e.type and e.remarks then @@ -441,9 +440,9 @@ function get_node_name(node_id) end function get_valid_nodes() - local show_node_info = uci_get_type("global_other", "show_node_info") or "0" + local show_node_info = uci_get_type("@global_other[0]", "show_node_info", "0") local nodes = {} - uci:foreach(appname, "nodes", function(e) + libuci:foreach(appname, "nodes", function(e) e.id = e[".name"] if e.type and e.remarks then if e.protocol and (e.protocol == "_balancing" or e.protocol == "_shunt" or e.protocol == "_iface") then @@ -540,15 +539,7 @@ function gen_short_uuid() end function uci_get_type(type, config, default) - local value = uci:get_first(appname, type, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. ".@" .. type .."[0]." .. config .. ")") - if (value == nil or value == "") and (default and default ~= "") then - value = default - end - return value -end - -function uci_get_type_id(id, config, default) - local value = uci:get(appname, id, config, default) or sys.exec("echo -n $(uci -q get " .. appname .. "." .. id .. "." .. config .. ")") + local value = libuci:get(appname, type, config) or default if (value == nil or value == "") and (default and default ~= "") then value = default end @@ -564,7 +555,7 @@ local function chmod_755(file) end function get_customed_path(e) - return uci_get_type("global_app", e .. "_file") + return uci_get_type("@global_app[0]", e .. "_file") end function finded_com(e) @@ -623,7 +614,7 @@ end function get_app_path(app_name) if com[app_name] then local def_path = com[app_name].default_path - local path = uci_get_type("global_app", app_name:gsub("%-","_") .. "_file") + local path = uci_get_type("@global_app[0]", app_name:gsub("%-","_") .. "_file") path = path and (#path>0 and path or def_path) or def_path return path end diff --git a/luci-app-passwall/luasrc/passwall/server_app.lua b/luci-app-passwall/luasrc/passwall/server_app.lua index 50357056b..ef267c649 100644 --- a/luci-app-passwall/luasrc/passwall/server_app.lua +++ b/luci-app-passwall/luasrc/passwall/server_app.lua @@ -3,7 +3,7 @@ local action = arg[1] local api = require "luci.passwall.api" local sys = api.sys -local uci = api.uci +local uci = api.libuci local jsonc = api.jsonc local CONFIG = "passwall_server" diff --git a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua index b818aadbf..12afe6874 100644 --- a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua +++ b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_hysteria2", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local jsonc = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua b/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua index ee095c1e6..b6ef39b3b 100644 --- a/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua +++ b/luci-app-passwall/luasrc/passwall/util_naiveproxy.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_naiveproxy", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local jsonc = api.jsonc function gen_config(var) diff --git a/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua b/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua index e6080001b..5e724e77b 100644 --- a/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua +++ b/luci-app-passwall/luasrc/passwall/util_shadowsocks.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_shadowsocks", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local jsonc = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index bfa24b46c..e6cdbc7d3 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_sing-box", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local sys = api.sys local jsonc = api.jsonc local appname = "passwall" diff --git a/luci-app-passwall/luasrc/passwall/util_trojan.lua b/luci-app-passwall/luasrc/passwall/util_trojan.lua index 848b689a5..31bd67a4a 100644 --- a/luci-app-passwall/luasrc/passwall/util_trojan.lua +++ b/luci-app-passwall/luasrc/passwall/util_trojan.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_trojan", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local json = api.jsonc function gen_config_server(node) diff --git a/luci-app-passwall/luasrc/passwall/util_tuic.lua b/luci-app-passwall/luasrc/passwall/util_tuic.lua index e138b6da5..be00dcb8c 100644 --- a/luci-app-passwall/luasrc/passwall/util_tuic.lua +++ b/luci-app-passwall/luasrc/passwall/util_tuic.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_tuic", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local json = api.jsonc function gen_config(var) diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index 5c7ec1fca..d26ac1b12 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -1,6 +1,6 @@ module("luci.passwall.util_xray", package.seeall) local api = require "luci.passwall.api" -local uci = api.uci +local uci = api.libuci local sys = api.sys local jsonc = api.jsonc local appname = "passwall" diff --git a/luci-app-passwall/luasrc/view/passwall/haproxy/status.htm b/luci-app-passwall/luasrc/view/passwall/haproxy/status.htm index 6d584583f..8a6362d3f 100644 --- a/luci-app-passwall/luasrc/view/passwall/haproxy/status.htm +++ b/luci-app-passwall/luasrc/view/passwall/haproxy/status.htm @@ -1,6 +1,6 @@ <% local api = require "luci.passwall.api" -local console_port = api.uci_get_type("global_haproxy", "console_port", "") +local console_port = api.uci_get_type("@global_haproxy[0]", "console_port", "") -%>

diff --git a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm index 304f25434..622828bad 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm @@ -36,7 +36,7 @@ table td, .table .td {