3 if(file_exists("config.php")) {
4 require_once("config.php");
6 // config file doesnt exist, we must abort sensibly
9 // get out master library for ga4php
10 require_once("../lib/lib.php");
14 // first we want to fork into the background like all good daemons should
15 //$pid = pcntl_fork();
21 // i am the parent, i shall leave
22 echo "i am a parent, i leave\n";
25 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
27 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
28 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER, 0666 | 'IPC_CREAT');
37 msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
40 case MSG_AUTH_USER_TOKEN:
41 echo "Call to auth user token\n";
42 // minimal checking, we leav it up to authenticateUser to do the real
44 if(!isset($msg["user"])) $msg["user"] = "";
45 if(!isset($msg["passcode"])) $msg["passcode"] = "";
46 $username = $msg["user"];
47 $passcode = $msg["passcode"];
49 msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $myga->authenticateUser($username, $passcode));
51 case MSG_ADD_USER_TOKEN:
52 echo "Call to add user token\n";
53 if(!isset($msg["username"])) {
54 msg_send($cl_queue, MSG_ADD_USER_TOKEN, false);
56 $username = $msg["username"];
58 msg_send($cl_queue, MSG_ADD_USER_TOKEN, $myga->setUser($username));
62 echo "Call to del user\n";
63 if(!isset($msg["username"])) {
64 msg_send($cl_queue, MSG_DELETE_USER, false);
66 $username = $msg["username"];
68 msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username));
70 case MSG_AUTH_USER_PASSWORD:
72 echo "Call to auth user pass\n";
73 if(!isset($msg["username"])) {
74 msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
77 if(!isset($msg["password"])) {
78 msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
82 $username = $msg["username"];
83 $password = $msg["password"];
84 $sql = "select users_password from users where users_username='$username'";
86 $res = $dbo->query($sql);
88 foreach($res as $row) {
89 $pass = $row["users_password"];
93 $ourpass = hash('sha512', $password);
94 echo "ourpass: $ourpass\nourhash: $pass\n";
95 if($ourpass == $pass) {
96 msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, true);
99 msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
104 case MSG_SET_USER_PASSWORD:
105 echo "Call to set user pass\n";
107 if(!isset($msg["username"])) {
108 msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
111 if(!isset($msg["password"])) {
112 msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
116 $username = $msg["username"];
117 $password = $msg["password"];
119 $pass = hash('sha512', $password);
121 $dbo = getDatabase();
122 $sql = "update users set users_password='$pass' where users_username='$username'";
126 msg_send($cl_queue, MSG_SET_USER_REALNAME, true);
129 // these are irrelavent yet
132 case MSG_SET_USER_REALNAME:
133 echo "Call to set user realname\n";
135 if(!isset($msg["username"])) {
136 msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
139 if(!isset($msg["realname"])) {
140 msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
144 $username = $msg["username"];
145 $realname = $msg["realname"];
146 $sql = "update users set users_realname='$realname' where users_username='$username'";
148 $dbo = getDatabase();
152 msg_send($cl_queue, MSG_SET_USER_REALNAME, true);
154 // TODO now set real name
156 case MSG_SET_USER_TOKEN:
158 echo "Call to set user token\n";
159 if(!isset($msg["username"])) {
160 msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
163 if(!isset($msg["tokenstring"])) {
164 msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
169 msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->setUserKey($username, $passcode));
171 // TODO now set token
173 case MSG_SET_USER_TOKEN_TYPE:
175 echo "Call to set user token type\n";
176 if(!isset($msg["username"])) {
177 msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
180 if(!isset($msg["tokentype"])) {
181 msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
185 $username = $msg["username"];
186 $tokentype = $msg["tokentype"];
188 msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, $myga->setTokenType($username, $tokentype));
190 // TODO now set token