added radclient stuff
authorpaulr <me@pjr.cc>
Tue, 7 Dec 2010 23:55:06 +0000 (10:55 +1100)
committerpaulr <me@pjr.cc>
Tue, 7 Dec 2010 23:55:06 +0000 (10:55 +1100)
authserver/authd/authd.php
authserver/lib/lib.php
authserver/www/admin.php

index 576a507..67b9627 100644 (file)
@@ -31,6 +31,38 @@ if($pid == -1) {
        while(true) {
                msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
                switch($msg_type) {
+                       case MSG_GET_RADIUS_CLIENTS:
+                               $sql = "select * from radclients";
+                               $dbo = getDatabase();
+                               $res = $dbo->query($sql);
+                               $clients = "";
+                               $i=0;
+                               foreach($res as $row) {
+                                       //              $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
+                                       $clients[$i]["name"] = $row["rad_name"];
+                                       $clients[$i]["ip"] = $row["rad_ip"];
+                                       $clients[$i]["secret"] = $row["rad_secret"];
+                                       $clients[$i]["desc"] = $row["rad_desc"];
+                               }
+                               msg_send($cl_queue, MSG_GET_RADIUS_CLIENTS, $clients);
+                               break;
+                       case MSG_REMOVE_RADIUS_CLIENT:
+                               // it should send us a client by rad_name - doesnt work yet
+                               $client = $msg["clientname"];
+                               $sql = "delete from radclients where rad_name='$client'";
+                               $res = $dbo->query($sql);
+                               updateRadius();
+                               msg_send($cl_queue, MSG_REMOVE_RADIUS_CLIENT, true);
+                               break;
+                       case MSG_ADD_RADIUS_CLIENT:
+                               $client = $msg["clientname"];
+                               $clientsecret = $msg["clientsecret"];
+                               $clientip = $msg["clientip"];
+                               $clientdesc = $msg["clientdescription"];
+                               $sql = "insert into radclients values (NULL, '$client', '$clientip', '$clientsecret', '$clientdesc')";
+                               updateRadius();
+                               msg_send($cl_queue, MSG_ADD_RADIUS_CLIENT, true);
+                               break;
                        case MSG_DELETE_USER_TOKEN:
                                $username = $msg["username"];
                                
index 83d7ced..90b0ddf 100644 (file)
@@ -18,6 +18,9 @@ define("MSG_GET_OTK_ID", 11);
 define("MSG_DELETE_USER_TOKEN", 12);
 define("MSG_SYNC_TOKEN", 13);
 define("MSG_GET_TOKEN_TYPE", 14);
+define("MSG_GET_RADIUS_CLIENTS", 15);
+define("MSG_REMOVE_RADIUS_CLIENT", 16);
+define("MSG_ADD_RADIUS_CLIENT", 17);
 
 // BASE_DIR = 
 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
@@ -38,8 +41,29 @@ function generateRandomString()
        return $str;
 }
 
+function updateRadius()
+{
+       // this is hardcoded for now.
+       $clientfile = "/opt/freeradius/clients.conf";
+       
+       $db = getDatabase();
+       
+       $hand = fopen($clientfile, "w");
+       $sql = "select * from radclients";
+       $res = $db->query($sql);
+       foreach($res as $row) {
+               $cname = $row["rad_name"];
+               $cip = $row["rad_ip"];
+               $csec = $row["rad_secret"];
+               $lines = "client $cname {\nipaddr = $cip\nsecret = $csec\nrequire_message_authenticator = no\n}";
+               fwrite($hand, $lines);
+       }
+       fclose($hand);
+}
+
 
-function getDatabase() {
+function getDatabase()
+{
        $dbobject = false;
        global $BASE_DIR;
        if(file_exists("$BASE_DIR/authserver/authd/gaasdata.sqlite")) {
@@ -56,6 +80,8 @@ function getDatabase() {
                }
                $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);';
                $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);
        }
        
        return $dbobject;
index 24d02b4..7f2c8a3 100644 (file)
@@ -72,8 +72,9 @@ if($myAC->getUserTokenType($username)=="HOTP") {
 ?> 
 
 <form method="post" action="?action=customtoken&username=<?php echo $username ?>">
-<h3>Custom Tokens - doesnt work yet</h3><br>
-For assiging in a user-created or hardware tokens<br>
+<h3>Custom Tokens</h3><br>
+For assiging in a user-created or hardware tokens.<br>
+If you assign a token this way, any previous token is removed and forever gone.<br>
 Token Key (hex) <input type="text" name="tokenkey"><br>
 Token Type 
 <select name="tokentype">