-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ejabberd_Wrapper.php
123 lines (107 loc) · 4.51 KB
/
Ejabberd_Wrapper.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
define ('EJABBERD_HOST', 'chat.xemzi.com');
class Ejabberd_Wrapper {
private static $ejabberdHost = EJABBERD_HOST;
private static function runCommand($argsString) {
if ($GLOBALS['environment'] == 'dev') {
er("args to ejabberd: $argsString");
return true;
}
exec('sudo /usr/sbin/ejabberdctl ' . $argsString . ' 2>&1',$output,$status);
error_log("command status: $status", 3, ERROR_LOG);
if($status == 0)
{
error_log("'$argsString' ran successfully\n", 3, ERROR_LOG);
return true;
}
else
{
error_log("problem runing command $argsString: " . print_r($output,true), 3, ERROR_LOG);
return false;
}
}
public static function register ($username, $password) {
return self::runCommand("register " . escapeshellarg($username) . " " . self::$ejabberdHost . " " . escapeshellarg($password) );
}
public static function unregister ($username) {
return self::runCommand("unregister " . escapeshellarg($username) . " " . self::$ejabberdHost );
}
public static function ban_account($userName, $reason) {
return self::runCommand("ban_account " . escapeshellarg($userName) . " " . self::$ejabberdHost . " " . escapeshellarg($reason) );
}
public static function change_password($userName,$newPass) {
return self::runCommand("change_password " . escapeshellarg($userName) . " " . self::$ejabberdHost . " " . escapeshellarg($newPass) );
}
public static function srg_create($groupName, $groupDescription = '') {
/*
* srg_create group host name description display
*/
return self::runCommand("srg_create " . escapeshellarg($groupName) . " " . self::$ejabberdHost . " " . escapeshellarg($groupName) . " " . escapeshellarg($groupDescription) . " " . escapeshellarg($groupName) );
}
public static function srg_delete($groupName) {
return self::runCommand("srg_delete " . escapeshellarg($groupName) . " " . self::$ejabberdHost );
}
public static function srg_user_add($userName, $groupName) {
/*
srg_user_add user host group grouphost
Add the JID user@host to the Shared Roster Group
*/
return self::runCommand("srg_user_add " . escapeshellarg($userName) . " " . self::$ejabberdHost . " " . escapeshellarg($groupName) . " " . self::$ejabberdHost );
}
public static function srg_user_del($userName, $groupName) {
return self::runCommand("srg_user_del " . escapeshellarg($userName) . " " . self::$ejabberdHost . " " . escapeshellarg($groupName) . " " . self::$ejabberdHost );
}
/*
* MUC Stuff (from mod_muc_admin)
*/
/*
* create_room name service host
Create a MUC room name@service in host
*/
public static function create_room($roomName) {
return self::runCommand("create_room " . escapeshellarg($roomName) . " conference." . self::$ejabberdHost . " " . self::$ejabberdHost);
}
/*
* destroy_room name service host
Destroy a MUC room
*/
public static function destroy_room($roomName) {
return self::runCommand("destroy_room " . escapeshellarg($roomName) . " conference." . self::$ejabberdHost . " " . self::$ejabberdHost );
}
/*
* get_room_occupants name service
Get the list of occupants of a MUC room
*/
public static function get_room_occupants($roomName) {
return self::runCommand("get_room_occupants " . escapeshellarg($roomName) . " conference." . self::$ejabberdHost );;
}
/*
* muc_online_rooms host
List existing rooms ('global' to get all vhosts)
*/
public static function muc_online_rooms($host = 'global') {
return self::runCommand("muc_online_rooms ". escapeshellarg($host));
}
/*
* send_direct_invitation room password reason users
Send a direct invitation to several destinations
*/
public static function send_direct_invitation($room, $reason = '', $users = array()) {
$uString = '';
foreach ($users as $user) {
$uString .= escapeshellarg($user) . '@' . self::$ejabberdHost . ' ';
}
return self::runCommand("send_direct_invitation ". $room . '@conference.' . self::$ejabberdHost . " '', " . escapeshellarg($reason) . " " . $users);
}
/*
* set_room_affiliation name service jid affiliation
* allowed affiliations: array('Owner', 'Admin', 'Member', 'Outcast', 'None')
*
*/
public static function set_room_affiliation($groupName, $userName, $affiliation) {
if (!in_array($affiliation , array('Owner', 'Admin', 'Member', 'Outcast', 'None'))) {
return false;
}
return self::runCommand("set_room_affiliation " . escapeshellarg($groupName) . ' ' . 'conference.' . self::$ejabberdHost . ' ' . escapeshellarg($affiliation));
}
}