small change to add hardware tokens to database.
[ga4php.git] / authserver / lib / lib.php
index 0d6ab36..6ae1d81 100644 (file)
@@ -1,8 +1,7 @@
 <?php
 
-if(!isset($MSG_QUEUE_KEY_ID_SERVER)) $MSG_QUEUE_KEY_ID_SERVER = "189751072"; // i would use ftok, but its crap
-if(!isset($MSG_QUEUE_KEY_ID_CLIENT)) $MSG_QUEUE_KEY_ID_CLIENT = "189751073"; // ftok is not ok!
-global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+if(!isset($TCP_PORT_NUMBER)) $TCP_PORT_NUMBER = 21446;
+global $TCP_PORT_NUMBER;
 
 define("MSG_AUTH_USER_TOKEN", 1);
 define("MSG_ADD_USER_TOKEN", 2);
@@ -23,6 +22,7 @@ define("MSG_REMOVE_RADIUS_CLIENT", 16);
 define("MSG_ADD_RADIUS_CLIENT", 17);
 
 // BASE_DIR = 
+// messy
 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
 global $BASE_DIR;
 
@@ -44,7 +44,9 @@ function generateRandomString()
 function updateRadius()
 {
        // this is hardcoded for now.
+       //$clientfile = "/etc/freeradius/clients.conf";
        $clientfile = "/tmp/clients.conf";
+       $reloadinit = "/etc/init.d/freeradius restart";
        
        $db = getDatabase();
        
@@ -56,10 +58,12 @@ function updateRadius()
                $cname = $row["rad_name"];
                $cip = $row["rad_ip"];
                $csec = $row["rad_secret"];
-               $lines = "client $cname {\nipaddr = $cip\nsecret = $csec\nrequire_message_authenticator = no\n}";
+               $lines = "client $cname {\nipaddr = $cip\nsecret = $csec\nrequire_message_authenticator = no\n}\n\n";
                fwrite($hand, $lines);
        }
        fclose($hand);
+       // not yet
+       //system($reloadinit);
 }
 
 
@@ -83,6 +87,8 @@ function getDatabase()
                $dbobject->query($sql);
                $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
                $dbobject->query($sql);
+               $sql = 'CREATE TABLE "hardwaretokens" ("tok_id" INTEGER PRIMARY KEY AUTOINCREMENT,"tok_name" TEXT, "tok_key" TEXT, "tok_type" TEXT);';
+               $dbobject->query($sql);
        }
        
        return $dbobject;
@@ -94,7 +100,7 @@ function closeDatabase($db) {
 
 class gaasGA extends GoogleAuthenticator {
        function getData($username) {
-               echo "called into getdata\n";
+               //echo "called into getdata\n";
                
                // get our database connection
                $dbObject = getDatabase();
@@ -106,17 +112,17 @@ class gaasGA extends GoogleAuthenticator {
                $result = $dbObject->query($sql);
                
                // check the result
-               echo "next1\n";
+               //echo "next1\n";
                if(!$result) return false;
                
                // now just retreieve all the data (there should only be one, but whatever)
-               echo "next2\n";
+               //echo "next2\n";
                $tokendata = false;
                foreach($result as $row) {
                        $tokendata = $row["users_tokendata"];
                }
 
-               echo "next3, $username, $tokendata\n";
+               //echo "next3, $username, $tokendata\n";
                // now we have our data, we just return it. If we got no data
                // we'll just return false by default
                return $tokendata;
@@ -134,11 +140,11 @@ class gaasGA extends GoogleAuthenticator {
                $res = $dbObject->query($sql);
                if($res->fetchColumn() > 0) {
                        // do update
-                       error_log("doing userdata update");
+                       //error_log("doing userdata update");
                        $sql = "update users set users_tokendata='$data' where users_username='$username'";
                } else {
                        // do insert
-                       error_log("doing user data create");
+                       //error_log("doing user data create");
                        $sql = "insert into users values (NULL, '$username', '', '', '$data', '')";
                }