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);
15 define("MSG_GET_USERS", 9);
17 if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
18 if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
20 function getDatabase() {
22 if(file_exists("gaasdata.sqlite")) {
24 $dbobject = new PDO("sqlite:gaasdata.sqlite");
25 } catch(PDOException $exep) {
26 error_log("execpt on db open");
30 $dbobject = new PDO("sqlite:gaasdata.sqlite");
31 } catch(PDOException $exep) {
32 error_log("execpt on db open");
34 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT);';
35 $dbobject->query($sql);
41 function closeDatabase($db) {
42 // doesnt do anything yet
45 class gaasGA extends GoogleAuthenticator {
46 function getData($username) {
48 // get our database connection
49 $dbObject = getDatabase();
51 // set the sql for retreiving the data
52 $sql = "select users_tokendata from users where users_username='$username'";
55 $result = $dbObject->query($sql);
58 if(!$result) return false;
60 // now just retreieve all the data (there should only be one, but whatever)
62 foreach($result as $row) {
63 $tokendata = $row["users_tokendata"];
66 // now we have our data, we just return it. If we got no data
67 // we'll just return false by default
70 // and there you have it, simple eh?
74 function putData($username, $data) {
75 // get our database connection
76 $dbObject = getDatabase();
78 // we need to check if the user exists, and if so put the data, if not create the data
79 $sql = "select * from users where users_username='$username'";
80 $res = $dbObject->query($sql);
81 if($res->fetchColumn() > 0) {
83 $sql = "update users set users_tokendata='$data' where users_username='$username'";
86 $sql = "insert into users values (NULL, '$username', '', '', '$data')";
89 if($dbObject->query($sql)) {
98 // get our database connection
99 $dbObject = getDatabase();
102 $sql = "select users_username from users";
105 $result = $dbObject->query($sql);
107 // iterate over the results - we expect a simple array containing
108 // a list of usernames
111 foreach($result as $row) {
112 $users[$i] = $row["username"];
116 // now return the list