3 if(!isset($MSG_QUEUE_KEY_ID_SERVER)) $MSG_QUEUE_KEY_ID_SERVER = "189751072";
4 if(!isset($MSG_QUEUE_KEY_ID_CLIENT)) $MSG_QUEUE_KEY_ID_CLIENT = "189751073";
5 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
7 define("MSG_AUTH_USER", 1);
8 define("MSG_ADD_USER", 2);
9 define("MSG_DELETE_USER", 2);
12 if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
13 if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
15 function getDatabase() {
17 if(file_exists("/tmp/gadata.sqlite")) {
19 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
20 } catch(PDOException $exep) {
21 error_log("execpt on db open");
25 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
26 } catch(PDOException $exep) {
27 error_log("execpt on db open");
29 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT,"users_tokendata" TEXT);';
30 $dbobject->query($sql);
36 function closeDatabase($db) {
37 // doesnt do anything yet
40 class gaasGA extends GoogleAuthenticator {
41 function getData($username) {
43 // get our database connection
44 $dbObject = getDatabase();
46 // set the sql for retreiving the data
47 $sql = "select users_tokendata from users where users_username='$username'";
50 $result = $dbObject->query($sql);
53 if(!$result) return false;
55 // now just retreieve all the data (there should only be one, but whatever)
57 foreach($result as $row) {
58 $tokendata = $row["users_tokendata"];
61 // now we have our data, we just return it. If we got no data
62 // we'll just return false by default
65 // and there you have it, simple eh?
69 // now we need a function for putting the data back into our user table.
70 // in this example, we wont check anything, we'll just overwrite it.
71 function putData($username, $data) {
72 // get our database connection
73 $dbObject = getDatabase();
75 // set the sql for updating the data
76 // token data is stored as a base64 encoded string, it should
77 // not need to be escaped in any way prior to storing in a database
78 // but feel free to call your databases "addslashes" (or whatever)
79 // function on $data prior to doing the SQL.
80 $sql = "delete from users where users_username='$username'";
81 $dbObject->query($sql);
83 $sql = "insert into users values (NULL, '$username', '$data')";
86 // now execute the sql and return straight away - you should probably
87 // clean up after yourselves, but im going to assume pdo does this
88 // for us anyway in this exmaple
89 if($dbObject->query($sql)) {
99 // get our database connection
100 $dbObject = getDatabase();
103 $sql = "select users_username from users";
106 $result = $dbObject->query($sql);
108 // iterate over the results - we expect a simple array containing
109 // a list of usernames
112 foreach($result as $row) {
113 $users[$i] = $row["username"];
117 // now return the list