renamed some functions about configuration handlers
authorpaulr <me@pjr.cc>
Tue, 8 Feb 2011 06:15:56 +0000 (17:15 +1100)
committerpaulr <me@pjr.cc>
Tue, 8 Feb 2011 06:15:56 +0000 (17:15 +1100)
gaas/gaasd/gaasclient.php
gaas/lib/gaasClientMessages.php
gaas/lib/gaasdLib.php
gaas/lib/gaasdMessages.php

index 8151e17..4c6fd35 100644 (file)
@@ -4,6 +4,6 @@ require_once("../lib/gaasdClient.php");
 
 $myga = new GAASClient();
 
-$myga->MSG_STATUS("asdf");
+$myga->MSG_INIT_SERVER("AD", "user", "password", "domain", "cdef", "adef");
 
-?>
\ No newline at end of file
+?>
index f401e1d..ee4233f 100644 (file)
@@ -8,8 +8,7 @@ function gaasStatus_clientsend($params)
 
 function gaasStatus_clientrecv($params)
 {
-       print_r($params);
-       echo "Server status is $params\n";
+       return $params;
 }
 
 
@@ -22,6 +21,7 @@ function gaasInitServer_clientsend($params)
        $msg["backend"] = $params[0];
        $msg["user"] = $params[1];
        $msg["pass"] = $params[2];
+       
        if($msg["backend"] == "AD") {
                $msg["domain"] = $params[3];
                $msg["clientdef"] = $params[4];
index a9fd81d..9af4dfb 100644 (file)
@@ -12,7 +12,7 @@ $backEnd = "";
 global $initState, $backEnd;
 if(file_exists($BASE_DIR."/gaas/gaasd/gaasd.sqlite")) {
        // then we check if the config vars we need exist in the db
-       $backEndType = confGetVar("backend");
+       $backEndType = confGetVal("backend");
        
        if($backEndType == "AD") {
                $backEnd = "AD";
@@ -94,7 +94,7 @@ function confDelVar($varname)
 }
 
 // a funciton to deal with Config Vars
-function confGetVar($varname)
+function confGetVal($varname)
 {
        $db = getDB();
        
@@ -114,7 +114,7 @@ function confGetVar($varname)
 }
 
 // and a function to put vars
-function confPutVar($varname, $value)
+function confSetVal($varname, $value)
 {
        $db = getDB();
        
@@ -129,21 +129,87 @@ function confPutVar($varname, $value)
 }
 
 // now we define our extended class
-class gaasGA extends GoogleAuthenticator
+class gaasdGA extends GoogleAuthenticator
 {
        
-       function getData($username)
-       {
+       function getData($username) {
+               //echo "called into getdata\n";
+               
+               // get our database connection
+               $dbObject = getDB();
+               
+               // set the sql for retreiving the data
+               $sql = "select users_tokendata from users where users_username='$username'";
+               
+               // run the query
+               $result = $dbObject->query($sql);
+               
+               // check the result
+               //echo "next1\n";
+               if(!$result) return false;
+               
+               // now just retreieve all the data (there should only be one, but whatever)
+               //echo "next2\n";
+               $tokendata = false;
+               foreach($result as $row) {
+                       $tokendata = $row["users_tokendata"];
+               }
+
+               //echo "next3, $username, $tokendata\n";
+               // now we have our data, we just return it. If we got no data
+               // we'll just return false by default
+               return $tokendata;
+               
+               // and there you have it, simple eh?
        }
        
        
-       function putData($username, $data)
-       {
+       function putData($username, $data) {
+               // get our database connection
+               $dbObject = getDB();
+               
+               // we need to check if the user exists, and if so put the data, if not create the data
+               $sql = "select * from users where users_username='$username'";
+               $res = $dbObject->query($sql);
+               if($res->fetchColumn() > 0) {
+                       // do update
+                       //error_log("doing userdata update");
+                       $sql = "update users set users_tokendata='$data' where users_username='$username'";
+               } else {
+                       // do insert
+                       //error_log("doing user data create");
+                       $sql = "insert into users values (NULL, '$username', '', '', '$data', '')";
+               }
+               
+               if($dbObject->query($sql)) {
+                       return true;
+               } else {
+                       return false;
+               }
+
        }
        
-       
-       function getUsers()
-       {
+       function getUsers() {
+               // get our database connection
+               $dbObject = getDB();
+               
+               // now the sql again
+               $sql = "select users_username from users";
+               
+               // run the query
+               $result = $dbObject->query($sql);
+               
+               // iterate over the results - we expect a simple array containing
+               // a list of usernames
+               $i = 0;
+               $users = array();
+               foreach($result as $row) {
+                       $users[$i] = $row["username"];
+                       $i++;
+               }
+               
+               // now return the list
+               return $users;
        }
 }
 ?>
\ No newline at end of file
index e518067..a74df01 100644 (file)
@@ -32,6 +32,9 @@ function gaasInitServer_server($msg)
        // IN expects
        // $m["user"] = "someuser";
        // $m["pass"] = "somepass";
+       if($initState != "init") {
+               return false;
+       }
        
        if($msg["backend"] == "AD") {
                $backEnd = "AD";
@@ -63,8 +66,21 @@ function gaasInitServer_server($msg)
                // 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;