Skip to content

A bot designed for connecting and managing a VPN server utilizing the xray xtls-reality technology. Users can connect to the server based on a subscription model.

License

Notifications You must be signed in to change notification settings

thefoxcc/XTLS-Reality-bot

 
 

Repository files navigation

PheeZz's XTLS-Reality bot

Code style: black Packaged with Poetry
!Ubuntu !Python !PostgreSQL !Telegram !Xray XTLS

Tested on

  • Ubuntu 23.04 LTS

RAM: 2GB
CPU core: 1
Storage: 30GB

  • Ubuntu 20.04 LTS

RAM: 2GB
CPU core: 2
Storage: 40GB

Installation methods

1 Using docker-compose

1.1 Create /etc/xray/config.json for xray

{
    "log": {
        "loglevel": "info"
    },
    "routing": {
        "rules": [],
        "domainStrategy": "AsIs"
    },
    "inbounds": [
        {
            "port": 443,
            "protocol": "vless",
            "tag": "vless_tls",
            "settings": {
                "clients": [],
                "decryption": "none"
            },
            "streamSettings": {
                "network": "tcp",
                "security": "reality",
                "realitySettings": {
                    "show": false,
                    "dest": "dl.google.com:443",  < anything else if you know to do
                    "xver": 0,
                    "serverNames": [
                        "dl.google.com" < anything else if you know to do
                    ],
                    "privateKey": "<your private key>", < openssl genpkey -algorithm x25519 -out x25519-priv.pem
                    "minClientVer": "",
                    "maxClientVer": "",
                    "maxTimeDiff": 0,
                    "shortIds": [
                        "<your short id>" < openssl rand -hex 8
                    ]
                }
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "tag": "block"
        }
    ]
}

1.2 Edit docker-compose.yaml with your ENV variables

1.3 Run compose

docker compose up -d --build

2 Using autoinstall.sh script (depricated, but still works)

wget https://raw.githubusercontent.com/PheeZz/XTLS-Reality-bot/main/autoinstall.sh && chmod +x autoinstall.sh && ./autoinstall.sh

3 Manual

3.1 First of all - install dependencies

git, curl, postgres

sudo apt install -y git curl postgresql postgresql-contrib
systemctl start postgresql.service

python 3.11, pip, poetry

sudo apt install -y software-properties-common
add-sudo apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.11 python3.11-dev python3.11-distutils python3.11-venv
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.11 get-pip.py
pip3.11 install poetry

XRAY (or you can install it with not default options, follow this guide)

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

3.2 Get keypair and shortid

3.2.1 Private and public keys
/usr/local/bin/xray x25519

Output will be something like:

Private key: CJcqQtcklhCMfiFW8A4BA0XsgKmRJk4-_l42bpnVn0I
Public key: JjAXPY-s2FkvVypfGN2c71NQsCW489Vxjtayo6hLmVM
3.2.2 Get shortid
openssl rand -hex 8

Output will be something like:

0ed36d458733a0bc

3.3 Configure XRAY config.json file

Path: /usr/local/etc/xray/config.json

config.json
{
    "log": {
        "loglevel": "info"
    },
    "routing": {
        "rules": [],
        "domainStrategy": "AsIs"
    },
    "inbounds": [
        {
            "port": 443,
            "protocol": "vless",
            "tag": "vless_tls",
            "settings": {
                "clients": [],
                "decryption": "none"
            },
            "streamSettings": {
                "network": "tcp",
                "security": "reality",
                "realitySettings": {
                    "show": false,
                    "dest": "dl.google.com:443",
                    "xver": 0,
                    "serverNames": [
                        "dl.google.com"
                    ],
                    "privateKey": "<your private key>",
                    "minClientVer": "",
                    "maxClientVer": "",
                    "maxTimeDiff": 0,
                    "shortIds": [
                        "<your short id>"
                    ]
                }
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "tag": "block"
        }
    ]
}

restart xray service

systemctl restart xray.service

3.4 Optional (!) confugure BBR

To increase performance, you can configure Bottleneck Bandwidth and Round-trip propagation time (BBR) congestion control algorithm on the server

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

3.5 Create postgresql user and database

enter psql shell

sudo -u postgres psql

create user and database

CREATE DATABASE <database_name>;
CREATE USER <user_name> WITH PASSWORD '<password>';
GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <user_name>;
GRANT ALL ON ALL TABLES IN SCHEMA "public" TO <user_name>;

in case of some errors with permission you can make user superuser

ALTER USER <user_name> WITH SUPERUSER;

exit psql shell

\q

3.5 Clone this repo

git clone https://github.com/PheeZz/XTLS-Reality-bot.git

3.6 Create venv and install python dependencies

cd XTLS-Reality-bot
poetry install

3.7 Configure .env file

nano source/data/.env
#telegram bot token
TG_BOT_TOKEN = "<token>"
#your bank card number, if you will use payments with "handmade" method
PAYMENT_CARD = "<card in string format>"
#your telegram id, you can get it from @userinfobot or @myidbot or @RawDataBot
ADMINS_IDS = "<id/ids>"
#any text you want to show in the start of every peer config file (for example in case MYVPN_Phone.conf - "MYVPN" is prefix)
CONFIGS_PREFIX = "XrayPheeZzVPN"

#how much subscription costs. example: "100₽", "10$"
BASE_SUBSCRIPTION_MONTHLY_PRICE = "100₽"

DB_NAME = "<your db name>"
DB_USER = "<your db user name>"
DB_USER_PASSWORD = "<your db user password>"
#database host, default localhost
DB_HOST = "localhost"
#database port, default 5432
DB_PORT = "5432"

XRAY_CONFIG_PATH = "/usr/local/etc/xray/config.json"
XRAY_PUBLICKEY = "<public key from step 3.3.1>"
XRAY_SHORTID = "<short id from step 3.3.1>"
XRAY_SNI = "dl.google.com"
#default max configs count for each user (admin can give bonus configs to any user through admin panel)
USER_DEFAULT_MAX_CONFIGS_COUNT = "2"

3.8 Create database tables

$(poetry env info --executable) create_database_tables.py

3.9 Create .service file for your bot

nano /etc/systemd/system/xtls-reality-bot.service
[Unit]
Description=XTLS-Reality telegram bot
After=network.target

[Service]
Type=simple
User=root
ExecStart=/bin/bash -c 'cd ~/XTLS-Reality-bot/ && $(poetry env info --executable) app.py'
Restart=on-failure

[Install]
WantedBy=multi-user.target

3.10 Enable and start it

systemctl enable xtls-reality-bot.service
systemctl start xtls-reality-bot.service

Finally, you can use your bot and enjoy it ❤️

Troubleshooting

Say "thank you ❤️"

You can support me by give ⭐️star to this repo or.. Donation..👉🏼👈🏼

ETH - 0x56936AE100f52F99E87767773Ccb2615f1E06ae4

About

A bot designed for connecting and managing a VPN server utilizing the xray xtls-reality technology. Users can connect to the server based on a subscription model.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 92.1%
  • Shell 7.5%
  • Dockerfile 0.4%