e43cda27776152d96ed26a1e8fba8282b417463b
[ga4php.git] / gaas / lib / globalLib.php
1 <?php
2
3 // the global lib sets alot of global variables, its fairly unexciting
4 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
5 global $BASE_DIR;
6
7 // the tcp port number we use for comms
8 $TCP_PORT_NUMBER = 21335;
9 global $TCP_PORT_NUMBER;
10
11
12
13
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
19 // the gaasd call's $MESSAGE[<MSG>]_server() for the server side
20 // and $MESSAGE[<msg>]_client() for the client side 
21 $MESSAGES[MSG_STATUS] = "gaasStatus";
22 $MESSAGES[MSG_INIT_SERVER] = "gaasInitServer";
23 $MESSAGES[MSG_SET_AD_LOGIN] = "gaasSetADLogin";
24 global $MESSAGES;
25
26
27
28
29
30
31
32 function adTestLogin($domain, $user, $password)
33 {
34         $servers = dns_get_record("_gc._tcp.$domain");
35         if(count($servers)<1) {
36                 echo "AD servers cant be found for $domain, fail!\n";
37         }
38         
39         echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
40         
41         // we should check all servers, but lets just go with 0 for now
42         $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
43         echo "Connected\n";
44         $bind = ldap_bind($cnt, "$user@$domain", "$password");
45         if($bind) {
46                 echo "bind is true $user@$domain $password\n";
47                 return true;
48         } else {
49                 echo "bind is false $user@$domain $password\n";
50                 return false;
51         }       
52 }
53
54 function getADGroups($domain, $user, $password)
55 {
56         
57 }
58
59 function generateRandomString($len)
60 {
61         $str = "";
62         $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
63         
64         for($i=0; $i<$len; $i++) {
65                 $str .= $strpos[rand(0, strlen($strpos)-1)];
66         }
67         
68         return $str;
69 }
70
71 function generateHexString($len)
72 {
73         $str = "";
74         $strpos = "0123456789ABCDEF";
75         
76         for($i=0; $i<$len; $i++) {
77                 $str .= $strpos[rand(0, strlen($strpos)-1)];
78         }
79         
80         return $str;
81 }
82
83
84 ?>