Giter Site home page Giter Site logo

rwlist / ovpn-bot Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 1.0 47 KB

Simple telegram bot for automatic OpenVPN configuration

License: MIT License

Go 94.10% Dockerfile 5.67% Shell 0.23%
telegram-bot bot openvpn openvpn-server self-hosted docker openvpn-installer openvpn-configuration

ovpn-bot's Introduction

ovpn-bot

Simple telegram bot for automatic OpenVPN configuration

How to install

Create configuration

Create docker-compose.yml with the following content:

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:

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:

ADMIN_TELEGRAM_ID=123456789
BOT_TOKEN=1231231231:AAAAAAAAABBBBCCCCCCCCCCCCCC

Start bot

When configuration is written to .env file, start the bot:

# 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

docker run -d \
    --name ovpn-tg-bot \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --env ADMIN_TELEGRAM_ID=123456789 \
    --env BOT_TOKEN=1231231231:AAAAAAAAABBBBCCCCCCCCCCCCCC \
    arthurwow/ovpnbot

or

docker run -d --name ovpn-tg-bot --volume /var/run/docker.sock:/var/run/docker.sock:ro --env ADMIN_TELEGRAM_ID=123456789 --env BOT_TOKEN=1231231231:AAAAAAAAABBBBCCCCCCCCCCCCCC arthurwow/ovpnbot

ADMIN_TELEGRAM_ID is a comma-separated list of the bot admins' Telegram IDs

Proxy

If you running this bot in Russia, you might want to use proxy to run this bot. You can do this easily with HTTP_PROXY envvar, example:

docker run -d \
    --name ovpn-tg-bot \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --env HTTP_PROXY=socks5://user:[email protected]:1080 \
    --env ADMIN_TELEGRAM_ID=123456789 \
    --env BOT_TOKEN=1231231231:AAAAAAAAABBBBCCCCCCCCCCCCCC \
    arthurwow/ovpnbot

ovpn-bot's People

Contributors

lodthe avatar petuhovskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bu11ettrain

ovpn-bot's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.