-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
57 lines (46 loc) · 985 Bytes
/
main.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
52
53
54
55
56
57
package main
import (
"bytes"
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"os"
"text/template"
"time"
)
var textTemplate = "template.txt"
func main() {
if len(os.Args) != 2 {
fmt.Println("Please provide a pfsense config xml file as an argument")
os.Exit(1)
}
file := os.Args[1]
if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
fmt.Printf("Could not find file %s\n", file)
os.Exit(1)
}
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("File %s could not be opened %s\n", file, err)
os.Exit(1)
}
pfConfig := &PFSenseConfig{}
err = xml.Unmarshal([]byte(data), &pfConfig)
if err != nil {
fmt.Printf("XML decoding error %s\n", err)
os.Exit(1)
}
t, err := template.ParseFiles(textTemplate)
if err != nil {
fmt.Printf("Template parsing error: %s\n", err)
os.Exit(1)
}
now := time.Now()
var b bytes.Buffer
t.Execute(&b, map[string]interface{}{
"T": now,
"Config": pfConfig,
})
fmt.Printf(b.String())
}