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");
+
+ echo "backend type is $backEndType\n";
if($backEndType == "AD") {
+ echo "init state should be true\n";
$backEnd = "AD";
// TODO: we should now check all vars are set, but for now this will surfice
return false;
}
- if($backEnd == "IN") {
- $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);';
- $dbobject->query($sql);
- }
-
+ // users_tokendata is used by ga4php, users_otk is the qrcode data link if needed,
+ // tokentype is the software/hardware token types
+ $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT, "users_qrcodeid" TEXT, "user_enabled" TEXT, "users_tokentype" TEXT);';
+ $dbobject->query($sql);
+ //if(!$res) {
+ //echo "Create user table failed\n";
+ //}
$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);';
return true;
}
+
+function hasToken($username)
+{
+ $db = getDB();
+
+ $sql = "select * from users where users_username='$username'";
+ $res = $db->query($sql);
+ if(!$res) return false;
+ foreach($res as $row) {
+ print_r($row);
+ }
+
+ return true;
+}
+
+function createUserInDB($username, $realname)
+{
+ $db = getDB();
+
+ $sql = "insert into users values (NULL, '$username', '$realname', '', '$data', '', '1', '')";
+}
+
// a funciton to deal with Config Vars
-function confGetVar($varname)
+function confGetVal($varname)
{
$db = getDB();
}
// and a function to put vars
-function confPutVar($varname, $value)
+function confSetVal($varname, $value)
{
$db = getDB();
}
// 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'";
+ echo "sql was: $sql\n";
+ $res = $dbObject->query($sql);
+ if($res->fetchColumn() > 0) {
+ // do update
+ //error_log("doing userdata update");
+ //"users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT, "users_qrcodeid" TEXT, "user_enabled" TEXT, "users_tokentype" TEXT)
+ $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', '', '1', 'software')";
+ }
+
+ 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