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) {
47 echo "called into getdata\n";
49 // get our database connection
50 $dbObject = getDatabase();
52 // set the sql for retreiving the data
53 $sql = "select users_tokendata from users where users_username='$username'";
56 $result = $dbObject->query($sql);
60 if(!$result) return false;
62 // now just retreieve all the data (there should only be one, but whatever)
65 foreach($result as $row) {
66 $tokendata = $row["users_tokendata"];
69 echo "next3, $username, $tokendata\n";
70 // now we have our data, we just return it. If we got no data
71 // we'll just return false by default
74 // and there you have it, simple eh?
78 function putData($username, $data) {
79 // get our database connection
80 $dbObject = getDatabase();
82 // we need to check if the user exists, and if so put the data, if not create the data
83 $sql = "select * from users where users_username='$username'";
84 $res = $dbObject->query($sql);
85 if($res->fetchColumn() > 0) {
87 $sql = "update users set users_tokendata='$data' where users_username='$username'";
90 $sql = "insert into users values (NULL, '$username', '', '', '$data')";
93 if($dbObject->query($sql)) {
101 function getUsers() {
102 // get our database connection
103 $dbObject = getDatabase();
106 $sql = "select users_username from users";
109 $result = $dbObject->query($sql);
111 // iterate over the results - we expect a simple array containing
112 // a list of usernames
115 foreach($result as $row) {
116 $users[$i] = $row["username"];
120 // now return the list