X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=gaas%2Flib%2FgaasdMessages.php;h=5ca73a0ffc10c06f58ceb2d57ce886d214995316;hp=e51806726d3f8311769dd13742993cb11825ad54;hb=2acdbc5f052f24af5de2ab013a4fae5eeb1c3305;hpb=01b5d6290a0d704099cef17071c1fc50b3049bee diff --git a/gaas/lib/gaasdMessages.php b/gaas/lib/gaasdMessages.php index e518067..5ca73a0 100644 --- a/gaas/lib/gaasdMessages.php +++ b/gaas/lib/gaasdMessages.php @@ -21,6 +21,7 @@ function gaasInitServer_server($msg) { global $initState, $backEnd; + error_log("Init server called\n"); // here we "init" the server, if we're ad, we attempt to connect to AD and if it all works // we then create the db // $m["backend"] = "AD|IN"; @@ -32,8 +33,21 @@ function gaasInitServer_server($msg) // IN expects // $m["user"] = "someuser"; // $m["pass"] = "somepass"; + echo "initstate is $initState\n"; + if($initState) { + echo "true\n"; + } else { + echo "false\n"; + } + if($initState) { + error_log("init server called when server already init'd\n"); + return false; + } if($msg["backend"] == "AD") { + echo "Backend is AD with params of\n"; + print_r($msg); + echo "\n"; $backEnd = "AD"; // attempt connect to AD, verify creds $addom = $msg["domain"]; @@ -41,7 +55,22 @@ function gaasInitServer_server($msg) $adpass = $msg["pass"]; $adclientdef = $msg["clientdef"]; $adadmindef = $msg["admindef"]; + // now wee test our logins... + // first look up the domain name stuff + $servers = dns_get_record("_gc._tcp.$addom"); + if(count($servers)<1) { + echo "AD servers cant be found, fail!\n"; + } + + // we should check all servers, but lets just go with 0 for now + $res = adTestLogin($addom, $adlogin, $adpass); + if(!$res) { + echo "AD login test failed\n"; + return false; + } else { + echo "AD login test succeeded\n"; + } // then @@ -53,21 +82,69 @@ function gaasInitServer_server($msg) confSetVal("ad.clientdef", $adclientdef); confSetVal("ad.admindef", $adadmindef); - $initState = "running"; + $initState = true; $backEnd = "AD"; // and that should be it... i think cept im in a forked erg.. lets assume it works, need pain i do not. + echo "its all good at the server\n"; return true; } else if($msg["backend"] == "IN") { // this ones simpler $backEnd = "IN"; createDB(); + + // create the user in the db + $username = $msg["user"]; + $password = $msg["pass"]; + + $myga = new gaasdGA(); + $myga->setUser($username); + + if($password == "") $pass = ""; + else $pass = hash('sha512', $password); + + $db = getDB(); + $db->query($sql = "update users set users_password='$pass' where users_username='$username'"); + $initState = "running"; - // then we need to "create user"; return true; } else { return false; } } + + +function gaasSetADLogin_server($msg) +{ + global $initState, $backEnd; + + if($initState != "running") { + return "not in running init state"; + } + + if($backEnd != "AD") { + return "not setup as AD client"; + } + + $addom = $msg["domain"]; + $adlogin = $msg["user"]; + $adpass = $msg["pass"]; + $adclientdef = $msg["clientdef"]; + $adadmindef = $msg["admindef"]; + + $res = adTestLogin($addmo, $adlogin, $adpass); + if($res != 0) { + return "not able to connect to AD with given cred's"; + } + + confSetVal("ad.domain", $addom); + confSetVal("ad.user", $adlogin); + confSetVal("ad.pass", $adpass); + confSetVal("ad.clientdef", $adclientdef); + confSetVal("ad.admindef", $adadmindef); + + return true; + +} ?> \ No newline at end of file