added new ad test
[ga4php.git] / gaas / lib / gaasdMessages.php
1 <?php
2
3 // this file defines all the messages used by gaaasd
4
5 // there are only really two status messages at this point - "init" meaning we have no been defined yet
6 // and "running" meaning we have been defined
7 function gaasStatus_server($messages)
8 {
9         global $initState, $backEnd;
10
11         $return = "init";
12         if($initState != false && $backEnd != "") {
13                 $return = "running";
14         }
15         
16         return $return;
17 }
18
19
20 function gaasInitServer_server($msg)
21 {
22         global $initState, $backEnd;
23         
24         // here we "init" the server, if we're ad, we attempt to connect to AD and if it all works
25         // we then create the db
26         // $m["backend"] = "AD|IN";
27         // AD expects:
28         // $m["domain"] = "somedomain.com";
29         // $m["user"] = "someuser";
30         // $m["pass"] = "somepassword";
31         // $m["userdef"] = "user definition paramaters";
32         // IN expects
33         // $m["user"] = "someuser";
34         // $m["pass"] = "somepass";
35         if($initState != "init") {
36                 return false;
37         }
38         
39         if($msg["backend"] == "AD") {
40                 $backEnd = "AD";
41                 // attempt connect to AD, verify creds
42                 $addom = $msg["domain"];
43                 $adlogin = $msg["user"];
44                 $adpass = $msg["pass"];
45                 $adclientdef = $msg["clientdef"];
46                 $adadmindef = $msg["admindef"];
47                 
48                 // now wee test our logins...
49                 // first look up the domain name stuff
50                 $servers = dns_get_record("_gc._tcp.$addom");
51                 if(count($servers)<1) {
52                         echo "AD servers cant be found, fail!\n";
53                 }
54                 
55                 // we should check all servers, but lets just go with 0 for now
56                 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
57                 ldap_bind($cnt, "$adlogin", "$adpass");
58                 
59                 
60                 
61                 // then
62                 createDB();
63                 confSetVal("ad.domain", $addom);
64                 confSetVal("ad.user", $adlogin);
65                 confSetVal("ad.pass", $adpass);
66                 confSetVal("ad.encryptionkey", generateHexString(32));
67                 confSetVal("ad.clientdef", $adclientdef);
68                 confSetVal("ad.admindef", $adadmindef);
69                 
70                 $initState = "running";
71                 $backEnd = "AD";
72                 
73                 // and that should be it... i think cept im in a forked erg.. lets assume it works, need pain i do not.
74                 
75                 return true;
76         } else if($msg["backend"] == "IN") {
77                 // this ones simpler
78                 $backEnd = "IN";
79                 createDB();
80                 
81                 // create the user in the db
82                 $username = $msg["user"];
83                 $password = $msg["pass"];
84                 
85                 $myga = new gaasdGA();
86                 $myga->setUser($username);
87                 
88                 if($password == "") $pass = "";
89                 else $pass = hash('sha512', $password);
90                 
91                 $db = getDB();
92                 $db->query($sql = "update users set users_password='$pass' where users_username='$username'");
93                 
94                 $initState = "running";
95                 return true;
96         } else {
97                 return false;
98         }
99 }
100 ?>