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);
15 if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
16 if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
18 function getDatabase() {
20 if(file_exists("gaasdata.sqlite")) {
22 $dbobject = new PDO("sqlite:gaasdata.sqlite");
23 } catch(PDOException $exep) {
24 error_log("execpt on db open");
28 $dbobject = new PDO("sqlite:gaasdata.sqlite");
29 } catch(PDOException $exep) {
30 error_log("execpt on db open");
32 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT);';
33 $dbobject->query($sql);
39 function closeDatabase($db) {
40 // doesnt do anything yet
43 class gaasGA extends GoogleAuthenticator {
44 function getData($username) {
46 // get our database connection
47 $dbObject = getDatabase();
49 // set the sql for retreiving the data
50 $sql = "select users_tokendata from users where users_username='$username'";
53 $result = $dbObject->query($sql);
56 if(!$result) return false;
58 // now just retreieve all the data (there should only be one, but whatever)
60 foreach($result as $row) {
61 $tokendata = $row["users_tokendata"];
64 // now we have our data, we just return it. If we got no data
65 // we'll just return false by default
68 // and there you have it, simple eh?
72 function putData($username, $data) {
73 // get our database connection
74 $dbObject = getDatabase();
76 // we need to check if the user exists, and if so put the data, if not create the data
77 $sql = "select * from users where users_username='$username'";
78 $res = $dbOject->query($sql);
79 if($res->fetchColumn() > 0) {
81 $sql = "update users set users_tokendata='$data' where users_username='$username'";
84 $sql = "insert into users values (NULL, '$username', '', '', '$data')";
87 if($dbObject->query($sql)) {
96 // get our database connection
97 $dbObject = getDatabase();
100 $sql = "select users_username from users";
103 $result = $dbObject->query($sql);
105 // iterate over the results - we expect a simple array containing
106 // a list of usernames
109 foreach($result as $row) {
110 $users[$i] = $row["username"];
114 // now return the list