radius clients stuff
authorpaulr <me@pjr.cc>
Wed, 8 Dec 2010 00:09:41 +0000 (11:09 +1100)
committerpaulr <me@pjr.cc>
Wed, 8 Dec 2010 00:09:41 +0000 (11:09 +1100)
authserver/authd/authd.php
authserver/lib/authClient.php
authserver/lib/lib.php
authserver/usercmd.php

index 67b9627..520a39f 100644 (file)
@@ -30,6 +30,7 @@ if($pid == -1) {
        
        while(true) {
                msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
+               echo "got message of type $msg_type\n";
                switch($msg_type) {
                        case MSG_GET_RADIUS_CLIENTS:
                                $sql = "select * from radclients";
@@ -50,16 +51,20 @@ if($pid == -1) {
                                // it should send us a client by rad_name - doesnt work yet
                                $client = $msg["clientname"];
                                $sql = "delete from radclients where rad_name='$client'";
+                               $dbo = getDatabase();
                                $res = $dbo->query($sql);
                                updateRadius();
                                msg_send($cl_queue, MSG_REMOVE_RADIUS_CLIENT, true);
                                break;
                        case MSG_ADD_RADIUS_CLIENT:
+                               echo "in addradclient\n";
                                $client = $msg["clientname"];
                                $clientsecret = $msg["clientsecret"];
                                $clientip = $msg["clientip"];
                                $clientdesc = $msg["clientdescription"];
                                $sql = "insert into radclients values (NULL, '$client', '$clientip', '$clientsecret', '$clientdesc')";
+                               $dbo = getDatabase();
+                               $res = $dbo->query($sql);
                                updateRadius();
                                msg_send($cl_queue, MSG_ADD_RADIUS_CLIENT, true);
                                break;
index ba6c2ff..9b8480f 100644 (file)
@@ -3,6 +3,34 @@
 require_once("lib.php");
 
 class GAAuthClient {
+       function addRadiusClient($clientname, $clientip, $clientsecret, $clientdesc) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+       
+               $message["clientname"] = $clientname;
+               $message["clientsecret"] = $clientsecret;
+               $message["clientip"] = $clientip;
+               $message["clientdescription"] = $clientdesc;
+               
+               msg_send($sr_queue, MSG_ADD_RADIUS_CLIENT, $message, true, true, $msg_err);
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               return $msg;
+       }
+       
        function syncUserToken($username, $tokenone, $tokentwo) {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
                
@@ -26,8 +54,7 @@ class GAAuthClient {
                msg_send($sr_queue, MSG_SYNC_TOKEN, $message, true, true, $msg_err);
                
                msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
-               return $msg;            
-               
+               return $msg;
        }
        
        function getUserTokenType($username) {
index 90b0ddf..0d6ab36 100644 (file)
@@ -44,10 +44,11 @@ function generateRandomString()
 function updateRadius()
 {
        // this is hardcoded for now.
-       $clientfile = "/opt/freeradius/clients.conf";
+       $clientfile = "/tmp/clients.conf";
        
        $db = getDatabase();
        
+       echo "in updateradius\n";
        $hand = fopen($clientfile, "w");
        $sql = "select * from radclients";
        $res = $db->query($sql);
index 1d4db80..3adf835 100644 (file)
@@ -39,10 +39,19 @@ if(!isset($argv[1])) {
        echo "\tradauth: radauth <username> <pin> - for radius, only returns a code\n";
        echo "\tsynctoken: synctoken <username> <tokenone> <tokentwo> - resync's a hotp token based on two token codes\n";
        echo "\ttokentype: tokentype <username> - gets the token type for a user\n";
+       echo "\taddradclient: addradclient <client_name> <client_ip> <client_secret>\n";
        return 0;       
 }
 
 switch($argv[1]) {
+       case "addradclient":
+               $msg = $myAC->addRadiusClient($argv[2], $argv[3], $argv[4], "");
+               if($msg) {
+                       echo "Added successfully\n";
+               } else {
+                       echo "Not added\n";
+               }
+               break;
        case "tokentype":
                $msg = $myAC->getUserTokenType($argv[2]);
                echo "token type: $msg\n";
@@ -133,5 +142,7 @@ switch($argv[1]) {
                        echo "\tHas Token?: ".$hastoken."\n\n";
                }
                break;
+       default:
+               echo "See the usage...\n";
 }
 ?>
\ No newline at end of file