Browse Source

Fix regressions introduced by new simple XML parser.

Maurizio Porrato 8 years ago
parent
commit
17eb5f0ca3

+ 5
- 2
frn/manager/database.py View File

129
                     ('ID', 'EA', 'PW', 'ON', 'BC', 'NN', 'CT', 'NT', 'DS', 'IP', 'registration', 'lastlogin', 'server', 'port'),
129
                     ('ID', 'EA', 'PW', 'ON', 'BC', 'NN', 'CT', 'NT', 'DS', 'IP', 'registration', 'lastlogin', 'server', 'port'),
130
                     data[0]))
130
                     data[0]))
131
                 log.msg("Mailing password to user %s" % str(u))
131
                 log.msg("Mailing password to user %s" % str(u))
132
-                with open('mailtemplate.txt','r') as tplfile:
132
+                tplfile = open('mailtemplate.txt','r')
133
+                try:
133
                     tpl = tplfile.read()
134
                     tpl = tplfile.read()
134
                     mailbody = string.Template(tpl).safe_substitute(u)
135
                     mailbody = string.Template(tpl).safe_substitute(u)
135
                     sendmail('127.0.0.1',
136
                     sendmail('127.0.0.1',
136
                         'admin@gnuradionetwork.org',
137
                         'admin@gnuradionetwork.org',
137
                         [u['EA']],
138
                         [u['EA']],
138
-                        mailbody, port=2525)
139
+                        mailbody, port=25)
140
+                finally:
141
+                    tplfile.close()
139
                 return "OK"
142
                 return "OK"
140
             return self._pool.runQuery(
143
             return self._pool.runQuery(
141
                 "SELECT * FROM frn_users WHERE _ea=?", (user.EA,)
144
                 "SELECT * FROM frn_users WHERE _ea=?", (user.EA,)

+ 1
- 1
frn/manager/remote.py View File

23
         def authReply(auth):
23
         def authReply(auth):
24
             self.resetDelay()
24
             self.resetDelay()
25
             self.authResult = auth
25
             self.authResult = auth
26
-            self.authDone = (auth['al'] == '0')
26
+            self.authDone = (auth['AL'] == '0')
27
             if self.authDone:
27
             if self.authDone:
28
                 self.deferred.callback(auth)
28
                 self.deferred.callback(auth)
29
         connection.sendServerLogin(self.user).addCallback(authReply)
29
         connection.sendServerLogin(self.user).addCallback(authReply)

+ 306
- 306
frn/protocol/client.py View File

1
-# -*- coding: utf-8 -*-
2
-#
3
-# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
4
-# See LICENSE.txt for copyright info
5
-
6
-from Queue import Queue
7
-from twisted.internet.protocol import ReconnectingClientFactory
8
-from twisted.protocols.policies import TimeoutMixin
9
-from twisted.internet.task import LoopingCall
10
-from twisted.python import log
11
-from frn.protocol import versions
12
-from frn.user import FRNUser
13
-from frn.protocol.common import BufferingLineReceiver
14
-from frn.utility import *
15
-
16
-
17
-class FRNClient(BufferingLineReceiver, TimeoutMixin):
18
-
19
-    def connectionMade(self):
20
-        BufferingLineReceiver.connectionMade(self)
21
-        self.user.VX = versions.client
1
+# -*- coding: utf-8 -*-
2
+#
3
+# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
4
+# See LICENSE.txt for copyright info
5
+
6
+from Queue import Queue
7
+from twisted.internet.protocol import ReconnectingClientFactory
8
+from twisted.protocols.policies import TimeoutMixin
9
+from twisted.internet.task import LoopingCall
10
+from twisted.python import log
11
+from frn.protocol import versions
12
+from frn.user import FRNUser
13
+from frn.protocol.common import BufferingLineReceiver
14
+from frn.utility import *
15
+
16
+
17
+class FRNClient(BufferingLineReceiver, TimeoutMixin):
18
+
19
+    def connectionMade(self):
20
+        BufferingLineReceiver.connectionMade(self)
21
+        self.user.VX = versions.client
22
         self.serverdata = {}
22
         self.serverdata = {}
23
-        self.txq = Queue()
24
-        self.setTimeout(25.0)
25
-        self.login()
26
-
23
+        self.txq = Queue()
24
+        self.setTimeout(25.0)
25
+        self.login()
26
+
27
     def connectionLost(self, reason):
27
     def connectionLost(self, reason):
28
         self.serverdata = {}
28
         self.serverdata = {}
29
         BufferingLineReceiver.connectionLost(self, reason)
29
         BufferingLineReceiver.connectionLost(self, reason)
30
 
30
 
31
-    def ready(self):
32
-        self.status = 'READY'
33
-        self.msgbuffer = []
34
-        self.phase = 0
35
-        self.expectRawData(1)
36
-
37
-    def startMultiLineMessage(self, msgtype):
38
-        self.status = msgtype
39
-        self.phase = None
40
-        self.setLineMode()
41
-
42
-    def stopMultiLineMessage(self):
43
-        handler = getattr(self, 'decode'+self.status, None)
44
-        status = self.status
45
-        message = self.msgbuffer
46
-        self.ready()
47
-        if handler is not None:
48
-            handler(message)
49
-        else:
50
-            self.unimplemented(status, message)
51
-
52
-    def collectMultiLineMessage(self, line):
53
-        if self.phase is None:
54
-            self.expected_lines = int(line.strip())
55
-            self.msgbuffer = []
56
-            self.phase = 0
57
-        else:
58
-            self.msgbuffer.append(line)
59
-            self.phase += 1
60
-        if self.phase >= self.expected_lines:
61
-            self.stopMultiLineMessage()
62
-
63
-    def lineReceived(self, line):
64
-        if self.status == 'AUTH':
65
-            if self.phase == 0:
66
-                self.latest_client_version = int(line.strip())
67
-                self.phase = 1
68
-            else:
69
-                self.serverdata = parseSimpleXML(line.strip())
70
-                if int(self.serverdata['sv']) > 2009004:
71
-                    self.sendLine(responseToChallange(
72
-                        self.serverdata['kp']))
73
-                self.ready()
74
-                self.setTimeout(10.0)
75
-                self.factory.resetDelay()
76
-                self.loginResponse(self.serverdata)
77
-        else:
78
-            self.collectMultiLineMessage(line)
79
-
80
-    def expectedReceived(self, data):
81
-        self.resetTimeout()
82
-        if self.status == 'READY':
83
-            packet_type = ord(data[0])
84
-            if packet_type == 0: # Keepalive
85
-                self.ready()
86
-                self.pong()
87
-            elif packet_type == 1: # TX ack
88
-                self.status = 'TX'
89
-                self.expectRawData(2)
90
-            elif packet_type == 2: # Audio
91
-                self.status = 'AUDIO'
92
-                self.expectRawData(327) # Two ID bytes + 10 GSM frames
93
-            elif packet_type == 3: # Client list
94
-                self.status = 'CLIENTS'
95
-                self.expectRawData(2) # Discard two null bytes
96
-            elif packet_type == 4: # Text
97
-                self.startMultiLineMessage('TEXT')
98
-            elif packet_type == 5: # Channel list
99
-                self.startMultiLineMessage('NETWORKS')
100
-            elif packet_type == 6: # Admin list
101
-                self.startMultiLineMessage('ADMIN')
102
-            elif packet_type == 7: # Access list
103
-                self.startMultiLineMessage('ACCESS')
104
-            elif packet_type == 8: # Block list
105
-                self.startMultiLineMessage('BLOCK')
106
-            elif packet_type == 9: # Mute list
107
-                self.startMultiLineMessage('MUTE')
108
-            elif packet_type == 10: # Access list flags
109
-                self.startMultiLineMessage('ACCESSFLAGS')
110
-            else:
111
-                log.err("Unknown packet type %d" % packet_type)
112
-        elif self.status == 'CLIENTS':
113
-            self.startMultiLineMessage('CLIENTS')
114
-        elif self.status == 'AUDIO':
115
-            self.ready()
116
-            self.decodeAUDIO(ord(data[0])*256+ord(data[1]), data[2:])
117
-        elif self.status == 'TX':
118
-            self.ready()
119
-            self.decodeTX(ord(data[0])*256+ord(data[1]))
120
-
121
-    def login(self):
122
-        ap = "CT:"+self.user.asXML(
123
-            'VX','EA','PW','ON','BC','DS','NN','CT','NT')
124
-        self.status = 'AUTH'
125
-        self.phase = 0
126
-        self.sendLine(ap)
127
-
128
-    def pong(self):
129
-        self.sendLine('P')
130
-
131
-    def setStatus(self, status):
132
-        self.sendLine('ST:%s' % str(status))
133
-
134
-    def stopTransmission(self):
135
-        self.sendLine('RX0')
136
-
137
-    def startTransmission(self):
138
-        self.sendLine('TX0')
139
-
140
-    def sendAudioFrame(self, frame):
141
-        self.resetTimeout()
142
-        self.sendLine('TX1')
143
-        self.transport.write(frame)
144
-
145
-    def streamStep(self, count):
146
-        if count > 1:
147
-            log.msg("WARNING: lost %d ticks" % (count-1))
148
-        for i in range(count):
149
-            self.sendAudioFrame(self.txq.get_nowait())
150
-
151
-    def stopStreaming(self):
152
-        self.txtimer.stop()
153
-
154
-    def _streamAck(self):
155
-        self.txtimer = LoopingCall.withCount(self.streamStep)
156
-        self.txtimer.start(0.20).addCallback(
157
-            lambda _: self.stopTransmission()).addErrback(
158
-            lambda _: self.stopTransmission())
159
-
160
-    def feedStreaming(self, frames):
161
-        if type(frames) == list:
162
-            for frame in frames:
163
-                self.txq.put_nowait(frame)
164
-        else:
165
-            self.txq.put_nowait(frames)
166
-
167
-    def startStreaming(self):
168
-        self.startTransmission()
169
-
170
-    def sendTextMessage(self, dest, text):
171
-        self.sendLine('TM:'+formatSimpleXML(dict(ID=dest, MS=text)))
172
-
173
-    def addAdmin(self, client_ip):
174
-        self.sendLine("AA:"+formatSimpleXML(dict(IP=client_ip)))
175
-
176
-    def removeAdmin(self, client_ip):
177
-        self.sendLine("DA:"+formatSimpleXML(dict(IP=client_ip)))
178
-
179
-    def addMute(self, client_ip):
180
-        self.sendLine("MC:"+formatSimpleXML(dict(IP=client_ip)))
181
-
182
-    def removeMute(self, client_ip):
183
-        self.sendLine("UM:"+formatSimpleXML(dict(IP=client_ip)))
184
-
185
-    def addBlock(self, client_ip):
186
-        self.sendLine("BC:"+formatSimpleXML(dict(IP=client_ip)))
187
-
188
-    def removeBlock(self, client_ip):
189
-        self.sendLine("UC:"+formatSimpleXML(dict(IP=client_ip)))
190
-
191
-    def addAccess(self, email):
192
-        self.sendLine("AT:"+formatSimpleXML(dict(EA=email)))
193
-
194
-    def removeAccess(self, email):
195
-        self.sendLine("DT:"+formatSimpleXML(dict(EA=email)))
196
-
197
-    def addTalk(self, email):
198
-        self.sendLine("ETX:"+formatSimpleXML(dict(EA=email)))
199
-
200
-    def removeTalk(self, email):
201
-        self.sendLine("RTX:"+formatSimpleXML(dict(EA=email)))
202
-
203
-    def accessFlagEnable(self, enable):
204
-        if enable:
205
-            v = 1
206
-        else:
207
-            v = 0
208
-        self.sendLine("ENA:%d" % v)
209
-
210
-    def accessFlagTalk(self, enable):
211
-        if enable:
212
-            v = 1
213
-        else:
214
-            v = 0
215
-        self.sendLine("TXR:%d" % v)
216
-
217
-    def unimplemented(self, status, msg):
218
-        log.msg("Unimplemented: %s: %s" % (status, msg))
219
-
220
-    def decodeAUDIO(self, from_id, frames):
221
-        self.audioFrameReceived(from_id, frames)
222
-
223
-    def decodeTX(self, my_id):
224
-        self._streamAck()
225
-
226
-    def decodeTEXT(self, msg):
227
-        self.textMessageReceived(msg[0], msg[1], msg[2])
228
-
229
-    def decodeCLIENTS(self, msg):
230
-        self.clientsListUpdated([parseSimpleXML(x) for x in msg])
231
-
232
-    def decodeNETWORKS(self, msg):
233
-        self.networksListUpdated(msg)
234
-
235
-    def decodeADMIN(self, msg):
236
-        self.adminListUpdated([parseSimpleXML(x) for x in msg])
237
-
238
-    def decodeACCESS(self, msg):
239
-        self.accessListUpdated([parseSimpleXML(x) for x in msg])
240
-
241
-    def decodeBLOCK(self, msg):
242
-        self.blockListUpdated([parseSimpleXML(x) for x in msg])
243
-
244
-    def decodeMUTE(self, msg):
245
-        self.muteListUpdated([parseSimpleXML(x) for x in msg])
246
-
247
-    def decodeACCESSFLAGS(self, msg):
248
-        self.accessFlagsUpdated(msg[0], msg[1])
249
-
250
-    def decodeUNKNOWN(self, code, msg):
251
-        log.msg("%s: %s" % (code, msg))
252
-
253
-    def loginResponse(self, info):
254
-        pass
255
-
256
-    def audioFrameReceived(self, from_id, frame):
257
-        pass
258
-
259
-    def textMessageReceived(self, client, message, target):
260
-        pass
261
-
262
-    def clientsListUpdated(self, clients):
263
-        pass
264
-
265
-    def networksListUpdated(self, networks):
266
-        pass
267
-
268
-    def adminListUpdated(self, admins):
269
-        pass
270
-
271
-    def accessListUpdated(self, access):
272
-        pass
273
-
274
-    def blockListUpdated(self, blocks):
275
-        pass
276
-
277
-    def muteListUpdated(self, mutes):
278
-        pass
279
-
280
-    def accessFlagsUpdated(self, access, talk):
281
-        pass
282
-
283
-
284
-class FRNClientFactory(ReconnectingClientFactory):
285
-
286
-    protocol = FRNClient
287
-    maxRetries = 10
288
-
289
-    def __init__(self, user):
290
-        self.user = user
291
-
292
-    def startedConnecting(self, connector):
293
-        log.msg('Started to connect')
294
-
295
-    def buildProtocol(self, addr):
296
-        log.msg('Connected')
297
-        p = ReconnectingClientFactory.buildProtocol(self, addr)
298
-        p.user = self.user
299
-        return p
300
-
301
-    def clientConnectionLost(self, connector, reason):
302
-        log.msg('Lost connection.  Reason: %s' % reason)
303
-        ReconnectingClientFactory.clientConnectionLost(
304
-            self, connector, reason)
305
-
306
-    def clientConnectionFailed(self, connector, reason):
307
-        log.err('Connection failed. Reason: %s' % reason)
308
-        ReconnectingClientFactory.clientConnectionFailed(
309
-            self, connector, reason)
310
-
311
-# vim: set et ai sw=4 ts=4 sts=4:
31
+    def ready(self):
32
+        self.status = 'READY'
33
+        self.msgbuffer = []
34
+        self.phase = 0
35
+        self.expectRawData(1)
36
+
37
+    def startMultiLineMessage(self, msgtype):
38
+        self.status = msgtype
39
+        self.phase = None
40
+        self.setLineMode()
41
+
42
+    def stopMultiLineMessage(self):
43
+        handler = getattr(self, 'decode'+self.status, None)
44
+        status = self.status
45
+        message = self.msgbuffer
46
+        self.ready()
47
+        if handler is not None:
48
+            handler(message)
49
+        else:
50
+            self.unimplemented(status, message)
51
+
52
+    def collectMultiLineMessage(self, line):
53
+        if self.phase is None:
54
+            self.expected_lines = int(line.strip())
55
+            self.msgbuffer = []
56
+            self.phase = 0
57
+        else:
58
+            self.msgbuffer.append(line)
59
+            self.phase += 1
60
+        if self.phase >= self.expected_lines:
61
+            self.stopMultiLineMessage()
62
+
63
+    def lineReceived(self, line):
64
+        if self.status == 'AUTH':
65
+            if self.phase == 0:
66
+                self.latest_client_version = int(line.strip())
67
+                self.phase = 1
68
+            else:
69
+                self.serverdata = parseSimpleXML(line.strip())
70
+                if int(self.serverdata['SV']) > 2009004:
71
+                    self.sendLine(responseToChallange(
72
+                        self.serverdata['KP']))
73
+                self.ready()
74
+                self.setTimeout(10.0)
75
+                self.factory.resetDelay()
76
+                self.loginResponse(self.serverdata)
77
+        else:
78
+            self.collectMultiLineMessage(line)
79
+
80
+    def expectedReceived(self, data):
81
+        self.resetTimeout()
82
+        if self.status == 'READY':
83
+            packet_type = ord(data[0])
84
+            if packet_type == 0: # Keepalive
85
+                self.ready()
86
+                self.pong()
87
+            elif packet_type == 1: # TX ack
88
+                self.status = 'TX'
89
+                self.expectRawData(2)
90
+            elif packet_type == 2: # Audio
91
+                self.status = 'AUDIO'
92
+                self.expectRawData(327) # Two ID bytes + 10 GSM frames
93
+            elif packet_type == 3: # Client list
94
+                self.status = 'CLIENTS'
95
+                self.expectRawData(2) # Discard two null bytes
96
+            elif packet_type == 4: # Text
97
+                self.startMultiLineMessage('TEXT')
98
+            elif packet_type == 5: # Channel list
99
+                self.startMultiLineMessage('NETWORKS')
100
+            elif packet_type == 6: # Admin list
101
+                self.startMultiLineMessage('ADMIN')
102
+            elif packet_type == 7: # Access list
103
+                self.startMultiLineMessage('ACCESS')
104
+            elif packet_type == 8: # Block list
105
+                self.startMultiLineMessage('BLOCK')
106
+            elif packet_type == 9: # Mute list
107
+                self.startMultiLineMessage('MUTE')
108
+            elif packet_type == 10: # Access list flags
109
+                self.startMultiLineMessage('ACCESSFLAGS')
110
+            else:
111
+                log.err("Unknown packet type %d" % packet_type)
112
+        elif self.status == 'CLIENTS':
113
+            self.startMultiLineMessage('CLIENTS')
114
+        elif self.status == 'AUDIO':
115
+            self.ready()
116
+            self.decodeAUDIO(ord(data[0])*256+ord(data[1]), data[2:])
117
+        elif self.status == 'TX':
118
+            self.ready()
119
+            self.decodeTX(ord(data[0])*256+ord(data[1]))
120
+
121
+    def login(self):
122
+        ap = "CT:"+self.user.asXML(
123
+            'VX','EA','PW','ON','BC','DS','NN','CT','NT')
124
+        self.status = 'AUTH'
125
+        self.phase = 0
126
+        self.sendLine(ap)
127
+
128
+    def pong(self):
129
+        self.sendLine('P')
130
+
131
+    def setStatus(self, status):
132
+        self.sendLine('ST:%s' % str(status))
133
+
134
+    def stopTransmission(self):
135
+        self.sendLine('RX0')
136
+
137
+    def startTransmission(self):
138
+        self.sendLine('TX0')
139
+
140
+    def sendAudioFrame(self, frame):
141
+        self.resetTimeout()
142
+        self.sendLine('TX1')
143
+        self.transport.write(frame)
144
+
145
+    def streamStep(self, count):
146
+        if count > 1:
147
+            log.msg("WARNING: lost %d ticks" % (count-1))
148
+        for i in range(count):
149
+            self.sendAudioFrame(self.txq.get_nowait())
150
+
151
+    def stopStreaming(self):
152
+        self.txtimer.stop()
153
+
154
+    def _streamAck(self):
155
+        self.txtimer = LoopingCall.withCount(self.streamStep)
156
+        self.txtimer.start(0.20).addCallback(
157
+            lambda _: self.stopTransmission()).addErrback(
158
+            lambda _: self.stopTransmission())
159
+
160
+    def feedStreaming(self, frames):
161
+        if type(frames) == list:
162
+            for frame in frames:
163
+                self.txq.put_nowait(frame)
164
+        else:
165
+            self.txq.put_nowait(frames)
166
+
167
+    def startStreaming(self):
168
+        self.startTransmission()
169
+
170
+    def sendTextMessage(self, dest, text):
171
+        self.sendLine('TM:'+formatSimpleXML(dict(ID=dest, MS=text)))
172
+
173
+    def addAdmin(self, client_ip):
174
+        self.sendLine("AA:"+formatSimpleXML(dict(IP=client_ip)))
175
+
176
+    def removeAdmin(self, client_ip):
177
+        self.sendLine("DA:"+formatSimpleXML(dict(IP=client_ip)))
178
+
179
+    def addMute(self, client_ip):
180
+        self.sendLine("MC:"+formatSimpleXML(dict(IP=client_ip)))
181
+
182
+    def removeMute(self, client_ip):
183
+        self.sendLine("UM:"+formatSimpleXML(dict(IP=client_ip)))
184
+
185
+    def addBlock(self, client_ip):
186
+        self.sendLine("BC:"+formatSimpleXML(dict(IP=client_ip)))
187
+
188
+    def removeBlock(self, client_ip):
189
+        self.sendLine("UC:"+formatSimpleXML(dict(IP=client_ip)))
190
+
191
+    def addAccess(self, email):
192
+        self.sendLine("AT:"+formatSimpleXML(dict(EA=email)))
193
+
194
+    def removeAccess(self, email):
195
+        self.sendLine("DT:"+formatSimpleXML(dict(EA=email)))
196
+
197
+    def addTalk(self, email):
198
+        self.sendLine("ETX:"+formatSimpleXML(dict(EA=email)))
199
+
200
+    def removeTalk(self, email):
201
+        self.sendLine("RTX:"+formatSimpleXML(dict(EA=email)))
202
+
203
+    def accessFlagEnable(self, enable):
204
+        if enable:
205
+            v = 1
206
+        else:
207
+            v = 0
208
+        self.sendLine("ENA:%d" % v)
209
+
210
+    def accessFlagTalk(self, enable):
211
+        if enable:
212
+            v = 1
213
+        else:
214
+            v = 0
215
+        self.sendLine("TXR:%d" % v)
216
+
217
+    def unimplemented(self, status, msg):
218
+        log.msg("Unimplemented: %s: %s" % (status, msg))
219
+
220
+    def decodeAUDIO(self, from_id, frames):
221
+        self.audioFrameReceived(from_id, frames)
222
+
223
+    def decodeTX(self, my_id):
224
+        self._streamAck()
225
+
226
+    def decodeTEXT(self, msg):
227
+        self.textMessageReceived(msg[0], msg[1], msg[2])
228
+
229
+    def decodeCLIENTS(self, msg):
230
+        self.clientsListUpdated([parseSimpleXML(x) for x in msg])
231
+
232
+    def decodeNETWORKS(self, msg):
233
+        self.networksListUpdated(msg)
234
+
235
+    def decodeADMIN(self, msg):
236
+        self.adminListUpdated([parseSimpleXML(x) for x in msg])
237
+
238
+    def decodeACCESS(self, msg):
239
+        self.accessListUpdated([parseSimpleXML(x) for x in msg])
240
+
241
+    def decodeBLOCK(self, msg):
242
+        self.blockListUpdated([parseSimpleXML(x) for x in msg])
243
+
244
+    def decodeMUTE(self, msg):
245
+        self.muteListUpdated([parseSimpleXML(x) for x in msg])
246
+
247
+    def decodeACCESSFLAGS(self, msg):
248
+        self.accessFlagsUpdated(msg[0], msg[1])
249
+
250
+    def decodeUNKNOWN(self, code, msg):
251
+        log.msg("%s: %s" % (code, msg))
252
+
253
+    def loginResponse(self, info):
254
+        pass
255
+
256
+    def audioFrameReceived(self, from_id, frame):
257
+        pass
258
+
259
+    def textMessageReceived(self, client, message, target):
260
+        pass
261
+
262
+    def clientsListUpdated(self, clients):
263
+        pass
264
+
265
+    def networksListUpdated(self, networks):
266
+        pass
267
+
268
+    def adminListUpdated(self, admins):
269
+        pass
270
+
271
+    def accessListUpdated(self, access):
272
+        pass
273
+
274
+    def blockListUpdated(self, blocks):
275
+        pass
276
+
277
+    def muteListUpdated(self, mutes):
278
+        pass
279
+
280
+    def accessFlagsUpdated(self, access, talk):
281
+        pass
282
+
283
+
284
+class FRNClientFactory(ReconnectingClientFactory):
285
+
286
+    protocol = FRNClient
287
+    maxRetries = 10
288
+
289
+    def __init__(self, user):
290
+        self.user = user
291
+
292
+    def startedConnecting(self, connector):
293
+        log.msg('Started to connect')
294
+
295
+    def buildProtocol(self, addr):
296
+        log.msg('Connected')
297
+        p = ReconnectingClientFactory.buildProtocol(self, addr)
298
+        p.user = self.user
299
+        return p
300
+
301
+    def clientConnectionLost(self, connector, reason):
302
+        log.msg('Lost connection.  Reason: %s' % reason)
303
+        ReconnectingClientFactory.clientConnectionLost(
304
+            self, connector, reason)
305
+
306
+    def clientConnectionFailed(self, connector, reason):
307
+        log.err('Connection failed. Reason: %s' % reason)
308
+        ReconnectingClientFactory.clientConnectionFailed(
309
+            self, connector, reason)
310
+
311
+# vim: set et ai sw=4 ts=4 sts=4:

+ 3
- 3
frn/protocol/manager.py View File

52
         def loginDone(result):
52
         def loginDone(result):
53
             self.managerdata = parseSimpleXML(result)
53
             self.managerdata = parseSimpleXML(result)
54
             log.msg("Server login results: %s" % str(self.managerdata))
54
             log.msg("Server login results: %s" % str(self.managerdata))
55
-            if int(self.managerdata['mc']) > 2009004:
55
+            if int(self.managerdata['MC']) > 2009004:
56
                 self.sendLine(responseToChallange(
56
                 self.sendLine(responseToChallange(
57
-                    self.managerdata['kp']))
58
-            if self.managerdata['al'] != '0':
57
+                    self.managerdata['KP']))
58
+            if self.managerdata['AL'] != '0':
59
                 self.transport.loseConnection()
59
                 self.transport.loseConnection()
60
             else:
60
             else:
61
                 self.pingtimer = LoopingCall(self.sendPing)
61
                 self.pingtimer = LoopingCall(self.sendPing)

+ 21
- 21
frn/protocol/server.py View File

103
                 return (userId, "")
103
                 return (userId, "")
104
         user.IP = self.clientAddress.host
104
         user.IP = self.clientAddress.host
105
         if self.factory.tracker.canLogin(user):
105
         if self.factory.tracker.canLogin(user):
106
-            return self.factory.manager.clientLogin(user).addCallback(loginReturned)
106
+            return self.factory.manager.clientLogin(self.factory.serverAuth, user).addCallback(loginReturned)
107
         else:
107
         else:
108
             log.msg("BLOCK %s" % repr(user))
108
             log.msg("BLOCK %s" % repr(user))
109
             return succeed(("BLOCK", ""))
109
             return succeed(("BLOCK", ""))
111
     def disconnect(self):
111
     def disconnect(self):
112
         self.stopPinging()
112
         self.stopPinging()
113
         if self.user is not None:
113
         if self.user is not None:
114
-			log.msg("Logging out client %s" % self.user)
115
-			self.factory.manager.clientLogout(self.user)
116
-			self.factory.tracker.logout(self)
117
-		self.transport.loseConnection()
114
+            log.msg("Logging out client %s" % self.user)
115
+            self.factory.manager.clientLogout(self.factory.serverAuth, self.user)
116
+            self.factory.tracker.logout(self)
117
+        self.transport.loseConnection()
118
 
118
 
119
     def decodeCT(self, body):
119
     def decodeCT(self, body):
120
         def authReturned(result):
120
         def authReturned(result):
169
 
169
 
170
     def decodeTM(self, body):
170
     def decodeTM(self, body):
171
         log.msg("TM: %s" % str(body))
171
         log.msg("TM: %s" % str(body))
172
-        if body['id'] == '':
172
+        if body['ID'] == '':
173
             msgtype = 'A'
173
             msgtype = 'A'
174
         else:
174
         else:
175
             msgtype = 'P'
175
             msgtype = 'P'
176
         for c in self.factory.tracker.getClientList(self.user.NT):
176
         for c in self.factory.tracker.getClientList(self.user.NT):
177
-            if msgtype == 'A' or c.ID == body['id']:
177
+            if msgtype == 'A' or c.ID == body['ID']:
178
                 if c.ID != self.user.ID or msgtype == 'A':
178
                 if c.ID != self.user.ID or msgtype == 'A':
179
                     client = self.factory.tracker.getClientProtocol(c.ID)
179
                     client = self.factory.tracker.getClientProtocol(c.ID)
180
-                    client.sendTextMessage(self.user.ID, body['ms'], msgtype)
180
+                    client.sendTextMessage(self.user.ID, body['MS'], msgtype)
181
 
181
 
182
     def decodeTX(self, body):
182
     def decodeTX(self, body):
183
         if body == '0':
183
         if body == '0':
190
 
190
 
191
     def decodeMC(self, body):
191
     def decodeMC(self, body):
192
         if self.role in ["OWNER","ADMIN"]:
192
         if self.role in ["OWNER","ADMIN"]:
193
-            self.factory.tracker.mute(self.user, body['ip'])
194
-            if self.factory.tracker.isLoggedIn(body['ip']):
195
-                self.factory.tracker.getClientProtocol(body['ip']).decodeRX('0')
193
+            self.factory.tracker.mute(self.user, body['IP'])
194
+            if self.factory.tracker.isLoggedIn(body['IP']):
195
+                self.factory.tracker.getClientProtocol(body['IP']).decodeRX('0')
196
 
196
 
197
     def decodeUM(self, body):
197
     def decodeUM(self, body):
198
         if self.role in ["OWNER","ADMIN"]:
198
         if self.role in ["OWNER","ADMIN"]:
199
-            self.factory.tracker.unMute(body['ip'])
199
+            self.factory.tracker.unMute(body['IP'])
200
 
200
 
201
     def decodeBC(self, body):
201
     def decodeBC(self, body):
202
         if self.role in ["OWNER","ADMIN"]:
202
         if self.role in ["OWNER","ADMIN"]:
203
-            self.factory.tracker.block(self.user, body['ip'])
204
-            self.factory.tracker.getClientProtocol(body['ip']).disconnect()
203
+            self.factory.tracker.block(self.user, body['IP'])
204
+            self.factory.tracker.getClientProtocol(body['IP']).disconnect()
205
 
205
 
206
     def decodeUC(self, body):
206
     def decodeUC(self, body):
207
         if self.role in ["OWNER","ADMIN"]:
207
         if self.role in ["OWNER","ADMIN"]:
208
-            self.factory.tracker.unBlock(body['ip'])
208
+            self.factory.tracker.unBlock(body['IP'])
209
 
209
 
210
     def decodeAA(self, body):
210
     def decodeAA(self, body):
211
         if self.role == "OWNER":
211
         if self.role == "OWNER":
212
-            self.factory.tracker.admin(body['ip'])
212
+            self.factory.tracker.admin(body['IP'])
213
 
213
 
214
     def decodeDA(self, body):
214
     def decodeDA(self, body):
215
         if self.role == "OWNER":
215
         if self.role == "OWNER":
216
-            self.factory.tracker.unAdmin(body['ip'])
216
+            self.factory.tracker.unAdmin(body['IP'])
217
 
217
 
218
     def decodeETX(self, body):
218
     def decodeETX(self, body):
219
         log.msg("decodeETX(%s)" % str(body))
219
         log.msg("decodeETX(%s)" % str(body))
220
         if self.role == "OWNER":
220
         if self.role == "OWNER":
221
-            self.factory.tracker.setAclTx(self.user.NT, body['ea'], True)
221
+            self.factory.tracker.setAclTx(self.user.NT, body['EA'], True)
222
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
222
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
223
 
223
 
224
     def decodeRTX(self, body):
224
     def decodeRTX(self, body):
225
         log.msg("decodeRTX(%s)" % str(body))
225
         log.msg("decodeRTX(%s)" % str(body))
226
         if self.role == "OWNER":
226
         if self.role == "OWNER":
227
-            self.factory.tracker.setAclTx(self.user.NT, body['ea'], False)
227
+            self.factory.tracker.setAclTx(self.user.NT, body['EA'], False)
228
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
228
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
229
 
229
 
230
     def decodeDT(self, body):
230
     def decodeDT(self, body):
231
         log.msg("decodeDT(%s)" % str(body))
231
         log.msg("decodeDT(%s)" % str(body))
232
         if self.role == "OWNER":
232
         if self.role == "OWNER":
233
-            self.factory.tracker.delAcl(self.user.NT, body['ea'])
233
+            self.factory.tracker.delAcl(self.user.NT, body['EA'])
234
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
234
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
235
 
235
 
236
     def decodeAT(self, body):
236
     def decodeAT(self, body):
237
         log.msg("decodeAT(%s)" % str(body))
237
         log.msg("decodeAT(%s)" % str(body))
238
         if self.role == "OWNER":
238
         if self.role == "OWNER":
239
-            self.factory.tracker.addAcl(self.user.NT, body['ea'])
239
+            self.factory.tracker.addAcl(self.user.NT, body['EA'])
240
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
240
             self.sendAccessList(self.factory.tracker.getAcl(self.user.NT))
241
 
241
 
242
     def decodeTXR(self, body):
242
     def decodeTXR(self, body):

+ 13
- 0
mailtemplate.txt View File

1
+From: GNURadioNetwork System Manager <admin@gnuradionetwork.org>
2
+To: $EA
3
+Subject: [GRN] $ON account data
4
+
5
+Callsign and operator name: $ON
6
+Password: $PW
7
+Operating mode: $BC
8
+Description: $DS
9
+City and locator: $CT
10
+Country: $NN
11
+
12
+Registration date: $registration
13
+Last login: $lastlogin

+ 3
- 3
stream.py View File

68
 
68
 
69
     def getClientName(self, client_id):
69
     def getClientName(self, client_id):
70
         if self.clientsById.has_key(client_id):
70
         if self.clientsById.has_key(client_id):
71
-            return self.clientsById[client_id]['on']
71
+            return self.clientsById[client_id]['ON']
72
         else:
72
         else:
73
             return client_id
73
             return client_id
74
 
74
 
77
         self.pong()
77
         self.pong()
78
 
78
 
79
     def loginResponse(self, info):
79
     def loginResponse(self, info):
80
-        log.msg("Login: %s" % info['al'])
80
+        log.msg("Login: %s" % info['AL'])
81
 
81
 
82
     def clientsListUpdated(self, clients):
82
     def clientsListUpdated(self, clients):
83
         self.clients = clients
83
         self.clients = clients
84
-        self.clientsById = dict([(i['id'], i) for i in clients])
84
+        self.clientsById = dict([(i['ID'], i) for i in clients])
85
 
85
 
86
 
86
 
87
 class FRNStreamFactory(FRNClientFactory):
87
 class FRNStreamFactory(FRNClientFactory):

+ 10
- 10
twisted/plugins/frncrosslink.py View File

34
 
34
 
35
     def getClientName(self, client_id):
35
     def getClientName(self, client_id):
36
         if self.clientsById.has_key(client_id):
36
         if self.clientsById.has_key(client_id):
37
-            return self.clientsById[client_id]['on']
37
+            return self.clientsById[client_id]['ON']
38
         else:
38
         else:
39
             return client_id
39
             return client_id
40
 
40
 
60
                     for server, port, u, factory in clients:
60
                     for server, port, u, factory in clients:
61
                         cl = []
61
                         cl = []
62
                         cl.append("<u>%s@%s:%d</u>" % (u.NT,server,port))
62
                         cl.append("<u>%s@%s:%d</u>" % (u.NT,server,port))
63
-                        role = factory.connection.serverdata.get('al', None)
63
+                        role = factory.connection.serverdata.get('AL', None)
64
                         if  role in ['OK', 'ADMIN', 'OWNER']:
64
                         if  role in ['OK', 'ADMIN', 'OWNER']:
65
                             for c in factory.connection.clients:
65
                             for c in factory.connection.clients:
66
                                 ss = cStatus.get(c['s'], '?')
66
                                 ss = cStatus.get(c['s'], '?')
67
-                                if c['m'] != '0':
67
+                                if c['M'] != '0':
68
                                     ss = ss.lower()
68
                                     ss = ss.lower()
69
                                 cl.append(" %s%s %s " % (
69
                                 cl.append(" %s%s %s " % (
70
-                                    cType.get(c['bc'], 'G'),
70
+                                    cType.get(c['BC'], 'G'),
71
                                     ss,
71
                                     ss,
72
-                                    c['on'].replace('<', '&lt;'),
72
+                                    c['ON'].replace('<', '&lt;'),
73
                                     ))
73
                                     ))
74
                         else:
74
                         else:
75
                             cl.append(" :!: DISCONNECTED :!: ")
75
                             cl.append(" :!: DISCONNECTED :!: ")
100
         global clients, talking, lastMessages
100
         global clients, talking, lastMessages
101
         if talking is None or talking == self:
101
         if talking is None or talking == self:
102
             talking = self
102
             talking = self
103
-            talkingUser = self.clients[from_id-1]['on']
103
+            talkingUser = self.clients[from_id-1]['ON']
104
             if len(lastMessages) > 0:
104
             if len(lastMessages) > 0:
105
                 if lastMessages[0] == talkingUser:
105
                 if lastMessages[0] == talkingUser:
106
                     talkingUser = None
106
                     talkingUser = None
126
         self.pong()
126
         self.pong()
127
 
127
 
128
     def loginResponse(self, info):
128
     def loginResponse(self, info):
129
-        log.msg("%s login: %s" % (self.user.ON, info['al']))
129
+        log.msg("%s login: %s" % (self.user.ON, info['AL']))
130
 
130
 
131
     def clientsListUpdated(self, clients):
131
     def clientsListUpdated(self, clients):
132
         self.clients = clients
132
         self.clients = clients
133
-        self.clientsById = dict([(i['id'], i) for i in clients])
133
+        self.clientsById = dict([(i['ID'], i) for i in clients])
134
         if self.clientId is None:
134
         if self.clientId is None:
135
             for c in clients:
135
             for c in clients:
136
-                if c['on'] == self.user.ON and c['bc'] == self.user.BC:
137
-                    self.clientId = c['id']
136
+                if c['ON'] == self.user.ON and c['BC'] == self.user.BC:
137
+                    self.clientId = c['ID']
138
 
138
 
139
 class FRNCrosslinkClientFactory(FRNClientFactory):
139
 class FRNCrosslinkClientFactory(FRNClientFactory):
140
     protocol = FRNCrosslinkClient
140
     protocol = FRNCrosslinkClient

+ 8
- 8
twisted/plugins/frnrecorder.py View File

34
 
34
 
35
     def getClientName(self, client_id):
35
     def getClientName(self, client_id):
36
         if self.clientsById.has_key(client_id):
36
         if self.clientsById.has_key(client_id):
37
-            return self.clientsById[client_id]['on']
37
+            return self.clientsById[client_id]['ON']
38
         else:
38
         else:
39
             return client_id
39
             return client_id
40
 
40
 
41
     def buildRecordingName(self, client_id):
41
     def buildRecordingName(self, client_id):
42
         ts = time.localtime()
42
         ts = time.localtime()
43
-        opname = sanitizeFilename(self.clients[client_id-1]['on'])
43
+        opname = sanitizeFilename(self.clients[client_id-1]['ON'])
44
         dirname = self.factory.recdir+"/"+time.strftime("%Y%m/%d/%H", ts)
44
         dirname = self.factory.recdir+"/"+time.strftime("%Y%m/%d/%H", ts)
45
         filename = time.strftime("%Y%m%d-%H%M%S-", ts) + opname + '.wav'
45
         filename = time.strftime("%Y%m%d-%H%M%S-", ts) + opname + '.wav'
46
         try:
46
         try:
82
 
82
 
83
     def archiveRecording(self, from_id):
83
     def archiveRecording(self, from_id):
84
         log.msg("%s stopped talking" %
84
         log.msg("%s stopped talking" %
85
-            self.clients[from_id-1]['on'])
85
+            self.clients[from_id-1]['ON'])
86
         self.closeFile()
86
         self.closeFile()
87
         self.recordingFile = None
87
         self.recordingFile = None
88
         self.recordingOperator = None
88
         self.recordingOperator = None
89
 
89
 
90
     def audioFrameReceived(self, from_id, frames):
90
     def audioFrameReceived(self, from_id, frames):
91
-        if self.recordingOperator != self.clients[from_id-1]['on']:
91
+        if self.recordingOperator != self.clients[from_id-1]['ON']:
92
             if self.recordingOperator is not None:
92
             if self.recordingOperator is not None:
93
                 self.closeFile()
93
                 self.closeFile()
94
-            self.recordingOperator = self.clients[from_id-1]['on']
94
+            self.recordingOperator = self.clients[from_id-1]['ON']
95
             self.recordingFile = file(self.buildRecordingName(from_id), 'wb')
95
             self.recordingFile = file(self.buildRecordingName(from_id), 'wb')
96
             self.recordingFile.write(WAV_HEADER)
96
             self.recordingFile.write(WAV_HEADER)
97
         self.recordingFile.write(frames)
97
         self.recordingFile.write(frames)
99
             self.parrot_timer.reset(AUDIO_TIMEOUT)
99
             self.parrot_timer.reset(AUDIO_TIMEOUT)
100
         except:
100
         except:
101
             log.msg("%s started talking" %
101
             log.msg("%s started talking" %
102
-                self.clients[from_id-1]['on'])
102
+                self.clients[from_id-1]['ON'])
103
             self.parrot_timer = self.factory.reactor.callLater(
103
             self.parrot_timer = self.factory.reactor.callLater(
104
                 AUDIO_TIMEOUT, self.archiveRecording, from_id)
104
                 AUDIO_TIMEOUT, self.archiveRecording, from_id)
105
         self.pong()
105
         self.pong()
106
 
106
 
107
     def loginResponse(self, info):
107
     def loginResponse(self, info):
108
-        log.msg("Login: %s" % info['al'])
108
+        log.msg("Login: %s" % info['AL'])
109
         self.setStatus(1)
109
         self.setStatus(1)
110
         self.recordingOperator = None
110
         self.recordingOperator = None
111
         self.recordingFile = None
111
         self.recordingFile = None
112
 
112
 
113
     def clientsListUpdated(self, clients):
113
     def clientsListUpdated(self, clients):
114
         self.clients = clients
114
         self.clients = clients
115
-        self.clientsById = dict([(i['id'], i) for i in clients])
115
+        self.clientsById = dict([(i['ID'], i) for i in clients])
116
 
116
 
117
 
117
 
118
 class FRNRecorderFactory(FRNClientFactory):
118
 class FRNRecorderFactory(FRNClientFactory):

Loading…
Cancel
Save