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"];
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__)."/../../");
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")) {
}
$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;
?>
<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">