3 // the global lib sets alot of global variables, its fairly unexciting
4 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
7 // the tcp port number we use for comms
8 $TCP_PORT_NUMBER = 21335;
9 global $TCP_PORT_NUMBER;
14 // the messages structure, used to extend gaas if needed
15 define("MSG_STATUS", 18);
16 define("MSG_INIT_SERVER", 19);
17 define("MSG_SET_AD_LOGIN", 20);
18 define("MSG_SET_CLIENT_GROUP", 21);
19 define("MSG_SET_ADMIN_GROUP", 22);
22 // the gaasd call's $MESSAGE[<MSG>]_server() for the server side
23 // and $MESSAGE[<msg>]_client() for the client side
24 $MESSAGES[MSG_STATUS] = "gaasStatus";
25 $MESSAGES[MSG_INIT_SERVER] = "gaasInitServer";
26 $MESSAGES[MSG_SET_AD_LOGIN] = "gaasSetADLogin";
27 $MESSAGES[MSG_SET_CLIENT_GROUP] = "gaasSetClientGroup";
28 $MESSAGES[MSG_SET_ADMIN_GROUP] = "gaasSetAdminGroup";
37 function adTestLogin($domain, $user, $password)
39 $servers = dns_get_record("_gc._tcp.$domain");
40 if(count($servers)<1) {
41 echo "AD servers cant be found for $domain, fail!\n";
44 echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
46 // we should check all servers, but lets just go with 0 for now
47 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
49 $bind = ldap_bind($cnt, "$user@$domain", "$password");
51 echo "login has succeeded\n";
54 echo "login has failed\n";
59 function getADGroups($domain, $user, $password)
61 $servers = dns_get_record("_gc._tcp.$domain");
62 if(count($servers)<1) {
63 echo "AD servers cant be found for $domain, fail!\n";
66 echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
68 // we should check all servers, but lets just go with 0 for now
69 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
71 $bind = ldap_bind($cnt, "$user@$domain", "$password");
73 echo "login has failed\n";
77 $ars = explode(".", $addom);
80 foreach($ars as $val) {
84 $basecn = preg_replace("/,$/", "", $tcn);
86 $sr = ldap_search($cnt, "$basecn", "(objectclass=group)");
87 $info = ldap_get_entries($cnt, $sr);
89 if($info["count"] < 1) {
90 echo "Couldn't find a matching group\n";
93 echo "Found a group, ".$info[0]["cn"][0]."\n";
94 echo "With a description of, ".$info[0]["description"][0]."\n";
95 echo "and a dn of, ".$info[0]["dn"]."\n";
101 function generateRandomString($len)
104 $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
106 for($i=0; $i<$len; $i++) {
107 $str .= $strpos[rand(0, strlen($strpos)-1)];
113 function generateHexString($len)
116 $strpos = "0123456789ABCDEF";
118 for($i=0; $i<$len; $i++) {
119 $str .= $strpos[rand(0, strlen($strpos)-1)];