diff --git a/.env b/.env new file mode 100644 index 0000000..c4f6044 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +ADMIN_TELEGRAM_ID= +BOT_TOKEN= \ No newline at end of file diff --git a/README.md b/README.md index 3d67317..e764ea0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,104 @@ # ovpn-bot Simple telegram bot for automatic OpenVPN configuration +## How to install + +### Create configuration + +Create `docker-compose.yml` with the following content: + +```yml +version: '3.7' +services: + bot: + image: arthurwow/ovpnbot + env_file: + - .env + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + restart: unless-stopped +``` + +Also create `.env` file with configuration: + +```env +ADMIN_TELEGRAM_ID= +BOT_TOKEN= +``` + +ADMIN_TELEGRAM_ID is your Telegram ID, which will be used to manage users. Use https://t.me/userinfobot to get it. Bot will reply with a message with your ID: + +``` +@ivanonov +Id: 123456789 <==== USE THIS ID TO WRITE IN .env FILE +First: Ivan +Last: Ivanov +Lang: en +``` + +BOT_TOKEN is a Telegram token issued by https://t.me/BotFather. You should talk to this bot to create a new bot and get a token for it. + +So, configured `.env` file should look like this: + +```env +ADMIN_TELEGRAM_ID=123456789 +BOT_TOKEN=1231231231:AAAAAAAAABBBBCCCCCCCCCCCCCC +``` + +### Start bot + +When configuration is written to `.env` file, start the bot: + +```bash +# Start the bot in the background +docker-compose up -d + +# Now bot should be working, check if it is: +docker-compose ps -a + +# If output is like this, State is Up, then bot is running +# +# Name Command State Ports +# ---------------------------------------- +# ovpn-bot_bot_1 ./app Up + +# Get public IP address of the instance, to use it later for +# VPN configuration. Remember this IP address for bot init! +curl ifconfig.me +``` + +Now it's time to setup VPN via bot. + +### Use bot + +First of all, write something to your bot. It should reply with help message. If not, something was wrong on the previous step. + +If bot is working, you can init your VPN server. To do that, write init command to the bot. You must replace 0.0.0.0 with the actual IP address of your VPN server, which can be obtained by running `curl ifconfig.me` on the same instance. +``` +/init tcp://0.0.0.0:443 +``` + +After some time to generate keys (it can take a while, sending dots in PM), you should see a message like this: + +``` +.... +An updated CRL has been created. +CRL file: /etc/openvpn/pki/crl.pem + + +Executing command: `docker run -v ovpn_data:/etc/openvpn -d --restart=always --name ovpn_udp -p 34231:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn ovpn_run --proto udp`fb79eba733f495b79878e3bc66710421a9ad0a931d217bc85c06e26fa098e659 +Executing command: `docker run -v ovpn_data:/etc/openvpn -d --restart=always --name ovpn_tcp -p 34231:1194/tcp --cap-add=NET_ADMIN kylemanna/openvpn ovpn_run --proto tcp`dc32c846369adf2a08dfd629bcb021ce23e709b571fb794c64898edecf3708ac +All done, init completed! +``` + +This message means that VPN is now running! + +The last step is to create user profiles. This is very simple, you just need to write `/generate profile_name` to create .ovpn profile with the name `profile_name`. You can create as many profiles as you want. + + +
+How to run bot without docker-compose + ## Installation ```bash @@ -32,15 +130,5 @@ docker run -d \ arthurwow/ovpnbot ``` -### docker-compose - -TODO: docker-compose - -## Commands +
-Supported commands: -- [X] Initialize containers -- [X] Show status -- [X] Generate config -- [X] Remove everything -- [X] Show help diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8adc8fa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.7' +services: + bot: + image: arthurwow/ovpnbot + env_file: + - .env + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + restart: unless-stopped \ No newline at end of file