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";
// 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;
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;
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) {
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);
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";
echo "\tHas Token?: ".$hastoken."\n\n";
}
break;
+ default:
+ echo "See the usage...\n";
}
?>
\ No newline at end of file