X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=authserver%2Flib%2Flib.php;h=90b0ddf9e4bdc5bbb10d3056ccfc35bae59b0337;hp=83d7ced8ddc527a53d942e9c67540f98419597e4;hb=684d7cc6c2ce6ba3f1ca5c48dda5c4efa9448455;hpb=2d6b0d3ff36c0e388ea51163cb2ebee072a03dab diff --git a/authserver/lib/lib.php b/authserver/lib/lib.php index 83d7ced..90b0ddf 100644 --- a/authserver/lib/lib.php +++ b/authserver/lib/lib.php @@ -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;