Merge pull request 'fix: fixed init and domain parser in script' (#5) from fix-init-and-parser into main

Reviewed-on: https://gitea.oyacoi.ru/pyrschtjag/xray-manager/pulls/5
This commit was merged in pull request #5.
This commit is contained in:
2026-04-05 14:25:16 +04:00
3 changed files with 43 additions and 19 deletions
-2
View File
@@ -44,8 +44,6 @@ git clone https://gitea.oyacoi.ru/pyrschtjag/xray-manager.git /opt/.xray-manager
cp /opt/.xray-manager/config/xray-manager.example /etc/config/xray-manager
# Инит-скрипт для управления сервисом
ln -s /opt/.xray-manager/init.d/xray-manager /etc/init.d/xray-manager
# Команда в PATH для быстрого доступа из любой папки
ln -s /opt/.xray-manager/xray-manager.sh /usr/sbin/xray-manager
```
## Команды управления
+27 -8
View File
@@ -1,26 +1,45 @@
#!/bin/sh /etc/rc.common
START=95
START=99
USE_PROCD=1
XRAY_BIN="/opt/.xray-manager/xray-manager.sh"
extra_command "update" "Download and refresh remote lists"
start_service() {
xray-manager start
procd_open_instance
procd_set_param command tail -f /dev/null
procd_set_param respawn
local timeout=20
while [ ! -s /proc/net/route ] && [ $timeout -gt 0 ]; do
sleep 1
timeout=$((timeout - 1))
done
timeout=20
while ! ping -q -c 1 -W 2 1.1.1.1 >/dev/null 2>&1 && [ $timeout -gt 0 ]; do
sleep 2
timeout=$((timeout - 2))
done
procd_open_instance "main"
procd_set_param command "$XRAY_BIN" start
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param limits core="unlimited"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
stop_service() {
xray-manager stop
"$XRAY_BIN" stop
}
reload_service() {
xray-manager reload
"$XRAY_BIN" reload
}
update() {
xray-manager update
"$XRAY_BIN" update
}
+16 -9
View File
@@ -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