Skip to content
Newer
Older
100644 465 lines (414 sloc) 24 KB
436d4e1 @malbon Lots of bug fixes -- thanks Norman
malbon authored May 28, 2005
1
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
2 # Service administration commands XEP-0133 for the xmpppy based transports written by Mike Albon
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
3 import xmpp, string
4094d61 @malbon Initial version of jep0133.py Administration module
malbon authored Mar 1, 2005
4 from xmpp.protocol import *
5 import xmpp.commands
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
6 import config
7 from xml.dom.minidom import parse
4094d61 @malbon Initial version of jep0133.py Administration module
malbon authored Mar 1, 2005
8
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
9 """This file is the XEP-0133 commands that are applicable to the transports.
4094d61 @malbon Initial version of jep0133.py Administration module
malbon authored Mar 1, 2005
10
11 Implemented commands as follows:
12
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
13 4.1. Add_User_Command:
14 4.2. Delete_User_Command:
15 4.18. List_Registered_Users_Command: Return a list of Registered Users
16 4.20. List_Online_Users_Command: Return a list of Online Users
17 4.21. List_Active_Users_Command: Return a list of Active Users
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
18 4.29. Edit_Admin_List_Command: Edit the Administrators list
19 4.30. Restart_Service_Command: Restarts the Service
20 4.31. Shutdown_Service_Command: Shuts down the Service
4094d61 @malbon Initial version of jep0133.py Administration module
malbon authored Mar 1, 2005
21
22
23 """
24
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
25 class Add_User_Command(xmpp.commands.Command_Handler_Prototype):
26 """This is the add user command as documented in section 4.1 of XEP-0133."""
27 name = NS_ADMIN_ADD_USER
28 description = 'Add User'
29 discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
30
31 def __init__(self,userfile,jid=''):
32 """Initialise the command object"""
33 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
34 self.initial = {'execute':self.cmdFirstStage }
35 self.userfile = userfile
36
37 def _DiscoHandler(self,conn,request,type):
38 """The handler for discovery events"""
39 if request.getFrom().getStripped() in config.admins:
40 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
41 else:
42 return None
43
44 def cmdFirstStage(self,conn,request):
45 """Set the session ID, and return the form containing the user's jid"""
46 if request.getFrom().getStripped() in config.admins:
47 # Setup session ready for form reply
48 session = self.getSessionID()
49 self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
50 # Setup form with existing data in
51 reply = request.buildReply('result')
52 form = DataForm(title='Adding a User',data=['Fill out this form to add a user', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The Jabber ID for the account to be added', typ='jid-single', name='accountjid')])
53 replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
54 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
55 self._owner.send(reply)
56 else:
57 self._owner.send(Error(request,ERR_FORBIDDEN))
58 raise NodeProcessed
59
60 def cmdSecondStage(self,conn,request):
61 """Apply and save the config"""
62 form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
63 session = request.getTagAttr('command','sessionid')
64 if self.sessions.has_key(session):
65 if self.sessions[session]['jid'] == request.getFrom():
66 reply = request.buildReply('result')
67 fromstripped = form.getField('accountjid').getValue().encode('utf8')
68 if not self.userfile.has_key(fromstripped):
69 self.userfile[fromstripped] = {}
70 self.userfile.sync()
71 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
72 self._owner.send(reply)
73 else:
74 self._owner.send(Error(request,ERR_BAD_REQUEST))
75 else:
76 self._owner.send(Error(request,ERR_BAD_REQUEST))
77 raise NodeProcessed
78
79 def cmdCancel(self,conn,request):
80 session = request.getTagAttr('command','sessionid')
81 if self.sessions.has_key(session):
82 del self.sessions[session]
83 reply = request.buildReply('result')
84 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
85 self._owner.send(reply)
86 else:
87 self._owner.send(Error(request,ERR_BAD_REQUEST))
88 raise NodeProcessed
89
90 class Delete_User_Command(xmpp.commands.Command_Handler_Prototype):
91 """This is the delete user command as documented in section 4.1 of XEP-0133."""
92 name = NS_ADMIN_DELETE_USER
93 description = 'Delete User'
94 discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
95
96 def __init__(self,userfile,jid=''):
97 """Initialise the command object"""
98 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
99 self.initial = {'execute':self.cmdFirstStage }
100 self.userfile = userfile
101
102 def _DiscoHandler(self,conn,request,type):
103 """The handler for discovery events"""
104 if request.getFrom().getStripped() in config.admins:
105 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
106 else:
107 return None
108
109 def cmdFirstStage(self,conn,request):
110 """Set the session ID, and return the form containing the user's jid"""
111 if request.getFrom().getStripped() in config.admins:
112 # Setup session ready for form reply
113 session = self.getSessionID()
114 self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
115 # Setup form with existing data in
116 reply = request.buildReply('result')
117 form = DataForm(title='Deleting a User',data=['Fill out this form to delete a user', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The Jabber ID for the account to be deleted', typ='jid-single', name='accountjid')])
118 replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
119 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
120 self._owner.send(reply)
121 else:
122 self._owner.send(Error(request,ERR_FORBIDDEN))
123 raise NodeProcessed
124
125 def cmdSecondStage(self,conn,request):
126 """Apply and save the config"""
127 form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
128 session = request.getTagAttr('command','sessionid')
129 if self.sessions.has_key(session):
130 if self.sessions[session]['jid'] == request.getFrom():
131 reply = request.buildReply('result')
132 fromstripped = form.getField('accountjid').getValue().encode('utf8')
133 if self.userfile.has_key(fromstripped):
134 del self.userfile[fromstripped]
135 self.userfile.sync()
136 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
137 self._owner.send(reply)
138 else:
139 self._owner.send(Error(request,ERR_BAD_REQUEST))
140 else:
141 self._owner.send(Error(request,ERR_BAD_REQUEST))
142 raise NodeProcessed
143
144 def cmdCancel(self,conn,request):
145 session = request.getTagAttr('command','sessionid')
146 if self.sessions.has_key(session):
147 del self.sessions[session]
148 reply = request.buildReply('result')
149 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
150 self._owner.send(reply)
151 else:
152 self._owner.send(Error(request,ERR_BAD_REQUEST))
153 raise NodeProcessed
154
155 class List_Registered_Users_Command(xmpp.commands.Command_Handler_Prototype):
156 """This is the registered users command as documented in section 4.18 of XEP-0133.
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
157 At the current time, no provision is made for splitting the userlist into sections"""
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
158 name = NS_ADMIN_REGISTERED_USERS_LIST
159 description = 'Get List of Registered Users'
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
160 discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
161
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
162 def __init__(self,userfile,jid=''):
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
163 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
164 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
165 self.initial = { 'execute':self.cmdFirstStage }
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
166 self.userfile = userfile
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
167
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
168 def _DiscoHandler(self,conn,request,type):
169 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
170 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
171 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
172 else:
173 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
174
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
175 def cmdFirstStage(self,conn,request):
176 """Build the reply to complete the request"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
177 if request.getFrom().getStripped() in config.admins:
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
178 reply = request.buildReply('result')
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
179 form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of registered users',name='registereduserjids',value=self.userfile.keys(),typ='jid-multi')])
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
180 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
181 self._owner.send(reply)
182 else:
183 self._owner.send(Error(request,ERR_FORBIDDEN))
184 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
185
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
186 class List_Online_Users_Command(xmpp.commands.Command_Handler_Prototype):
187 """This is the online users command as documented in section 4.20 of XEP-0133.
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
188 At the current time, no provision is made for splitting the userlist into sections"""
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
189 name = NS_ADMIN_ONLINE_USERS_LIST
190 description = 'Get List of Online Users'
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
191 discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
192
02b62c7 @normanr fixed registered users adhoc
normanr authored May 29, 2006
193 def __init__(self,users,jid=''):
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
194 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
195 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
196 self.initial = { 'execute':self.cmdFirstStage }
02b62c7 @normanr fixed registered users adhoc
normanr authored May 29, 2006
197 self.users = users
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
198
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
199 def _DiscoHandler(self,conn,request,type):
200 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
201 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
202 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
203 else:
204 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
205
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
206 def cmdFirstStage(self,conn,request):
207 """Build the reply to complete the request"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
208 if request.getFrom().getStripped() in config.admins:
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
209 reply = request.buildReply('result')
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
210 form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of online users',name='onlineuserjids',value=self.users.keys(),typ='jid-multi')])
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
211 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
212 self._owner.send(reply)
213 else:
214 self._owner.send(Error(request,ERR_FORBIDDEN))
215 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
216
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
217 class List_Active_Users_Command(xmpp.commands.Command_Handler_Prototype):
218 """This is the active users command as documented in section 4.21 of XEP-0133.
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
219 At the current time, no provision is made for splitting the userlist into sections"""
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
220 name = NS_ADMIN_ACTIVE_USERS_LIST
221 description = 'Get List of Active Users'
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
222 discofeatures = [xmpp.commands.NS_COMMANDS,xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
223
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
224 def __init__(self,users,jid=''):
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
225 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
226 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
227 self.initial = { 'execute':self.cmdFirstStage }
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
228 self.users = users
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
229
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
230 def _DiscoHandler(self,conn,request,type):
231 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
232 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
233 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
234 else:
235 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
236
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
237 def cmdFirstStage(self,conn,request):
238 """Build the reply to complete the request"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
239 if request.getFrom().getStripped() in config.admins:
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
240 reply = request.buildReply('result')
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
241 form = DataForm(typ='result',data=[DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The list of active users',name='activeuserjids',value=self.users.keys(),typ='jid-multi')])
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
242 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':self.getSessionID(),'status':'completed'},payload=[form])
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
243 self._owner.send(reply)
244 else:
245 self._owner.send(Error(request,ERR_FORBIDDEN))
246 raise NodeProcessed
4094d61 @malbon Initial version of jep0133.py Administration module
malbon authored Mar 1, 2005
247
248
249 class Edit_Admin_List_Command(xmpp.commands.Command_Handler_Prototype):
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
250 """This command enables the editing of the administrators list as documented in section 4.29 of XEP-0133.
251 (the users of XEP-0133 commands in this case)"""
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
252 name = NS_ADMIN_EDIT_ADMIN
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
253 description = 'Edit Admin List'
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
254 discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
255
02b62c7 @normanr fixed registered users adhoc
normanr authored May 29, 2006
256 def __init__(self,jid=''):
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
257 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
258 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
259 self.initial = {'execute':self.cmdFirstStage }
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
260
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
261 def _DiscoHandler(self,conn,request,type):
262 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
263 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
264 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
265 else:
266 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
267
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
268 def cmdFirstStage(self,conn,request):
269 """Set the session ID, and return the form containing the current administrators"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
270 if request.getFrom().getStripped() in config.admins:
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
271 # Setup session ready for form reply
272 session = self.getSessionID()
273 self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
274 # Setup form with existing data in
275 reply = request.buildReply('result')
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
276 form = DataForm(title='Editing the Admin List',data=['Fill out this form to edit the list of entities who have administrative privileges', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='The Admin List', typ='jid-multi', name='adminjids',value=config.admins)])
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
277 replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
278 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
279 self._owner.send(reply)
280 else:
281 self._owner.send(Error(request,ERR_FORBIDDEN))
282 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
283
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
284 def cmdSecondStage(self,conn,request):
285 """Apply and save the config"""
286 form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
287 session = request.getTagAttr('command','sessionid')
288 if self.sessions.has_key(session):
289 if self.sessions[session]['jid'] == request.getFrom():
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
290 config.admins = form.getField('adminjids').getValues()
0125b1d @normanr added admin disco functionality to view all registered and online users
normanr authored May 29, 2006
291 if len(config.admins) == 1 and len(config.admins[0]) == 0:
292 config.admins = []
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
293 doc = parse(config.configFile)
294 admins = doc.getElementsByTagName('admins')[0]
295 for el in [x for x in admins.childNodes]:
296 admins.removeChild(el)
297 el.unlink()
298 for admin in config.admins:
299 txt = doc.createTextNode('\n ')
300 admins.appendChild(txt)
301 txt = doc.createTextNode(admin)
302 el = doc.createElement('jid')
303 el.appendChild(txt)
304 admins.appendChild(el)
305 txt = doc.createTextNode('\n ')
306 admins.appendChild(txt)
dde9513 @normanr fixed command namespaces
normanr authored Jun 3, 2006
307 attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'}
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
308 payload=[]
309 try:
310 f = open(config.configFile,'w')
311 doc.writexml(f)
312 f.close()
313 except IOError, (errno, strerror):
314 # attrs['status'] = 'canceled' # Psi doesn't display the form if we cancel the command
315 form = DataForm(typ='result',data=[DataField(value="I/O error(%s): %s" % (errno, strerror),typ='fixed')])
316 payload.append(form)
317 doc.unlink()
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
318 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
319 reply.addChild(name='command',namespace=NS_COMMANDS,attrs=attrs,payload=payload)
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
320 self._owner.send(reply)
321 else:
322 self._owner.send(Error(request,ERR_BAD_REQUEST))
323 else:
324 self._owner.send(Error(request,ERR_BAD_REQUEST))
325 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
326
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
327 def cmdCancel(self,conn,request):
328 session = request.getTagAttr('command','sessionid')
329 if self.sessions.has_key(session):
330 del self.sessions[session]
331 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
332 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
e91478f @normanr Commands now work. Errors are also returned if continuing an invalid …
normanr authored Jul 7, 2005
333 self._owner.send(reply)
334 else:
335 self._owner.send(Error(request,ERR_BAD_REQUEST))
336 raise NodeProcessed
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
337
338
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
339 class Restart_Service_Command(xmpp.commands.Command_Handler_Prototype):
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
340 """This is the restart service command as documented in section 4.30 of XEP-0133."""
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
341 name = NS_ADMIN_RESTART
342 description = 'Restart Service'
343 discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
344
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
345 def __init__(self,transport,jid=''):
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
346 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
347 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
348 self.initial = {'execute':self.cmdFirstStage }
349 self.transport = transport
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
350
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
351 def _DiscoHandler(self,conn,request,type):
352 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
353 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
354 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
355 else:
356 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
357
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
358 def cmdFirstStage(self,conn,request):
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
359 """Set the session ID, and return the form containing the restart reason"""
360 if request.getFrom().getStripped() in config.admins:
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
361 # Setup session ready for form reply
362 session = self.getSessionID()
363 self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
364 # Setup form with existing data in
365 reply = request.buildReply('result')
366 form = DataForm(title='Restarting the Service',data=['Fill out this form to restart the service', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='Announcement', typ='text-multi', name='announcement')])
367 replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
368 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
369 self._owner.send(reply)
370 else:
371 self._owner.send(Error(request,ERR_FORBIDDEN))
372 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
373
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
374 def cmdSecondStage(self,conn,request):
375 """Apply and save the config"""
376 form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
377 session = request.getTagAttr('command','sessionid')
378 if self.sessions.has_key(session):
379 if self.sessions[session]['jid'] == request.getFrom():
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
380 self.transport.offlinemsg = '\n'.join(form.getField('announcement').getValues())
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
381 self.transport.restart = 1
382 self.transport.online = 0
383 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
384 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
385 self._owner.send(reply)
386 else:
387 self._owner.send(Error(request,ERR_BAD_REQUEST))
388 else:
389 self._owner.send(Error(request,ERR_BAD_REQUEST))
390 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
391
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
392 def cmdCancel(self,conn,request):
393 session = request.getTagAttr('command','sessionid')
394 if self.sessions.has_key(session):
395 del self.sessions[session]
396 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
397 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
30bd161 @normanr added restart and online users commands
normanr authored Sep 17, 2005
398 self._owner.send(reply)
399 else:
400 self._owner.send(Error(request,ERR_BAD_REQUEST))
401 raise NodeProcessed
402
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
403 class Shutdown_Service_Command(xmpp.commands.Command_Handler_Prototype):
ec11937 @normanr Added service admin commands for adding and deleting users
normanr authored Jul 22, 2007
404 """This is the shutdown service command as documented in section 4.31 of XEP-0133."""
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
405 name = NS_ADMIN_SHUTDOWN
406 description = 'Shut Down Service'
407 discofeatures = [xmpp.commands.NS_COMMANDS, xmpp.NS_DATA]
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
408
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
409 def __init__(self,transport,jid=''):
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
410 """Initialise the command object"""
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
411 xmpp.commands.Command_Handler_Prototype.__init__(self,jid)
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
412 self.initial = {'execute':self.cmdFirstStage }
413 self.transport = transport
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
414
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
415 def _DiscoHandler(self,conn,request,type):
416 """The handler for discovery events"""
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
417 if request.getFrom().getStripped() in config.admins:
12d2ac4 @normanr added server registrations
normanr authored Oct 22, 2005
418 return xmpp.commands.Command_Handler_Prototype._DiscoHandler(self,conn,request,type)
419 else:
420 return None
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
421
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
422 def cmdFirstStage(self,conn,request):
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
423 """Set the session ID, and return the form containing the shutdown reason"""
424 if request.getFrom().getStripped() in config.admins:
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
425 # Setup session ready for form reply
426 session = self.getSessionID()
427 self.sessions[session] = {'jid':request.getFrom(),'actions':{'cancel':self.cmdCancel,'next':self.cmdSecondStage,'execute':self.cmdSecondStage}}
428 # Setup form with existing data in
429 reply = request.buildReply('result')
430 form = DataForm(title='Shutting Down the Service',data=['Fill out this form to shut down the service', DataField(typ='hidden',name='FORM_TYPE',value=NS_ADMIN),DataField(desc='Announcement', typ='text-multi', name='announcement')])
431 replypayload = [Node('actions',attrs={'execute':'next'},payload=[Node('next')]),form]
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
432 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'executing'},payload=replypayload)
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
433 self._owner.send(reply)
434 else:
435 self._owner.send(Error(request,ERR_FORBIDDEN))
436 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
437
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
438 def cmdSecondStage(self,conn,request):
439 """Apply and save the config"""
440 form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
441 session = request.getTagAttr('command','sessionid')
442 if self.sessions.has_key(session):
443 if self.sessions[session]['jid'] == request.getFrom():
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
444 self.transport.offlinemsg = '\n'.join(form.getField('announcement').getValues())
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
445 self.transport.online = 0
446 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
447 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'})
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
448 self._owner.send(reply)
449 else:
450 self._owner.send(Error(request,ERR_BAD_REQUEST))
451 else:
452 self._owner.send(Error(request,ERR_BAD_REQUEST))
453 raise NodeProcessed
9275b49 @normanr migrated to xml configuration file, and added a 'connect all users' a…
normanr authored May 21, 2006
454
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
455 def cmdCancel(self,conn,request):
456 session = request.getTagAttr('command','sessionid')
457 if self.sessions.has_key(session):
458 del self.sessions[session]
459 reply = request.buildReply('result')
af7bf1c @normanr moving admin namespace constants from jep0133 to to protocol
normanr authored Apr 9, 2007
460 reply.addChild(name='command',namespace=NS_COMMANDS,attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'canceled'})
0ebf976 @normanr added shutdown command, added x:data forms to registration, fixed who…
normanr authored Aug 21, 2005
461 self._owner.send(reply)
462 else:
463 self._owner.send(Error(request,ERR_BAD_REQUEST))
464 raise NodeProcessed
Something went wrong with that request. Please try again.