1
2
3
4
5 from xmpp import *
6 from xmppd import *
7 import time
8
10 """ Message handler for items address directly to the server. """
11 NS='message'
16
19
21 print "MH ",str(stanza)
22 try:
23 body = stanza.getBody()
24 split_jid = session.getSplitJID()
25 bare_jid = session.getBareJID()
26 if body == '1':
27 out_body = 'The items below show each resource, its priority, last date of activity, and total connection time:\nNote: All times in GMT.\n\n'
28 for resource in self._owner.Router._data[bare_jid].keys():
29 cr = self._owner.Router._data[bare_jid][resource]
30 s = self._owner.getsession(bare_jid+'/'+resource)
31 out_body += 're:%s pri:%s last:%s up:%s\n'%(resource,cr.getPriority(),time.strftime('%m-%d-%y %H:%M:%S',time.gmtime(s.last_seen)),self.readableTimeDurration(time.time() - s.conn_since))
32
33 elif body == '2':
34 out_body = ''
35 data = []
36 item = 1
37 for resource in self._owner.Router._data[bare_jid].keys():
38 if resource != session.getResource():
39 s = self._owner.getsession(bare_jid+'/'+resource)
40 s.enqueue(Message(to=s.peer,body='Hello,\nThis location has been remotely disconnected.',frm=session.ourname))
41 data += [s]
42 out_body += '%i) %s\n'%(item,resource)
43 item += 1
44 for term_session in data:
45 term_session.terminate_stream()
46
47 if out_body != '':
48 out_body = 'The following resources were logged-out:\n\n' + out_body
49
50 out_body += 'You are now logged-in from one location.'
51
52 elif body == '3' or body == 'info':
53 out_body = 'System status for %s:\n\n'%session.ourname
54 data = self._owner.tool_get_status()
55 out_body += """ Uptime: %(uptime)s
56 Software: %(soft)s
57 No. Routes: %(no_routes)i
58 No. Connected Servers: %(no_conn_servers)i
59 No. of Registered Users: %(no_registered)i
60 No. of Messages Routed: %(no_msg_routed)i
61 No. Authorized Connections (1/user): %(no_reg_users_conn)i"""%data
62
63 elif body == '4' or body == 'page':
64 someone_online = False
65 for x in self._owner.administrators[session.ourname]:
66 s = self._owner.getsession(x+'@'+session.ourname)
67 if s:
68 someone_online = True
69 s.enqueue(Message(to=x+'@'+session.ourname,body='Hey %s,\nYour friendly server here. JID <%s> has just paged you.'%(s.getName(),session.peer),frm=session.ourname))
70 if someone_online == True:
71 out_body = 'A page has been sent to an administrator.\nWe cannot guarantee that it will be returned.\n\nThank-you.'
72 else:
73 out_body = 'A page could not be sent to an administrator at this time. Please try back in an hour.\n\nThank-you.'
74
75 elif len(body) > 1 and body.find('5') == 0 and session.isAdmin == True:
76 self.DEBUG('MESSAGE HANDLER: %s'%body,'info')
77 JIDS = body[2:len(body)].split(' ')
78 self.DEBUG('MESSAGE HANDLER: %s'%str(JIDS),'info')
79 jid_1 = self._owner.tool_split_jid(JIDS[0])
80 jid_2 = self._owner.tool_split_jid(JIDS[1])
81 out_body = 'Retrieving info for JID <%s> relative to JID <%s>:\n\n'%(JIDS[0],JIDS[1])
82 if jid_2 == None:
83 if jid_1 == None: JIDS[0] = JIDS[0]+'@'+session.ourname
84 roster = self._owner.DB.pull_roster(session.ourname,JIDS[1],JIDS[0])
85 else:
86 roster = self._owner.DB.pull_roster(jid_2[1],jid_2[0],JIDS[0])
87 if roster == None:
88 out_body += 'No data found.'
89 else:
90 for x,y in roster.iteritems():
91 out_body += '%s=%s\n'%(x,y)
92
93
94
95 else:
96 out_body = """Hello %s! Welcome to Help Desk.
97 The following menu below will give you options to choose from:
98
99 1. View all locations that I am currently logged in with.
100 2. Log-out all other locations except this one.
101 3. Get my system status.
102 4. Page an admin for later IM"""%session.getName()
103
104 M=Message(to=session.peer,body=out_body,frm=session.ourname)
105
106 session.enqueue(M)
107 except Exception, val:
108 self.DEBUG('MESSAGE HANDLER CRASHED!\n%s'%val,'error')
109 raise NodeProcessed
110