renamed some functions about configuration handlers
[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                 // now wee test our logins...
48                 
49                 
50                 // then
51                 createDB();
52                 confSetVal("ad.domain", $addom);
53                 confSetVal("ad.user", $adlogin);
54                 confSetVal("ad.pass", $adpass);
55                 confSetVal("ad.encryptionkey", generateHexString(32));
56                 confSetVal("ad.clientdef", $adclientdef);
57                 confSetVal("ad.admindef", $adadmindef);
58                 
59                 $initState = "running";
60                 $backEnd = "AD";
61                 
62                 // and that should be it... i think cept im in a forked erg.. lets assume it works, need pain i do not.
63                 
64                 return true;
65         } else if($msg["backend"] == "IN") {
66                 // this ones simpler
67                 $backEnd = "IN";
68                 createDB();
69                 
70                 // create the user in the db
71                 $username = $msg["user"];
72                 $password = $msg["pass"];
73                 
74                 $myga = new gaasdGA();
75                 $myga->setUser($username);
76                 
77                 if($password == "") $pass = "";
78                 else $pass = hash('sha512', $password);
79                 
80                 $db = getDB();
81                 $db->query($sql = "update users set users_password='$pass' where users_username='$username'");
82                 
83                 $initState = "running";
84                 return true;
85         } else {
86                 return false;
87         }
88 }
89 ?>