From: paulr Date: Wed, 8 Dec 2010 00:09:41 +0000 (+1100) Subject: radius clients stuff X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=commitdiff_plain;h=c3c37cd9f486175adf0351de80c19efd02892ca6 radius clients stuff --- diff --git a/authserver/authd/authd.php b/authserver/authd/authd.php index 67b9627..520a39f 100644 --- a/authserver/authd/authd.php +++ b/authserver/authd/authd.php @@ -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; diff --git a/authserver/lib/authClient.php b/authserver/lib/authClient.php index ba6c2ff..9b8480f 100644 --- a/authserver/lib/authClient.php +++ b/authserver/lib/authClient.php @@ -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) { diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index 90b0ddf..0d6ab36 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -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); diff --git a/authserver/usercmd.php b/authserver/usercmd.php index 1d4db80..3adf835 100644 --- a/authserver/usercmd.php +++ b/authserver/usercmd.php @@ -39,10 +39,19 @@ if(!isset($argv[1])) { echo "\tradauth: radauth - for radius, only returns a code\n"; echo "\tsynctoken: synctoken - resync's a hotp token based on two token codes\n"; echo "\ttokentype: tokentype - gets the token type for a user\n"; + echo "\taddradclient: addradclient \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