-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseConfig.py
47 lines (41 loc) · 1.11 KB
/
parseConfig.py
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
import json
import sys
def parseJSON(jsonPath, defaultConfigPath, ipsecConfigPath):
try:
f = open(jsonPath, 'r')
strjson=f.read().replace('\n', '')
jsObj = json.loads(str(strjson))
try:
dc = open(defaultConfigPath)
lines = dc.readlines()
r = open(ipsecConfigPath, 'w')
r.writelines(lines)
default = jsObj["default"]
if(default):
r.write("conn %default\n")
for p in default:
r.write("\t" + p + "=" + default[p] + "\n")
r.write("\n")
psa = jsObj["psa"]
if(psa):
r.write("conn psa\n")
for p in psa:
if psa[p] != "":
r.write("\t" + p + "=" + psa[p] + "\n")
elif p == "left":
r.write("\t" + p + "=%any" + "\n")
elif p == "leftsourceip":
r.write("\t" + p + "=%config" + "\n")
r.write("\n")
#r.close()
except Exception,e:
print str(e)
print "Can't open ipsec config file"
except Exception,e:
print str(e)
print "Can't open json config file"
args = sys.argv
if len(args) == 4:
parseJSON(args[1],args[2],args[3])
else:
print "Usage: parseConfig.py [jsonPath] [defaultConfigPath] [ipsecConfigPath]"