|
|
|
|
@@ -67,7 +67,10 @@ start_main() {
|
|
|
|
|
|
|
|
|
|
config_foreach process_validate_service
|
|
|
|
|
|
|
|
|
|
sleep 3
|
|
|
|
|
# Sync time for DoH/DoT
|
|
|
|
|
/usr/sbin/ntpd -q -p 194.190.168.1 -p 216.239.35.0 -p 216.239.35.4 -p 162.159.200.1 -p 162.159.200.123
|
|
|
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
|
|
mkdir -p /tmp/podkop
|
|
|
|
|
|
|
|
|
|
@@ -160,7 +163,7 @@ stop_main() {
|
|
|
|
|
|
|
|
|
|
if [ -f /var/run/podkop_list_update.pid ]; then
|
|
|
|
|
pid=$(cat /var/run/podkop_list_update.pid)
|
|
|
|
|
if kill -0 "$pid"; then
|
|
|
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
|
|
|
kill "$pid" 2>/dev/null
|
|
|
|
|
log "Stopped list_update"
|
|
|
|
|
fi
|
|
|
|
|
@@ -375,8 +378,6 @@ save_dnsmasq_config() {
|
|
|
|
|
|
|
|
|
|
dnsmasq_add_resolver() {
|
|
|
|
|
log "Save dnsmasq config"
|
|
|
|
|
save_dnsmasq_config "dhcp.@dnsmasq[0].noresolv" "dhcp.@dnsmasq[0].podkop_noresolv"
|
|
|
|
|
save_dnsmasq_config "dhcp.@dnsmasq[0].cachesize" "dhcp.@dnsmasq[0].podkop_cachesize"
|
|
|
|
|
|
|
|
|
|
uci -q delete dhcp.@dnsmasq[0].podkop_server
|
|
|
|
|
for server in $(uci get dhcp.@dnsmasq[0].server 2>/dev/null); do
|
|
|
|
|
@@ -388,6 +389,9 @@ dnsmasq_add_resolver() {
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
save_dnsmasq_config "dhcp.@dnsmasq[0].noresolv" "dhcp.@dnsmasq[0].podkop_noresolv"
|
|
|
|
|
save_dnsmasq_config "dhcp.@dnsmasq[0].cachesize" "dhcp.@dnsmasq[0].podkop_cachesize"
|
|
|
|
|
|
|
|
|
|
log "Configure dnsmasq for sing-box"
|
|
|
|
|
uci set dhcp.@dnsmasq[0].noresolv="1"
|
|
|
|
|
uci set dhcp.@dnsmasq[0].cachesize="0"
|
|
|
|
|
@@ -418,11 +422,11 @@ dnsmasq_restore() {
|
|
|
|
|
|
|
|
|
|
local server=$(uci get dhcp.@dnsmasq[0].server 2>/dev/null)
|
|
|
|
|
if [[ "$server" == "127.0.0.42" ]]; then
|
|
|
|
|
uci -q delete dhcp.@dnsmasq[0].server
|
|
|
|
|
uci -q delete dhcp.@dnsmasq[0].server 2>/dev/null
|
|
|
|
|
for server in $(uci get dhcp.@dnsmasq[0].podkop_server 2>/dev/null); do
|
|
|
|
|
uci add_list dhcp.@dnsmasq[0].server="$server"
|
|
|
|
|
done
|
|
|
|
|
uci delete dhcp.@dnsmasq[0].podkop_server
|
|
|
|
|
uci delete dhcp.@dnsmasq[0].podkop_server 2>/dev/null
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
uci delete dhcp.@dnsmasq[0].podkop_cachesize
|
|
|
|
|
@@ -939,6 +943,9 @@ sing_box_outdound() {
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
"block")
|
|
|
|
|
log "Block mode"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
log "Requires *vpn* or *proxy* value"
|
|
|
|
|
return
|
|
|
|
|
@@ -1219,8 +1226,8 @@ sing_box_config_vless() {
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
log "Config VLESS created successfully"
|
|
|
|
|
else
|
|
|
|
|
log "Error: VLESS invalid JSON config generated"
|
|
|
|
|
return 1
|
|
|
|
|
log "[critical] Error: VLESS invalid JSON config generated"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1458,27 +1465,54 @@ sing_box_rules() {
|
|
|
|
|
local rule_set="$1"
|
|
|
|
|
local outbound="$2"
|
|
|
|
|
|
|
|
|
|
# Check if there is an outbound rule for "tproxy-in"
|
|
|
|
|
local rule_exists=$(jq -r '.route.rules[] | select(.outbound == "'"$outbound"'" and .inbound == ["tproxy-in"])' "$SING_BOX_CONFIG")
|
|
|
|
|
config_get mode "$section" "mode"
|
|
|
|
|
|
|
|
|
|
if [[ -n "$rule_exists" ]]; then
|
|
|
|
|
# If a rule for tproxy-in exists, add a new rule_set to the existing rule
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
--arg outbound "$outbound" \
|
|
|
|
|
'(.route.rules[] | select(.outbound == $outbound and .inbound == ["tproxy-in"]) .rule_set) += [$rule_set]' \
|
|
|
|
|
"$SING_BOX_CONFIG" >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
if [[ "$mode" == "block" ]]; then
|
|
|
|
|
# Action reject
|
|
|
|
|
# Check if there is an rule with reject"
|
|
|
|
|
local rule_exists=$(jq -r '.route.rules[] | select(.inbound == ["tproxy-in"] and .action == "reject")' "$SING_BOX_CONFIG")
|
|
|
|
|
|
|
|
|
|
if [[ -n "$rule_exists" ]]; then
|
|
|
|
|
# If a rule for rejectexists, add a new rule_set to the existing rule
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
'(.route.rules[] | select(.inbound == ["tproxy-in"] and .action == "reject") .rule_set) += [$rule_set]' \
|
|
|
|
|
"$SING_BOX_CONFIG" > /tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
else
|
|
|
|
|
# If there is no rule for reject, create a new one with rule_set
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
'.route.rules += [{
|
|
|
|
|
"inbound": ["tproxy-in"],
|
|
|
|
|
"rule_set": [$rule_set],
|
|
|
|
|
"action": "reject"
|
|
|
|
|
}]' "$SING_BOX_CONFIG" > /tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
fi
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
# If there is no rule for tproxy-in, create a new one with rule_set
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
--arg outbound "$outbound" \
|
|
|
|
|
'.route.rules += [{
|
|
|
|
|
"inbound": ["tproxy-in"],
|
|
|
|
|
"rule_set": [$rule_set],
|
|
|
|
|
"outbound": $outbound,
|
|
|
|
|
"action": "route"
|
|
|
|
|
}]' "$SING_BOX_CONFIG" >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
# Action route
|
|
|
|
|
# Check if there is an outbound rule for "tproxy-in"
|
|
|
|
|
local rule_exists=$(jq -r '.route.rules[] | select(.outbound == "'"$outbound"'" and .inbound == ["tproxy-in"])' "$SING_BOX_CONFIG")
|
|
|
|
|
|
|
|
|
|
if [[ -n "$rule_exists" ]]; then
|
|
|
|
|
# If a rule for tproxy-in exists, add a new rule_set to the existing rule
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
--arg outbound "$outbound" \
|
|
|
|
|
'(.route.rules[] | select(.outbound == $outbound and .inbound == ["tproxy-in"]) .rule_set) += [$rule_set]' \
|
|
|
|
|
"$SING_BOX_CONFIG" >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
else
|
|
|
|
|
# If there is no rule for tproxy-in, create a new one with rule_set
|
|
|
|
|
jq \
|
|
|
|
|
--arg rule_set "$rule_set" \
|
|
|
|
|
--arg outbound "$outbound" \
|
|
|
|
|
'.route.rules += [{
|
|
|
|
|
"inbound": ["tproxy-in"],
|
|
|
|
|
"rule_set": [$rule_set],
|
|
|
|
|
"outbound": $outbound,
|
|
|
|
|
"action": "route"
|
|
|
|
|
}]' "$SING_BOX_CONFIG" >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json "$SING_BOX_CONFIG"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1572,18 +1606,24 @@ list_custom_url_domains_create() {
|
|
|
|
|
local section="$2"
|
|
|
|
|
local URL="$1"
|
|
|
|
|
local filename=$(basename "$URL")
|
|
|
|
|
local filepath="/tmp/podkop/${filename}"
|
|
|
|
|
|
|
|
|
|
config_get_bool detour "main" "detour" "0"
|
|
|
|
|
if [ "$detour" -eq 1 ]; then
|
|
|
|
|
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -O "/tmp/podkop/${filename}" "$URL"
|
|
|
|
|
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -O "$filepath" "$URL"
|
|
|
|
|
else
|
|
|
|
|
wget -O "/tmp/podkop/${filename}" "$URL"
|
|
|
|
|
wget -O "$filepath" "$URL"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if grep -q $'\r' "$filepath"; then
|
|
|
|
|
log "$filename has Windows line endings (CRLF). Converting to Unix (LF)"
|
|
|
|
|
sed -i 's/\r$//' "$filepath"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
while IFS= read -r domain; do
|
|
|
|
|
log "From downloaded file: $domain"
|
|
|
|
|
sing_box_ruleset_domains_json $domain $section
|
|
|
|
|
done <"/tmp/podkop/$filename"
|
|
|
|
|
done <"$filepath"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process_domains_list_url() {
|
|
|
|
|
@@ -1617,19 +1657,25 @@ list_custom_url_subnets_create() {
|
|
|
|
|
local section="$2"
|
|
|
|
|
local URL="$1"
|
|
|
|
|
local filename=$(basename "$URL")
|
|
|
|
|
local filepath="/tmp/podkop/${filename}"
|
|
|
|
|
|
|
|
|
|
config_get_bool detour "main" "detour" "0"
|
|
|
|
|
if [ "$detour" -eq 1 ]; then
|
|
|
|
|
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -O "/tmp/podkop/${filename}" "$URL"
|
|
|
|
|
http_proxy="http://127.0.0.1:4534" https_proxy="http://127.0.0.1:4534" wget -O "$filepath" "$URL"
|
|
|
|
|
else
|
|
|
|
|
wget -O "/tmp/podkop/${filename}" "$URL"
|
|
|
|
|
wget -O "$filepath" "$URL"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if grep -q $'\r' "$filepath"; then
|
|
|
|
|
log "$filename has Windows line endings (CRLF). Converting to Unix (LF)"
|
|
|
|
|
sed -i 's/\r$//' "$filepath"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
while IFS= read -r subnet; do
|
|
|
|
|
log "From local file: $subnet"
|
|
|
|
|
sing_box_ruleset_subnets_json $subnet $section
|
|
|
|
|
nft add element inet PodkopTable podkop_subnets { $subnet }
|
|
|
|
|
done <"/tmp/podkop/$filename"
|
|
|
|
|
done <"$filepath"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process_subnet_for_section_remote() {
|
|
|
|
|
|