X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=authserver%2Flib%2FauthClient.php;h=4f398ac767409a384e139f1503b2b47b481c6f48;hb=f10680a1827dd8e4c65eaaef810ee7fd498e5a1e;hp=d97bc196237fd8960dea45d48805b5ac3c25b3d0;hpb=7cdd4cb7ea1bec4975802863a1143da1369d288c;p=ga4php.git diff --git a/authserver/lib/authClient.php b/authserver/lib/authClient.php index d97bc19..4f398ac 100644 --- a/authserver/lib/authClient.php +++ b/authserver/lib/authClient.php @@ -4,61 +4,74 @@ require_once("lib.php"); class GAAuthClient { - function setUserToken($username, $token) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; - + // this functiuon will now act as our generic send/recieve client funciton + // im doing this because im going to move from ipc messaging to a tcp connection + // shortly and i want to encapsulate the send/receive behaviour + // things we need to add here are: + // 1) a way of saying "more data coming" cause getusers wont fit into one message + // 2) timeouts and locking + + // io think this function should now "work" more or less as is + function sendReceive($message_type, $message) { + // yeah... this is totally gunna work + global $TCP_PORT_NUMBER; - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { + $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + $res = socket_connect($socket, "127.0.0.1", $TCP_PORT_NUMBER); + if(!$res) { + socket_close($socket); 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); + $msg["type"] = $message_type; + $msg["data"] = $message; - } - - function setUserPass($username, $password) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; + $datacomp = base64_encode(serialize($msg)); + $tosend = "AC:$datacomp:EOD"; + socket_send($socket, $tosend, strlen($tosend), 0); - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { - return false; + // get up to one meg of data - this is bad... i can feel this function + // hurting alot + // TODO FIX THIS - its garbage code... im not really sure how to handle this really + // we need to read back as AS:data:EOD - i think it now does.. i hope, tho we need + // timeouts now. + $recvd = ""; + $continue = true; + while($continue) { + $size = socket_recv($socket, $recvd_a, 1024, 0); + $recvd .= $recvd_a; + if(preg_match("/.*\:EOD$/", $recvd)) { + // we have a full string... break out + $continue = false; + break; + } } - - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) { + + + // first check we got something that makes sense + if(preg_match("/^AS:.*:EOD/", $recvd) < 1) { + socket_close($socket); + // we have a problem jim 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); + $xps = explode(":", $recvd); - } - - function authUserPass($username, $password) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; + $component = unserialize(base64_decode($xps[1])); - - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { + if($component["type"] != $message_type) { + // we have a problem jim + socket_close($socket); 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); + socket_close($socket); + return $component["data"]; } - function deleteUser($username) { + function sendReceiveIPC($message_type, $message) { global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; @@ -74,109 +87,126 @@ class GAAuthClient { $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT); $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER); + msg_send($sr_queue, $message_type, $message, true, true, $msg_err); + msg_receive($cl_queue, 0, $msg_type, 131072, $msg); + + return $msg; } - function setUserRealName($username, $realname) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; - + function addRadiusClient($clientname, $clientip, $clientsecret, $clientdesc) { + + $message["clientname"] = $clientname; + $message["clientsecret"] = $clientsecret; + $message["clientip"] = $clientip; + $message["clientdescription"] = $clientdesc; - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { - return false; - } + return $this->sendReceive(MSG_ADD_RADIUS_CLIENT, $message); + } - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) { - return false; - } - // TODO we need to setup a client queue sem lock here + function deleteRadiusClient($clientname) { + $message["clientname"] = $clientname; - $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT); - $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER); + return $this->sendReceive(MSG_REMOVE_RADIUS_CLIENT, $message); } - function authUserToken($username, $passcode) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; - - - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { - return false; - } + function getRadiusClients() { + return $this->sendReceive(MSG_GET_RADIUS_CLIENTS, ""); + } + + + function syncUserToken($username, $tokenone, $tokentwo) { + $message["username"] = $username; + $message["tokenone"] = $tokenone; + $message["tokentwo"] = $tokentwo; - 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["user"] = $username; - $message["passcode"] = $passcode; - - msg_send($sr_queue, MSG_AUTH_USER, $message, true, true, $msg_err); - echo "message sent\n"; - - msg_receive($cl_queue, 0, $msg_type, 16384, $msg); - echo "message received?\n"; - print_r($msg); - - return $msg; + return $this->sendReceive(MSG_SYNC_TOKEN, $messgae); } - function addUser($username) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; - - - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { - return false; - } + function getUserTokenType($username) { + $message["username"] = $username; - 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); - - + return $this->sendReceive(MSG_GET_TOKEN_TYPE, $message); + } + + function setUserToken($username, $token) { $message["username"] = $username; + $message["tokenstring"] = $token; - msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err); - echo "message sent\n"; - - msg_receive($cl_queue, 0, $msg_type, 16384, $msg); - echo "message received?\n"; - print_r($msg); - - return $msg; + return $this->sendReceive(MSG_GET_USER_TOKEN, $message); + } + + function setUserPass($username, $password) { + $message["username"] = $username; + $message["password"] = $password; + return $this->sendReceive(MSG_SET_USER_PASSWORD, $message); } + + function getOtkID($username) { + $message["username"] = $username; - function setTokenType($username, $tokentype) { - global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT; - - - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) { - return false; - } + return $this->sendReceive(MSG_GET_OTK_ID, $message); + } + + function getOtkPng($username, $otk) { + $message["otk"] = $otk; + $message["username"] = $username; - if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) { - return false; - } + return $this->sendReceive(MSG_GET_OTK_PNG, $message); + } + + function authUserPass($username, $password) { + $message["username"] = $username; + $message["password"] = $password; - // TODO we need to setup a client queue sem lock here + return $this->sendReceive(MSG_AUTH_USER_PASSWORD, $message); + } + + function deleteUser($username) { + $message["username"] = $username; - $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT); - $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER); + return $this->sendReceive(MSG_DELETE_USER, $message); + } + + function setUserRealName($username, $realname) { + $message["username"] = $username; + $message["realname"] = $realname; + return $this->sendReceive(MSG_SET_USER_REALNAME, $message); + } + + function getUsers() { + return $this->sendReceive(MSG_GET_USERS, ""); + } + + function authUserToken($username, $passcode) { + $message["username"] = $username; + $message["passcode"] = $passcode; + return $this->sendReceive(MSG_AUTH_USER_TOKEN, $message); + } + + function deleteUserToken($username) { $message["username"] = $username; + return $this->sendReceive(MSG_DELETE_USER_TOKEN, $message); + } + + function addUser($username, $tokentype="", $hexkey="") { + $message["username"] = $username; + if($tokentype!="") $message["tokentype"] = $tokentype; + if($hexkey!="") $message["hexkey"] = $hexkey; + + return $this->sendReceive(MSG_ADD_USER_TOKEN, $message); + } + + function setUserTokenType($username, $tokentype) { + $message["username"] = $username; + $message["tokentype"] = $tokentype; + return $this->sendReceive(MSG_SET_USER_TOKEN_TYPE, $message); } } -?> \ No newline at end of file +?>