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);
16 define("MSG_GET_OTK_PNG", 10);
17 define("MSG_GET_OTK_ID", 11);
18 define("MSG_DELETE_USER_TOKEN", 12);
19 define("MSG_SYNC_TOKEN", 13);
20 define("MSG_GET_TOKEN_TYPE", 14);
21 define("MSG_GET_RADIUS_CLIENTS", 15);
22 define("MSG_REMOVE_RADIUS_CLIENT", 16);
23 define("MSG_ADD_RADIUS_CLIENT", 17);
27 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
31 require_once(dirname(__FILE__)."/../../lib/ga4php.php");
33 function generateRandomString()
36 $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
38 for($i=0; $i<128; $i++) {
39 $str .= $strpos[rand(0, strlen($strpos)-1)];
45 function updateRadius()
47 // this is hardcoded for now.
48 //$clientfile = "/etc/freeradius/clients.conf";
49 $clientfile = "/tmp/clients.conf";
50 $reloadinit = "/etc/init.d/freeradius restart";
54 echo "in updateradius\n";
55 $hand = fopen($clientfile, "w");
56 $sql = "select * from radclients";
57 $res = $db->query($sql);
58 foreach($res as $row) {
59 $cname = $row["rad_name"];
60 $cip = $row["rad_ip"];
61 $csec = $row["rad_secret"];
62 $lines = "client $cname {\nipaddr = $cip\nsecret = $csec\nrequire_message_authenticator = no\n}\n\n";
63 fwrite($hand, $lines);
67 //system($reloadinit);
71 function getDatabase()
75 if(file_exists("$BASE_DIR/authserver/authd/gaasdata.sqlite")) {
77 $dbobject = new PDO("sqlite:$BASE_DIR/authserver/authd/gaasdata.sqlite");
78 } catch(PDOException $exep) {
79 error_log("execpt on db open");
83 $dbobject = new PDO("sqlite:$BASE_DIR/authserver/authd/gaasdata.sqlite");
84 } catch(PDOException $exep) {
85 error_log("execpt on db open");
87 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT, "users_realname" TEXT, "users_password" TEXT, "users_tokendata" TEXT, "users_otk" TEXT);';
88 $dbobject->query($sql);
89 $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
90 $dbobject->query($sql);
96 function closeDatabase($db) {
97 // doesnt do anything yet
100 class gaasGA extends GoogleAuthenticator {
101 function getData($username) {
102 echo "called into getdata\n";
104 // get our database connection
105 $dbObject = getDatabase();
107 // set the sql for retreiving the data
108 $sql = "select users_tokendata from users where users_username='$username'";
111 $result = $dbObject->query($sql);
115 if(!$result) return false;
117 // now just retreieve all the data (there should only be one, but whatever)
120 foreach($result as $row) {
121 $tokendata = $row["users_tokendata"];
124 echo "next3, $username, $tokendata\n";
125 // now we have our data, we just return it. If we got no data
126 // we'll just return false by default
129 // and there you have it, simple eh?
133 function putData($username, $data) {
134 // get our database connection
135 $dbObject = getDatabase();
137 // we need to check if the user exists, and if so put the data, if not create the data
138 $sql = "select * from users where users_username='$username'";
139 $res = $dbObject->query($sql);
140 if($res->fetchColumn() > 0) {
142 error_log("doing userdata update");
143 $sql = "update users set users_tokendata='$data' where users_username='$username'";
146 error_log("doing user data create");
147 $sql = "insert into users values (NULL, '$username', '', '', '$data', '')";
150 if($dbObject->query($sql)) {
158 function getUsers() {
159 // get our database connection
160 $dbObject = getDatabase();
163 $sql = "select users_username from users";
166 $result = $dbObject->query($sql);
168 // iterate over the results - we expect a simple array containing
169 // a list of usernames
172 foreach($result as $row) {
173 $users[$i] = $row["username"];
177 // now return the list