Skip to content

Commit

Permalink
update 2024-08-27 00:46:41
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzok8 committed Aug 26, 2024
1 parent 89a3416 commit 1ae9adf
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
6 changes: 4 additions & 2 deletions luci-app-bypass/luasrc/controller/bypass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ function check_site(host, port)
end

function get_ip_geo_info()
local result = luci.sys.exec('curl --retry 3 -m 10 -LfsA "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36" https://ip-api.com/json/')
local result = luci.sys.exec('curl --retry 3 -m 10 -LfsA "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36" http://ip-api.com/json/')
local json = require "luci.jsonc"
local info = json.parse(result)

return {
flag = string.lower(info.countryCode) or "un",
country = get_country_name(info.countryCode) or "Unknown",
ip = info.query
ip = info.query,
isp = info.isp
}
end

Expand All @@ -198,6 +199,7 @@ function check_ip()
e.ip = geo_info.ip
e.flag = geo_info.flag
e.country = geo_info.country
e.isp = geo_info.isp
e.baidu = check_site('www.baidu.com', port)
e.taobao = check_site('www.taobao.com', port)
e.google = check_site('www.google.com', port)
Expand Down
4 changes: 2 additions & 2 deletions luci-app-bypass/luasrc/view/bypass/status_bottom.htm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

function write_status(data) {
document.querySelector(".flag img").src = _ASSETS + "flags/" + data.flag + ".svg";
document.querySelector(".status-info").innerHTML = data.ip + "<br>" + data.country;
document.querySelector(".status-info").innerHTML = data.ip + "<br>" + data.country + "&nbsp;" + data.isp;
document.querySelector(".i1").src = data.baidu ? _ASSETS + "img/site_icon_01.png" : _ASSETS + "img/site_icon1_01.png";
document.querySelector(".i2").src = data.taobao ? _ASSETS + "img/site_icon_02.png" : _ASSETS + "img/site_icon1_02.png";
document.querySelector(".i3").src = data.google ? _ASSETS + "img/site_icon_03.png" : _ASSETS + "img/site_icon1_03.png";
Expand All @@ -112,7 +112,7 @@
);

document.addEventListener('DOMContentLoaded', function() {
setTimeout("resize()",10)
setTimeout("resize()",100)
fetch(CHECK_IP_URL)
.then(response => response.json())
.then(data => {
Expand Down
16 changes: 14 additions & 2 deletions luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
m = Map(appname)

-- [[ Haproxy Settings ]]--
s = m:section(TypedSection, "global_haproxy")
s = m:section(TypedSection, "global_haproxy", translate("Basic Settings"))
s.anonymous = true

s:append(Template(appname .. "/haproxy/status"))
Expand Down Expand Up @@ -56,6 +56,18 @@ o:value("tcp", "TCP")
o:value("passwall_logic", translate("URL Test") .. string.format("(passwall %s)", translate("Inner implement")))
o:depends("balancing_enable", true)

---- Passwall Inner implement Probe URL
o = s:option(Value, "health_probe_url", translate("Probe URL"))
o.default = "https://www.google.com/generate_204"
o:value("https://cp.cloudflare.com/", "Cloudflare")
o:value("https://www.gstatic.com/generate_204", "Gstatic")
o:value("https://www.google.com/generate_204", "Google")
o:value("https://www.youtube.com/generate_204", "YouTube")
o:value("https://connect.rom.miui.com/generate_204", "MIUI (CN)")
o:value("https://connectivitycheck.platform.hicloud.com/generate_204", "HiCloud (CN)")
o.description = translate("The URL used to detect the connection status.")
o:depends("health_check_type", "passwall_logic")

---- Health Check Inter
o = s:option(Value, "health_check_inter", translate("Health Check Inter"), translate("Units:seconds"))
o.default = "60"
Expand All @@ -69,7 +81,7 @@ end
o:depends("health_check_type", "passwall_logic")

-- [[ Balancing Settings ]]--
s = m:section(TypedSection, "haproxy_config", "",
s = m:section(TypedSection, "haproxy_config", translate("Node List"),
"<font color='red'>" ..
translate("Add a node, Export Of Multi WAN Only support Multi Wan. Load specific gravity range 1-256. Multiple primary servers can be load balanced, standby will only be enabled when the primary server is offline! Multiple groups can be set, Haproxy port same one for each group.") ..
"\n" .. translate("Note that the node configuration parameters for load balancing must be consistent when use TCP health check type, otherwise it cannot be used normally!") ..
Expand Down
8 changes: 8 additions & 0 deletions luci-app-passwall/root/usr/share/passwall/haproxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,11 @@ listen console
f_out:write("\n" .. string.format(str, console_port, (console_user and console_user ~= "" and console_password and console_password ~= "") and "stats auth " .. console_user .. ":" .. console_password or ""))

f_out:close()

--passwall内置健康检查URL
if health_check_type == "passwall_logic" then
local probeUrl = uci:get(appname, "@global_haproxy[0]", "health_probe_url") or "https://www.google.com/generate_204"
local f_url = io.open(haproxy_path .. "/Probe_URL", "w")
f_url:write(probeUrl)
f_url:close()
end
12 changes: 11 additions & 1 deletion luci-app-passwall/root/usr/share/passwall/haproxy_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ listen_address=$1
listen_port=$2
server_address=$3
server_port=$4
status=$(/usr/bin/curl -I -o /dev/null -skL -x socks5h://${server_address}:${server_port} --connect-timeout 3 --retry 3 -w %{http_code} "https://www.google.com/generate_204")

probe_file="/tmp/etc/passwall/haproxy/Probe_URL"
probeUrl="https://www.google.com/generate_204"
if [ -f "$probe_file" ]; then
firstLine=$(head -n 1 "$probe_file" | tr -d ' \t')
if [ -n "$firstLine" ]; then
probeUrl="$firstLine"
fi
fi

status=$(/usr/bin/curl -I -o /dev/null -skL -x socks5h://${server_address}:${server_port} --connect-timeout 3 --retry 3 -w %{http_code} "${probeUrl}")
case "$status" in
204|\
200)
Expand Down

0 comments on commit 1ae9adf

Please sign in to comment.