Remove telegram completely (#13)
This commit is contained in:
parent
067715f48a
commit
bd4a0a0880
|
|
@ -7,6 +7,8 @@ A modern web interface to manage your WireGuard VPN setup.
|
|||
|
||||
Fork of [ngoduykhanh/wireguard-ui](https://github.com/ngoduykhanh/wireguard-ui) by [Khanh Ngo](https://github.com/ngoduykhanh).
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Modern React frontend with [shadcn/ui](https://ui.shadcn.com/) components
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io/fs"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -133,14 +132,6 @@ func APICreateClient(db store.IStore) echo.HandlerFunc {
|
|||
return apiBadRequest(c, "Email is required")
|
||||
}
|
||||
|
||||
// validate telegram userid
|
||||
if client.TgUserid != "" {
|
||||
idNum, err := strconv.ParseInt(client.TgUserid, 10, 64)
|
||||
if err != nil || idNum == 0 {
|
||||
return apiBadRequest(c, "Telegram userid must be a non-zero number")
|
||||
}
|
||||
}
|
||||
|
||||
server, err := db.GetServer()
|
||||
if err != nil {
|
||||
return apiInternalError(c, "Cannot fetch server config")
|
||||
|
|
@ -238,13 +229,6 @@ func APIUpdateClient(db store.IStore) echo.HandlerFunc {
|
|||
return apiNotFound(c, "Client not found")
|
||||
}
|
||||
|
||||
if _client.TgUserid != "" {
|
||||
idNum, err := strconv.ParseInt(_client.TgUserid, 10, 64)
|
||||
if err != nil || idNum == 0 {
|
||||
return apiBadRequest(c, "Telegram userid must be a non-zero number")
|
||||
}
|
||||
}
|
||||
|
||||
server, err := db.GetServer()
|
||||
if err != nil {
|
||||
return apiInternalError(c, "Cannot fetch server config")
|
||||
|
|
@ -296,7 +280,6 @@ func APIUpdateClient(db store.IStore) echo.HandlerFunc {
|
|||
|
||||
client.Name = _client.Name
|
||||
// email is immutable after creation — preserve original
|
||||
client.TgUserid = _client.TgUserid
|
||||
client.Enabled = _client.Enabled
|
||||
client.UseServerDNS = _client.UseServerDNS
|
||||
client.AllocatedIPs = _client.AllocatedIPs
|
||||
|
|
|
|||
|
|
@ -266,23 +266,6 @@ func TestAPICreateClient_InvalidExtraAllowedIPs(t *testing.T) {
|
|||
assert.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
}
|
||||
|
||||
func TestAPICreateClient_InvalidTelegramUserid(t *testing.T) {
|
||||
env := setupTestEnv(t)
|
||||
|
||||
body := map[string]interface{}{
|
||||
"name": "TG Bad",
|
||||
"email": "tg@test.com",
|
||||
"telegram_userid": "notanumber",
|
||||
"allocated_ips": []string{"10.252.1.50/32"},
|
||||
"allowed_ips": []string{"0.0.0.0/0"},
|
||||
"extra_allowed_ips": []string{},
|
||||
}
|
||||
req, rec := jsonRequest(http.MethodPost, "/api/v1/clients", body)
|
||||
c := env.echo.NewContext(req, rec)
|
||||
err := APICreateClient(env.db)(c)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
}
|
||||
|
||||
func TestAPICreateClient_WithPresharedKeyDash(t *testing.T) {
|
||||
env := setupTestEnv(t)
|
||||
|
|
@ -440,34 +423,6 @@ func TestAPIUpdateClient_InvalidAllowedIPs(t *testing.T) {
|
|||
assert.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
}
|
||||
|
||||
func TestAPIUpdateClient_InvalidTelegramUserid(t *testing.T) {
|
||||
env := setupTestEnv(t)
|
||||
id := xid.New().String()
|
||||
now := time.Now().UTC()
|
||||
|
||||
env.db.SaveClient(model.Client{
|
||||
ID: id, Name: "Orig", PublicKey: "pub1",
|
||||
AllocatedIPs: []string{"10.252.1.72/32"}, AllowedIPs: []string{"0.0.0.0/0"},
|
||||
ExtraAllowedIPs: []string{}, SubnetRanges: []string{},
|
||||
Enabled: true, CreatedAt: now, UpdatedAt: now,
|
||||
})
|
||||
|
||||
body := map[string]interface{}{
|
||||
"name": "TG bad",
|
||||
"telegram_userid": "notanumber",
|
||||
"allocated_ips": []string{"10.252.1.72/32"},
|
||||
"allowed_ips": []string{"0.0.0.0/0"},
|
||||
"extra_allowed_ips": []string{},
|
||||
"public_key": "pub1",
|
||||
}
|
||||
req, rec := jsonRequest(http.MethodPut, "/api/v1/clients/"+id, body)
|
||||
c := env.echo.NewContext(req, rec)
|
||||
c.SetParamNames("id")
|
||||
c.SetParamValues(id)
|
||||
err := APIUpdateClient(env.db)(c)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, rec.Code)
|
||||
}
|
||||
|
||||
// --- APIDownloadClientConfig Tests ---
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ type Client struct {
|
|||
PublicKey string `json:"public_key"`
|
||||
PresharedKey string `json:"preshared_key"`
|
||||
Name string `json:"name"`
|
||||
TgUserid string `json:"telegram_userid"`
|
||||
Email string `json:"email"`
|
||||
SubnetRanges []string `json:"subnet_ranges,omitempty"`
|
||||
AllocatedIPs []string `json:"allocated_ips"`
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 671 KiB |
|
|
@ -15,7 +15,6 @@ CREATE TABLE IF NOT EXISTS clients (
|
|||
preshared_key TEXT NOT NULL DEFAULT '',
|
||||
name TEXT NOT NULL DEFAULT '',
|
||||
email TEXT NOT NULL DEFAULT '',
|
||||
telegram_userid TEXT NOT NULL DEFAULT '',
|
||||
subnet_ranges TEXT NOT NULL DEFAULT '[]',
|
||||
allocated_ips TEXT NOT NULL DEFAULT '[]',
|
||||
allowed_ips TEXT NOT NULL DEFAULT '[]',
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ func (o *SqliteDB) GetServer() (model.Server, error) {
|
|||
// GetClients returns all clients, optionally with QR codes
|
||||
func (o *SqliteDB) GetClients(hasQRCode bool) ([]model.ClientData, error) {
|
||||
rows, err := o.db.Query(
|
||||
`SELECT id, private_key, public_key, preshared_key, name, email, telegram_userid,
|
||||
`SELECT id, private_key, public_key, preshared_key, name, email,
|
||||
subnet_ranges, allocated_ips, allowed_ips, extra_allowed_ips,
|
||||
endpoint, additional_notes, use_server_dns, enabled, created_at, updated_at
|
||||
FROM clients`,
|
||||
|
|
@ -309,7 +309,7 @@ func (o *SqliteDB) GetClientByID(clientID string, qrCodeSettings model.QRCodeSet
|
|||
clientData := model.ClientData{}
|
||||
|
||||
row := o.db.QueryRow(
|
||||
`SELECT id, private_key, public_key, preshared_key, name, email, telegram_userid,
|
||||
`SELECT id, private_key, public_key, preshared_key, name, email,
|
||||
subnet_ranges, allocated_ips, allowed_ips, extra_allowed_ips,
|
||||
endpoint, additional_notes, use_server_dns, enabled, created_at, updated_at
|
||||
FROM clients WHERE id = ?`, clientID,
|
||||
|
|
@ -347,17 +347,16 @@ func (o *SqliteDB) SaveClient(client model.Client) error {
|
|||
extraJSON, _ := json.Marshal(client.ExtraAllowedIPs)
|
||||
|
||||
_, err := o.db.Exec(
|
||||
`INSERT INTO clients (id, private_key, public_key, preshared_key, name, email, telegram_userid,
|
||||
`INSERT INTO clients (id, private_key, public_key, preshared_key, name, email,
|
||||
subnet_ranges, allocated_ips, allowed_ips, extra_allowed_ips,
|
||||
endpoint, additional_notes, use_server_dns, enabled, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
private_key = excluded.private_key,
|
||||
public_key = excluded.public_key,
|
||||
preshared_key = excluded.preshared_key,
|
||||
name = excluded.name,
|
||||
email = excluded.email,
|
||||
telegram_userid = excluded.telegram_userid,
|
||||
subnet_ranges = excluded.subnet_ranges,
|
||||
allocated_ips = excluded.allocated_ips,
|
||||
allowed_ips = excluded.allowed_ips,
|
||||
|
|
@ -368,7 +367,7 @@ func (o *SqliteDB) SaveClient(client model.Client) error {
|
|||
enabled = excluded.enabled,
|
||||
updated_at = excluded.updated_at`,
|
||||
client.ID, client.PrivateKey, client.PublicKey, client.PresharedKey,
|
||||
client.Name, client.Email, client.TgUserid,
|
||||
client.Name, client.Email,
|
||||
string(subnetJSON), string(allocJSON), string(allowJSON), string(extraJSON),
|
||||
client.Endpoint, client.AdditionalNotes, client.UseServerDNS, client.Enabled,
|
||||
client.CreatedAt, client.UpdatedAt,
|
||||
|
|
@ -500,7 +499,7 @@ func scanClientFrom(s scanner) (model.Client, error) {
|
|||
var subnetJSON, allocJSON, allowJSON, extraJSON string
|
||||
err := s.Scan(
|
||||
&c.ID, &c.PrivateKey, &c.PublicKey, &c.PresharedKey,
|
||||
&c.Name, &c.Email, &c.TgUserid,
|
||||
&c.Name, &c.Email,
|
||||
&subnetJSON, &allocJSON, &allowJSON, &extraJSON,
|
||||
&c.Endpoint, &c.AdditionalNotes, &c.UseServerDNS, &c.Enabled,
|
||||
&c.CreatedAt, &c.UpdatedAt,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# This file was generated using wireguard-ui (https://github.com/ngoduykhanh/wireguard-ui)
|
||||
# This file was generated using wireguard-ui (https://github.com/DigitalTolk/wireguard-ui)
|
||||
# Please don't modify it manually, otherwise your change might get replaced.
|
||||
|
||||
# Address updated at: {{ .serverConfig.Interface.UpdatedAt }}
|
||||
|
|
@ -17,7 +17,6 @@ Table = {{ .globalSettings.Table }}
|
|||
# ID: {{ .Client.ID }}
|
||||
# Name: {{ .Client.Name }}
|
||||
# Email: {{ .Client.Email }}
|
||||
# Telegram: {{ .Client.TgUserid }}
|
||||
# Created at: {{ .Client.CreatedAt }}
|
||||
# Update at: {{ .Client.UpdatedAt }}
|
||||
{{- if .Client.AdditionalNotes}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue