mostly authclient/authd comms
authorpaulr <me@pjr.cc>
Sat, 4 Dec 2010 17:51:55 +0000 (04:51 +1100)
committerpaulr <me@pjr.cc>
Sat, 4 Dec 2010 17:51:55 +0000 (04:51 +1100)
authserver/authd/authd.php
authserver/lib/authClient.php
authserver/lib/lib.php
authserver/usercmd.php

index 05ef636..5fdb3e1 100644 (file)
@@ -38,6 +38,7 @@ if($pid == -1) {
                print_r($msg);
                switch($msg_type) {
                        case MSG_AUTH_USER_TOKEN:
+                               echo "Call to auth user token\n";
                                // minimal checking, we leav it up to authenticateUser to do the real
                                // checking
                                if(!isset($msg["user"])) $msg["user"] = "";
@@ -48,6 +49,7 @@ if($pid == -1) {
                                msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $myga->authenticateUser($username, $passcode));
                                break;
                        case MSG_ADD_USER_TOKEN:
+                               echo "Call to add user token\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_ADD_USER_TOKEN, false); 
                                } else {
@@ -57,6 +59,7 @@ if($pid == -1) {
                                }
                                break;
                        case MSG_DELETE_USER:
+                               echo "Call to del user\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_DELETE_USER, false);    
                                } else {
@@ -66,6 +69,7 @@ if($pid == -1) {
                                }
                        case MSG_AUTH_USER_PASSWORD:
                                // TODO
+                               echo "Call to auth user pass\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
                                        break;
@@ -76,14 +80,29 @@ if($pid == -1) {
                                }
                                
                                $username = $msg["username"];
-                               $sql = "select users_password from users where username='$username'";
+                               $password = $msg["password"];
+                               $sql = "select users_password from users where users_username='$username'";
                                $dbo = getDatabase();
-                               
+                               $res = $dbo->query($sql);
+                               $pass = "";
+                               foreach($res as $row) {
+                                       $pass = $row["users_password"];
+                               }
                                
                                // TODO now do auth
+                               $ourpass = hash('sha512', $password);
+                               echo "ourpass: $ourpass\nourhash: $pass\n";
+                               if($ourpass == $pass) {
+                                       msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, true);
+                                       
+                               } else {
+                                       msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
+                                       
+                               }
                                
                                break;
                        case MSG_SET_USER_PASSWORD:
+                               echo "Call to set user pass\n";
                                // TODO
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
@@ -94,10 +113,24 @@ if($pid == -1) {
                                        break;
                                }
                                
+                               $username = $msg["username"];
+                               $password = $msg["password"];
+                               
+                               $pass = hash('sha512', $password);
+                               
+                               $dbo = getDatabase();
+                               $sql = "update users set users_password='$pass' where users_username='$username'";
+                               
+                               $dbo->query($sql);
+
+                               msg_send($cl_queue, MSG_SET_USER_REALNAME, true);
+                               
+                               
                                // these are irrelavent yet
                                // TODO now set pass
                                break;
                        case MSG_SET_USER_REALNAME:
+                               echo "Call to set user realname\n";
                                // TODO
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
@@ -110,7 +143,8 @@ if($pid == -1) {
                                
                                $username = $msg["username"];
                                $realname = $msg["realname"];
-                               $sql = "update set users_realnemd='$realname' where username='$username'";
+                               $sql = "update users set users_realname='$realname' where users_username='$username'";
+                               echo "sql: $sql\n";
                                $dbo = getDatabase();
                                
                                $dbo->query($sql);
@@ -121,6 +155,7 @@ if($pid == -1) {
                                break;
                        case MSG_SET_USER_TOKEN:
                                // TODO
+                               echo "Call to set user token\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
                                        break;
@@ -137,6 +172,7 @@ if($pid == -1) {
                                break;                  
                        case MSG_SET_USER_TOKEN_TYPE:
                                // TODO
+                               echo "Call to set user token type\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
                                        break;
index d97bc19..a3a2172 100644 (file)
@@ -20,6 +20,17 @@ class GAAuthClient {
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
+               $message["username"] = $username;
+               $message["token"] = $token;
+               
+               msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
+               
+               
        }
        
        function setUserPass($username, $password) {
@@ -37,7 +48,17 @@ class GAAuthClient {
                
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["password"] = $password;
+               
+               msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
+               echo "message sent\n";
                
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);          
+       
        }
        
        function authUserPass($username, $password) {
@@ -55,6 +76,16 @@ class GAAuthClient {
                
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["password"] = $password;
+               
+               msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
@@ -73,6 +104,15 @@ class GAAuthClient {
                
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               
+               msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
@@ -91,6 +131,16 @@ class GAAuthClient {
                
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["realname"] = $realname;
+               
+               msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
@@ -111,7 +161,7 @@ class GAAuthClient {
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
                
-               $message["user"] = $username;
+               $message["username"] = $username;
                $message["passcode"] = $passcode;
                
                msg_send($sr_queue, MSG_AUTH_USER, $message, true, true, $msg_err);
@@ -144,7 +194,7 @@ class GAAuthClient {
                
                $message["username"] = $username;
                
-               msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err);
+               msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
                echo "message sent\n";
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
@@ -173,8 +223,18 @@ class GAAuthClient {
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
                
+               
                $message["username"] = $username;
+               $message["tokentype"] = $tokentype;
+               
+               msg_send($sr_queue, MSG_ADD_USER, $message, 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;
                
        }
 }
index 6b4e771..eb4fc64 100644 (file)
@@ -76,7 +76,7 @@ class gaasGA extends GoogleAuthenticator {
                
                // we need to check if the user exists, and if so put the data, if not create the data
                $sql = "select * from users where users_username='$username'";
-               $res = $dbOject->query($sql);
+               $res = $dbObject->query($sql);
                if($res->fetchColumn() > 0) {
                        // do update
                        $sql = "update users set users_tokendata='$data' where users_username='$username'";
index bbd8247..fb22db0 100644 (file)
@@ -49,16 +49,22 @@ switch($argv[1]) {
                $myAC->addUser($argv[2]);
                break;
        case "delete":
+               $myAC->deleteUser($argv[2]);
                break;
        case "authpass":
+               $myAC->authUserPass($argv[2], $argv[3]);
                break;
        case "setpass":
+               $myAC->setUserPass($argv[2], $argv[3]);
                break;
        case "setname":
+               $myAC->setUserRealName($argv[2], $argv[3]);
                break;
        case "settoken":
+               $myAC->setUserToken($argv[2], $argv[3]);
                break;
        case "settype":
+               $myAC->setUserTokenType($argv[2], $argv[3]);
                break;
 }
 ?>
\ No newline at end of file