mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-21 20:12:33 +03:00
Update jsondb.go
This commit is contained in:
parent
1315d9f749
commit
10c034f5c7
1 changed files with 22 additions and 0 deletions
|
@ -42,6 +42,7 @@ func (o *JsonDB) Init() error {
|
||||||
var serverInterfacePath string = path.Join(serverPath, "interfaces.json")
|
var serverInterfacePath string = path.Join(serverPath, "interfaces.json")
|
||||||
var serverKeyPairPath string = path.Join(serverPath, "keypair.json")
|
var serverKeyPairPath string = path.Join(serverPath, "keypair.json")
|
||||||
var globalSettingPath string = path.Join(serverPath, "global_settings.json")
|
var globalSettingPath string = path.Join(serverPath, "global_settings.json")
|
||||||
|
var hashesPath string = path.Join(serverPath, "hashes.json")
|
||||||
var userPath string = path.Join(serverPath, "users.json")
|
var userPath string = path.Join(serverPath, "users.json")
|
||||||
// create directories if they do not exist
|
// create directories if they do not exist
|
||||||
if _, err := os.Stat(clientPath); os.IsNotExist(err) {
|
if _, err := os.Stat(clientPath); os.IsNotExist(err) {
|
||||||
|
@ -102,6 +103,14 @@ func (o *JsonDB) Init() error {
|
||||||
o.conn.Write("server", "global_settings", globalSetting)
|
o.conn.Write("server", "global_settings", globalSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hashes
|
||||||
|
if _, err := os.Stat(hashesPath); os.IsNotExist(err) {
|
||||||
|
clientServerHashes := new(model.ClientServerHashes)
|
||||||
|
clientServerHashes.Client = "none"
|
||||||
|
clientServerHashes.Server = "none"
|
||||||
|
o.conn.Write("server", "hashes", clientServerHashes)
|
||||||
|
}
|
||||||
|
|
||||||
// user info
|
// user info
|
||||||
if _, err := os.Stat(userPath); os.IsNotExist(err) {
|
if _, err := os.Stat(userPath); os.IsNotExist(err) {
|
||||||
user := new(model.User)
|
user := new(model.User)
|
||||||
|
@ -255,3 +264,16 @@ func (o *JsonDB) SaveServerKeyPair(serverKeyPair model.ServerKeypair) error {
|
||||||
func (o *JsonDB) SaveGlobalSettings(globalSettings model.GlobalSetting) error {
|
func (o *JsonDB) SaveGlobalSettings(globalSettings model.GlobalSetting) error {
|
||||||
return o.conn.Write("server", "global_settings", globalSettings)
|
return o.conn.Write("server", "global_settings", globalSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *JsonDB) GetPath() string {
|
||||||
|
return o.dbPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *JsonDB) GetHashes() (model.ClientServerHashes, error) {
|
||||||
|
hashes := model.ClientServerHashes{}
|
||||||
|
return hashes, o.conn.Read("server", "hashes", &hashes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *JsonDB) SaveHashes(hashes model.ClientServerHashes) error {
|
||||||
|
return o.conn.Write("server", "hashes", hashes)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue