From 1d6adec6039a635e97e31592bbbcbf4357e33c28 Mon Sep 17 00:00:00 2001 From: paulr Date: Tue, 8 Feb 2011 02:24:26 +1100 Subject: [PATCH] Initial coding of the gaasd new auth server. --- doco/pseudo.txt | 7 ++ gaas/gaasd/gaasd.php | 50 ++++++++++++++ gaas/html/admin.php | 9 +++ gaas/html/index.php | 9 +++ gaas/html/setup.php | 6 ++ gaas/lib/gaasdClient.php | 5 ++ gaas/lib/gaasdLib.php | 152 ++++++++++++++++++++++++++++++++++++++++++++ gaas/lib/htmlLib.php | 5 ++ unittests/gaasdlibconf.php | 30 +++++++++ 9 files changed, 273 insertions(+), 0 deletions(-) create mode 100644 doco/pseudo.txt create mode 100644 gaas/gaasd/gaasd.php create mode 100644 gaas/html/admin.php create mode 100644 gaas/html/index.php create mode 100644 gaas/html/setup.php create mode 100644 gaas/lib/gaasdClient.php create mode 100644 gaas/lib/gaasdLib.php create mode 100644 gaas/lib/htmlLib.php create mode 100644 unittests/gaasdlibconf.php diff --git a/doco/pseudo.txt b/doco/pseudo.txt new file mode 100644 index 0000000..7aa375f --- /dev/null +++ b/doco/pseudo.txt @@ -0,0 +1,7 @@ +I am the pseudo code for how gaasd will work... + +start: + am I inited? + yes: load from datastore (AD, database, etc) + no: tell any request returns "uninited" + figure out my datastore. \ No newline at end of file diff --git a/gaas/gaasd/gaasd.php b/gaas/gaasd/gaasd.php new file mode 100644 index 0000000..cb716a7 --- /dev/null +++ b/gaas/gaasd/gaasd.php @@ -0,0 +1,50 @@ + \ No newline at end of file diff --git a/gaas/html/admin.php b/gaas/html/admin.php new file mode 100644 index 0000000..cd0ec3c --- /dev/null +++ b/gaas/html/admin.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/gaas/html/index.php b/gaas/html/index.php new file mode 100644 index 0000000..cd0ec3c --- /dev/null +++ b/gaas/html/index.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/gaas/html/setup.php b/gaas/html/setup.php new file mode 100644 index 0000000..62d1a91 --- /dev/null +++ b/gaas/html/setup.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/gaas/lib/gaasdClient.php b/gaas/lib/gaasdClient.php new file mode 100644 index 0000000..36da285 --- /dev/null +++ b/gaas/lib/gaasdClient.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/gaas/lib/gaasdLib.php b/gaas/lib/gaasdLib.php new file mode 100644 index 0000000..5cfe52f --- /dev/null +++ b/gaas/lib/gaasdLib.php @@ -0,0 +1,152 @@ +query($sql); + } + + $sql = 'CREATE TABLE "config" ("conf_id" INTEGER PRIMARY KEY AUTOINCREMENT,"conf_name" TEXT, "conf_value" TEXT);'; + $dbobject->query($sql); + $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);'; + $dbobject->query($sql); + $sql = 'CREATE TABLE "hardwaretokens" ("tok_id" INTEGER PRIMARY KEY AUTOINCREMENT,"tok_name" TEXT, "tok_key" TEXT, "tok_type" TEXT);'; + $dbobject->query($sql); + + return true; +} + +// a function to get the database +function getDB() +{ + $dbobject = false; + global $BASE_DIR, $DB_HANDLE; + if($DB_HANDLE != false) return $DB_HANDLE; + if(file_exists("$BASE_DIR/gaas/gaasd/gaasd.sqlite")) { + try { + $dbobject = new PDO("sqlite:$BASE_DIR/gaas/gaasd/gaasd.sqlite"); + } catch(PDOException $exep) { + error_log("execpt on db open"); + return false; + } + } else { + return false; + } + + $DB_HANDLE = $dbobject; + return $dbobject; +} + + +function confDelVar($varname) +{ + $db = getDB(); + + $sql = "delete from config where conf_name='$varname'"; + $db->query($sql); + + return true; +} + +// a funciton to deal with Config Vars +function confGetVar($varname) +{ + $db = getDB(); + + $sql = "select conf_value from config where conf_name='$varname'"; + + $result = $db->query($sql); + + if(!$result) return false; + + $val = ""; + foreach($result as $row) { + $val = $row["conf_value"]; + } + + // TOTALLY GUNNA WORK! + return $val; +} + +// and a function to put vars +function confPutVar($varname, $value) +{ + $db = getDB(); + + $sql = "delete from config where conf_name='$varname'"; + $db->query($sql); + + $sql = "insert into config values (NULL, '$varname','$value')"; + $db->query($sql); + + // TODO: do all this better + return true; +} + +// now we define our extended class +class gaasGA extends GoogleAuthenticator +{ + + function getData($username) + { + } + + + function putData($username, $data) + { + } + + + function getUsers() + { + } +} +?> \ No newline at end of file diff --git a/gaas/lib/htmlLib.php b/gaas/lib/htmlLib.php new file mode 100644 index 0000000..7b75e9a --- /dev/null +++ b/gaas/lib/htmlLib.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/unittests/gaasdlibconf.php b/unittests/gaasdlibconf.php new file mode 100644 index 0000000..a86cc0b --- /dev/null +++ b/unittests/gaasdlibconf.php @@ -0,0 +1,30 @@ + \ No newline at end of file -- 1.7.0.4