From 242d7297741ef90fc1e18af4f5e7e3f374adb2ca Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:38:32 +0800 Subject: [PATCH] luci: add Socks log --- luci-app-passwall/luasrc/controller/passwall.lua | 13 +++++++++++++ .../model/cbi/passwall/client/socks_config.lua | 7 ++++++- .../luasrc/view/passwall/global/footer.htm | 11 ++++++++++- luci-app-passwall/root/usr/share/passwall/app.sh | 8 ++++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 5cd4fac87..c7f958c44 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -54,6 +54,7 @@ function index() entry({"admin", "services", appname, "socks_autoswitch_remove_node"}, call("socks_autoswitch_remove_node")).leaf = true entry({"admin", "services", appname, "get_now_use_node"}, call("get_now_use_node")).leaf = true entry({"admin", "services", appname, "get_redir_log"}, call("get_redir_log")).leaf = true + entry({"admin", "services", appname, "get_socks_log"}, call("get_socks_log")).leaf = true entry({"admin", "services", appname, "get_log"}, call("get_log")).leaf = true entry({"admin", "services", appname, "clear_log"}, call("clear_log")).leaf = true entry({"admin", "services", appname, "status"}, call("status")).leaf = true @@ -179,6 +180,18 @@ function get_redir_log() end 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 + local content = luci.sys.exec("cat ".. path) + content = content:gsub("\n", "
") + luci.http.write(content) + else + luci.http.write(string.format("", i18n.translate("Not enabled log"))) + end +end + function get_log() -- luci.sys.exec("[ -f /tmp/log/passwall.log ] && sed '1!G;h;$!d' /tmp/log/passwall.log > /tmp/log/passwall_show.log") luci.http.write(luci.sys.exec("[ -f '/tmp/log/passwall.log' ] && cat /tmp/log/passwall.log")) 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 5f1f1e4a0..b357a99ea 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,7 @@ local api = require "luci.passwall.api" local appname = "passwall" local uci = api.uci +local has_singbox = api.finded_com("singbox") local has_xray = api.finded_com("xray") m = Map(appname) @@ -53,12 +54,16 @@ o.default = n + 1080 o.datatype = "port" o.rmempty = false -if has_xray then +if has_singbox or has_xray then o = s:option(Value, "http_port", "HTTP " .. translate("Listen Port") .. " " .. translate("0 is not use")) o.default = 0 o.datatype = "port" end +o = s:option(Flag, "log", translate("Enable") .. " " .. translate("Log")) +o.default = 1 +o.rmempty = false + o = s:option(Flag, "enable_autoswitch", translate("Auto Switch")) o.default = 0 o.rmempty = false diff --git a/luci-app-passwall/luasrc/view/passwall/global/footer.htm b/luci-app-passwall/luasrc/view/passwall/global/footer.htm index 59afbb364..5a7a518f0 100644 --- a/luci-app-passwall/luasrc/view/passwall/global/footer.htm +++ b/luci-app-passwall/luasrc/view/passwall/global/footer.htm @@ -125,12 +125,21 @@ local api = require "luci.passwall.api" node_select.title = node_select.options[node_select.options.selectedIndex].text; } + var new_html = "" + var new_a = document.createElement("a"); new_a.innerHTML = "<%:Edit%>"; new_a.href = "#"; new_a.setAttribute("onclick","location.href='" + '<%=api.url("node_config")%>' + "/" + node_select_value + "'"); + new_html = new_a.outerHTML; + + var log_a = document.createElement("a"); + log_a.innerHTML = "<%:Log%>"; + log_a.href = "#"; + log_a.setAttribute("onclick", "window.open('" + '<%=api.url("get_socks_log")%>' + "?name=" + id.replace("cbi-passwall-", "") + "', '_blank')"); + new_html += " " + log_a.outerHTML; - node_select.insertAdjacentHTML("afterend", "  " + new_a.outerHTML); + node_select.insertAdjacentHTML("afterend", "  " + new_html); } } catch(err) { } diff --git a/luci-app-passwall/root/usr/share/passwall/app.sh b/luci-app-passwall/root/usr/share/passwall/app.sh index f55259d32..eb97bbe7e 100755 --- a/luci-app-passwall/root/usr/share/passwall/app.sh +++ b/luci-app-passwall/root/usr/share/passwall/app.sh @@ -1021,9 +1021,11 @@ start_socks() { local port=$(config_n_get $id port) local config_file="SOCKS_${id}.json" local log_file="SOCKS_${id}.log" + local log=$(config_n_get $id log 1) + [ "$log" == "0" ] && log_file="" local http_port=$(config_n_get $id http_port 0) local http_config_file="HTTP2SOCKS_${id}.json" - run_socks flag=$id node=$node bind=0.0.0.0 socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file + run_socks flag=$id node=$node bind=0.0.0.0 socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file log_file=$log_file echo $node > $TMP_ID_PATH/socks_${id} #自动切换逻辑 @@ -1049,10 +1051,12 @@ socks_node_switch() { local port=$(config_n_get $flag port) local config_file="SOCKS_${flag}.json" local log_file="SOCKS_${flag}.log" + local log=$(config_n_get $flag log 1) + [ "$log" == "0" ] && log_file="" local http_port=$(config_n_get $flag http_port 0) local http_config_file="HTTP2SOCKS_${flag}.json" LOG_FILE="/dev/null" - run_socks flag=$flag node=$new_node bind=0.0.0.0 socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file + run_socks flag=$flag node=$new_node bind=0.0.0.0 socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file log_file=$log_file echo $new_node > $TMP_ID_PATH/socks_${flag} } }