From 41bf0bc92ce579b88dbd147df8fdd4025c96c1f1 Mon Sep 17 00:00:00 2001 From: 0xCA <0xCA@users.noreply.github.com> Date: Fri, 29 Dec 2023 13:22:12 +0500 Subject: [PATCH] Telegram support (#488) --- README.md | 3 + custom/js/helper.js | 18 ++++- go.mod | 1 + go.sum | 2 + handler/routes.go | 78 +++++++++++++++++++-- main.go | 67 +++++++++++++----- model/client.go | 7 +- store/jsondb/jsondb.go | 27 +++++++ telegram/bot.go | 155 +++++++++++++++++++++++++++++++++++++++++ templates/base.html | 13 +++- templates/clients.html | 123 +++++++++++++++++++++++++++++++- templates/wg.conf | 1 + util/cache.go | 4 ++ util/util.go | 121 ++++++++++++++++++++++++++++++++ 14 files changed, 588 insertions(+), 32 deletions(-) create mode 100644 telegram/bot.go diff --git a/README.md b/README.md index b366d0c..003ff39 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,9 @@ docker-compose up | `SMTP_PASSWORD_FILE` | Optional filepath for the SMTP user password. Leave `SMTP_PASSWORD` blank to take effect | N/A | | `SMTP_AUTH_TYPE` | The SMTP authentication type. Possible values: `PLAIN`, `LOGIN`, `NONE` | `NONE` | | `SMTP_ENCRYPTION` | The encryption method. Possible values: `NONE`, `SSL`, `SSLTLS`, `TLS`, `STARTTLS` | `STARTTLS` | +| `TELEGRAM_TOKEN` | Telegram bot token for distributing configs to clients | N/A | +| `TELEGRAM_ALLOW_CONF_REQUEST` | Allow users to get configs from the bot by sending a message | `false` | +| `TELEGRAM_FLOOD_WAIT` | Time in minutes before the next conf request is processed | `60` | ### Defaults for server configuration diff --git a/custom/js/helper.js b/custom/js/helper.js index 4f21c1c..d98eacb 100644 --- a/custom/js/helper.js +++ b/custom/js/helper.js @@ -1,5 +1,20 @@ function renderClientList(data) { $.each(data, function(index, obj) { + // render telegram button + let telegramButton = '' + if (obj.Client.telegram_userid) { + telegramButton = `
+ +
` + } + + let telegramHtml = ""; + if (obj.Client.telegram_userid && obj.Client.telegram_userid.length > 0) { + telegramHtml = `` + } + // render client status css tag style let clientStatusHtml = '>' if (obj.Client.enabled) { @@ -43,7 +58,7 @@ function renderClientList(data) { data-target="#modal_email_client" data-clientid="${obj.Client.id}" data-clientname="${obj.Client.name}">Email - + ${telegramButton}
+
+ Additional configuration + +
+ + +
+
+ + +