1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gidkom\OpenFireRestApi; |
4
|
|
|
|
5
|
|
|
use \Gidkom\OpenFireRestApi\RestClient; |
6
|
|
|
|
7
|
|
|
class OpenFireRestApi extends RestClient |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
parent::__construct(); |
14
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get all registered users |
21
|
|
|
* |
22
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
23
|
|
|
*/ |
24
|
|
|
public function getUsers($opts = []) |
25
|
|
|
{ |
26
|
|
|
$query = ''; |
27
|
|
|
|
28
|
|
|
if(isset($opts['search'])) $query .= '?search='.$opts['search']; |
29
|
|
|
|
30
|
|
|
$endpoint = '/users'.$query; |
31
|
|
|
return $this->doRequest('GET', $endpoint); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get information for a specified user |
37
|
|
|
* |
38
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
39
|
|
|
*/ |
40
|
|
|
public function getUser($username) |
41
|
|
|
{ |
42
|
|
|
$endpoint = '/users/'.$username; |
43
|
|
|
return $this->doRequest('GET', $endpoint); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Creates a new OpenFire user |
49
|
|
|
* |
50
|
|
|
* @param string $username Username |
51
|
|
|
* @param string $password Password |
52
|
|
|
* @param string|false $name Name (Optional) |
53
|
|
|
* @param string|false $email Email (Optional) |
54
|
|
|
* @param string[]|false $groups Groups (Optional) |
55
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
56
|
|
|
*/ |
57
|
|
|
public function addUser($username, $password, $name=false, $email=false, $groups=false) |
58
|
|
|
{ |
59
|
|
|
$endpoint = '/users'; |
60
|
|
|
return $this->doRequest('POST', $endpoint, compact('username', 'password','name','email', 'groups')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Deletes an OpenFire user |
66
|
|
|
* |
67
|
|
|
* @param string $username Username |
68
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
69
|
|
|
*/ |
70
|
|
|
public function deleteUser($username) |
71
|
|
|
{ |
72
|
|
|
$endpoint = '/users/'.$username; |
73
|
|
|
return $this->doRequest('DELETE', $endpoint); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Updates an OpenFire user |
78
|
|
|
* |
79
|
|
|
* @param string $username Username |
80
|
|
|
* @param string|false $password Password (Optional) |
81
|
|
|
* @param string|false $name Name (Optional) |
82
|
|
|
* @param string|false $email Email (Optional) |
83
|
|
|
* @param string[]|false $groups Groups (Optional) |
84
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
85
|
|
|
*/ |
86
|
|
|
public function updateUser($username, $password, $name=false, $email=false, $groups=false) |
87
|
|
|
{ |
88
|
|
|
$endpoint = '/users/'.$username; |
89
|
|
|
return $this->doRequest('PUT', $endpoint, compact('username', 'password','name','email', 'groups')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Retrieve all user groups |
95
|
|
|
* |
96
|
|
|
* @param string $username Username |
97
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
98
|
|
|
*/ |
99
|
|
|
public function userGroups($username) |
100
|
|
|
{ |
101
|
|
|
$endpoint = '/users/'.$username.'/groups'; |
102
|
|
|
return $this->doRequest('GET', $endpoint); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Add user to groups |
107
|
|
|
* |
108
|
|
|
* @param string $username Username |
109
|
|
|
* @param Array $groups Groups to add user |
110
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
111
|
|
|
*/ |
112
|
|
|
public function addToGroups($username, $groups) |
113
|
|
|
{ |
114
|
|
|
$endpoint = '/users/'.$username.'/groups'; |
115
|
|
|
return $this->doRequest('POST', $endpoint, $groups); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Add user to a group |
120
|
|
|
* |
121
|
|
|
* @param string $username Username |
122
|
|
|
* @param string $groups Groups to add user |
|
|
|
|
123
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
124
|
|
|
*/ |
125
|
|
|
public function addToGroup($username, $groupName) |
126
|
|
|
{ |
127
|
|
|
$endpoint = '/users/'.$username.'/groups/'.$groupName; |
128
|
|
|
return $this->doRequest('POST', $endpoint ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Delete user from a group |
134
|
|
|
* |
135
|
|
|
* @param string $username Username |
136
|
|
|
* @param string $groups Groups to add user |
|
|
|
|
137
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
138
|
|
|
*/ |
139
|
|
|
public function deleteFromGroup($username, $groupName) |
140
|
|
|
{ |
141
|
|
|
$endpoint = '/users/'.$username.'/groups/'.$groupName; |
142
|
|
|
return $this->doRequest('DELETE', $endpoint ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* lockout/Disable an OpenFire user |
148
|
|
|
* |
149
|
|
|
* @param string $username Username |
150
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
151
|
|
|
*/ |
152
|
|
|
public function lockoutUser($username) |
153
|
|
|
{ |
154
|
|
|
$endpoint = '/lockouts/'.$username; |
155
|
|
|
return $this->doRequest('POST', $endpoint); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* unlocks an OpenFire user |
161
|
|
|
* |
162
|
|
|
* @param string $username Username |
163
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
164
|
|
|
*/ |
165
|
|
|
public function unlockUser($username) |
166
|
|
|
{ |
167
|
|
|
$endpoint = '/lockouts/'.$username; |
168
|
|
|
return $this->doRequest('DELETE', $endpoint); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* List user rosters |
174
|
|
|
* |
175
|
|
|
* @param string $username Username |
176
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
177
|
|
|
*/ |
178
|
|
|
public function userRosters($username) |
179
|
|
|
{ |
180
|
|
|
$endpoint = '/users/'.$username.'/roster'; |
181
|
|
|
return $this->doRequest('GET', $endpoint, compact('jid','name','subscriptionType')); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Adds to this OpenFire user's roster |
187
|
|
|
* |
188
|
|
|
* @param string $username Username |
189
|
|
|
* @param string $jid JID |
190
|
|
|
* @param string|false $name Name (Optional) |
191
|
|
|
* @param int|false $subscriptionType Subscription (Optional) |
192
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
193
|
|
|
*/ |
194
|
|
|
public function addToRoster($username, $jid, $name=false, $subscriptionType=false) |
195
|
|
|
{ |
196
|
|
|
$endpoint = '/users/'.$username.'/roster'; |
197
|
|
|
return $this->doRequest('POST', $endpoint, compact('jid','name','subscriptionType')); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Removes from this OpenFire user's roster |
203
|
|
|
* |
204
|
|
|
* @param string $username Username |
205
|
|
|
* @param string $jid JID |
206
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
207
|
|
|
*/ |
208
|
|
|
public function deleteFromRoster($username, $jid) |
209
|
|
|
{ |
210
|
|
|
$endpoint = '/users/'.$username.'/roster/'.$jid; |
211
|
|
|
return $this->doRequest('DELETE', $endpoint, $jid); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Updates this OpenFire user's roster |
216
|
|
|
* |
217
|
|
|
* @param string $username Username |
218
|
|
|
* @param string $jid JID |
219
|
|
|
* @param string|false $nickname Nick Name (Optional) |
220
|
|
|
* @param int|false $subscriptionType Subscription (Optional) |
221
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
222
|
|
|
*/ |
223
|
|
|
public function updateRoster($username, $jid, $nickname=false, $subscriptionType=false) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$endpoint = '/users/'.$username.'/roster/'.$jid; |
226
|
|
|
return $this->doRequest('PUT', $endpoint, $jid, compact('jid','username','subscriptionType')); |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
|
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Gell all active sessions |
234
|
|
|
* |
235
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
236
|
|
|
*/ |
237
|
|
|
public function getChatRoom($name) |
238
|
|
|
{ |
239
|
|
|
return $this->doRequest('GET', '/chatrooms/'.$name); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Gell all chat rooms |
244
|
|
|
* |
245
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
246
|
|
|
*/ |
247
|
|
|
public function getAllChatRooms() |
248
|
|
|
{ |
249
|
|
|
return $this->doRequest('GET', '/chatrooms?type=all'); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Create a chat room |
255
|
|
|
* |
256
|
|
|
* @param string $params Params |
257
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
258
|
|
|
*/ |
259
|
|
|
public function createChatRoom($params = []) |
260
|
|
|
{ |
261
|
|
|
return $this->doRequest('POST', '/chatrooms', $params); |
|
|
|
|
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Update a chat room |
267
|
|
|
* |
268
|
|
|
* @param string $params Params |
269
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
270
|
|
|
*/ |
271
|
|
|
public function updateChatRoom($roomName, $params = []) |
272
|
|
|
{ |
273
|
|
|
return $this->doRequest('PUT', '/chatrooms/'.$roomName, $params); |
|
|
|
|
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Delete a chat room |
279
|
|
|
* |
280
|
|
|
* @param string $name Name of the Group to delete |
|
|
|
|
281
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
282
|
|
|
*/ |
283
|
|
|
public function deleteChatRoom($roomName) |
284
|
|
|
{ |
285
|
|
|
return $this->doRequest('DELETE', '/chatrooms/'.$roomName); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Get chat room participants |
290
|
|
|
* |
291
|
|
|
* @param string $name Name of the chatroom |
|
|
|
|
292
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
293
|
|
|
*/ |
294
|
|
|
public function getChatRoomParticipants($roomName) |
295
|
|
|
{ |
296
|
|
|
return $this->doRequest('GET', '/chatrooms/'.$roomName.'/participants'); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Get chat room occupants |
301
|
|
|
* |
302
|
|
|
* @param string $name Name of the chatroom |
|
|
|
|
303
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
304
|
|
|
*/ |
305
|
|
|
public function getChatRoomOccupants($roomName) |
306
|
|
|
{ |
307
|
|
|
return $this->doRequest('GET', '/chatrooms/'.$roomName.'/occupants'); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Add user with role to chatroom |
312
|
|
|
* |
313
|
|
|
* @param string $name Name of the user or jid |
314
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
315
|
|
|
*/ |
316
|
|
|
public function addUserRoleToChatRoom($roomName, $name, $roles) |
317
|
|
|
{ |
318
|
|
|
return $this->doRequest('POST', '/chatrooms/'.$roomName.'/'.$roles.'/'.$name); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Add group with role to chatroom |
324
|
|
|
* |
325
|
|
|
* @param string $name Name of the group |
326
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
327
|
|
|
*/ |
328
|
|
|
public function addGroupRoleToChatRoom($roomName, $name, $roles) |
329
|
|
|
{ |
330
|
|
|
return $this->doRequest('POST', '/chatrooms/'.$roomName.'/'.$roles.'/group/'.$name); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Delete a user from a chat room |
336
|
|
|
* |
337
|
|
|
* @param string $name Name of the group |
338
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
339
|
|
|
*/ |
340
|
|
|
public function deleteChatRoomUser($roomName, $name, $roles) |
341
|
|
|
{ |
342
|
|
|
return $this->doRequest('DELETE', '/chatrooms/'.$roomName.'/'.$roles.'/'.$name); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Retrieve all system properties |
348
|
|
|
* |
349
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
350
|
|
|
*/ |
351
|
|
|
public function getSystemProperties() |
352
|
|
|
{ |
353
|
|
|
return $this->doRequest('GET', '/system/properties'); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Retrieve a system property |
358
|
|
|
* |
359
|
|
|
* @param string $name Name of property |
|
|
|
|
360
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
361
|
|
|
*/ |
362
|
|
|
public function getSystemProperty($propertyName) |
363
|
|
|
{ |
364
|
|
|
return $this->doRequest('GET', '/system/properties/'.$propertyName); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Create a system property |
370
|
|
|
* |
371
|
|
|
* @param array $data new property with value |
372
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
373
|
|
|
*/ |
374
|
|
|
public function createSystemProperty($data) |
375
|
|
|
{ |
376
|
|
|
return $this->doRequest('POST', '/system/properties', $data); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Update a system property |
382
|
|
|
* |
383
|
|
|
* @param string $propertyName name of property to update |
384
|
|
|
* @param array $data new property with value |
385
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
386
|
|
|
*/ |
387
|
|
|
public function updateSystemProperty($propertyName, $data) |
388
|
|
|
{ |
389
|
|
|
return $this->doRequest('POST', '/system/properties/'.$propertyName, $data); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Delete a system property |
395
|
|
|
* |
396
|
|
|
* @param array $data new property with value |
|
|
|
|
397
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
398
|
|
|
*/ |
399
|
|
|
public function deleteSystemProperty($propertyName) |
400
|
|
|
{ |
401
|
|
|
return $this->doRequest('DELETE', '/system/properties/'.$propertyName); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* Retrieve concurrent sessions |
407
|
|
|
* |
408
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
409
|
|
|
*/ |
410
|
|
|
public function getConcurrentSessons() |
411
|
|
|
{ |
412
|
|
|
return $this->doRequest('GET', '/system/statistics/sessions'); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Get all groups |
418
|
|
|
* |
419
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
420
|
|
|
*/ |
421
|
|
|
public function getGroups() |
422
|
|
|
{ |
423
|
|
|
$endpoint = '/groups'; |
424
|
|
|
return $this->doRequest('GET', $endpoint); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* Retrieve a group |
429
|
|
|
* |
430
|
|
|
* @param string $name Name of group |
431
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
432
|
|
|
*/ |
433
|
|
|
public function getGroup($name) |
434
|
|
|
{ |
435
|
|
|
$endpoint = '/groups/'.$name; |
436
|
|
|
return $this->doRequest('GET', $endpoint); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Create a group |
441
|
|
|
* |
442
|
|
|
* @param string $name Name of the group |
443
|
|
|
* @param string $description Some description of the group |
444
|
|
|
* |
445
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
446
|
|
|
*/ |
447
|
|
|
public function createGroup($name, $description = false) |
448
|
|
|
{ |
449
|
|
|
$endpoint = '/groups/'; |
450
|
|
|
return $this->doRequest('POST', $endpoint, compact('name','description')); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Delete a group |
455
|
|
|
* |
456
|
|
|
* @param string $name Name of the Group to delete |
457
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
458
|
|
|
*/ |
459
|
|
|
public function deleteGroup($name) |
460
|
|
|
{ |
461
|
|
|
$endpoint = '/groups/'.$name; |
462
|
|
|
return $this->doRequest('DELETE', $endpoint); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* Update a group (description) |
467
|
|
|
* |
468
|
|
|
* @param string $name Name of group |
469
|
|
|
* @param string $description Some description of the group |
470
|
|
|
* |
471
|
|
|
*/ |
472
|
|
|
public function updateGroup($name, $description) |
473
|
|
|
{ |
474
|
|
|
$endpoint = '/groups/'.$name; |
475
|
|
|
return $this->doRequest('PUT', $endpoint, compact('name','description')); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Retrieve all sessions |
481
|
|
|
* |
482
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
483
|
|
|
*/ |
484
|
|
|
public function getSessions() |
485
|
|
|
{ |
486
|
|
|
$endpoint = '/sessions'; |
487
|
|
|
return $this->doRequest('GET', $endpoint); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Retrieve all user sessions |
492
|
|
|
* |
493
|
|
|
* @param string $username Username of user |
494
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
495
|
|
|
*/ |
496
|
|
|
public function getUserSessions($username) |
497
|
|
|
{ |
498
|
|
|
$endpoint = '/sessions/'.$username; |
499
|
|
|
return $this->doRequest('GET', $endpoint); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Close all user sessions |
505
|
|
|
* @param string $username Username of user |
506
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
507
|
|
|
*/ |
508
|
|
|
public function closeUserSessions($username) |
509
|
|
|
{ |
510
|
|
|
$endpoint = '/sessions/'.$username; |
511
|
|
|
return $this->doRequest('DELETE', $endpoint); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Send a broadcast message to all online users |
516
|
|
|
* |
517
|
|
|
* @param string $content message to send |
|
|
|
|
518
|
|
|
* @return json|false Json with data or error, or False when something went fully wrong |
519
|
|
|
*/ |
520
|
|
|
public function broadcastMessage($message = '') |
521
|
|
|
{ |
522
|
|
|
$content =['body'=> $message]; |
523
|
|
|
$endpoint = '/messages/users'; |
524
|
|
|
return $this->doRequest('POST', $endpoint, $content); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
} |
528
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.