//exit(0);
// first we want to fork into the background like all good daemons should
//$pid = pcntl_fork();
+
+// uncomment this bit and comment the fork above to stop it going into the background
$pid = 0;
if($pid == -1) {
echo "i am a parent, i leave\n";
exit(0);
} else {
+ // here is where i need to swithc to TCP network protocol stuff
+ // i must bind 127.0.0.1 though.
+ // what i want to happen is this:
+ // 1) server receives connection
+ // 2) server forks off process to process connection
+ // 3) main server continues.
+ // a forked process thingy should be fully self contained and capable of dealing
+ // with "problems", i.e. the parent doesnt want to have to clean up children
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
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";
+ $dbo = getDatabase();
+ $res = $dbo->query($sql);
+ $clients = "";
+ $i=0;
+ foreach($res as $row) {
+ // $sql = 'CREATE TABLE "radclients" ("rad_id" INTEGER PRIMARY KEY AUTOINCREMENT,"rad_name" TEXT, "rad_ip" TEXT, "rad_secret" TEXT, "rad_desc" TEXT);';
+ $clients[$i]["name"] = $row["rad_name"];
+ $clients[$i]["ip"] = $row["rad_ip"];
+ $clients[$i]["secret"] = $row["rad_secret"];
+ $clients[$i]["desc"] = $row["rad_desc"];
+ $i++;
+ }
+ msg_send($cl_queue, MSG_GET_RADIUS_CLIENTS, $clients);
+ break;
+ case MSG_REMOVE_RADIUS_CLIENT:
+ // 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"];
+ $dbo = getDatabase();
+
+ // check for existing clients with same name
+ $sql = "select * from radclients where rad_name='$client'";
+ echo "doing select, $sql\n";
+ $res = $dbo->query($sql);
+ if($res->fetchColumn() > 0) {
+ msg_send($cl_queue, MSG_ADD_RADIUS_CLIENT, "name");
+
+ } else {
+ // check for existing clients with same ip
+ $sql = "select * from radclients where rad_ip='$clientip'";
+ $res = $dbo->query($sql);
+ echo "doing select, $sql\n";
+ if($res->fetchColumn() > 0) {
+ msg_send($cl_queue, MSG_ADD_RADIUS_CLIENT, "ip");
+
+ } else {
+ $sql = "insert into radclients values (NULL, '$client', '$clientip', '$clientsecret', '$clientdesc')";
+ $res = $dbo->query($sql);
+ updateRadius();
+ msg_send($cl_queue, MSG_ADD_RADIUS_CLIENT, true);
+ break;
+ }
+ }
+ break;
case MSG_DELETE_USER_TOKEN:
$username = $msg["username"];
$tokenone = $msg["tokenone"];
$tokentwo = $msg["tokentwo"];
- msg_send($cl_queue,MSG_SYNC_TOKEN, $myga->resyncCode($username, $tokenone, $tokentwo));
+ msg_send($cl_queue, MSG_SYNC_TOKEN, $myga->resyncCode($msg["username"], $tokenone, $tokentwo));
}
break;
+ case MSG_GET_TOKEN_TYPE:
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_GET_TOKEN_TYPE, false);
+ } else {
+ msg_send($cl_queue, MSG_GET_TOKEN_TYPE, $myga->getTokenType($msg["username"]));
+ }
+ break;
case MSG_ADD_USER_TOKEN:
echo "Call to add user token\n";
if(!isset($msg["username"])) {
$myga->setUser($username, $tokentype, "", $hexkey);
$url = $myga->createUrl($username);
+ echo "Url was: $url\n";
if(!file_exists("$BASE_DIR/authserver/authd/otks")) mkdir("$BASE_DIR/authserver/authd/otks");
$otk = generateRandomString();
- system("qrencode -o $BASE_DIR/authserver/authd/otks/$otk.png $url");
+ system("qrencode -o $BASE_DIR/authserver/authd/otks/$otk.png '$url'");
$sql = "update users set users_otk='$otk' where users_username='$username'";
$dbo = getDatabase();
break;
case MSG_GET_USERS:
// TODO this needs to be better
- $sql = "select * from users";
+ $sql = "select * from users order by users_username";
$dbo = getDatabase();
$res = $dbo->query($sql);