diff --git a/core/README.md b/core/README.md index 490f233..09e261f 100644 --- a/core/README.md +++ b/core/README.md @@ -1,208 +1,484 @@ +# Hysteria2 Management CLI Guide -# Hysteria2 CLI Tool +This document provides a comprehensive guide to using the `cli.py` script, a command-line interface for managing Hysteria2 and related services. It covers installation, user management, advanced configurations, and troubleshooting. The commands are organized into sections for clarity. Each command is described with its options, arguments, and expected behavior. -## Overview +## Table of Contents +1. [Hysteria2 Management](#hysteria2-management) + * [install-hysteria2](#install-hysteria2) + * [uninstall-hysteria2](#uninstall-hysteria2) + * [update-hysteria2](#update-hysteria2) + * [restart-hysteria2](#restart-hysteria2) + * [change-hysteria2-port](#change-hysteria2-port) + * [change-hysteria2-sni](#change-hysteria2-sni) + * [backup-hysteria](#backup-hysteria) + * [restore-hysteria2](#restore-hysteria2) +2. [User Management](#user-management) + * [list-users](#list-users) + * [get-user](#get-user) + * [add-user](#add-user) + * [edit-user](#edit-user) + * [reset-user](#reset-user) + * [remove-user](#remove-user) + * [show-user-uri](#show-user-uri) +3. [Server Management](#server-management) + * [traffic-status](#traffic-status) + * [server-info](#server-info) + * [manage\_obfs](#manage_obfs) + * [ip-address](#ip-address) + * [update-geo](#update-geo) + * [masquerade](#masquerade) +4. [Advanced Menu](#advanced-menu) + * [install-tcp-brutal](#install-tcp-brutal) + * [install-warp](#install-warp) + * [uninstall-warp](#uninstall-warp) + * [configure-warp](#configure-warp) + * [warp-status](#warp-status) + * [telegram](#telegram) + * [singbox](#singbox) + * [normal-sub](#normal-sub) + * [webpanel](#webpanel) + * [get-webpanel-url](#get-webpanel-url) + * [get-webpanel-api-token](#get-webpanel-api-token) + * [get-webpanel-services-status](#get-webpanel-services-status) + * [get-services-status](#get-services-status) +5. [Running the script](#running-the-script) -The Hysteria2 CLI Tool is a powerful command-line utility designed to manage Hysteria2 and associated services. With updated functionality, it now includes advanced SNI management, traffic monitoring, IP address configurations, and enhanced user management features. +## Hysteria2 Management ---- +This section covers commands related to installing, updating, and configuring the core Hysteria2 service. -## Commands +### `install-hysteria2` -### Hysteria2 Management +Installs and configures Hysteria2. -#### Install Hysteria2 ```bash -python3 cli.py install-hysteria2 --port PORT --sni SNI -``` -- `--port`, `-p`: **Required.** Port for the Hysteria2 server. -- `--sni`, `-s`: Optional. SNI value (default: `bts.com`). - -#### Uninstall Hysteria2 -```bash -python3 cli.py uninstall-hysteria2 +./cli.py install-hysteria2 --port --sni ``` -#### Update Hysteria2 +* **`--port` / `-p` (Required):** The port number Hysteria2 will listen on. This must be an integer. +* **`--sni` / `-s` (Optional):** The Server Name Indication (SNI) to use. Defaults to `bts.com`. + +**Example:** + ```bash -python3 cli.py update-hysteria2 +./cli.py install-hysteria2 -p 443 -s example.com ``` -#### Restart Hysteria2 +### `uninstall-hysteria2` + +Uninstalls Hysteria2. + ```bash -python3 cli.py restart-hysteria2 +./cli.py uninstall-hysteria2 ``` -#### Change Port +### `update-hysteria2` + +Updates the Hysteria2 core to the latest version. + ```bash -python3 cli.py change-hysteria2-port --port NEW_PORT +./cli.py update-hysteria2 ``` -- `--port`, `-p`: **Required.** New port for the Hysteria2 server. -#### Change SNI +### `restart-hysteria2` + +Restarts the Hysteria2 service. + ```bash -python3 cli.py change-hysteria2-sni --sni NEW_SNI +./cli.py restart-hysteria2 ``` -- `--sni`, `-s`: **Required.** New SNI value. ---- +### `change-hysteria2-port` -### User Management +Changes the port Hysteria2 listens on. -#### Add User ```bash -python3 cli.py add-user --username USERNAME --traffic-limit LIMIT --expiration-days DAYS [--password PASSWORD] [--creation-date DATE] +./cli.py change-hysteria2-port --port ``` -- `--username`, `-u`: **Required.** Username for the new user. -- `--traffic-limit`, `-t`: **Required.** Traffic limit in GB. -- `--expiration-days`, `-e`: **Required.** Number of days until expiration. -- `--password`, `-p`: Optional. Custom password (auto-generated if not provided). -- `--creation-date`, `-c`: Optional. Custom creation date (current date if not provided). -#### Edit User +* **`--port` / `-p` (Required):** The new port number. + +**Example:** + ```bash -python3 cli.py edit-user --username USERNAME [OPTIONS] +./cli.py change-hysteria2-port -p 8080 ``` -- `--new-username`, `-nu`: New username. -- `--new-traffic-limit`, `-nt`: New traffic limit in GB. -- `--new-expiration-days`, `-ne`: New expiration days. -- `--renew-password`, `-rp`: Generate a new password. -- `--renew-creation-date`, `-rc`: Reset creation date. -- `--blocked`, `-b`: Block/unblock the user. -#### Show User URI +### `change-hysteria2-sni` + +Changes the SNI used by Hysteria2. + ```bash -python3 cli.py show-user-uri --username USERNAME [OPTIONS] +./cli.py change-hysteria2-sni --sni ``` -- `--qrcode`, `-qr`: Generate a QR code. -- `--ipv`, `-ip`: Specify IP version (4 or 6). -- `--all`, `-a`: Show both IPv4 and IPv6 URIs. -- `--singbox`, `-s`: Generate a Singbox sublink. -- `--normalsub`, `-n`: Generate a Normal sublink. -#### Other User Commands -- Get User Info: +* **`--sni` / `-s` (Required):** The new SNI. + +**Example:** + +```bash +./cli.py change-hysteria2-sni -s mynew.sni.com +``` + +### `backup-hysteria` +Back up the current hysteria configuration. +```bash +./cli.py backup-hysteria +``` +Creates a zip file containing your configuration files in the `/etc/hysteria/` directory. + + +### `restore-hysteria2` + +Restores Hysteria configuration from a backup ZIP file. + +```bash +./cli.py restore-hysteria2 +``` +* `backup_file_path`: Path to the ZIP file containing the backup. It must be a path to an *existing* file. It cannot be a directory. It must be readable. + +**Example** +```bash +./cli.py restore-hysteria2 /path/to/backup.zip +``` + + +## User Management + +This section details commands for managing Hysteria2 users. + +### `list-users` + +Lists all configured Hysteria2 users. + +```bash +./cli.py list-users +``` +The output will be in JSON format + +### `get-user` + +Retrieves detailed information about a specific user. + +```bash +./cli.py get-user --username +``` + +* **`--username` / `-u` (Required):** The username of the user to retrieve. + +**Example:** + +```bash +./cli.py get-user -u testuser +``` +The output will be in JSON format + +### `add-user` + +Adds a new Hysteria2 user. + +```bash +./cli.py add-user --username --traffic-limit --expiration-days --password --creation-date +``` + +* **`--username` / `-u` (Required):** The username for the new user. +* **`--traffic-limit` / `-t` (Required):** The traffic limit for the user, in gigabytes (GB). +* **`--expiration-days` / `-e` (Required):** The number of days until the user account expires. +* **`--password` / `-p` (Optional):** The password for the user. +* **`--creation-date` / `-c` (Optional):** The account creation date in `YYYY-MM-DD` format. + +**Example:** + +```bash +./cli.py add-user -u newuser -t 100 -e 30 -p mysecretpassword -c 2023-12-25 +``` + +### `edit-user` + +Edits an existing Hysteria2 user's settings. + +```bash +./cli.py edit-user --username --new-username --new-traffic-limit --new-expiration-days --renew-password --renew-creation-date --blocked +``` + +* **`--username` / `-u` (Required):** The username of the user to edit. +* **`--new-username` / `-nu` (Optional):** The new username for the user. +* **`--new-traffic-limit` / `-nt` (Optional):** The new traffic limit in GB. +* **`--new-expiration-days` / `-ne` (Optional):** The new number of expiration days. +* **`--renew-password` / `-rp` (Optional, Flag):** If included, renews the user's password. +* **`--renew-creation-date` / `-rc` (Optional, Flag):** If included, resets the user's creation date. +* **`--blocked` / `-b` (Optional, Flag):** If included, blocks the user. + +**Example (changing traffic limit and blocking):** + +```bash +./cli.py edit-user -u testuser -nt 50 -b +``` + +### `reset-user` + +Resets a user's traffic statistics. + +```bash +./cli.py reset-user --username +``` + +* **`--username` / `-u` (Required):** The username to reset. + +### `remove-user` + +Removes a Hysteria2 user. + +```bash +./cli.py remove-user --username +``` + +* **`--username` / `-u` (Required):** The username to remove. + +### `show-user-uri` + +Generates and displays the Hysteria2 URI for a user, optionally as a QR code. + +```bash +./cli.py show-user-uri --username --qrcode --ipv --all --singbox --normalsub +``` + +* **`--username` / `-u` (Required):** The username for which to generate the URI. +* **`--qrcode` / `-qr` (Optional, Flag):** If included, generates a QR code of the URI. +* **`--ipv` / `-ip` (Optional):** Specifies the IP version (4 or 6) for the URI. Defaults to 4. +* **`--all` / `-a` (Optional, Flag):** Shows both IPv4 and IPv6 URIs. +* **`--singbox` / `-s` (Optional, Flag):** Includes a Singbox subscription link if the Singbox service is active. +* **`--normalsub` / `-n` (Optional, Flag):** Includes a Normal-Sub subscription link if the normalsub service is active. +**Example (generating a QR code for IPv6):** + +```bash +./cli.py show-user-uri -u testuser -qr -ip 6 +``` + +## Server Management + +This section covers server-related commands. + +### `traffic-status` + +Displays the current traffic usage statistics. + +```bash +./cli.py traffic-status +``` + +### `server-info` + +Displays server information. + +```bash +./cli.py server-info +``` +The output will be in JSON format + +### `manage_obfs` + +Manages Obfuscation (obfs) settings in the Hysteria2 configuration. + +```bash +./cli.py manage_obfs --remove +./cli.py manage_obfs --generate +``` + +* **`--remove` / `-r` (Optional, Flag):** Removes obfs from the configuration. +* **`--generate` / `-g` (Optional, Flag):** Generates a new obfs configuration. +* **Mutually Exclusive**: you should supply only one of `--remove` or `--generate`. Supplying Neither will print an error. + +### `ip-address` + +Manages the server's IP addresses stored in `.configs.env`. + +```bash +./cli.py ip-address +./cli.py ip-address --edit --ipv4 +./cli.py ip-address --edit --ipv6 +``` + +* **No Options:** Adds auto-detected IP addresses to the configuration. +* **`--edit` (Optional, Flag):** Enables manual editing of IP addresses. +* **`-4` / `--ipv4` (Optional):** Specifies a new IPv4 address (requires `--edit`). +* **`-6` / `--ipv6` (Optional):** Specifies a new IPv6 address (requires `--edit`). + * **With Edit** You *must* supply at least one of `--ipv4` or `--ipv6`. + +### `update-geo` + +Updates GeoIP and GeoSite data files. + +```bash +./cli.py update-geo --country +``` + +* **`--country` / `-c` (Optional):** The country for which to update Geo files (`iran`, `china`, or `russia`). Defaults to `iran`. + +**Example (updating for China):** + +```bash +./cli.py update-geo -c china +``` + +### `masquerade` + +Manages the masquerade settings in the Hysteria2 configuration. + +```bash +./cli.py masquerade --remove +./cli.py masquerade --enable +``` + +* **`--remove` / `-r` (Optional, Flag):** Removes the masquerade configuration. +* **`--enable` / `-e` (Optional):** Enables masquerade with the specified domain. +* **Mutually Exclusive**: you should supply only one of `--remove` or `--enable`. Supplying Neither will print an error. + +**Example (enabling masquerade):** + +```bash +./cli.py masquerade -e example.com +``` + +## Advanced Menu + +This section describes commands that provide additional functionality. + +### `install-tcp-brutal` + +Installs TCP Brutal. + +```bash +./cli.py install-tcp-brutal +``` + +### `install-warp` + +Installs WARP. + +```bash +./cli.py install-warp +``` + +### `uninstall-warp` + +Uninstalls WARP. + +```bash +./cli.py uninstall-warp +``` + +### `configure-warp` + +Configures WARP settings. + +```bash +./cli.py configure-warp --all --popular-sites --domestic-sites --block-adult-sites --warp-option