mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-08 00:56:58 +03:00
Telegram support (#488)
This commit is contained in:
parent
841db62347
commit
41bf0bc92c
14 changed files with 588 additions and 32 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/sdomino/scribble"
|
||||
|
@ -161,6 +162,20 @@ func (o *JsonDB) Init() error {
|
|||
}
|
||||
}
|
||||
|
||||
// init cache
|
||||
clients, err := o.GetClients(false)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, cl := range clients {
|
||||
client := cl.Client
|
||||
if client.Enabled && len(client.TgUserid) > 0 {
|
||||
if userid, err := strconv.ParseInt(client.TgUserid, 10, 64); err == nil {
|
||||
util.UpdateTgToClientID(userid, client.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -314,6 +329,17 @@ func (o *JsonDB) GetClientByID(clientID string, qrCodeSettings model.QRCodeSetti
|
|||
func (o *JsonDB) SaveClient(client model.Client) error {
|
||||
clientPath := path.Join(path.Join(o.dbPath, "clients"), client.ID+".json")
|
||||
output := o.conn.Write("clients", client.ID, client)
|
||||
if output == nil {
|
||||
if client.Enabled && len(client.TgUserid) > 0 {
|
||||
if userid, err := strconv.ParseInt(client.TgUserid, 10, 64); err == nil {
|
||||
util.UpdateTgToClientID(userid, client.ID)
|
||||
}
|
||||
} else {
|
||||
util.RemoveTgToClientID(client.ID)
|
||||
}
|
||||
} else {
|
||||
util.RemoveTgToClientID(client.ID)
|
||||
}
|
||||
err := util.ManagePerms(clientPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -322,6 +348,7 @@ func (o *JsonDB) SaveClient(client model.Client) error {
|
|||
}
|
||||
|
||||
func (o *JsonDB) DeleteClient(clientID string) error {
|
||||
util.RemoveTgToClientID(clientID)
|
||||
return o.conn.Delete("clients", clientID)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue