diff --git a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr index 3893d763828..240408992a7 100755 --- a/luci-app-ssr-plus/root/etc/init.d/shadowsocksr +++ b/luci-app-ssr-plus/root/etc/init.d/shadowsocksr @@ -609,6 +609,9 @@ prepare_clash_runtime_config() { local client_policy_stats local client_rules local enable_fake_ip + local socks5_auth + local socks5_user + local socks5_pass cache_file="$(get_clash_cache_file "$sid")" workdir="$(get_clash_workdir "$sid")" @@ -625,6 +628,16 @@ prepare_clash_runtime_config() { client_policy_stats="" client_rules=0 enable_fake_ip="$(uci_get_by_type server_subscribe enable_fake_ip "")" + socks5_auth="$(uci_get_by_type socks5_proxy socks5_auth noauth)" + socks5_user="$(uci_get_by_type socks5_proxy socks5_user "")" + socks5_pass="$(uci_get_by_type socks5_proxy socks5_pass "")" + + if [ "$socks5_auth" = "password" ]; then + if [ -z "$socks5_user" ] || [ -z "$socks5_pass" ]; then + echolog "警告:SOCKS5 代理未完整配置用户名或密码,已自动降级为无认证模式 (noauth)。" + socks5_auth="noauth" + fi + fi [ -s "$cache_file" ] || return 1 @@ -671,6 +684,12 @@ prepare_clash_runtime_config() { if [ -n "$socks_port" ] && [ "$socks_port" != "0" ]; then echo "socks-port: $socks_port" >>"$overlay_file" + if [ "$socks5_auth" = "password" ]; then + cat >>"$overlay_file" <<-EOF + authentication: + - "$socks5_user:$socks5_pass" + EOF + fi fi merge_stats="$(/usr/bin/lua "$CLASH_YAML_HELPER" merge "$raw_file" "$overlay_file" "$runtime_file" 2>/dev/null)" || return 1 diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/clash_yaml.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/clash_yaml.lua index c87d448a395..fcb9853da29 100644 --- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/clash_yaml.lua +++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/clash_yaml.lua @@ -56,7 +56,7 @@ local function load_yaml(path) end local function quote_nameserver_policy_keys(rendered) - rendered = rendered:gsub("[^\n]*", function(line) + rendered = rendered:gsub("[^\n]+", function(line) local indent = line:match("^(%s*)geosite:geolocation%-!cn:%s*$") if indent then return indent .. '"geosite:geolocation-!cn":'