3 require_once("lib.php");
7 function setUserToken($username, $token) {
8 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
11 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
15 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
18 // TODO we need to setup a client queue sem lock here
20 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
21 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
23 $message["username"] = $username;
24 $message["tokenstring"] = $token;
26 msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
28 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
32 function setUserPass($username, $password) {
33 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
36 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
40 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
43 // TODO we need to setup a client queue sem lock here
45 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
46 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
48 $message["username"] = $username;
49 $message["password"] = $password;
51 msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
53 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
58 function getOtkID($username) {
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 msg_send($sr_queue, MSG_GET_OTK_ID, $message, true, true, $msg_err);
77 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
83 function getOtkPng($username, $otk) {
84 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
87 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
91 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
94 // TODO we need to setup a client queue sem lock here
96 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
97 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
99 $message["otk"] = $otk;
100 $message["username"] = $username;
101 error_log("sending message, $otk");
102 msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
104 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
110 function authUserPass($username, $password) {
111 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
114 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
118 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
121 // TODO we need to setup a client queue sem lock here
123 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
124 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
126 $message["username"] = $username;
127 $message["password"] = $password;
129 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
131 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
135 function deleteUser($username) {
136 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
139 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
143 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
146 // TODO we need to setup a client queue sem lock here
148 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
149 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
151 $message["username"] = $username;
153 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
155 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
161 function setUserRealName($username, $realname) {
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;
178 $message["realname"] = $realname;
180 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
182 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
186 function getUsers() {
187 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
190 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
194 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
197 // TODO we need to setup a client queue sem lock here
199 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
200 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
202 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
204 msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
209 function authUserToken($username, $passcode) {
210 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
213 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
217 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
220 // TODO we need to setup a client queue sem lock here
222 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
223 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
226 $message["username"] = $username;
227 $message["passcode"] = $passcode;
229 msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
231 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
236 function addUser($username, $tokentype="", $hexkey="") {
237 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
240 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
244 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
248 // TODO we need to setup a client queue sem lock here
250 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
251 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
254 $message["username"] = $username;
255 if($tokentype!="") $message["tokentype"] = $tokentype;
256 if($hexkey!="") $message["hexkey"] = $hexkey;
258 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
260 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
265 function setUserTokenType($username, $tokentype) {
266 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
269 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
273 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
277 // TODO we need to setup a client queue sem lock here
279 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
280 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
284 $message["username"] = $username;
285 $message["tokentype"] = $tokentype;
287 msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
289 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);