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 if(!isset($TCP_PORT_NUMBER)) $TCP_PORT_NUMBER = 21446;
8 global $TCP_PORT_NUMBER;
10 define("MSG_AUTH_USER_TOKEN", 1);
11 define("MSG_ADD_USER_TOKEN", 2);
12 define("MSG_DELETE_USER", 3);
13 define("MSG_AUTH_USER_PASSWORD", 4);
14 define("MSG_SET_USER_PASSWORD", 5);
15 define("MSG_SET_USER_REALNAME", 6);
16 define("MSG_SET_USER_TOKEN", 7);
17 define("MSG_SET_USER_TOKEN_TYPE", 8);
18 define("MSG_GET_USERS", 9);
19 define("MSG_GET_OTK_PNG", 10);
20 define("MSG_GET_OTK_ID", 11);
21 define("MSG_DELETE_USER_TOKEN", 12);
22 define("MSG_SYNC_TOKEN", 13);
23 define("MSG_GET_TOKEN_TYPE", 14);
24 define("MSG_GET_RADIUS_CLIENTS", 15);
25 define("MSG_REMOVE_RADIUS_CLIENT", 16);
26 define("MSG_ADD_RADIUS_CLIENT", 17);
30 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
34 require_once(dirname(__FILE__)."/../../lib/ga4php.php");
36 function generateRandomString()
39 $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
41 for($i=0; $i<128; $i++) {
42 $str .= $strpos[rand(0, strlen($strpos)-1)];
48 function updateRadius()
50 // this is hardcoded for now.
51 //$clientfile = "/etc/freeradius/clients.conf";
52 $clientfile = "/tmp/clients.conf";
53 $reloadinit = "/etc/init.d/freeradius restart";
57 echo "in updateradius\n";
58 $hand = fopen($clientfile, "w");
59 $sql = "select * from radclients";
60 $res = $db->query($sql);
61 foreach($res as $row) {
62 $cname = $row["rad_name"];
63 $cip = $row["rad_ip"];
64 $csec = $row["rad_secret"];
65 $lines = "client $cname {\nipaddr = $cip\nsecret = $csec\nrequire_message_authenticator = no\n}\n\n";
66 fwrite($hand, $lines);
70 //system($reloadinit);
74 function getDatabase()
78 if(file_exists("$BASE_DIR/authserver/authd/gaasdata.sqlite")) {
80 $dbobject = new PDO("sqlite:$BASE_DIR/authserver/authd/gaasdata.sqlite");
81 } catch(PDOException $exep) {
82 error_log("execpt on db open");
86 $dbobject = new PDO("sqlite:$BASE_DIR/authserver/authd/gaasdata.sqlite");
87 } catch(PDOException $exep) {
88 error_log("execpt on db open");
90 $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);';
91 $dbobject->query($sql);
92 $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
93 $dbobject->query($sql);
99 function closeDatabase($db) {
100 // doesnt do anything yet
103 class gaasGA extends GoogleAuthenticator {
104 function getData($username) {
105 echo "called into getdata\n";
107 // get our database connection
108 $dbObject = getDatabase();
110 // set the sql for retreiving the data
111 $sql = "select users_tokendata from users where users_username='$username'";
114 $result = $dbObject->query($sql);
118 if(!$result) return false;
120 // now just retreieve all the data (there should only be one, but whatever)
123 foreach($result as $row) {
124 $tokendata = $row["users_tokendata"];
127 echo "next3, $username, $tokendata\n";
128 // now we have our data, we just return it. If we got no data
129 // we'll just return false by default
132 // and there you have it, simple eh?
136 function putData($username, $data) {
137 // get our database connection
138 $dbObject = getDatabase();
140 // we need to check if the user exists, and if so put the data, if not create the data
141 $sql = "select * from users where users_username='$username'";
142 $res = $dbObject->query($sql);
143 if($res->fetchColumn() > 0) {
145 error_log("doing userdata update");
146 $sql = "update users set users_tokendata='$data' where users_username='$username'";
149 error_log("doing user data create");
150 $sql = "insert into users values (NULL, '$username', '', '', '$data', '')";
153 if($dbObject->query($sql)) {
161 function getUsers() {
162 // get our database connection
163 $dbObject = getDatabase();
166 $sql = "select users_username from users";
169 $result = $dbObject->query($sql);
171 // iterate over the results - we expect a simple array containing
172 // a list of usernames
175 foreach($result as $row) {
176 $users[$i] = $row["username"];
180 // now return the list