• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DigitalTolk / wireguard-ui / 24791061837

22 Apr 2026 04:50PM UTC coverage: 81.067%. First build
24791061837

push

github

web-flow
Add auditlogs (#1)

* Add auditlogs

* test

* test

* test

* test

* test

* test

164 of 233 branches covered (70.39%)

Branch coverage included in aggregate %.

1878 of 2390 new or added lines in 34 files covered. (78.58%)

2722 of 3327 relevant lines covered (81.82%)

6.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.95
/handler/api_v1_server.go
1
package handler
2

3
import (
4
        "net/http"
5
        "time"
6

7
        "github.com/labstack/echo/v4"
8
        "github.com/labstack/gommon/log"
9
        "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
10

11
        "github.com/DigitalTolk/wireguard-ui/model"
12
        "github.com/DigitalTolk/wireguard-ui/store"
13
        "github.com/DigitalTolk/wireguard-ui/util"
14
)
15

16
// APIGetServer returns server config (interface + keypair)
17
func APIGetServer(db store.IStore) echo.HandlerFunc {
1✔
18
        return func(c echo.Context) error {
2✔
19
                server, err := db.GetServer()
1✔
20
                if err != nil {
1✔
NEW
21
                        return apiInternalError(c, "Cannot get server config")
×
NEW
22
                }
×
23
                return c.JSON(http.StatusOK, server)
1✔
24
        }
25
}
26

27
// APIUpdateServerInterface updates server interface settings
28
func APIUpdateServerInterface(db store.IStore) echo.HandlerFunc {
3✔
29
        return func(c echo.Context) error {
6✔
30
                var serverInterface model.ServerInterface
3✔
31
                if err := c.Bind(&serverInterface); err != nil {
4✔
32
                        return apiBadRequest(c, "Invalid request body")
1✔
33
                }
1✔
34

35
                if !util.ValidateServerAddresses(serverInterface.Addresses) {
3✔
36
                        return apiBadRequest(c, "Interface IP address must be in CIDR format")
1✔
37
                }
1✔
38

39
                serverInterface.UpdatedAt = time.Now().UTC()
1✔
40

1✔
41
                if err := db.SaveServerInterface(serverInterface); err != nil {
1✔
NEW
42
                        return apiInternalError(c, "Cannot save server interface")
×
NEW
43
                }
×
44

45
                log.Infof("Updated server interfaces: %v", serverInterface)
1✔
46
                return c.JSON(http.StatusOK, serverInterface)
1✔
47
        }
48
}
49

50
// APIRegenerateServerKeypair generates a new server keypair
51
func APIRegenerateServerKeypair(db store.IStore) echo.HandlerFunc {
1✔
52
        return func(c echo.Context) error {
2✔
53
                key, err := wgtypes.GeneratePrivateKey()
1✔
54
                if err != nil {
1✔
NEW
55
                        return apiInternalError(c, "Cannot generate WireGuard key pair")
×
NEW
56
                }
×
57

58
                kp := model.ServerKeypair{
1✔
59
                        PrivateKey: key.String(),
1✔
60
                        PublicKey:  key.PublicKey().String(),
1✔
61
                        UpdatedAt:  time.Now().UTC(),
1✔
62
                }
1✔
63

1✔
64
                if err := db.SaveServerKeyPair(kp); err != nil {
1✔
NEW
65
                        return apiInternalError(c, "Cannot save server keypair")
×
NEW
66
                }
×
67

68
                log.Infof("Regenerated server keypair")
1✔
69
                return c.JSON(http.StatusOK, kp)
1✔
70
        }
71
}
72

73
// APIGetSettings returns global settings
74
func APIGetSettings(db store.IStore) echo.HandlerFunc {
1✔
75
        return func(c echo.Context) error {
2✔
76
                settings, err := db.GetGlobalSettings()
1✔
77
                if err != nil {
1✔
NEW
78
                        return apiInternalError(c, "Cannot get global settings")
×
NEW
79
                }
×
80
                return c.JSON(http.StatusOK, settings)
1✔
81
        }
82
}
83

84
// APIUpdateSettings updates global settings
85
func APIUpdateSettings(db store.IStore) echo.HandlerFunc {
3✔
86
        return func(c echo.Context) error {
6✔
87
                var settings model.GlobalSetting
3✔
88
                if err := c.Bind(&settings); err != nil {
4✔
89
                        return apiBadRequest(c, "Invalid request body")
1✔
90
                }
1✔
91

92
                if !util.ValidateIPAddressList(settings.DNSServers) {
3✔
93
                        return apiBadRequest(c, "Invalid DNS server address")
1✔
94
                }
1✔
95

96
                settings.UpdatedAt = time.Now().UTC()
1✔
97

1✔
98
                if err := db.SaveGlobalSettings(settings); err != nil {
1✔
NEW
99
                        return apiInternalError(c, "Cannot save global settings")
×
NEW
100
                }
×
101

102
                log.Infof("Updated global settings")
1✔
103
                return c.JSON(http.StatusOK, settings)
1✔
104
        }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc