-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync-master.go
51 lines (44 loc) · 1.23 KB
/
sync-master.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package opnborg
import (
"encoding/xml"
"errors"
"strings"
)
// global
var syncPKG string
// readMasterConf
func readMasterConf(config *OPNCall) (*OPNCall, error) {
// setup
if config.Debug {
displayChan <- []byte("[STARTING][MASTER][READ-MASTER-CONFIG]")
}
// fetch current XML from master server
masterXML, err := fetchXML(config.Sync.Master, config)
if err != nil {
displayChan <- []byte("[MASTER][ERROR][FAIL:UNABLE-TO-FETCH] " + config.Sync.Master)
return config, err
}
// validate XML
if !isValidXML(string(masterXML)) {
return config, errors.New("[INVALID-XML-FILE]")
}
if config.Debug {
displayChan <- []byte("[MASTER][OK][SUCCESS:XML-VALIDATION] " + config.Sync.Master)
}
// xml unmarshal
var opn Opnsense
if err = xml.Unmarshal(masterXML, &opn); err != nil {
displayChan <- []byte("[MASTER][ERROR][XML-PARSE][PLUGINS]" + err.Error())
return config, err
}
if config.Debug {
displayChan <- []byte("[MASTER][PLUGINS]" + opn.System.Firmware.Plugins)
}
syncPKG = opn.System.Firmware.Plugins // global
config.Sync.PKG.Packages = strings.Split(opn.System.Firmware.Plugins, ",")
// fin
if config.Debug {
displayChan <- []byte("[MASTER][OK][SUCCESS:MASTER-CONFIG-READ-AND-PROCESSED]")
}
return config, nil
}