3 require_once("globalLib.php");
4 require_once("gaasdMessages.php");
7 require_once(dirname(__FILE__)."/../../lib/ga4php.php");
9 // first we check if our db exists, if not, we're not inited
12 global $initState, $backEnd;
13 if(file_exists($BASE_DIR."/gaas/gaasd/gaasd.sqlite")) {
14 // then we check if the config vars we need exist in the db
15 $backEndType = confGetVar("backend");
17 if($backEndType == "AD") {
20 // TODO: we should now check all vars are set, but for now this will surfice
24 if($backEndType == "internal") {
30 // have a gloval db handle so we dont have to keep opening the db all the time
31 // this may go away when we consider the implications for a parallel gaasd
36 // a function to create our db
37 // TODO: error checking
41 global $BASE_DIR, $initState, $backEnd;
43 $dbobject = new PDO("sqlite:$BASE_DIR/gaas/gaasd/gaasd.sqlite");
44 } catch(PDOException $exep) {
45 error_log("execpt on db open");
49 if($backEnd == "IN") {
50 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT, "users_otk" TEXT);';
51 $dbobject->query($sql);
54 $sql = 'CREATE TABLE "config" ("conf_id" INTEGER PRIMARY KEY AUTOINCREMENT,"conf_name" TEXT, "conf_value" TEXT);';
55 $dbobject->query($sql);
56 $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
57 $dbobject->query($sql);
58 $sql = 'CREATE TABLE "hardwaretokens" ("tok_id" INTEGER PRIMARY KEY AUTOINCREMENT,"tok_name" TEXT, "tok_key" TEXT, "tok_type" TEXT);';
59 $dbobject->query($sql);
64 // a function to get the database
68 global $BASE_DIR, $DB_HANDLE;
69 if($DB_HANDLE != false) return $DB_HANDLE;
70 if(file_exists("$BASE_DIR/gaas/gaasd/gaasd.sqlite")) {
72 $dbobject = new PDO("sqlite:$BASE_DIR/gaas/gaasd/gaasd.sqlite");
73 } catch(PDOException $exep) {
74 error_log("execpt on db open");
81 $DB_HANDLE = $dbobject;
86 function confDelVar($varname)
90 $sql = "delete from config where conf_name='$varname'";
96 // a funciton to deal with Config Vars
97 function confGetVar($varname)
101 $sql = "select conf_value from config where conf_name='$varname'";
103 $result = $db->query($sql);
105 if(!$result) return false;
108 foreach($result as $row) {
109 $val = $row["conf_value"];
112 // TOTALLY GUNNA WORK!
116 // and a function to put vars
117 function confPutVar($varname, $value)
121 $sql = "delete from config where conf_name='$varname'";
124 $sql = "insert into config values (NULL, '$varname','$value')";
127 // TODO: do all this better
131 // now we define our extended class
132 class gaasGA extends GoogleAuthenticator
135 function getData($username)
140 function putData($username, $data)