-
Notifications
You must be signed in to change notification settings - Fork 0
/
adhoc.py
73 lines (62 loc) · 3.37 KB
/
adhoc.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
# $Id$
import sys, xmpp
from xmpp.protocol import *
import config
from jep0133 import *
class AdHocCommands:
def __init__(self, userfile):
self.userfile = userfile
def PlugIn(self, transport):
self.commands = xmpp.commands.Commands(transport.disco)
self.commands.PlugIn(transport.jabber)
# XEP-0133 commands:
transport.cmdadduser = Add_User_Command(self.userfile,jid=config.jid)
transport.cmdadduser.plugin(self.commands)
transport.cmddeleteuser = Delete_User_Command(self.userfile,jid=config.jid)
transport.cmddeleteuser.plugin(self.commands)
transport.cmdlistregisteredusers = List_Registered_Users_Command(self.userfile,jid=config.jid)
transport.cmdlistregisteredusers.plugin(self.commands)
transport.cmdlistonlineusers = List_Online_Users_Command(transport.userlist,jid=config.jid)
transport.cmdlistonlineusers.plugin(self.commands)
transport.cmdlistactiveusers = List_Active_Users_Command(transport.userlist,jid=config.jid)
transport.cmdlistactiveusers.plugin(self.commands)
transport.cmdeditadminusers = Edit_Admin_List_Command(jid=config.jid)
transport.cmdeditadminusers.plugin(self.commands)
transport.cmdrestartservice = Restart_Service_Command(transport,jid=config.jid)
transport.cmdrestartservice.plugin(self.commands)
transport.cmdshutdownservice = Shutdown_Service_Command(transport,jid=config.jid)
transport.cmdshutdownservice.plugin(self.commands)
# transport wide commands:
transport.cmdconnectusers = Connect_Registered_Users_Command(self.userfile)
transport.cmdconnectusers.plugin(self.commands)
class Connect_Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
"""This is the """
name = "connect-users"
description = 'Connect all registered users'
discofeatures = [xmpp.commands.NS_COMMANDS]
def __init__(self,userfile):
"""Initialise the command object"""
xmpp.commands.Command_Handler_Prototype.__init__(self,config.jid)
self.initial = { 'execute':self.cmdFirstStage }
self.userfile = userfile
def _DiscoHandler(self,conn,request,type):
"""The handler for discovery events"""
if request.getFrom().getStripped() in config.admins:
return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
else:
return None
def cmdFirstStage(self,conn,request):
"""Build the reply to complete the request"""
if request.getFrom().getStripped() in config.admins:
for each in self.userfile.keys():
conn.send(Presence(to=each, frm = config.jid, typ = 'probe'))
if self.userfile[each].has_key('servers'):
for server in self.userfile[each]['servers']:
conn.send(Presence(to=each, frm = '%s@%s'%(server,config.jid), typ = 'probe'))
reply = request.buildReply('result')
form = DataForm(typ='result',data=[DataField(value='Command completed.',typ='fixed')])
reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
self._owner.send(reply)
else:
self._owner.send(Error(request,ERR_FORBIDDEN))
raise NodeProcessed