3 require_once("lib.php");
6 function syncUserToken($username, $tokenone, $tokentwo) {
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);
22 $message["username"] = $username;
23 $message["tokenone"] = $tokenone;
24 $message["tokentwo"] = $tokentwo;
26 msg_send($sr_queue, MSG_SYNC_TOKEN, $message, true, true, $msg_err);
28 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
33 function getUserTokenType($username) {
34 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
37 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
41 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
44 // TODO we need to setup a client queue sem lock here
46 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
47 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
49 $message["username"] = $username;
50 msg_send($sr_queue, MSG_GET_TOKEN_TYPE, $message, true, true, $msg_err);
52 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
56 function setUserToken($username, $token) {
57 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
60 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
64 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
67 // TODO we need to setup a client queue sem lock here
69 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
70 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
72 $message["username"] = $username;
73 $message["tokenstring"] = $token;
75 msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
77 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
81 function setUserPass($username, $password) {
82 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
85 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
89 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
92 // TODO we need to setup a client queue sem lock here
94 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
95 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
97 $message["username"] = $username;
98 $message["password"] = $password;
100 msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
102 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
107 function getOtkID($username) {
108 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
111 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
115 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
118 // TODO we need to setup a client queue sem lock here
120 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
121 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
123 $message["username"] = $username;
124 msg_send($sr_queue, MSG_GET_OTK_ID, $message, true, true, $msg_err);
126 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
132 function getOtkPng($username, $otk) {
133 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
136 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
140 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
143 // TODO we need to setup a client queue sem lock here
145 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
146 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
148 $message["otk"] = $otk;
149 $message["username"] = $username;
150 error_log("sending message, $otk");
151 msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
153 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
159 function authUserPass($username, $password) {
160 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
163 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
167 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
170 // TODO we need to setup a client queue sem lock here
172 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
173 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
175 $message["username"] = $username;
176 $message["password"] = $password;
178 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
180 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
184 function deleteUser($username) {
185 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
188 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
192 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
195 // TODO we need to setup a client queue sem lock here
197 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
198 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
200 $message["username"] = $username;
202 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
204 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
210 function setUserRealName($username, $realname) {
211 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
214 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
218 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
221 // TODO we need to setup a client queue sem lock here
223 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
224 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
226 $message["username"] = $username;
227 $message["realname"] = $realname;
229 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
231 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
235 function getUsers() {
236 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
239 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
243 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
246 // TODO we need to setup a client queue sem lock here
248 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
249 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
251 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
253 msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
258 function authUserToken($username, $passcode) {
259 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
262 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
266 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
269 // TODO we need to setup a client queue sem lock here
271 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
272 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
275 $message["username"] = $username;
276 $message["passcode"] = $passcode;
278 msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
280 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
285 function deleteUserToken($username) {
287 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)) {
297 // TODO we need to setup a client queue sem lock here
299 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
300 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
303 $message["username"] = $username;
305 msg_send($sr_queue, MSG_DELETE_USER_TOKEN, $message, true, true, $msg_err);
307 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
312 function addUser($username, $tokentype="", $hexkey="") {
313 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
316 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
320 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
324 // TODO we need to setup a client queue sem lock here
326 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
327 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
330 $message["username"] = $username;
331 if($tokentype!="") $message["tokentype"] = $tokentype;
332 if($hexkey!="") $message["hexkey"] = $hexkey;
334 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
336 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
341 function setUserTokenType($username, $tokentype) {
342 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
345 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
349 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
353 // TODO we need to setup a client queue sem lock here
355 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
356 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
360 $message["username"] = $username;
361 $message["tokentype"] = $tokentype;
363 msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
365 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);