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 setUserToken($username, $token) {
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 $message["tokenstring"] = $token;
52 msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
54 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
58 function setUserPass($username, $password) {
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);
74 $message["username"] = $username;
75 $message["password"] = $password;
77 msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
79 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
84 function getOtkID($username) {
85 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
88 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
92 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
95 // TODO we need to setup a client queue sem lock here
97 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
98 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
100 $message["username"] = $username;
101 msg_send($sr_queue, MSG_GET_OTK_ID, $message, true, true, $msg_err);
103 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
109 function getOtkPng($username, $otk) {
110 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
113 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
117 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
120 // TODO we need to setup a client queue sem lock here
122 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
123 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
125 $message["otk"] = $otk;
126 $message["username"] = $username;
127 error_log("sending message, $otk");
128 msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
130 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
136 function authUserPass($username, $password) {
137 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
140 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
144 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
147 // TODO we need to setup a client queue sem lock here
149 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
150 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
152 $message["username"] = $username;
153 $message["password"] = $password;
155 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
157 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
161 function deleteUser($username) {
162 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
165 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
169 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
172 // TODO we need to setup a client queue sem lock here
174 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
175 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
177 $message["username"] = $username;
179 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
181 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
187 function setUserRealName($username, $realname) {
188 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
191 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
195 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
198 // TODO we need to setup a client queue sem lock here
200 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
201 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
203 $message["username"] = $username;
204 $message["realname"] = $realname;
206 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
208 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
212 function getUsers() {
213 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
216 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
220 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
223 // TODO we need to setup a client queue sem lock here
225 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
226 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
228 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
230 msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
235 function authUserToken($username, $passcode) {
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);
252 $message["username"] = $username;
253 $message["passcode"] = $passcode;
255 msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
257 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
262 function deleteUserToken($username) {
264 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
266 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
270 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
274 // TODO we need to setup a client queue sem lock here
276 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
277 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
280 $message["username"] = $username;
282 msg_send($sr_queue, MSG_DELETE_USER_TOKEN, $message, true, true, $msg_err);
284 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
289 function addUser($username, $tokentype="", $hexkey="") {
290 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
293 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
297 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
301 // TODO we need to setup a client queue sem lock here
303 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
304 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
307 $message["username"] = $username;
308 if($tokentype!="") $message["tokentype"] = $tokentype;
309 if($hexkey!="") $message["hexkey"] = $hexkey;
311 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
313 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
318 function setUserTokenType($username, $tokentype) {
319 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
322 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
326 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
330 // TODO we need to setup a client queue sem lock here
332 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
333 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
337 $message["username"] = $username;
338 $message["tokentype"] = $tokentype;
340 msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
342 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);