fix: fixed init and domain parser in script
This commit is contained in:
+16
-9
@@ -81,6 +81,8 @@ _nft_init() {
|
||||
|
||||
nft add chain ip "$TABLE" prerouting { type filter hook prerouting priority mangle \; policy accept \; } 2>/dev/null
|
||||
nft flush chain ip "$TABLE" prerouting
|
||||
|
||||
nft add rule ip "$TABLE" prerouting udp dport 67-68 accept
|
||||
nft add rule ip "$TABLE" prerouting fib daddr type local accept
|
||||
|
||||
local mark_hex=$(printf '0x%x' "$TPROXY_MARK")
|
||||
@@ -191,33 +193,38 @@ _process_item() {
|
||||
;;
|
||||
uip|udom)
|
||||
_log "Checking $id..." "info" "1"
|
||||
local tmp_all="$CACHE_DIR/dl_all_$id"; : > "$tmp_all"
|
||||
local tmp_all="$CACHE_DIR/dl_all_$id"
|
||||
: > "$tmp_all"
|
||||
local dl_ok=0
|
||||
|
||||
for url in $val; do
|
||||
local url_hash=$(echo "$url" | md5sum | cut -c1-8)
|
||||
local etag_file="$CACHE_DIR/${id}_${url_hash}.etag"
|
||||
local cache_raw="$CACHE_DIR/${id}_${url_hash}.raw"
|
||||
local header_file="$CACHE_DIR/header_$id"
|
||||
local old_etag=$(cat "$etag_file" 2>/dev/null | tr -d '\r\n ')
|
||||
local etag_header=""; [ -n "$old_etag" ] && etag_header="-H 'If-None-Match: \"$old_etag\"'"
|
||||
|
||||
eval "curl -sSfL --connect-timeout 10 $etag_header -D '$header_file' '$url'" >> "$tmp_all"
|
||||
local tmp_single="$CACHE_DIR/tmp_dl_$url_hash"
|
||||
eval "curl -sSfL --connect-timeout 10 $etag_header -D '$header_file' '$url'" > "$tmp_single"
|
||||
local exit_code=$?
|
||||
local current_etag=$(grep -i "^etag:" "$header_file" | sed 's/[Ee][Tt][Aa][Gg]: //; s/W\///; s/["\r\n ]//g')
|
||||
|
||||
if grep -q "HTTP/.* 304" "$header_file" 2>/dev/null; then
|
||||
_log " -> $url_hash: 304 Not Modified" "info" "1"
|
||||
[ -f "$fullpath" ] && cat "$fullpath" >> "$tmp_all"
|
||||
[ -f "$cache_raw" ] && cat "$cache_raw" >> "$tmp_all"
|
||||
dl_ok=1
|
||||
elif [ $exit_code -eq 0 ]; then
|
||||
elif [ $exit_code -eq 0 ] && [ -s "$tmp_single" ]; then
|
||||
_log " -> $url_hash: 200 OK" "info" "1"
|
||||
local current_etag=$(grep -i "^etag:" "$header_file" | sed 's/[Ee][Tt][Aa][Gg]: //; s/W\///; s/["\r\n ]//g')
|
||||
[ -n "$current_etag" ] && echo "$current_etag" > "$etag_file"
|
||||
cat "$tmp_single" > "$cache_raw"
|
||||
cat "$tmp_single" >> "$tmp_all"
|
||||
dl_ok=1
|
||||
else
|
||||
_log " -> $url_hash: Error (Code: $exit_code)" "warn" "1"
|
||||
[ -f "$fullpath" ] && cat "$fullpath" >> "$tmp_all"
|
||||
_log " -> $url_hash: Error. Trying cache..." "warn" "1"
|
||||
[ -f "$cache_raw" ] && cat "$cache_raw" >> "$tmp_all"
|
||||
fi
|
||||
rm -f "$header_file"; echo "" >> "$tmp_all"
|
||||
rm -f "$header_file" "$tmp_single"; echo "" >> "$tmp_all"
|
||||
done
|
||||
|
||||
if [ "$dl_ok" = "1" ] && [ -s "$tmp_all" ]; then
|
||||
@@ -225,7 +232,7 @@ _process_item() {
|
||||
if [ "$type" = "uip" ]; then
|
||||
sed 's/\r//g; /^#/d; /^[[:space:]]*$/d' "$tmp_all" | awk '{print ($1 ~ /\//) ? $1 : $1"/32"}' | sort -u > "$out"
|
||||
else
|
||||
tr '[:upper:]' '[:lower:]' < "$tmp_all" | grep -oE '([a-z0-9-]+\.)+[a-z]{2,}' | sort -u | \
|
||||
tr 'A-Z' 'a-z' < "$tmp_all" | grep -oE '([a-z0-9-]+\.)+[a-z]{2,}' | sort -u | \
|
||||
sed "s|^|nftset=/|; s|\$|/4#ip#$TABLE#s_$id|" > "$out"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user