update 2024-03-20 00:20:04

This commit is contained in:
kenzok8 2024-03-20 00:20:04 +08:00
parent 029bd2df22
commit 3583b5857a
11 changed files with 95 additions and 26 deletions

View File

@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-passwall2 PKG_NAME:=luci-app-passwall2
PKG_VERSION:=1.28-2 PKG_VERSION:=1.28-3
PKG_RELEASE:= PKG_RELEASE:=
PKG_CONFIG_DEPENDS:= \ PKG_CONFIG_DEPENDS:= \

File diff suppressed because one or more lines are too long

View File

@ -52,6 +52,7 @@ function index()
entry({"admin", "services", appname, "socks_autoswitch_remove_node"}, call("socks_autoswitch_remove_node")).leaf = true 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_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_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, "get_log"}, call("get_log")).leaf = true
entry({"admin", "services", appname, "clear_log"}, call("clear_log")).leaf = true entry({"admin", "services", appname, "clear_log"}, call("clear_log")).leaf = true
entry({"admin", "services", appname, "status"}, call("status")).leaf = true entry({"admin", "services", appname, "status"}, call("status")).leaf = true
@ -167,6 +168,18 @@ function get_redir_log()
end end
end end
function get_socks_log()
local name = luci.http.formvalue("name")
local path = "/tmp/etc/passwall2/SOCKS_" .. name .. ".log"
if nixio.fs.access(path) then
local content = luci.sys.exec("cat ".. path)
content = content:gsub("\n", "<br />")
luci.http.write(content)
else
luci.http.write(string.format("<script>alert('%s');window.close();</script>", i18n.translate("Not enabled log")))
end
end
function get_log() function get_log()
-- luci.sys.exec("[ -f /tmp/log/passwall2.log ] && sed '1!G;h;$!d' /tmp/log/passwall2.log > /tmp/log/passwall2_show.log") -- luci.sys.exec("[ -f /tmp/log/passwall2.log ] && sed '1!G;h;$!d' /tmp/log/passwall2.log > /tmp/log/passwall2_show.log")
luci.http.write(luci.sys.exec("[ -f '/tmp/log/passwall2.log' ] && cat /tmp/log/passwall2.log")) luci.http.write(luci.sys.exec("[ -f '/tmp/log/passwall2.log' ] && cat /tmp/log/passwall2.log"))

View File

@ -141,6 +141,10 @@ o.default = 0
o:depends("auto_update", true) o:depends("auto_update", true)
o = s:option(Value, "user_agent", translate("User-Agent")) o = s:option(Value, "user_agent", translate("User-Agent"))
o.default = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36" o.default = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
o:value("curl")
o:value("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0")
o:value("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0")
o:value("Passwall2/OpenWrt")
return m return m

View File

@ -61,6 +61,10 @@ if has_singbox or has_xray then
o.datatype = "port" o.datatype = "port"
end 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 = s:option(Flag, "enable_autoswitch", translate("Auto Switch"))
o.default = 0 o.default = 0
o.rmempty = false o.rmempty = false

View File

@ -10,7 +10,7 @@ jsonc = require "luci.jsonc"
i18n = require "luci.i18n" i18n = require "luci.i18n"
appname = "passwall2" appname = "passwall2"
curl_args = {"-skfL", "--connect-timeout 3", "--retry 3", "-m 60"} curl_args = { "-skfL", "--connect-timeout 3", "--retry 3" }
command_timeout = 300 command_timeout = 300
OPENWRT_ARCH = nil OPENWRT_ARCH = nil
DISTRIB_ARCH = nil DISTRIB_ARCH = nil
@ -805,7 +805,10 @@ function to_download(app_name, url, size)
end end
end end
local return_code, result = curl_logic(url, tmp_file, curl_args) local _curl_args = clone(curl_args)
table.insert(_curl_args, "-m 60")
local return_code, result = curl_logic(url, tmp_file, _curl_args)
result = return_code == 0 result = return_code == 0
if not result then if not result then

View File

@ -114,12 +114,22 @@ local api = require "luci.passwall2.api"
node_select.title = node_select.options[node_select.options.selectedIndex].text; node_select.title = node_select.options[node_select.options.selectedIndex].text;
} }
var new_html = ""
var new_a = document.createElement("a"); var new_a = document.createElement("a");
new_a.innerHTML = "<%:Edit%>"; new_a.innerHTML = "<%:Edit%>";
new_a.href = "#"; new_a.href = "#";
new_a.setAttribute("onclick","location.href='" + '<%=api.url("node_config")%>' + "/" + node_select_value + "'"); new_a.setAttribute("onclick","location.href='" + '<%=api.url("node_config")%>' + "/" + node_select_value + "'");
new_html = new_a.outerHTML;
node_select.insertAdjacentHTML("afterend", "&nbsp&nbsp" + 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-passwall2-", "") + "', '_blank')");
new_html += "&nbsp" + log_a.outerHTML;
node_select.insertAdjacentHTML("afterend", "&nbsp&nbsp" + new_html);
} }
} catch(err) { } catch(err) {
} }

View File

@ -2,6 +2,7 @@
<% <%
local api = require "luci.passwall2.api" local api = require "luci.passwall2.api"
-%> -%>
<script src="<%=resource%>/qrcode.min.js"></script>
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
let has_singbox = "<%=api.finded_com("singbox")%>" let has_singbox = "<%=api.finded_com("singbox")%>"
let has_xray = "<%=api.finded_com("xray")%>" let has_xray = "<%=api.finded_com("xray")%>"
@ -72,6 +73,20 @@ local api = require "luci.passwall2.api"
}; };
return r; return r;
} }
function genQrcode(btn, urlname, sid) {
var qrcode_div = document.getElementById("qrcode_div");
qrcode_div.style.display = null;
document.getElementById("qrcode").innerHTML = "";
var url = buildUrl(btn, urlname, sid);
if (url) {
var qrcode = new QRCode(document.getElementById("qrcode"), {
width: 150,
height: 150
});
qrcode.makeCode(url);
}
}
function buildUrl(btn, urlname, sid) { function buildUrl(btn, urlname, sid) {
var opt = { var opt = {
@ -115,12 +130,6 @@ local api = require "luci.passwall2.api"
return "" return ""
} }
} }
var s = document.getElementById(urlname + "-status");
if (!s) {
alert("Never");
return false;
}
opt.base = "cbid." + urlname + "." + sid; opt.base = "cbid." + urlname + "." + sid;
opt.client = urlname.indexOf("server") === -1; opt.client = urlname.indexOf("server") === -1;
var v_type = opt.get("type").value; var v_type = opt.get("type").value;
@ -369,12 +378,27 @@ local api = require "luci.passwall2.api"
} }
if (url) { if (url) {
url = protocol.toLowerCase() + "://" + url; url = protocol.toLowerCase() + "://" + url;
return url;
} else {
alert("<%:Not a supported scheme:%> " + v_type);
}
return false;
}
function exportUrl(btn, urlname, sid) {
var url = buildUrl(btn, urlname, sid);
if (url) {
var textarea = document.createElement("textarea"); var textarea = document.createElement("textarea");
textarea.textContent = url; textarea.textContent = url;
textarea.style.position = "fixed"; textarea.style.position = "fixed";
document.body.appendChild(textarea); document.body.appendChild(textarea);
textarea.select(); textarea.select();
try { try {
var s = document.getElementById(urlname + "-status");
if (!s) {
alert("Never");
return false;
}
document.execCommand("copy"); // Security exception may be thrown by some browsers. document.execCommand("copy"); // Security exception may be thrown by some browsers.
s.innerHTML = "<font color='green'><%:Share URL to clipboard successfully.%></font>"; s.innerHTML = "<font color='green'><%:Share URL to clipboard successfully.%></font>";
} catch (ex) { } catch (ex) {
@ -382,11 +406,7 @@ local api = require "luci.passwall2.api"
} finally { } finally {
document.body.removeChild(textarea); document.body.removeChild(textarea);
} }
//alert(url);
} else {
alert("<%:Not a supported scheme:%> " + v_type);
} }
return false;
} }
function fromUrl(btn, urlname, sid) { function fromUrl(btn, urlname, sid) {
@ -906,6 +926,10 @@ local api = require "luci.passwall2.api"
//]]></script> //]]></script>
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:From Share URL%>' onclick="return fromUrl(this, '<%=self.option%>', '<%=self.value%>')" /> <input type="button" class="btn cbi-button cbi-button-apply" value='<%:From Share URL%>' onclick="return fromUrl(this, '<%=self.option%>', '<%=self.value%>')" />
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Build Share URL%>' onclick="return buildUrl(this, '<%=self.option%>', '<%=self.value%>')" /> <input type="button" class="btn cbi-button cbi-button-apply" value='<%:Build Share URL%>' onclick="return exportUrl(this, '<%=self.option%>', '<%=self.value%>')" />
<input type="button" class="btn cbi-button cbi-button-apply" value='<%:Generate QRCode%>' onclick="return genQrcode(this, '<%=self.option%>', '<%=self.value%>')" />
<div id="qrcode_div" style="margin-top: 1rem;display:none">
<div id="qrcode"></div>
</div>
<span id="<%=self.option%>-status"></span> <span id="<%=self.option%>-status"></span>
<%+cbi/valuefooter%> <%+cbi/valuefooter%>

View File

@ -418,6 +418,9 @@ msgstr "导入分享URL"
msgid "Build Share URL" msgid "Build Share URL"
msgstr "导出分享URL" msgstr "导出分享URL"
msgid "Generate QRCode"
msgstr "生成二维码"
msgid "Import Finished" msgid "Import Finished"
msgstr "导入完成:" msgstr "导入完成:"

View File

@ -543,8 +543,13 @@ run_socks() {
local _extra_param="-local_http_port $http_port" local _extra_param="-local_http_port $http_port"
} }
[ -n "$relay_port" ] && _extra_param="${_extra_param} -server_host $server_host -server_port $port" [ -n "$relay_port" ] && _extra_param="${_extra_param} -server_host $server_host -server_port $port"
[ "${log_file}" != "/dev/null" ] && {
local loglevel=$(config_t_get global loglevel "warn")
[ "$loglevel" = "warning" ] && loglevel="warn"
_extra_param="${_extra_param} -log 1 -loglevel $loglevel -logfile $log_file"
}
lua $UTIL_SINGBOX gen_config -flag SOCKS_$flag -node $node -local_socks_port $socks_port ${_extra_param} > $config_file lua $UTIL_SINGBOX gen_config -flag SOCKS_$flag -node $node -local_socks_port $socks_port ${_extra_param} > $config_file
ln_run "$(first_type $(config_t_get global_app singbox_file) sing-box)" "sing-box" $log_file run -c "$config_file" ln_run "$(first_type $(config_t_get global_app singbox_file) sing-box)" "sing-box" /dev/null run -c "$config_file"
;; ;;
xray) xray)
[ "$http_port" != "0" ] && { [ "$http_port" != "0" ] && {
@ -625,10 +630,12 @@ socks_node_switch() {
local port=$(config_n_get $flag port) local port=$(config_n_get $flag port)
local config_file="SOCKS_${flag}.json" local config_file="SOCKS_${flag}.json"
local log_file="SOCKS_${flag}.log" local log_file="SOCKS_${flag}.log"
local log=$(config_n_get $id log 1)
[ "$log" == "0" ] && log_file=""
local http_port=$(config_n_get $flag http_port 0) local http_port=$(config_n_get $flag http_port 0)
local http_config_file="HTTP2SOCKS_${flag}.json" local http_config_file="HTTP2SOCKS_${flag}.json"
LOG_FILE="/dev/null" 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} echo $new_node > $TMP_ID_PATH/socks_${flag}
} }
} }
@ -718,9 +725,11 @@ start_socks() {
local port=$(config_n_get $id port) local port=$(config_n_get $id port)
local config_file="SOCKS_${id}.json" local config_file="SOCKS_${id}.json"
local log_file="SOCKS_${id}.log" local log_file="SOCKS_${id}.log"
local log=$(config_n_get $flag log 1)
[ "$log" == "0" ] && log_file=""
local http_port=$(config_n_get $id http_port 0) local http_port=$(config_n_get $id http_port 0)
local http_config_file="HTTP2SOCKS_${id}.json" 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} echo $node > $TMP_ID_PATH/socks_${id}
#自动切换逻辑 #自动切换逻辑

View File

@ -891,13 +891,11 @@ local function processData(szType, content, add_mode, add_from)
end end
local function curl(url, file, ua) local function curl(url, file, ua)
if not ua or ua == "" then local curl_args = api.clone(api.curl_args)
ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36" if ua and ua ~= "" and ua ~= "curl" then
table.insert(curl_args, '--user-agent "' .. ua .. '"')
end end
local args = { local return_code, result = api.curl_logic(url, file, curl_args)
"-skL", "--retry 3", "--connect-timeout 3", '--user-agent "' .. ua .. '"'
}
local return_code, result = api.curl_logic(url, file, args)
return return_code return return_code
end end