added a socket test
[ga4php.git] / authserver / authd / authd.php
index df57ed1..912e12b 100644 (file)
@@ -10,6 +10,8 @@ require_once("../lib/lib.php");
 //exit(0);
 // first we want to fork into the background like all good daemons should
 //$pid = pcntl_fork();
+
+// uncomment this bit and comment the fork above to stop it going into the background
 $pid = 0;
 
 if($pid == -1) {
@@ -19,6 +21,14 @@ if($pid == -1) {
        echo "i am a parent, i leave\n";
        exit(0);
 } else {
+       // here is where i need to swithc to TCP network protocol stuff
+       // i must bind 127.0.0.1 though.
+       // what i want to happen is this:
+       // 1) server receives connection
+       // 2) server forks off process to process connection
+       // 3) main server continues.
+       // a forked process thingy should be fully self contained and capable of dealing
+       // with "problems", i.e. the parent doesnt want to have to clean up children
        global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
        
        $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
@@ -210,9 +220,10 @@ if($pid == -1) {
                                        $myga->setUser($username, $tokentype, "", $hexkey);
                                        
                                        $url = $myga->createUrl($username);
+                                       echo "Url was: $url\n";
                                        if(!file_exists("$BASE_DIR/authserver/authd/otks")) mkdir("$BASE_DIR/authserver/authd/otks");
                                        $otk = generateRandomString();
-                                       system("qrencode -o $BASE_DIR/authserver/authd/otks/$otk.png $url");
+                                       system("qrencode -o $BASE_DIR/authserver/authd/otks/$otk.png '$url'");
                                        
                                        $sql = "update users set users_otk='$otk' where users_username='$username'";
                                        $dbo = getDatabase();
@@ -380,7 +391,7 @@ if($pid == -1) {
                                break;
                        case MSG_GET_USERS:
                                // TODO this needs to be better
-                               $sql = "select * from users";
+                               $sql = "select * from users order by users_username";
                                
                                $dbo = getDatabase();
                                $res = $dbo->query($sql);