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 getOtkPng($otk) {
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["otk"] = $otk;
75 error_log("sending message, $otk");
76 msg_send($sr_queue, MSG_GET_OTK_PNG, $message, true, true, $msg_err);
78 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
84 function authUserPass($username, $password) {
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 $message["password"] = $password;
103 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
105 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
109 function deleteUser($username) {
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["username"] = $username;
127 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
129 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
135 function setUserRealName($username, $realname) {
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;
152 $message["realname"] = $realname;
154 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
156 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
160 function getUsers() {
161 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
164 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
168 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
171 // TODO we need to setup a client queue sem lock here
173 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
174 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
176 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
178 msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
183 function authUserToken($username, $passcode) {
184 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
187 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
191 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
194 // TODO we need to setup a client queue sem lock here
196 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
197 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
200 $message["username"] = $username;
201 $message["passcode"] = $passcode;
203 msg_send($sr_queue, MSG_AUTH_USER_TOKEN, $message, true, true, $msg_err);
204 echo "message sent\n";
206 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
211 function addUser($username, $tokentype="", $hexkey="") {
212 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
215 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
219 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);
229 $message["username"] = $username;
230 if($tokentype!="") $message["tokentype"] = $tokentype;
231 if($hexkey!="") $message["hexkey"] = $hexkey;
233 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
235 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
240 function setUserTokenType($username, $tokentype) {
241 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
244 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
248 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
252 // TODO we need to setup a client queue sem lock here
254 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
255 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
259 $message["username"] = $username;
260 $message["tokentype"] = $tokentype;
262 msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err);
264 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);