{
global $argv;
echo "Usage: ".$argv[0]." command [options]\n";
- echo "\nCommands:\n\tinit AD user password domain clientgroup admingroup\n";
- echo "\tinit IN user password\n";
+ echo "\nCommands:\n\tinit AD user password domain clientgroup admingroup - init for active directory installation\n";
+ echo "\tinit IN user password - init for internal database\n";
+ echo "\tstatus - return the status of the server\n";
+ 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 "\n";
exit(0);
}
}
switch($argv[1]) {
+ case "status":
+ $ret = $myga->MSG_STATUS();
+ echo "Status: $ret\n";
+ break;
case "init":
if($argv[2] == "AD") {
if($argc < 7) usage();
echo "initialising server failed\n";
}
break;
+ case "setadlogin":
+ $ret = $myga->MSG_SET_AD_LOGIN($argv[2], $argv[3], $argv[4]);
+ if($ret) {
+ echo "Resetting AD login details succeeded\n";
+ } else {
+ echo "Resetting AD login details failed\n";
+ }
+ break;
+ case "setclientgroup":
+ $ret = $myga->MSG_SET_CLIENT_GROUP($argv[2]);
+ if($ret) {
+ echo "Resetting AD client group details succeeded\n";
+ } else {
+ echo "Resetting AD client group details failed\n";
+ }
+ break;
+ case "setadmingroup":
+ $ret = $myga->MSG_SET_ADMIN_GROUP($argv[2]);
+ if($ret) {
+ echo "Resetting AD admin group details succeeded\n";
+ } else {
+ echo "Resetting AD admin group details failed\n";
+ }
+ break;
default:
echo "No such command, ".$argv[1]."\n";
usage();
// thie file defines the messages sent too and from the gaas client.
function gaasStatus_clientsend($params)
{
- return $params[0];
+ return $params;
}
function gaasStatus_clientrecv($params)
function gaasSetADLogin_clientsend($params)
{
+ $msg["domain"] = $params[2];
+ $msg["user"] = $params[0];
+ $msg["pass"] = $params[1];
+ return $msg;
}
function gaasSetADLogin_clientrecv($params)
{
-
+ return $params;
}
+
+function gaasSetClientGroup_clientsend($params)
+{
+ $msg["clientgroup"] = $params[0];
+ return $msg;
+}
+
+function gaasSetClientGroup_clientrecv($params)
+{
+ return $params;
+}
+
+function gaasSetAdminGroup_clientsend($params)
+{
+ $msg["admingroup"] = $params[0];
+ return $msg;
+}
+
+function gaasSetAdminGroup_clientrecv($params)
+{
+ return $params;
+}
+
?>
\ No newline at end of file
$addom = $msg["domain"];
$adlogin = $msg["user"];
$adpass = $msg["pass"];
- $adclientdef = $msg["clientdef"];
- $adadmindef = $msg["admindef"];
$res = adTestLogin($addmo, $adlogin, $adpass);
if($res != 0) {
confSetVal("ad.domain", $addom);
confSetVal("ad.user", $adlogin);
confSetVal("ad.pass", $adpass);
- confSetVal("ad.clientdef", $adclientdef);
- confSetVal("ad.admindef", $adadmindef);
return true;
}
+
+function gaasSetAdminGroup_server($msg)
+{
+ confSetVal("ad.admindef", $msg["admingroup"]);
+
+ return true;
+}
+
+function gaasSetClientGroup_server($msg)
+{
+ confSetVal("ad.clientdef", $msg["clientgroup"]);
+
+ return true;
+}
+
?>
\ No newline at end of file
define("MSG_STATUS", 18);
define("MSG_INIT_SERVER", 19);
define("MSG_SET_AD_LOGIN", 20);
+define("MSG_SET_CLIENT_GROUP", 21);
+define("MSG_SET_ADMIN_GROUP", 22);
+
// the gaasd call's $MESSAGE[<MSG>]_server() for the server side
// and $MESSAGE[<msg>]_client() for the client side
$MESSAGES[MSG_STATUS] = "gaasStatus";
$MESSAGES[MSG_INIT_SERVER] = "gaasInitServer";
$MESSAGES[MSG_SET_AD_LOGIN] = "gaasSetADLogin";
+$MESSAGES[MSG_SET_CLIENT_GROUP] = "gaasSetClientGroup";
+$MESSAGES[MSG_SET_ADMIN_GROUP] = "gaasSetAdminGroup";
global $MESSAGES;
function getADGroups($domain, $user, $password)
{
+ $servers = dns_get_record("_gc._tcp.$domain");
+ if(count($servers)<1) {
+ echo "AD servers cant be found for $domain, fail!\n";
+ }
+
+ echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
+
+ // we should check all servers, but lets just go with 0 for now
+ $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
+ echo "Connected\n";
+ $bind = ldap_bind($cnt, "$user@$domain", "$password");
+ if(!$bind) {
+ echo "login has failed\n";
+ return false;
+ }
+
+ $ars = explode(".", $addom);
+
+ $tcn = "";
+ foreach($ars as $val) {
+ $tcn .= "DC=$val,";
+ }
+
+ $basecn = preg_replace("/,$/", "", $tcn);
+
+ $sr = ldap_search($cnt, "$basecn", "(objectclass=group)");
+ $info = ldap_get_entries($cnt, $sr);
+
+ if($info["count"] < 1) {
+ echo "Couldn't find a matching group\n";
+ return 0;
+ } else {
+ echo "Found a group, ".$info[0]["cn"][0]."\n";
+ echo "With a description of, ".$info[0]["description"][0]."\n";
+ echo "and a dn of, ".$info[0]["dn"]."\n";
+ }
+ return $info;
}
function generateRandomString($len)