3 require_once("lib.php");
7 // this functiuon will now act as our generic send/recieve client funciton
8 // im doing this because im going to move from ipc messaging to a tcp connection
9 // shortly and i want to encapsulate the send/receive behaviour
10 // things we need to add here are:
11 // 1) a way of saying "more data coming" cause getusers wont fit into one message
12 // 2) timeouts and locking
14 // io think this function should now "work" more or less as is
15 function sendReceive($message_type, $message) {
16 // yeah... this is totally gunna work
17 global $TCP_PORT_NUMBER;
19 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
20 $res = socket_connect($socket, "127.0.0.1", $TCP_PORT_NUMBER);
22 socket_close($socket);
26 $msg["type"] = $message_type;
27 $msg["data"] = $message;
29 $datacomp = base64_encode(serialize($msg));
30 $tosend = "AC:$datacomp:EOD";
32 socket_send($socket, $tosend, strlen($tosend), 0);
34 // get up to one meg of data - this is bad... i can feel this function
36 // TODO FIX THIS - its garbage code... im not really sure how to handle this really
37 // we need to read back as AS:data:EOD - i think it now does.. i hope, tho we need
42 $size = socket_recv($socket, $recvd_a, 1024, 0);
44 if(preg_match("/.*\:EOD$/", $recvd)) {
45 // we have a full string... break out
52 // first check we got something that makes sense
53 if(preg_match("/^AS:.*:EOD/", $recvd) < 1) {
54 socket_close($socket);
55 // we have a problem jim
59 $xps = explode(":", $recvd);
61 $component = unserialize(base64_decode($xps[1]));
63 if($component["type"] != $message_type) {
64 // we have a problem jim
65 socket_close($socket);
69 socket_close($socket);
71 return $component["data"];
74 function addRadiusClient($clientname, $clientip, $clientsecret, $clientdesc) {
76 $message["clientname"] = $clientname;
77 $message["clientsecret"] = $clientsecret;
78 $message["clientip"] = $clientip;
79 $message["clientdescription"] = $clientdesc;
81 return $this->sendReceive(MSG_ADD_RADIUS_CLIENT, $message);
84 function deleteRadiusClient($clientname) {
85 $message["clientname"] = $clientname;
87 return $this->sendReceive(MSG_REMOVE_RADIUS_CLIENT, $message);
91 function getRadiusClients() {
92 return $this->sendReceive(MSG_GET_RADIUS_CLIENTS, "");
96 function syncUserToken($username, $tokenone, $tokentwo) {
97 $message["username"] = $username;
98 $message["tokenone"] = $tokenone;
99 $message["tokentwo"] = $tokentwo;
101 return $this->sendReceive(MSG_SYNC_TOKEN, $messgae);
104 function getUserTokenType($username) {
105 $message["username"] = $username;
107 return $this->sendReceive(MSG_GET_TOKEN_TYPE, $message);
110 function setUserToken($username, $token) {
111 $message["username"] = $username;
112 $message["tokenstring"] = $token;
114 return $this->sendReceive(MSG_GET_USER_TOKEN, $message);
117 function setUserPass($username, $password) {
118 $message["username"] = $username;
119 $message["password"] = $password;
121 return $this->sendReceive(MSG_SET_USER_PASSWORD, $message);
124 function getOtkID($username) {
125 $message["username"] = $username;
127 return $this->sendReceive(MSG_GET_OTK_ID, $message);
130 function getOtkPng($username, $otk) {
131 $message["otk"] = $otk;
132 $message["username"] = $username;
134 return $this->sendReceive(MSG_GET_OTK_PNG, $message);
137 function authUserPass($username, $password) {
138 $message["username"] = $username;
139 $message["password"] = $password;
141 return $this->sendReceive(MSG_AUTH_USER_PASSWORD, $message);
144 function deleteUser($username) {
145 $message["username"] = $username;
147 return $this->sendReceive(MSG_DELETE_USER, $message);
150 function setUserRealName($username, $realname) {
151 $message["username"] = $username;
152 $message["realname"] = $realname;
154 return $this->sendReceive(MSG_SET_USER_REALNAME, $message);
157 function getUsers() {
158 return $this->sendReceive(MSG_GET_USERS, "");
161 function authUserToken($username, $passcode) {
162 $message["username"] = $username;
163 $message["passcode"] = $passcode;
165 return $this->sendReceive(MSG_AUTH_USER_TOKEN, $message);
168 function deleteUserToken($username) {
169 $message["username"] = $username;
171 return $this->sendReceive(MSG_DELETE_USER_TOKEN, $message);
174 function addUser($username, $tokentype="", $hexkey="") {
175 $message["username"] = $username;
176 if($tokentype!="") $message["tokentype"] = $tokentype;
177 if($hexkey!="") $message["hexkey"] = $hexkey;
179 return $this->sendReceive(MSG_ADD_USER_TOKEN, $message);
182 function setUserTokenType($username, $tokentype) {
183 $message["username"] = $username;
184 $message["tokentype"] = $tokentype;
186 return $this->sendReceive(MSG_SET_USER_TOKEN_TYPE, $message);