Replace from-scratch rewrite with real ngoduykhanh/wireguard-ui fork
The from-scratch Go rewrite had unresolved bugs (missing go.sum, UI 404s, path issues) from being built without a working local Go toolchain to verify against. Switching strategy: use the actual upstream wireguard-ui codebase (proven, battle-tested single-server manager) as the base, and extend it for multi-server support instead of re-deriving everything from zero. Kept our own installers (bootstrap.sh, update.sh, scripts/install.sh, scripts/proxmox-install.sh) - these still apply, just need updating to build/install the upstream module layout instead of the old cmd/wireguard-ui-multi structure. Module path intentionally left as upstream's own (github.com/ngoduykhanh/wireguard-ui) for now to avoid touching every internal import; revisit if this needs to be fully rebranded. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
6eeea65ede
commit
867dc7740a
@@ -0,0 +1,88 @@
|
||||
package jsondb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/ngoduykhanh/wireguard-ui/model"
|
||||
"github.com/ngoduykhanh/wireguard-ui/util"
|
||||
)
|
||||
|
||||
func (o *JsonDB) GetWakeOnLanHosts() ([]model.WakeOnLanHost, error) {
|
||||
var hosts []model.WakeOnLanHost
|
||||
|
||||
// read all client json file in "hosts" directory
|
||||
records, err := o.conn.ReadAll(model.WakeOnLanHostCollectionName)
|
||||
if err != nil {
|
||||
return hosts, err
|
||||
}
|
||||
|
||||
// build the ClientData list
|
||||
for _, f := range records {
|
||||
host := model.WakeOnLanHost{}
|
||||
|
||||
// get client info
|
||||
if err := json.Unmarshal(f, &host); err != nil {
|
||||
return hosts, fmt.Errorf("cannot decode client json structure: %v", err)
|
||||
}
|
||||
|
||||
// create the list of hosts and their qrcode data
|
||||
hosts = append(hosts, host)
|
||||
}
|
||||
|
||||
return hosts, nil
|
||||
}
|
||||
|
||||
func (o *JsonDB) GetWakeOnLanHost(macAddress string) (*model.WakeOnLanHost, error) {
|
||||
host := &model.WakeOnLanHost{
|
||||
MacAddress: macAddress,
|
||||
}
|
||||
resourceName, err := host.ResolveResourceName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = o.conn.Read(model.WakeOnLanHostCollectionName, resourceName, host)
|
||||
if err != nil {
|
||||
host = nil
|
||||
}
|
||||
return host, err
|
||||
}
|
||||
|
||||
func (o *JsonDB) DeleteWakeOnHostLanHost(macAddress string) error {
|
||||
host := &model.WakeOnLanHost{
|
||||
MacAddress: macAddress,
|
||||
}
|
||||
resourceName, err := host.ResolveResourceName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return o.conn.Delete(model.WakeOnLanHostCollectionName, resourceName)
|
||||
}
|
||||
|
||||
func (o *JsonDB) SaveWakeOnLanHost(host model.WakeOnLanHost) error {
|
||||
resourceName, err := host.ResolveResourceName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wakeOnLanHostPath := path.Join(path.Join(o.dbPath, model.WakeOnLanHostCollectionName), resourceName+".json")
|
||||
output := o.conn.Write(model.WakeOnLanHostCollectionName, resourceName, host)
|
||||
err = util.ManagePerms(wakeOnLanHostPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
func (o *JsonDB) DeleteWakeOnHost(host model.WakeOnLanHost) error {
|
||||
resourceName, err := host.ResolveResourceName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return o.conn.Delete(model.WakeOnLanHostCollectionName, resourceName)
|
||||
}
|
||||
Reference in New Issue
Block a user