3 require_once("lib.php");
6 function addRadiusClient($clientname, $clientip, $clientsecret, $clientdesc) {
7 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
10 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
14 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
17 // TODO we need to setup a client queue sem lock here
19 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
20 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
23 $message["clientname"] = $clientname;
24 $message["clientsecret"] = $clientsecret;
25 $message["clientip"] = $clientip;
26 $message["clientdescription"] = $clientdesc;
28 msg_send($sr_queue, MSG_ADD_RADIUS_CLIENT, $message, true, true, $msg_err);
30 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
34 function deleteRadiusClient($clientname) {
35 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
38 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
42 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
45 // TODO we need to setup a client queue sem lock here
47 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
48 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
51 $message["clientname"] = $clientname;
52 msg_send($sr_queue, MSG_REMOVE_RADIUS_CLIENT, $message, true, true, $msg_err);
54 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
58 function getRadiusClients() {
59 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
62 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
66 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
69 // TODO we need to setup a client queue sem lock here
71 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
72 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
75 msg_send($sr_queue, MSG_GET_RADIUS_CLIENTS, "", true, true, $msg_err);
77 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
82 function syncUserToken($username, $tokenone, $tokentwo) {
83 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
86 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
90 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
93 // TODO we need to setup a client queue sem lock here
95 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
96 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
98 $message["username"] = $username;
99 $message["tokenone"] = $tokenone;
100 $message["tokentwo"] = $tokentwo;
102 msg_send($sr_queue, MSG_SYNC_TOKEN, $message, true, true, $msg_err);
104 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
108 function getUserTokenType($username) {
109 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
112 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
116 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
119 // TODO we need to setup a client queue sem lock here
121 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
122 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
124 $message["username"] = $username;
125 msg_send($sr_queue, MSG_GET_TOKEN_TYPE, $message, true, true, $msg_err);
127 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
131 function setUserToken($username, $token) {
132 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
135 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
139 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
142 // TODO we need to setup a client queue sem lock here
144 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
145 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
147 $message["username"] = $username;
148 $message["tokenstring"] = $token;
150 msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
152 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
156 function setUserPass($username, $password) {
157 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
160 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
164 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
167 // TODO we need to setup a client queue sem lock here
169 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
170 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
172 $message["username"] = $username;
173 $message["password"] = $password;
175 msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
177 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
182 function getOtkID($username) {
183 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
186 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
190 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
193 // TODO we need to setup a client queue sem lock here
195 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
196 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
198 $message["username"] = $username;
199 msg_send($sr_queue, MSG_GET_OTK_ID, $message, true, true, $msg_err);
201 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
207 function getOtkPng($username, $otk) {
208 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
211 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
215 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
218 // TODO we need to setup a client queue sem lock here
220 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
221 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
223 $message["otk"] = $otk;
224 $message["username"] = $username;
225 error_log("sending message, $otk");
226 msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
228 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
234 function authUserPass($username, $password) {
235 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
238 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
242 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
245 // TODO we need to setup a client queue sem lock here
247 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
248 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
250 $message["username"] = $username;
251 $message["password"] = $password;
253 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
255 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
259 function deleteUser($username) {
260 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
263 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
267 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
270 // TODO we need to setup a client queue sem lock here
272 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
273 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
275 $message["username"] = $username;
277 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
279 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
285 function setUserRealName($username, $realname) {
286 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
289 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
293 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
296 // TODO we need to setup a client queue sem lock here
298 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
299 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
301 $message["username"] = $username;
302 $message["realname"] = $realname;
304 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
306 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
310 function getUsers() {
311 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
314 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
318 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
321 // TODO we need to setup a client queue sem lock here
323 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
324 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
326 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
328 msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
333 function authUserToken($username, $passcode) {
334 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
337 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
341 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
344 // TODO we need to setup a client queue sem lock here
346 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
347 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
350 $message["username"] = $username;
351 $message["passcode"] = $passcode;
353 msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
355 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
360 function deleteUserToken($username) {
362 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
364 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
368 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
372 // TODO we need to setup a client queue sem lock here
374 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
375 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
378 $message["username"] = $username;
380 msg_send($sr_queue, MSG_DELETE_USER_TOKEN, $message, true, true, $msg_err);
382 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
387 function addUser($username, $tokentype="", $hexkey="") {
388 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
391 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
395 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
399 // TODO we need to setup a client queue sem lock here
401 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
402 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
405 $message["username"] = $username;
406 if($tokentype!="") $message["tokentype"] = $tokentype;
407 if($hexkey!="") $message["hexkey"] = $hexkey;
409 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
411 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
416 function setUserTokenType($username, $tokentype) {
417 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
420 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
424 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
428 // TODO we need to setup a client queue sem lock here
430 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
431 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
435 $message["username"] = $username;
436 $message["tokentype"] = $tokentype;
438 msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
440 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);