From 07e42724b584df5d317a72b0e0ed1bafbc744b8f Mon Sep 17 00:00:00 2001 From: paulr Date: Mon, 6 Dec 2010 01:23:32 +1100 Subject: [PATCH] a working authd/authclient - mostly --- authserver/authd/authd.php | 12 +++++++-- authserver/authd/gaasdata.sqlite | Bin 0 -> 3072 bytes authserver/lib/authClient.php | 39 ++++++++----------------------- authserver/usercmd.php | 48 ++++++++++++++++++++++++++++++------- lib/ga4php.php | 5 +++- 5 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 authserver/authd/gaasdata.sqlite diff --git a/authserver/authd/authd.php b/authserver/authd/authd.php index 2474b3a..afe3883 100644 --- a/authserver/authd/authd.php +++ b/authserver/authd/authd.php @@ -76,7 +76,11 @@ if($pid == -1) { } else { $username = $msg["username"]; global $myga; - msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username)); + $sql = "delete from users where users_username='$username'"; + $dbo = getDatabase(); + $dbo->query($sql); + + msg_send($cl_queue, MSG_DELETE_USER, true); } break; case MSG_AUTH_USER_PASSWORD: @@ -177,8 +181,10 @@ if($pid == -1) { } global $myga; - $myga->setUserKey($username, $passcode); - msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->createUrl($username)); + $username = $msg["username"]; + $token = $msg["tokenstring"]; + $return = $myga->setUserKey($username, $token); + msg_send($cl_queue, MSG_SET_USER_TOKEN, $return); // TODO now set token break; diff --git a/authserver/authd/gaasdata.sqlite b/authserver/authd/gaasdata.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..d9792cad1598e90affc0204ee6b3df75d1822a07 GIT binary patch literal 3072 zcmeHJ&rjPh6tW41v3ra-)(=jD4 zxI2lAgC<1o-gfbpVHo)Cs9JNG2U%VX+OzmZg*C{|dU77l8-#H|E$WgJm)U*SCr8vL zeNQ-yL#R!;Xg-ittV-A*f{sO#Jiu8XqgUXcGS9Em3=%wJ7wIBM=CY7$d{^}*)_x;+ zYN;!*SrxcLcncZtx9`8I-fHudxX?_5LzDR;HJzj=or~{Xmbh2aJX?Zx*oDH_wG)0> z*cOlZh_?Na_rZ?&4`;wue(AR-Lv}DL(++T2Q?rPsiQAc3Ug+%GT|P*|A?aY%=P!CJl2r*Mw5vWka&sJwvps{YsEZmw_U&HDE1({64B-eKLq)vpNt1AqU#*#H0l literal 0 HcmV?d00001 diff --git a/authserver/lib/authClient.php b/authserver/lib/authClient.php index 677be24..a29af89 100644 --- a/authserver/lib/authClient.php +++ b/authserver/lib/authClient.php @@ -21,16 +21,12 @@ class GAAuthClient { $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER); $message["username"] = $username; - $message["token"] = $token; + $message["tokenstring"] = $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); - - + return $msg; } function setUserPass($username, $password) { @@ -53,12 +49,10 @@ class GAAuthClient { $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); - + + return $msg; } function authUserPass($username, $password) { @@ -81,12 +75,9 @@ class GAAuthClient { $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); - + return $msg; } function deleteUser($username) { @@ -108,11 +99,10 @@ class GAAuthClient { $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); + + return $msg; } @@ -136,12 +126,9 @@ class GAAuthClient { $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); - + return $msg; } function getUsers() { @@ -161,11 +148,8 @@ class GAAuthClient { $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, 524288, $msg); - echo "message received?\n"; - print_r($msg); return $msg; } @@ -227,7 +211,7 @@ class GAAuthClient { return $msg; } - function setTokenType($username, $tokentype) { + function setUserTokenType($username, $tokentype) { global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; @@ -249,12 +233,9 @@ class GAAuthClient { $message["username"] = $username; $message["tokentype"] = $tokentype; - msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err); - echo "message sent\n"; + msg_send($sr_queue, MSG_SET_USER_TOKEN_TYPE, $message, true, true, $msg_err); msg_receive($cl_queue, 0, $msg_type, 16384, $msg); - echo "message received?\n"; - print_r($msg); return $msg; diff --git a/authserver/usercmd.php b/authserver/usercmd.php index 289922a..e58cd65 100644 --- a/authserver/usercmd.php +++ b/authserver/usercmd.php @@ -41,9 +41,9 @@ if(!isset($argv[1])) { switch($argv[1]) { case "auth": if($myAC->authUserToken($argv[2], $argv[3])==1) { - echo "Pass!"; + echo "Pass!\n"; } else { - echo "Fail!"; + echo "Fail!\n"; } break; case "add": @@ -51,25 +51,55 @@ switch($argv[1]) { echo "Created user, ".$argv[2]." returned $return\n"; break; case "delete": - $myAC->deleteUser($argv[2]); + $res = $myAC->deleteUser($argv[2]); + if($res) { + echo "Deleted\n"; + } else { + echo "Failure?\n"; + } break; case "authpass": - $myAC->authUserPass($argv[2], $argv[3]); + $ret = $myAC->authUserPass($argv[2], $argv[3]); + if($ret) echo "Authenticated\n"; + else echo "Failed\n"; break; case "setpass": - $myAC->setUserPass($argv[2], $argv[3]); + $res = $myAC->setUserPass($argv[2], $argv[3]); + if($res) echo "Password Set\n"; + else echo "Failure?\n"; break; case "setname": - $myAC->setUserRealName($argv[2], $argv[3]); + $ret = $myAC->setUserRealName($argv[2], $argv[3]); + if($ret) echo "Real Name Set\n"; + else echo "Failure?\n"; break; case "settoken": - $myAC->setUserToken($argv[2], $argv[3]); + $ret = $myAC->setUserToken($argv[2], $argv[3]); + if($ret) echo "Token Set\n"; + else echo "Failure?\n"; break; case "settype": - $myAC->setUserTokenType($argv[2], $argv[3]); + $ret = $myAC->setUserTokenType($argv[2], $argv[3]); + if($ret) echo "Token Type Set\n"; + else echo "Failure?\n"; break; case "getusers": - $myAC->getUsers(); + $users = $myAC->getUsers(); + foreach($users as $user) { + if($user["realname"] != "") $realname = $user["realname"]; + else $realname = "- Not Set -"; + + if($user["haspass"]) $haspass = "Yes"; + else $haspass = "No"; + + if($user["hastoken"]) $hastoken = "Yes"; + else $hastoken = "No"; + + echo "Username: ".$user["username"]."\n"; + echo "\tReal Name: ".$realname."\n"; + echo "\tHas Password?: ".$haspass."\n"; + echo "\tHas Token?: ".$hastoken."\n\n"; + } break; } ?> \ No newline at end of file diff --git a/lib/ga4php.php b/lib/ga4php.php index 3435d03..6c4e156 100644 --- a/lib/ga4php.php +++ b/lib/ga4php.php @@ -112,7 +112,10 @@ abstract class GoogleAuthenticator { // consider scrapping this $token = $this->internalGetData($username); $token["tokenkey"] = $key; - $this->internalPutData($username, $token); + $this->internalPutData($username, $token); + + // TODO error checking + return true; } -- 1.7.0.4