diff --git a/README.md b/README.md index fcf3963..b917b7b 100644 --- a/README.md +++ b/README.md @@ -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). +![WireGuard UI Screenshot](screenshot.png) + ## Features - Modern React frontend with [shadcn/ui](https://ui.shadcn.com/) components diff --git a/handler/api_v1_clients.go b/handler/api_v1_clients.go index 005f8fb..208f456 100644 --- a/handler/api_v1_clients.go +++ b/handler/api_v1_clients.go @@ -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 diff --git a/handler/api_v1_clients_test.go b/handler/api_v1_clients_test.go index c15c546..f267990 100644 --- a/handler/api_v1_clients_test.go +++ b/handler/api_v1_clients_test.go @@ -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 --- diff --git a/model/client.go b/model/client.go index d835124..a79e683 100644 --- a/model/client.go +++ b/model/client.go @@ -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"` diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..f60e02e Binary files /dev/null and b/screenshot.png differ diff --git a/store/sqlitedb/schema.sql b/store/sqlitedb/schema.sql index 8310cc9..f4ee4d1 100644 --- a/store/sqlitedb/schema.sql +++ b/store/sqlitedb/schema.sql @@ -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 '[]', diff --git a/store/sqlitedb/sqlitedb.go b/store/sqlitedb/sqlitedb.go index 1ad15fe..c78f0c0 100644 --- a/store/sqlitedb/sqlitedb.go +++ b/store/sqlitedb/sqlitedb.go @@ -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, diff --git a/templates/wg.conf b/templates/wg.conf index 34891f0..2f76df1 100644 --- a/templates/wg.conf +++ b/templates/wg.conf @@ -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}}