From 2e2593d79cc3b24e0db34ec434e7f4383cf3651d Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 5 Dec 2010 05:14:06 +1100 Subject: [PATCH] comms work between authd and authclient --- authserver/authd/authd.php | 32 +++++++++++++++++++++++++++++++- authserver/lib/authClient.php | 26 ++++++++++++++++++++++++++ authserver/lib/lib.php | 1 + authserver/usercmd.php | 4 ++++ lib/ga4php.php | 7 +++---- 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/authserver/authd/authd.php b/authserver/authd/authd.php index 5fdb3e1..e6a21b7 100644 --- a/authserver/authd/authd.php +++ b/authserver/authd/authd.php @@ -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; } } diff --git a/authserver/lib/authClient.php b/authserver/lib/authClient.php index a3a2172..a9e8da4 100644 --- a/authserver/lib/authClient.php +++ b/authserver/lib/authClient.php @@ -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; diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index eb4fc64..4ec2389 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -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"); diff --git a/authserver/usercmd.php b/authserver/usercmd.php index fb22db0..910372e 100644 --- a/authserver/usercmd.php +++ b/authserver/usercmd.php @@ -34,6 +34,7 @@ if(!isset($argv[1])) { echo "\tsetname: setname - sets the real name for a user\n"; echo "\tsettoken: settoken - sets the key (hex) for a token\n"; echo "\tsettype: settype - 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 diff --git a/lib/ga4php.php b/lib/ga4php.php index 2be25ff..a052575 100644 --- a/lib/ga4php.php +++ b/lib/ga4php.php @@ -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 -- 1.7.0.4