refactor-fix

This commit is contained in:
root
2026-04-12 20:00:19 +04:00
parent e80f3f0171
commit 3462c3a9ad
2 changed files with 53 additions and 4 deletions
+10 -3
View File
@@ -6,7 +6,6 @@ USE_PROCD=1
XRAYMANAGER_BIN="/opt/.xray-manager/xray-manager.sh"
extra_command "update" "Download and refresh remote lists"
extra_command "reload" "Quick reload using local cache"
start_service() {
"$XRAYMANAGER_BIN" start
@@ -21,9 +20,17 @@ stop_service() {
}
reload_service() {
"$XRAYMANAGER_BIN" reload
if procd_running "xray-manager" "main"; then
"$XRAYMANAGER_BIN" reload
else
echo "xray-manager is not running"
fi
}
update() {
"$XRAYMANAGER_BIN" update
if procd_running "xray-manager" "main"; then
"$XRAYMANAGER_BIN" update
else
echo "xray-manager is not running"
fi
}
+43 -1
View File
@@ -57,7 +57,7 @@ _init_vars() {
for var in $required_vars; do
eval val=\$$var
if [ -z "$val" ]; then
_log "[config] critical variable '$var' is missing" "err"
_log "[config] variable '$var' is missing" "err"
return 1
fi
done
@@ -72,6 +72,47 @@ _init_vars() {
return 0
}
_validate_config() {
_log "[config] validating uci syntax and paths" "debug"
local dns_confdir
dns_confdir=$(uci -q get dhcp.@dnsmasq[0].confdir)
if [ -z "$dns_confdir" ] || ! echo "$dns_confdir" | grep -q "$DNSMASQ_DIR"; then
_log "[dnsmasq] $DNSMASQ_DIR is not set in dhcp.@dnsmasq[0].confdir" "warn"
fi
local allowed_opts="name direction exclude parent ip domain url_ip url_domain"
validate_list_section() {
local s="$1" name direction
config_get name "$s" name
config_get direction "$s" direction "dst"
if [ -z "$name" ]; then
_log "[config] section $s is missing 'option name'" "err"
exit 1
fi
local current_opt
for current_opt in $(uci show xray-manager."$s" | cut -d'.' -f3 | cut -d'=' -f1 | sort -u); do
case "$current_opt" in
.*) continue ;;
esac
if ! echo "$allowed_opts" | grep -qw "$current_opt"; then
_log "[$name] unknown option found: '$current_opt'" "err"
exit 1
fi
done
case "$direction" in
src|dst|out|force_src) ;;
*) _log "[$name] invalid direction: $direction" "err"; exit 1 ;;
esac
}
config_foreach validate_list_section "xray-list"
}
_nft_init() {
_log "[$TABLE] initializing nft table" "debug"
nft add table ip "$TABLE" 2>/dev/null
@@ -291,6 +332,7 @@ _process_section() {
_run() {
_log "[main] starting execution ($1)" "info"
_init_vars || return 1
_validate_config
DNS_CHANGES=0; NEED_UPDATE=0; : > "$ACTIVE_LIST"
[ "$FULL_LOAD" = "1" ] && _wait_for_net