Remove legacy default-server page, unify on multi-server registry
Deletes /wg-server (route, handlers, template) entirely and adds generic /servers/:id/interface and /servers/:id/keypair endpoints + UI in the All Servers page, so every server (including the default one) is managed through the same per-server registry. Drops the write-through dual-write hacks that kept the old single-server collection in sync - the registry is now the single source of truth. One-time legacy-install migration path is untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
2212141ba3
commit
58db6839c3
+9
-48
@@ -325,11 +325,13 @@ func (o *JsonDB) migrateLegacyServer() error {
|
||||
}
|
||||
|
||||
// NOTE: the legacy "server" directory is intentionally left in place
|
||||
// (not renamed/removed) at this stage. Existing store methods (GetServer,
|
||||
// GetGlobalSettings, SaveServerInterface, ...) still read/write it
|
||||
// directly until they are switched over to the new per-server layout;
|
||||
// removing it now would break the running app. The rename-to-backup
|
||||
// step happens once those methods are migrated.
|
||||
// (not renamed/removed). GetGlobalSettings/SaveGlobalSettings still read
|
||||
// and write the app-wide settings record there (DNS/MTU/
|
||||
// PersistentKeepalive are not yet per-server concerns); every other
|
||||
// server-scoped read/write now goes exclusively through the per-server
|
||||
// registry (servers/<id>.json via GetServerByID/UpdateServerInterface/
|
||||
// UpdateServerKeyPair/GetServerSettings), so this directory is kept only
|
||||
// as a landing spot for one-time migration and for global settings.
|
||||
log.Printf("Migrated legacy single-server DB to multi-server layout (server id: %s); legacy db/server/ kept in place for now", serverID)
|
||||
return nil
|
||||
}
|
||||
@@ -387,27 +389,6 @@ func (o *JsonDB) GetGlobalSettings() (model.GlobalSetting, error) {
|
||||
return settings, o.conn.Read("server", "global_settings", &settings)
|
||||
}
|
||||
|
||||
// GetServer func to query Server settings from the database
|
||||
func (o *JsonDB) GetServer() (model.Server, error) {
|
||||
server := model.Server{}
|
||||
// read server interface information
|
||||
serverInterface := model.ServerInterface{}
|
||||
if err := o.conn.Read("server", "interfaces", &serverInterface); err != nil {
|
||||
return server, err
|
||||
}
|
||||
|
||||
// read server key pair information
|
||||
serverKeyPair := model.ServerKeypair{}
|
||||
if err := o.conn.Read("server", "keypair", &serverKeyPair); err != nil {
|
||||
return server, err
|
||||
}
|
||||
|
||||
// create Server object and return
|
||||
server.Interface = &serverInterface
|
||||
server.KeyPair = &serverKeyPair
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func (o *JsonDB) GetClients(hasQRCode bool) ([]model.ClientData, error) {
|
||||
var clients []model.ClientData
|
||||
|
||||
@@ -429,7 +410,7 @@ func (o *JsonDB) GetClients(hasQRCode bool) ([]model.ClientData, error) {
|
||||
|
||||
// generate client qrcode image in base64
|
||||
if hasQRCode && client.PrivateKey != "" {
|
||||
server, _ := o.GetServer()
|
||||
server, _ := o.GetServerByID(util.DefaultServerID)
|
||||
globalSettings, _ := o.GetGlobalSettings()
|
||||
|
||||
png, err := qrcode.Encode(util.BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
|
||||
@@ -459,7 +440,7 @@ func (o *JsonDB) GetClientByID(clientID string, qrCodeSettings model.QRCodeSetti
|
||||
|
||||
// generate client qrcode image in base64
|
||||
if qrCodeSettings.Enabled && client.PrivateKey != "" {
|
||||
server, _ := o.GetServer()
|
||||
server, _ := o.GetServerByID(util.DefaultServerID)
|
||||
globalSettings, _ := o.GetGlobalSettings()
|
||||
client := client
|
||||
if !qrCodeSettings.IncludeDNS {
|
||||
@@ -508,26 +489,6 @@ func (o *JsonDB) DeleteClient(clientID string) error {
|
||||
return o.conn.Delete("clients", clientID)
|
||||
}
|
||||
|
||||
func (o *JsonDB) SaveServerInterface(serverInterface model.ServerInterface) error {
|
||||
serverInterfacePath := path.Join(path.Join(o.dbPath, "server"), "interfaces.json")
|
||||
output := o.conn.Write("server", "interfaces", serverInterface)
|
||||
err := util.ManagePerms(serverInterfacePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (o *JsonDB) SaveServerKeyPair(serverKeyPair model.ServerKeypair) error {
|
||||
serverKeyPairPath := path.Join(path.Join(o.dbPath, "server"), "keypair.json")
|
||||
output := o.conn.Write("server", "keypair", serverKeyPair)
|
||||
err := util.ManagePerms(serverKeyPairPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (o *JsonDB) SaveGlobalSettings(globalSettings model.GlobalSetting) error {
|
||||
globalSettingsPath := path.Join(path.Join(o.dbPath, "server"), "global_settings.json")
|
||||
output := o.conn.Write("server", "global_settings", globalSettings)
|
||||
|
||||
@@ -11,13 +11,10 @@ type IStore interface {
|
||||
SaveUser(user model.User) error
|
||||
DeleteUser(username string) error
|
||||
GetGlobalSettings() (model.GlobalSetting, error)
|
||||
GetServer() (model.Server, error)
|
||||
GetClients(hasQRCode bool) ([]model.ClientData, error)
|
||||
GetClientByID(clientID string, qrCode model.QRCodeSettings) (model.ClientData, error)
|
||||
SaveClient(client model.Client) error
|
||||
DeleteClient(clientID string) error
|
||||
SaveServerInterface(serverInterface model.ServerInterface) error
|
||||
SaveServerKeyPair(serverKeyPair model.ServerKeypair) error
|
||||
SaveGlobalSettings(globalSettings model.GlobalSetting) error
|
||||
GetWakeOnLanHosts() ([]model.WakeOnLanHost, error)
|
||||
GetWakeOnLanHost(macAddress string) (*model.WakeOnLanHost, error)
|
||||
|
||||
Reference in New Issue
Block a user