3 if(!isset($MSG_QUEUE_KEY_ID_SERVER)) $MSG_QUEUE_KEY_ID_SERVER = "189751072"; // i would use ftok, but its crap
4 if(!isset($MSG_QUEUE_KEY_ID_CLIENT)) $MSG_QUEUE_KEY_ID_CLIENT = "189751073"; // ftok is not ok!
5 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
7 define("MSG_AUTH_USER_TOKEN", 1);
8 define("MSG_ADD_USER_TOKEN", 2);
9 define("MSG_DELETE_USER", 3);
10 define("MSG_AUTH_USER_PASSWORD", 4);
11 define("MSG_SET_USER_PASSWORD", 5);
12 define("MSG_SET_USER_REALNAME", 6);
13 define("MSG_SET_USER_TOKEN", 7);
14 define("MSG_SET_USER_TOKEN_TYPE", 8);
16 if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
17 if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
19 function getDatabase() {
21 if(file_exists("gaasdata.sqlite")) {
23 $dbobject = new PDO("sqlite:gaasdata.sqlite");
24 } catch(PDOException $exep) {
25 error_log("execpt on db open");
29 $dbobject = new PDO("sqlite:gaasdata.sqlite");
30 } catch(PDOException $exep) {
31 error_log("execpt on db open");
33 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT);';
34 $dbobject->query($sql);
40 function closeDatabase($db) {
41 // doesnt do anything yet
44 class gaasGA extends GoogleAuthenticator {
45 function getData($username) {
47 // get our database connection
48 $dbObject = getDatabase();
50 // set the sql for retreiving the data
51 $sql = "select users_tokendata from users where users_username='$username'";
54 $result = $dbObject->query($sql);
57 if(!$result) return false;
59 // now just retreieve all the data (there should only be one, but whatever)
61 foreach($result as $row) {
62 $tokendata = $row["users_tokendata"];
65 // now we have our data, we just return it. If we got no data
66 // we'll just return false by default
69 // and there you have it, simple eh?
73 function putData($username, $data) {
74 // get our database connection
75 $dbObject = getDatabase();
77 // we need to check if the user exists, and if so put the data, if not create the data
78 $sql = "select * from users where users_username='$username'";
79 $res = $dbOject->query($sql);
80 if($res->fetchColumn() > 0) {
82 $sql = "update users set users_tokendata='$data' where users_username='$username'";
85 $sql = "insert into users values (NULL, '$username', '', '', '$data')";
88 if($dbObject->query($sql)) {
97 // get our database connection
98 $dbObject = getDatabase();
101 $sql = "select users_username from users";
104 $result = $dbObject->query($sql);
106 // iterate over the results - we expect a simple array containing
107 // a list of usernames
110 foreach($result as $row) {
111 $users[$i] = $row["username"];
115 // now return the list