fb6d895b14b467e6bd4cc15801d51d9e155096fe
[ga4php.git] / authserver / authd / authd.php
1 <?php
2
3 if(file_exists("config.php")) {
4         require_once("config.php");
5 } else {
6         // config file doesnt exist, we must abort sensibly
7 }
8
9 // get out master library for ga4php
10 require_once("../lib/lib.php");
11
12         
13 //exit(0);
14 // first we want to fork into the background like all good daemons should
15 //$pid = pcntl_fork();
16 $pid = 0;
17
18 if($pid == -1) {
19         
20 } else if($pid) {
21         // i am the parent, i shall leave
22         echo "i am a parent, i leave\n";
23         exit(0);
24 } else {
25         
26         
27         /// ok, this is just testing stuff... create queue
28         global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
29         
30         
31         
32         $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
33         $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER, 0666 | 'IPC_CREAT');
34
35         $myga = new gaasGA();
36         global $myga;
37         
38         
39         print_r($myga);
40         
41         while(true) {
42                 msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
43                 print_r($msg);
44                 switch($msg_type) {
45                         case MSG_AUTH_USER:
46                                 // minimal checking, we leav it up to authenticateUser to do the real
47                                 // checking
48                                 if(!isset($msg["user"])) $msg["user"] = "";
49                                 if(!isset($msg["passcode"])) $msg["passcode"] = "";
50                                 $username = $msg["user"];
51                                 $passcode = $msg["passcode"];
52                                 global $myga;
53                                 msg_send($cl_queue, MSG_AUTH_USER, $myga->authenticateUser($username, $passcode));
54                                 break;
55                         case MSG_ADD_USER:
56                                 if(!isset($msg["username"])) {
57                                         msg_send($cl_queue, MSG_ADD_USER, false);       
58                                 } else {
59                                         $username = $msg["username"];                           
60                                         global $myga;
61                                         msg_send($cl_queue, MSG_ADD_USER, $myga->setUser($username));
62                                 }
63                                 break;
64                         case MSG_DELETE_USER:
65                                 break;
66                 }               
67         }       
68 }
69
70 ?>