added a provision user code
authorpaulr <me@pjr.cc>
Fri, 25 Feb 2011 17:34:18 +0000 (04:34 +1100)
committerpaulr <me@pjr.cc>
Fri, 25 Feb 2011 17:34:18 +0000 (04:34 +1100)
added a hasToken() function

gaas/gaasd/gaasclient.php
gaas/lib/gaasClientMessages.php
gaas/lib/gaasdLib.php
gaas/lib/gaasdMessages.php
gaas/lib/globalLib.php

index b03a216..d671d5c 100644 (file)
@@ -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:
index 332295a..9f5f256 100644 (file)
@@ -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
index ab6b4ad..18ce1bf 100644 (file)
@@ -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)
 {
index 94fb8c0..5115759 100644 (file)
@@ -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
index f3fe9fb..a49f1ef 100644 (file)
@@ -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[<MSG>]_server() for the server side
 // and $MESSAGE[<msg>]_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];
                }
        }