comms work between authd and authclient
authorpaulr <me@pjr.cc>
Sat, 4 Dec 2010 18:14:06 +0000 (05:14 +1100)
committerpaulr <me@pjr.cc>
Sat, 4 Dec 2010 18:14:06 +0000 (05:14 +1100)
authserver/authd/authd.php
authserver/lib/authClient.php
authserver/lib/lib.php
authserver/usercmd.php
lib/ga4php.php

index 5fdb3e1..e6a21b7 100644 (file)
@@ -67,6 +67,7 @@ if($pid == -1) {
                                        global $myga;
                                        msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username));
                                }
+                               break;
                        case MSG_AUTH_USER_PASSWORD:
                                // TODO
                                echo "Call to auth user pass\n";
@@ -188,7 +189,36 @@ if($pid == -1) {
                                msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, $myga->setTokenType($username, $tokentype));
                                
                                // TODO now set token 
-                               break;                  
+                               break;
+                       case MSG_GET_USERS:
+                               // TODO this needs to be better
+                               $sql = "select * from users";
+                               
+                               $dbo = getDatabase();
+                               $res = $dbo->query($sql);
+                               
+                               $users = "";
+                               $i = 0;
+                               foreach($res as $row) {
+                                       $users[$i]["username"] = $row["users_username"];
+                                       $users[$i]["realname"] = $row["users_realname"];
+                                       if($row["users_password"]!="") {
+                                               $users[$i]["haspass"] = true;
+                                       } else {
+                                               $users[$i]["haspass"] = false;
+                                       }
+                                       echo "user: ".$users[$i]["username"]." has tdata: \"".$row["users_tokendata"]."\"\n";
+                                       if($row["users_tokendata"]!="") {
+                                               $users[$i]["hastoken"] = true;
+                                       } else {
+                                               $users[$i]["hastoken"] = false;
+                                       }
+                                       $i++; 
+                               }
+                               msg_send($cl_queue, GET_USERS, $users);
+                               
+                               // TODO now set token 
+                               break;
                                
                }               
        }       
index a3a2172..a9e8da4 100644 (file)
@@ -144,6 +144,32 @@ class GAAuthClient {
                
        }
        
+       function getUsers() {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
+               
+               return $msg;
+       }
+       
        function authUserToken($username, $passcode) {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
                
index eb4fc64..4ec2389 100644 (file)
@@ -12,6 +12,7 @@ define("MSG_SET_USER_PASSWORD", 5);
 define("MSG_SET_USER_REALNAME", 6);
 define("MSG_SET_USER_TOKEN", 7);
 define("MSG_SET_USER_TOKEN_TYPE", 8);
+define("MSG_GET_USERS", 9);
 
 if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
 if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
index fb22db0..910372e 100644 (file)
@@ -34,6 +34,7 @@ if(!isset($argv[1])) {
        echo "\tsetname: setname <username> <realname> - sets the real name for a user\n";
        echo "\tsettoken: settoken <username> <tokenkey> - sets the key (hex) for a token\n";
        echo "\tsettype: settype <username> <tokentype> - sets a token type for a user\n";
+       echo "\tgetusers: getusers - gets a list of users\n";
        return 0;       
 }
 
@@ -66,5 +67,8 @@ switch($argv[1]) {
        case "settype":
                $myAC->setUserTokenType($argv[2], $argv[3]);
                break;
+       case "getusers":
+               $myAC->getUsers();
+               break;
 }
 ?>
\ No newline at end of file
index 2be25ff..a052575 100644 (file)
@@ -53,7 +53,8 @@ abstract class GoogleAuthenticator {
        // the function used inside the class to put the data into the
        // datastore using the overloaded data saving class
        function internalPutData($username, $data) {
-               $enco = base64_encode(serialize($data));
+               if($data == "") $enco = "";
+               else $enco = base64_encode(serialize($data));
                
                return $this->putData($username, $enco);
        }
@@ -118,9 +119,7 @@ abstract class GoogleAuthenticator {
        // self explanitory?
        function deleteUser($username) {
                // oh, we need to figure out how to do thi?
-               $data = $this->internalGetData($username);
-               $data["tokenkey"] = "";
-               $this->internalPutData($username);              
+               $this->internalPutData($username, "");          
        }
        
        // user has input their user name and some code, authenticate