-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjuniper.go
More file actions
88 lines (72 loc) · 1.82 KB
/
juniper.go
File metadata and controls
88 lines (72 loc) · 1.82 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"io/ioutil"
"regexp"
"strings"
"github.com/urfave/cli"
)
// TransformScreenOSConfig transforms the ScreenOS configuration to the desired values
func TransformScreenOSConfig(c *cli.Context) error {
input, err := ioutil.ReadFile(file)
if err != nil {
handleError(err)
}
values := make(map[string]string)
values["tunnel_interface_1"] = t1
values["tunnel_interface_2"] = t1
values["internal_zone"] = zone
values["cidr"] = cidr
values["external_interface"] = externalif
checkValueWarnings(values)
r := strings.NewReplacer(
"tunnel.1", t1,
"tunnel.2", t2,
"Trust", zone,
"10.0.0.0/16", cidr,
"ethernet0/0", externalif,
"# set route", "set route",
)
VpnConfig := r.Replace(string(input))
if comments == true {
regex := regexp.MustCompile("(?m)[\r\n]*.*#.*$")
output := regex.ReplaceAllString(VpnConfig, "")
fmt.Println(output)
} else {
fmt.Println(VpnConfig)
}
return nil
}
// TransformJunOSConfig transforms the JunOS configuration to the desired values
func TransformJunOSConfig(c *cli.Context) error {
input, err := ioutil.ReadFile(file)
if err != nil {
handleError(err)
}
values := make(map[string]string)
values["tunnel_interface_1"] = t1
values["tunnel_interface_2"] = t1
values["internal_zone"] = zone
values["external_zone"] = zone
values["cidr"] = cidr
values["external_interface"] = externalif
checkValueWarnings(values)
r := strings.NewReplacer(
"st0.1", t1,
"st0.2", t2,
"Trust", zone,
"Untrust", externalzone,
"10.0.0.0/16", cidr,
"ge-0/0/0.0", externalif,
"# set routing-options", "set routing-options",
)
VpnConfig := r.Replace(string(input))
if comments == true {
regex := regexp.MustCompile("(?m)[\r\n]*.*#.*$")
output := regex.ReplaceAllString(VpnConfig, "")
fmt.Println(output)
} else {
fmt.Println(VpnConfig)
}
return nil
}