WireGuard VPN via Telegram

WireGuard VPN via Telegram

Hello, Habre!

Idea

From the first weeks of using Wireguard, I was sick of the idea of ​​making the Wireguard management system and its installation as simple as possible, although it would seem much easier.

Of course, there are already projects that simplify the installation of Wireguard as much as possible, the same wg-easy (https://github.com/wg-easy/wg-easy), but I wanted to create something of my own, and here I am.

The stack in use

I decided on the toolkit almost immediately:

As I think you already know, the Telegram robot is written in Python, using the PyTelegramBotApi library. I used this library, not Aiogram, because I already had experience working with it, and this work does not need the power of asynchrony, at least in my idea. All basic commands are executed through bash scripts called by Python. And as a result, it all comes together through Docker.

Getting Started

Before you start using the bot, you need to add the following parameters to the `config.py` file.

# config.py
mainid = []  # ID пользователей, которые имеют доступ к боту
api_tg = ""  # API ключ Telegram

You can find out your id from the bot @get_myidbot, and you can get the APi key from @BotFather.

Run via Python

  1. Install the dependencies by running the following command:

pip install --no-cache-dir -r requirements.txt
  1. Start the bot with the following command:

python3 main.py

Running via Docker

Start the bot in Docker mode with the following command:

docker-compose up -d

Management via Telegram

After starting the bot, go to the administration section and select and click the “Install Wireguard” button, and wait for everything to be installed. Here you can save the configured configuration and import it as a backup copy

Then we can go to the control panel and click the “Config” button to make sure that the Wireguard server is running.

To add a client, click the “Add config” button and enter a name for the new config. The robot will issue a QR code, configuration file and configuration text.

If you then click “Configs”, the bot will issue changes to the server configuration file, client configurations, and IP addresses with client names.

To delete the config, click the “Delete config” button, and according to the instructions, delete the desired unnecessary client

What can this bot do?

This project is aimed at the rapid deployment of a VPN network.
The functionality of the bot is currently implemented:

  • Access to the robot is limited to a limited number of people

  • Installing and configuring the Wireguard server

  • Add/Remove user configurations

  • Save and import server configuration

The functionality of the robot is planned to be implemented in the future:

  • Refinement of existing functionality

  • Saving multiple configurations

  • Import configurations from a file

  • Enable/Disable user configurations on a timer

  • Manage multiple VPN networks simultaneously

  • Combining several VPN networks into one

Conclusion

Link to GitHub

Thanks for reading my first article! Evaluate the idea, give advice – together we will create the perfect tool for managing WireGuard.

Related posts