-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.py
152 lines (126 loc) · 4.7 KB
/
configure.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
import sys
import string
import random
import os
import socket
globalhostname = ""
def generateCode():
# Fill the template with the correct data
global jabber_template
global globalhostname
if os.name == "posix":
# If no hostname was previously specified, get one from the system
if globalhostname == "":
hostname = socket.gethostname()
else:
hostname = globalhostname
path = os.sep+"usr"+os.sep+"share"+os.sep+"spade"
else:
# If no hostname was previously specified, get one from the system
if globalhostname == "":
hostname = socket.gethostbyaddr(socket.gethostname())[0]
else:
hostname = globalhostname
path = "usr"+os.sep+"share"+os.sep+"spade"
if hostname == "localhost":
hostname = "127.0.0.1"
print "Translating localhost DNS to IP (127.0.0.1)."
acc_passwd = "".join([string.ascii_letters[int(random.randint(0,len(string.ascii_letters)-1))] for a in range(8)])
ams_passwd = "".join([string.ascii_letters[int(random.randint(0,len(string.ascii_letters)-1))] for a in range(8)])
df_passwd = "".join([string.ascii_letters[int(random.randint(0,len(string.ascii_letters)-1))] for a in range(8)])
spadexml = """
<spade>
<platform>
<hostname>""" + hostname + """</hostname>
<port>5222</port>
<path>"""+path+"""</path>
</platform>
<acc>
<hostname>acc."""+hostname+"""</hostname>
<password>"""+acc_passwd+"""</password>
<port>5222</port>
#MTPS#
</acc>
<ams>
<hostname>ams."""+hostname+"""</hostname>
<password>"""+ams_passwd+"""</password>
<port>5222</port>
</ams>
<df>
<hostname>df."""+hostname+"""</hostname>
<password>"""+df_passwd+"""</password>
<port>5222</port>
</df>
</spade>
"""
# Now fill the MTPs information
mtp_str = "\n"
for file in os.listdir("spade/mtp"):
try:
# If its a python script
if file[-3:] == ".py":
fname = file[:-3]
mtp_str = mtp_str + '''\t\t\t<mtp name="''' + fname + '''">\n\t\t\t\t<instance>''' + fname + '''</instance>\n'''
mtp_str = mtp_str + """\t\t\t\t<protocol>""" + fname + """</protocol>\n"""
mtp_str = mtp_str + """\t\t\t</mtp>\n\n"""
except Exception, e:
print "EXCEPTION GETTING MTPS: ", str(e)
# Fill the data
# GUS: By default, no MTPs, thank you
#spadexml = spadexml.replace("#MTPS#", mtp_str)
spadexml = spadexml.replace("#MTPS#", "")
file = open("etc/spade.xml", "w+")
file.write(spadexml)
file.close()
# Generating real xmppd.xml
if os.name == 'posix':
xmppdxml = '''
<server>
<servernames>
<name>'''+hostname+'''</name>
</servernames>
<certificate file="xmppd.pem"/>
<spool path="'''+str(os.environ['HOME'])+'''/.spade/spool"/>
<plugins>
<MUC jid="muc.'''+hostname+'''" name="SPADE MUC Component"/>
<WQ jid="wq.'''+hostname+'''" name="SPADE Workgroup Queues"/>
</plugins>
<components>
<AMS jid="ams.'''+hostname+'''" name="AMS" username="ams" password="'''+ams_passwd+'''"/>
<DF jid="df.'''+hostname+'''" name="DF" username="df" password="'''+df_passwd+'''"/>
<ACC jid="acc.'''+hostname+'''" name="ACC" username="acc" password="'''+acc_passwd+'''"/>
</components>
</server>
'''
else:
xmppdxml = '''
<server>
<servernames>
<name>'''+hostname+'''</name>
</servernames>
<certificate file="xmppd.pem"/>
<spool path="usr/share/spade/xmppd/spool"/>
<plugins>
<MUC jid="muc.'''+hostname+'''" name="SPADE MUC Component"/>
<WQ jid="wq.'''+hostname+'''" name="SPADE Workgroup Queues"/>
</plugins>
<components>
<AMS jid="ams.'''+hostname+'''" name="AMS" username="ams" password="'''+ams_passwd+'''"/>
<DF jid="df.'''+hostname+'''" name="DF" username="df" password="'''+df_passwd+'''"/>
<ACC jid="acc.'''+hostname+'''" name="ACC" username="acc" password="'''+acc_passwd+'''"/>
</components>
</server>
'''
file = open("etc/xmppd.xml", "w+")
file.write(xmppdxml)
file.close()
if __name__ == '__main__':
# We look for a command line parameter
if len(sys.argv) > 1:
# There is a parameter
globalhostname = sys.argv[1]
else:
# There is no parameter (i.e. macho-mode)
pass
generateCode()