### Server Startup and Operation Logs Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Example log output showing the server starting up, loading configurations, building its lookup table, and handling redirect and 404 requests. ```log 2025/01/15 12:00:00 Starting Subscription URL Redirect Server... 2025/01/15 12:00:00 Loaded server configuration from config.json 2025/01/15 12:00:00 Loaded 2455 user mappings from subscription_url_mapping.json 2025/01/15 12:00:00 Built path lookup with 2455 entries 2025/01/15 12:00:00 Starting HTTP server on 0.0.0.0:8080 2025/01/15 12:00:00 Server started successfully. Press Ctrl+C to stop. 2025/01/15 12:00:01 Redirecting: /sub/user1/key123 -> /sub/newtoken456 2025/01/15 12:00:02 404 Not Found: /sub/unknown/path ``` -------------------------------- ### Start Redirect Server (Default Files) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Starts the redirect server using default configuration and mapping files. ```bash ./redirect-server ``` -------------------------------- ### Enable and Start systemd Service Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Commands to enable the redirect server service to start on boot and to start, stop, or check its status. ```bash sudo systemctl enable redirect-server sudo systemctl start redirect-server sudo systemctl status redirect-server ``` -------------------------------- ### Install Dependencies and Run Migration Source: https://github.com/pasarguard/migrations/blob/main/x-ui/README.md Installs project dependencies using uv and then runs the main migration script. Pip alternative is provided. ```bash # Install dependencies using uv (recommended) or pip uv sync # Or: pip install python-dotenv # Run migration with default paths (expects x-ui.db in x-ui directory) uv run migrate.py ``` -------------------------------- ### Install Dependencies and Run Migration Source: https://github.com/pasarguard/migrations/blob/main/marzneshin/README.md Installs project dependencies using uv or pip, then configures and runs the migration script. Ensure you copy and edit the .env file with your database credentials before running. ```bash # Install dependencies using uv (recommended) or pip uv sync # Or: pip install pymysql python-dotenv xxhash # Configure and run cp .env.example .env # Edit .env with your database credentials uv run migrate.py ``` -------------------------------- ### Install uv Package Manager Source: https://github.com/pasarguard/migrations/blob/main/marzneshin/README.md Installs the uv package manager. Use the Linux/macOS or Windows command based on your operating system. Visit the GitHub repository for alternative installation methods. ```bash # Linux/macOS curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```powershell # Windows (PowerShell) powershell -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Start Redirect Server (Custom Files) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Starts the redirect server with custom configuration and mapping files using short or long flags. ```bash # Using short flags ./redirect-server -c config.json -m subscription_url_mapping.json # Using long flags ./redirect-server --config /path/to/config.json --map /path/to/mapping.json ``` -------------------------------- ### Install Pasarguard Redirect Server Source: https://github.com/pasarguard/migrations/blob/main/README.md Installs the redirect server for handling old URL redirects. This script prompts for the URL mapping file and guides through server configuration. ```bash # Run the automated installer with interactive setup curl -fsSL https://raw.githubusercontent.com/PasarGuard/migrations/main/redirect-server/install_redirect_server.sh | sudo bash ``` -------------------------------- ### Install uv Package Manager Source: https://github.com/pasarguard/migrations/blob/main/x-ui/README.md Installs the uv package manager using a script. Supports Linux/macOS and Windows. ```bash # Linux/macOS curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```powershell # Windows (PowerShell) powershell -c "irm https://astral.sh/uv/install.ps1 | iex" ``` ```bash # Or visit: https://github.com/astral-sh/uv ``` -------------------------------- ### Automated Installation Script Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Installs the redirect server using a curl script. Supports pinning to a specific Git tag. ```bash curl -fsSL https://raw.githubusercontent.com/PasarGuard/migrations/main/redirect-server/install_redirect_server.sh | sudo bash ``` ```bash curl -fsSL https://raw.githubusercontent.com/PasarGuard/migrations/main/redirect-server/install_redirect_server.sh | sudo bash -s -- v1.2.3 ``` -------------------------------- ### Run Migration with Custom Options Source: https://github.com/pasarguard/migrations/blob/main/x-ui/README.md Example of running the migration script with custom paths for input database, schema database, output folder, and log level. ```bash uv run migrate.py \ --input-db /path/to/x-ui.db \ --schema-db /path/to/pasarguard-schema.db \ --output-folder /path/to/output \ --log-level DEBUG ``` -------------------------------- ### Install Marzneshin Dependencies Source: https://github.com/pasarguard/migrations/blob/main/README.md Installs the necessary Python dependencies for the Marzneshin migration using uv or pip. Ensure your .env file is configured before running. ```bash # Install dependencies using uv (recommended) or pip uv sync # Or: pip install pymysql python-dotenv xxhash ``` -------------------------------- ### HTTP Server Configuration (Same Domain) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Example configuration for an HTTP server listening on port 8080 on the same domain. ```json { "host": "0.0.0.0", "port": 8080, "redirect_domain": "", "ssl": { "enabled": false } } ``` -------------------------------- ### HTTPS Server Configuration (Embedded Certificates) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Example configuration for an HTTPS server with embedded SSL certificates. ```json { "host": "0.0.0.0", "port": 443, "redirect_domain": "", "ssl": { "enabled": true, "cert": "-----BEGIN CERTIFICATE-----\nMIIC...\n-----END CERTIFICATE-----", "key": "-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----" } } ``` -------------------------------- ### HTTP Server Configuration (Custom Redirect Domain) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Example configuration for an HTTP server that redirects to a custom domain. ```json { "host": "0.0.0.0", "port": 8080, "redirect_domain": "https://new-server.example.com", "ssl": { "enabled": false } } ``` -------------------------------- ### Generate Subscription URL Mapping Source: https://github.com/pasarguard/migrations/blob/main/x-ui/README.md Generates a subscription URL mapping file using the migration tool. Includes default and custom path examples. ```bash # Generate subscription URL mapping uv run migration/generate_subscription_url_mapping.py --output subscription_url_mapping.json # Or with custom paths uv run migration/generate_subscription_url_mapping.py \ --xui-db /path/to/x-ui.db \ --pasarguard-db /path/to/output-db/db.sqlite3 \ --output subscription_url_mapping.json ``` -------------------------------- ### Test Redirect Server Source: https://github.com/pasarguard/migrations/blob/main/README.md Tests a specific redirect by making a curl request to a sample old URL. Replace the example URL with your actual old URL to verify functionality. ```bash # Test a redirect (replace with your old URL) curl -I http://localhost:8080/sub/old_username/old_key ``` -------------------------------- ### Build Redirect Server Binary Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Builds the redirect-server binary from the source code. Ensure you are in the redirect-server directory. ```bash cd redirect-server go build -o redirect-server ``` -------------------------------- ### Prepare x-ui Database Source: https://github.com/pasarguard/migrations/blob/main/x-ui/README.md Copies the x-ui SQLite database file to the 'x-ui' directory for the migration tool. Includes Windows equivalent. ```bash # Copy your x-ui database to the x-ui directory cp /path/to/your/x-ui.db x-ui/ # Or on Windows: # copy C:\path\to\your\x-ui.db x-ui\ ``` -------------------------------- ### Server Configuration File (config.json) Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Contains essential server settings like host, port, redirect domain, panel type, and SSL configuration. ```json { "host": "0.0.0.0", "port": 8080, "redirect_domain": "", "panel": "x-ui", "ssl": { "enabled": false, "cert": "", "key": "" } } ``` -------------------------------- ### Configure and Run Marzneshin Migration Source: https://github.com/pasarguard/migrations/blob/main/README.md Configures the Marzneshin migration by copying and editing the environment file, then runs the migration script. This generates the subscription URL mapping file. ```bash # Configure and run cp .env.example .env # Edit .env with your database credentials uv run migrate.py ``` -------------------------------- ### Execute Migration Script Source: https://github.com/pasarguard/migrations/blob/main/marzneshin/README.md Runs the migration script using uv or directly via Python after activating the virtual environment. The script accepts various command-line options to customize the migration process. ```bash uv run migrate.py [OPTIONS] # Or activate the virtual environment and use python directly source .venv/bin/activate # Linux/macOS # .venv\Scripts\activate # Windows python migrate.py [OPTIONS] ``` -------------------------------- ### View Redirect Server Logs Source: https://github.com/pasarguard/migrations/blob/main/README.md Displays the real-time logs for the redirect-server service. Use this for monitoring and troubleshooting. ```bash # View logs sudo journalctl -u redirect-server -f ``` -------------------------------- ### Clone Migration Repository Source: https://github.com/pasarguard/migrations/blob/main/README.md Clones the Pasarguard migrations repository to your local machine. This is the first step in preparing for the migration process. ```bash # Clone (or fork) the repository git clone https://github.com/PasarGuard/migrations.git cd migrations ``` -------------------------------- ### URL Mapping File for x-ui Panel Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Defines URL redirects for the x-ui panel, including generated timestamp, user counts, and URL format mappings. ```json { "generated_at": "2025-01-15 12:00:00", "total_users": 100, "mapped_users": 98, "not_found_users": 2, "panel": "x-ui", "url_formats": { "old_format": "/sub/{email}/{key}", "new_format": "/sub/{token}" }, "mappings": { "user@example.com": { "user_id": 1, "old_subscription_url": "/sub/user@example.com/key123", "new_subscription_url": "/sub/token456", "inbound_id": 1 } } } ``` -------------------------------- ### systemd Service File for Redirect Server Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Configuration for a systemd service to manage the redirect server process on Linux. Ensure the User, WorkingDirectory, and ExecStart paths are correctly set for your environment. ```ini [Unit] Description=Subscription URL Redirect Server After=network.target [Service] Type=simple User=www-data WorkingDirectory=/opt/redirect-server ExecStart=/opt/redirect-server/redirect-server -config /opt/redirect-server/mapping.json Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target ``` -------------------------------- ### Check Redirect Server Status Source: https://github.com/pasarguard/migrations/blob/main/README.md Verifies the operational status of the redirect-server service. This is a post-installation check to ensure the server is running correctly. ```bash # Check service status sudo systemctl status redirect-server ``` -------------------------------- ### URL Mapping File for Marzneshin Panel Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Defines URL redirects for the Marzneshin panel, including generated timestamp, user counts, and URL format mappings. ```json { "generated_at": "2025-01-15 12:00:00", "total_users": 100, "mapped_users": 98, "not_found_users": 2, "panel": "marzneshin", "url_formats": { "old_format": "/sub/{username}/{key}", "new_format": "/sub/{token}" }, "mappings": { "username1": { "user_id": 1, "old_subscription_url": "/sub/username1/key123", "new_subscription_url": "/sub/token456" } } } ``` -------------------------------- ### Add uv to PATH Source: https://github.com/pasarguard/migrations/blob/main/marzneshin/README.md Adds the uv executable to your system's PATH environment variable. This command is for Linux/macOS systems. For Windows, refer to system environment variable settings. ```bash # Linux/macOS - Add to PATH source $HOME/.cargo/env # Or: export PATH="$HOME/.cargo/bin:$PATH" ``` -------------------------------- ### Nginx Reverse Proxy Configuration Source: https://github.com/pasarguard/migrations/blob/main/redirect-server/README.md Nginx configuration snippet to proxy requests to the redirect server, ensuring original protocol information is passed. This is crucial for applications that rely on the original scheme (HTTP/HTTPS). ```nginx location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.