From 7ab48347fa3382418a4b7dd59a978c075ef530c2 Mon Sep 17 00:00:00 2001 From: paulr Date: Sat, 26 Feb 2011 04:34:18 +1100 Subject: [PATCH] added a provision user code added a hasToken() function --- gaas/gaasd/gaasclient.php | 19 +++++++++++++++---- gaas/lib/gaasClientMessages.php | 7 +++++++ gaas/lib/gaasdLib.php | 16 ++++++++++++++++ gaas/lib/gaasdMessages.php | 15 +++++++++++++-- gaas/lib/globalLib.php | 6 +++--- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/gaas/gaasd/gaasclient.php b/gaas/gaasd/gaasclient.php index b03a216..d671d5c 100644 --- a/gaas/gaasd/gaasclient.php +++ b/gaas/gaasd/gaasclient.php @@ -16,8 +16,9 @@ function usage() echo "\tsetadlogin username password domain\n"; echo "\tsetclientgroup groupname - change the group membership requirements for client's with AD\n"; echo "\tsetadmingroup groupname - change the group membership requirements for admin's with AD\n"; - echo "\tprovisionuser username [HOTP|TOTP] [KEY]- provision the user \"username\"\n"; + echo "\tprovision username [HOTP|TOTP] [KEY]- provision the user \"username\"\n"; echo "\tgetusers [admin|client] [part-of-username] [yes] - get user list with admin or client group, part of a username and return only those with tokens (yes)\n"; + echo "\tdeleteuser username - deletes the key for the specified user\n"; echo "\n"; exit(0); } @@ -66,6 +67,9 @@ switch($argv[1]) { echo "Resetting AD admin group details failed\n"; } break; + case "provision": + $username = $argv[2]; + break; case "getusers": $group = "client"; $partof = ""; @@ -74,9 +78,16 @@ switch($argv[1]) { if(isset($argv[3])) $partof = $argv[3]; if(isset($argv[4])) $onlytokens = $argv[4]; $ret = $myga->MSG_GET_USERS($group, $partof, $onlytokens); - //print_r($ret); - foreach($ret as $user) { - echo $user["realname"]." (".$user["username"].")\n"; + foreach($ret as $user => $real) { + echo "$real ($user)\n"; + } + break; + case "deleteuser": + $ret = $myga->MSG_DELETE_USER($argv[2]); + if($ret) { + echo "Delete user token succeeded\n"; + } else { + echo "Delete user token failed\n"; } break; default: diff --git a/gaas/lib/gaasClientMessages.php b/gaas/lib/gaasClientMessages.php index 332295a..9f5f256 100644 --- a/gaas/lib/gaasClientMessages.php +++ b/gaas/lib/gaasClientMessages.php @@ -95,4 +95,11 @@ function gaasGetUsers_clientsend($params) return $msg; } + +function gaasDeleteUser_clientsend($params) +{ + $msg["username"] = $params[0]; + + return $msg; +} ?> \ No newline at end of file diff --git a/gaas/lib/gaasdLib.php b/gaas/lib/gaasdLib.php index ab6b4ad..18ce1bf 100644 --- a/gaas/lib/gaasdLib.php +++ b/gaas/lib/gaasdLib.php @@ -96,6 +96,22 @@ function confDelVar($varname) return true; } + +function hasToken($username) +{ + $db = getDB(); + + $sql = "select * from users where users_username='$username'"; + $res = $db->query($sql); + if(!$res) return false; + foreach($res as $row) { + print_r($row); + } + + return true; +} + + // a funciton to deal with Config Vars function confGetVal($varname) { diff --git a/gaas/lib/gaasdMessages.php b/gaas/lib/gaasdMessages.php index 94fb8c0..5115759 100644 --- a/gaas/lib/gaasdMessages.php +++ b/gaas/lib/gaasdMessages.php @@ -198,12 +198,23 @@ function gaasGetUsers_server($msg) $addom = confGetVal("ad.domain"); $aduser = confGetVal("ad.user"); $adpass = confGetVal("ad.pass"); - echo "using group $adgroup for $group\n"; + //echo "using group $adgroup for $group\n"; $users = getUsersInGroup($addom, $aduser, $adpass, $adgroup); + foreach($users as $user => $real) { + hasToken($user); + } } else { // internal db - } + } return $users; } + +function gaasDeleteUser_server($msg) +{ + $username = $msg["username"]; + $db = getDB(); + $db->query($sql = "delete from users where users_username='$username'"); + +} ?> \ No newline at end of file diff --git a/gaas/lib/globalLib.php b/gaas/lib/globalLib.php index f3fe9fb..a49f1ef 100644 --- a/gaas/lib/globalLib.php +++ b/gaas/lib/globalLib.php @@ -19,6 +19,7 @@ define("MSG_SET_CLIENT_GROUP", 21); define("MSG_SET_ADMIN_GROUP", 22); define("MSG_PROVISION_USER",23); define("MSG_GET_USERS", 24); +define("MSG_DELETE_USER", 25); // the gaasd call's $MESSAGE[]_server() for the server side // and $MESSAGE[]_client() for the client side @@ -29,6 +30,7 @@ $MESSAGES[MSG_SET_CLIENT_GROUP] = "gaasSetClientGroup"; // groupname $MESSAGES[MSG_SET_ADMIN_GROUP] = "gaasSetAdminGroup"; $MESSAGES[MSG_PROVISION_USER] = "gaasProvisionUser"; // username $MESSAGES[MSG_GET_USERS] = "gaasGetUsers"; // [admin|client], [name pattern], [only with tokens] +$MESSAGES[MSG_DELETE_USER] = "gaasDeleteUser"; // username global $MESSAGES; @@ -198,9 +200,7 @@ function getUsersInGroup($domain, $adlogin, $adpass, $group) $i = 0; foreach($info as $kpot => $lpot) { if(isset($lpot["samaccountname"])) { - $arbi[$i]["username"] = $lpot["samaccountname"][0]; - $arbi[$i]["realname"] = $lpot["name"][0]; - $i++; + $arbi[$lpot["samaccountname"][0]] = $lpot["name"][0]; } } -- 1.7.0.4