diff --git a/core/scripts/scheduler.sh b/core/scripts/scheduler.sh index 64257f3..38b2746 100644 --- a/core/scripts/scheduler.sh +++ b/core/scripts/scheduler.sh @@ -49,12 +49,13 @@ After=network.target [Service] Type=simple User=root -WorkingDirectory=/etc/hysteria/core/scripts/hysteria2 +WorkingDirectory=/etc/hysteria ExecStart=/etc/hysteria/hysteria2_venv/bin/python3 /etc/hysteria/core/scripts/hysteria2/auth_server.py Restart=always -RestartSec=3 -Environment="USERS_FILE=/etc/hysteria/users.json" -Environment="CONFIG_FILE=/etc/hysteria/config.json" +RestartSec=10 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=hysteria-Auth [Install] WantedBy=multi-user.target diff --git a/upgrade.sh b/upgrade.sh index f97a6c2..383d906 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -7,7 +7,7 @@ trap 'echo -e "\n❌ An error occurred. Aborting."; exit 1' ERR HYSTERIA_INSTALL_DIR="/etc/hysteria" HYSTERIA_VENV_DIR="$HYSTERIA_INSTALL_DIR/hysteria2_venv" REPO_URL="https://github.com/ReturnFI/Blitz" -REPO_BRANCH="main" +REPO_BRANCH="auth" GEOSITE_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geosite.dat" GEOIP_URL="https://raw.githubusercontent.com/Chocolate4U/Iran-v2ray-rules/release/geoip.dat" @@ -34,7 +34,6 @@ FILES=( "$HYSTERIA_INSTALL_DIR/.configs.env" "$HYSTERIA_INSTALL_DIR/nodes.json" "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot/.env" - # "$HYSTERIA_INSTALL_DIR/core/scripts/singbox/.env" "$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/.env" "$HYSTERIA_INSTALL_DIR/core/scripts/normalsub/Caddyfile.normalsub" "$HYSTERIA_INSTALL_DIR/core/scripts/webpanel/.env" @@ -77,15 +76,22 @@ for FILE in "${FILES[@]}"; do fi done +# ========== Update Configuration ========== +info "Updating Hysteria configuration for HTTP authentication..." +auth_block='{"type": "http", "http": {"url": "http://127.0.0.1:28262/auth", "timeout": "5s"}}' +if [[ -f "$HYSTERIA_INSTALL_DIR/config.json" ]]; then + jq --argjson auth_block "$auth_block" '.auth = $auth_block' "$HYSTERIA_INSTALL_DIR/config.json" > "$HYSTERIA_INSTALL_DIR/config.json.tmp" && mv "$HYSTERIA_INSTALL_DIR/config.json.tmp" "$HYSTERIA_INSTALL_DIR/config.json" + success "config.json updated to use aiohttp auth server." +else + warn "config.json not found after restore. Skipping auth update." +fi + # ========== Permissions ========== info "Setting ownership and permissions..." chown hysteria:hysteria "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" chmod 640 "$HYSTERIA_INSTALL_DIR/ca.key" "$HYSTERIA_INSTALL_DIR/ca.crt" - -# chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/singbox" chown -R hysteria:hysteria "$HYSTERIA_INSTALL_DIR/core/scripts/telegrambot" - -chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/user.sh" +chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/auth_server.py" chmod +x "$HYSTERIA_INSTALL_DIR/core/scripts/hysteria2/kick.py" # ========== Virtual Environment ========== @@ -97,26 +103,29 @@ pip install --upgrade pip >/dev/null pip install -r requirements.txt >/dev/null success "Python environment ready." -# ========== Scheduler ========== -info "Ensuring scheduler is set..." +# ========== Systemd Services ========== +info "Ensuring systemd services are configured..." if source "$HYSTERIA_INSTALL_DIR/core/scripts/scheduler.sh"; then - if ! check_scheduler_service; then - if setup_hysteria_scheduler; then - success "Scheduler service configured." - else - warn "Scheduler setup failed, but continuing upgrade..." - fi + if ! check_auth_server_service; then + setup_hysteria_auth_server && success "Auth server service configured." || warn "Auth server setup failed." else - success "Scheduler already set." + success "Auth server service already configured." + fi + + if ! check_scheduler_service; then + setup_hysteria_scheduler && success "Scheduler service configured." || warn "Scheduler setup failed." + else + success "Scheduler service already set." fi else - warn "Failed to source scheduler.sh, continuing without scheduler setup..." + warn "Failed to source scheduler.sh, continuing without service setup..." fi # ========== Restart Services ========== SERVICES=( hysteria-caddy.service hysteria-server.service + hysteria-auth.service hysteria-scheduler.service hysteria-telegram-bot.service hysteria-normal-sub.service @@ -130,7 +139,7 @@ for SERVICE in "${SERVICES[@]}"; do if systemctl status "$SERVICE" &>/dev/null; then systemctl restart "$SERVICE" && success "$SERVICE restarted." || warn "$SERVICE failed to restart." else - warn "$SERVICE not found or not installed. Skipping..." + warn "$SERVICE not found. Skipping..." fi done @@ -144,4 +153,4 @@ fi # ========== Launch Menu ========== sleep 10 chmod +x menu.sh -./menu.sh +./menu.sh \ No newline at end of file