mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-24 19:52:56 +03:00
작업중 커밋
This commit is contained in:
parent
4be3a65691
commit
a3376d1974
10 changed files with 251 additions and 18 deletions
|
@ -38,10 +38,12 @@ func New(dbPath string) (*JsonDB, error) {
|
|||
func (o *JsonDB) Init() error {
|
||||
var clientPath string = path.Join(o.dbPath, "clients")
|
||||
var serverPath string = path.Join(o.dbPath, "server")
|
||||
var wakeOnLanListPath string = path.Join(o.dbPath, model.WakeOnLanHostCollectionName)
|
||||
var serverInterfacePath string = path.Join(serverPath, "interfaces.json")
|
||||
var serverKeyPairPath string = path.Join(serverPath, "keypair.json")
|
||||
var globalSettingPath string = path.Join(serverPath, "global_settings.json")
|
||||
var userPath string = path.Join(serverPath, "users.json")
|
||||
|
||||
// create directories if they do not exist
|
||||
if _, err := os.Stat(clientPath); os.IsNotExist(err) {
|
||||
os.MkdirAll(clientPath, os.ModePerm)
|
||||
|
@ -99,6 +101,10 @@ func (o *JsonDB) Init() error {
|
|||
o.conn.Write("server", "users", user)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(wakeOnLanListPath); os.IsNotExist(err) {
|
||||
os.MkdirAll(wakeOnLanListPath, os.ModePerm)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -221,3 +227,29 @@ func (o *JsonDB) SaveServerKeyPair(serverKeyPair model.ServerKeypair) error {
|
|||
func (o *JsonDB) SaveGlobalSettings(globalSettings model.GlobalSetting) error {
|
||||
return o.conn.Write("server", "global_settings", globalSettings)
|
||||
}
|
||||
|
||||
// FIXME 완성되면 이 주석을 지워라 작업중
|
||||
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([]byte(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
|
||||
}
|
||||
|
|
|
@ -16,4 +16,6 @@ type IStore interface {
|
|||
SaveServerInterface(serverInterface model.ServerInterface) error
|
||||
SaveServerKeyPair(serverKeyPair model.ServerKeypair) error
|
||||
SaveGlobalSettings(globalSettings model.GlobalSetting) error
|
||||
// FIXME 완성되면 이 주석을 지워라
|
||||
GetWakeOnLanHosts() ([]model.WakeOnLanHost, error)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue