fix: fixed init and domain parser in script #5
@@ -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
|
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
|
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
@@ -1,26 +1,45 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
START=95
|
START=99
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
|
XRAY_BIN="/opt/.xray-manager/xray-manager.sh"
|
||||||
|
|
||||||
extra_command "update" "Download and refresh remote lists"
|
extra_command "update" "Download and refresh remote lists"
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
xray-manager start
|
local timeout=20
|
||||||
procd_open_instance
|
while [ ! -s /proc/net/route ] && [ $timeout -gt 0 ]; do
|
||||||
procd_set_param command tail -f /dev/null
|
sleep 1
|
||||||
procd_set_param respawn
|
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
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
xray-manager stop
|
"$XRAY_BIN" stop
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_service() {
|
reload_service() {
|
||||||
xray-manager reload
|
"$XRAY_BIN" reload
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
xray-manager update
|
"$XRAY_BIN" update
|
||||||
}
|
}
|
||||||
|
|||||||
+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 add chain ip "$TABLE" prerouting { type filter hook prerouting priority mangle \; policy accept \; } 2>/dev/null
|
||||||
nft flush chain ip "$TABLE" prerouting
|
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
|
nft add rule ip "$TABLE" prerouting fib daddr type local accept
|
||||||
|
|
||||||
local mark_hex=$(printf '0x%x' "$TPROXY_MARK")
|
local mark_hex=$(printf '0x%x' "$TPROXY_MARK")
|
||||||
@@ -191,33 +193,38 @@ _process_item() {
|
|||||||
;;
|
;;
|
||||||
uip|udom)
|
uip|udom)
|
||||||
_log "Checking $id..." "info" "1"
|
_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
|
local dl_ok=0
|
||||||
|
|
||||||
for url in $val; do
|
for url in $val; do
|
||||||
local url_hash=$(echo "$url" | md5sum | cut -c1-8)
|
local url_hash=$(echo "$url" | md5sum | cut -c1-8)
|
||||||
local etag_file="$CACHE_DIR/${id}_${url_hash}.etag"
|
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 header_file="$CACHE_DIR/header_$id"
|
||||||
local old_etag=$(cat "$etag_file" 2>/dev/null | tr -d '\r\n ')
|
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\"'"
|
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 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
|
if grep -q "HTTP/.* 304" "$header_file" 2>/dev/null; then
|
||||||
_log " -> $url_hash: 304 Not Modified" "info" "1"
|
_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
|
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"
|
_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"
|
[ -n "$current_etag" ] && echo "$current_etag" > "$etag_file"
|
||||||
|
cat "$tmp_single" > "$cache_raw"
|
||||||
|
cat "$tmp_single" >> "$tmp_all"
|
||||||
dl_ok=1
|
dl_ok=1
|
||||||
else
|
else
|
||||||
_log " -> $url_hash: Error (Code: $exit_code)" "warn" "1"
|
_log " -> $url_hash: Error. Trying cache..." "warn" "1"
|
||||||
[ -f "$fullpath" ] && cat "$fullpath" >> "$tmp_all"
|
[ -f "$cache_raw" ] && cat "$cache_raw" >> "$tmp_all"
|
||||||
fi
|
fi
|
||||||
rm -f "$header_file"; echo "" >> "$tmp_all"
|
rm -f "$header_file" "$tmp_single"; echo "" >> "$tmp_all"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$dl_ok" = "1" ] && [ -s "$tmp_all" ]; then
|
if [ "$dl_ok" = "1" ] && [ -s "$tmp_all" ]; then
|
||||||
@@ -225,7 +232,7 @@ _process_item() {
|
|||||||
if [ "$type" = "uip" ]; then
|
if [ "$type" = "uip" ]; then
|
||||||
sed 's/\r//g; /^#/d; /^[[:space:]]*$/d' "$tmp_all" | awk '{print ($1 ~ /\//) ? $1 : $1"/32"}' | sort -u > "$out"
|
sed 's/\r//g; /^#/d; /^[[:space:]]*$/d' "$tmp_all" | awk '{print ($1 ~ /\//) ? $1 : $1"/32"}' | sort -u > "$out"
|
||||||
else
|
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"
|
sed "s|^|nftset=/|; s|\$|/4#ip#$TABLE#s_$id|" > "$out"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user