diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8b9667f --- /dev/null +++ b/install.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# DragonX Installer +# Original author: Danilo (refactored for DragonX) +set -e + +INSTALL_DIR="$HOME/DragonX" +REPO_URL="https://git.dr2.site/penguinehis/DragonX-SSH-Proxy" + +echo "Installing DragonX into $INSTALL_DIR..." + +# Update apt and install dependencies +if command -v apt >/dev/null 2>&1; then + sudo apt update + sudo apt install -y git unzip wget screen +fi + +# Fetch code +if [ -d "$INSTALL_DIR/.git" ]; then + echo "Existing repo detected. Pulling latest..." + git -C "$INSTALL_DIR" pull --rebase --autostash || true +else + rm -rf "$INSTALL_DIR" + git clone --depth 1 "$REPO_URL" "$INSTALL_DIR" +fi + +# Ensure executables are present & executable +chmod +x "$INSTALL_DIR/proxy.sh" 2>/dev/null || true +chmod +x "$INSTALL_DIR/dragon_go-ARM" 2>/dev/null || true +chmod +x "$INSTALL_DIR/dragon_go-x86" 2>/dev/null || true + +# Create global command +sudo ln -sf "$INSTALL_DIR/proxy.sh" /usr/local/bin/dragonx + +echo "✅ Installation finished! Use 'dragonx' to open the menu." +echo "Tip: Start ports from the menu; each port runs as its own systemd service." diff --git a/proxy.sh b/proxy.sh index fd10f1a..d653641 100644 --- a/proxy.sh +++ b/proxy.sh @@ -1,11 +1,24 @@ #!/usr/bin/env bash +# DragonX Manager - systemd + full menu +# Multi-port support +# Original author: Danilo (refactored for DragonX) + +PROXY_DIR="$HOME/DragonX" +SERVICE_PREFIX="dragonx_port" +LOG_DIR="$PROXY_DIR/logs" +PORTS_FILE="$PROXY_DIR/ports.list" + +mkdir -p "$LOG_DIR" +mkdir -p "$PROXY_DIR" + +# Detect architecture automatically ARCH=$(uname -m) case "$ARCH" in x86_64|i386|i686) - PROXY_BIN="./dragon_go-x86" + BIN_NAME="dragon_go-x86" ;; aarch64|armv7l|armv6l|arm*) - PROXY_BIN="./dragon_go-ARM" + BIN_NAME="dragon_go-ARM" ;; *) echo "Unsupported architecture: $ARCH" @@ -13,24 +26,129 @@ case "$ARCH" in ;; esac -read -p "Enter proxy port (e.g. 80 or 443): " PORT -SESSION="proxy_${PORT}" +# Function to create/update a systemd service +update_service() { + local PORT=$1 + local SERVICE_NAME="${SERVICE_PREFIX}_${PORT}.service" + sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null < 65535 )); do + echo "⚠️ Enter a valid port (1-65535)." + read -p "Enter proxy port: " PORT + done - *) - echo "Invalid action. Please run the script and enter 'start' or 'stop'." - exit 1 - ;; -esac + if ! grep -q "^$PORT$" "$PORTS_FILE" 2>/dev/null; then + echo $PORT >> "$PORTS_FILE" + fi + + update_service $PORT + sudo systemctl start "${SERVICE_PREFIX}_${PORT}.service" + echo "✅ DragonX started on port $PORT" + read -p "Press ENTER to return to the menu..." +} + +# Stop a port +stop_port() { + read -p "Enter port to stop: " PORT + local SERVICE_NAME="${SERVICE_PREFIX}_${PORT}.service" + sudo systemctl stop "$SERVICE_NAME" + echo "🛑 DragonX stopped on port $PORT" + read -p "Press ENTER to return to the menu..." +} + +# Restart a port +restart_port() { + read -p "Enter port to restart: " PORT + update_service $PORT + sudo systemctl restart "${SERVICE_PREFIX}_${PORT}.service" + echo "🔄 DragonX restarted on port $PORT" + read -p "Press ENTER to return to the menu..." +} + +# Remove all configured ports and services +uninstall_dragonx() { + echo "❌ Removing DragonX..." + if [ -f "$PORTS_FILE" ]; then + while read -r PORT; do + sudo systemctl stop "${SERVICE_PREFIX}_${PORT}.service" + sudo systemctl disable "${SERVICE_PREFIX}_${PORT}.service" + sudo rm -f "/etc/systemd/system/${SERVICE_PREFIX}_${PORT}.service" + done < "$PORTS_FILE" + rm -f "$PORTS_FILE" + fi + sudo systemctl daemon-reload + rm -rf "$PROXY_DIR" + sudo rm -f /usr/local/bin/dragonx + echo "✅ DragonX removed successfully!" + exit 0 +} + +# Main menu +menu() { + clear + echo "==============================" + echo " DragonX" + echo "==============================" + + if [ -f "$PORTS_FILE" ]; then + HAS_ACTIVE=0 + echo "Active ports:" + while read -r PORT; do + local SERVICE_NAME="${SERVICE_PREFIX}_${PORT}.service" + if systemctl is-active --quiet "$SERVICE_NAME"; then + echo " - Port $PORT (🟢 Active)" + HAS_ACTIVE=1 + fi + done < "$PORTS_FILE" + + if [ $HAS_ACTIVE -eq 0 ]; then + echo "No active ports" + fi + else + echo "No active ports" + fi + + echo "------------------------------" + echo "1) Start DragonX (add port)" + echo "2) Stop DragonX (port)" + echo "3) Restart DragonX (port)" + echo "4) Uninstall DragonX" + echo "5) Exit" + echo "==============================" + read -p "Choose an option: " option + + case $option in + 1) start_port ;; + 2) stop_port ;; + 3) restart_port ;; + 4) uninstall_dragonx ;; + 5) exit 0 ;; + *) echo "Invalid option!"; sleep 1; menu ;; + esac +} + +# Menu loop +while true; do + menu +done