echo "i am a parent, i leave\n";
exit(0);
} else {
-
-
- /// ok, this is just testing stuff... create queue
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
-
-
$cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
$sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER, 0666 | 'IPC_CREAT');
msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
print_r($msg);
switch($msg_type) {
- case MSG_AUTH_USER:
+ case MSG_AUTH_USER_TOKEN:
// minimal checking, we leav it up to authenticateUser to do the real
// checking
if(!isset($msg["user"])) $msg["user"] = "";
$username = $msg["user"];
$passcode = $msg["passcode"];
global $myga;
- msg_send($cl_queue, MSG_AUTH_USER, $myga->authenticateUser($username, $passcode));
+ msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $myga->authenticateUser($username, $passcode));
break;
- case MSG_ADD_USER:
+ case MSG_ADD_USER_TOKEN:
if(!isset($msg["username"])) {
- msg_send($cl_queue, MSG_ADD_USER, false);
+ msg_send($cl_queue, MSG_ADD_USER_TOKEN, false);
} else {
$username = $msg["username"];
global $myga;
- msg_send($cl_queue, MSG_ADD_USER, $myga->setUser($username));
+ msg_send($cl_queue, MSG_ADD_USER_TOKEN, $myga->setUser($username));
}
break;
case MSG_DELETE_USER:
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_DELETE_USER, false);
+ } else {
+ $username = $msg["username"];
+ global $myga;
+ msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username));
+ }
+ case MSG_AUTH_USER_PASSWORD:
+ // TODO
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
+ break;
+ }
+ if(!isset($msg["password"])) {
+ msg_send($cl_queue, MSG_AUTH_USER_PASSWORD, false);
+ break;
+ }
+
+ $username = $msg["username"];
+ $sql = "select users_password from users where username='$username'";
+ $dbo = getDatabase();
+
+
+ // TODO now do auth
+
break;
+ case MSG_SET_USER_PASSWORD:
+ // TODO
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
+ break;
+ }
+ if(!isset($msg["password"])) {
+ msg_send($cl_queue, MSG_SET_USER_PASSWORD, false);
+ break;
+ }
+
+ // these are irrelavent yet
+ // TODO now set pass
+ break;
+ case MSG_SET_USER_REALNAME:
+ // TODO
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
+ break;
+ }
+ if(!isset($msg["realname"])) {
+ msg_send($cl_queue, MSG_SET_USER_REALNAME, false);
+ break;
+ }
+
+ $username = $msg["username"];
+ $realname = $msg["realname"];
+ $sql = "update set users_realnemd='$realname' where username='$username'";
+ $dbo = getDatabase();
+
+ $dbo->query($sql);
+
+ msg_send($cl_queue, MSG_SET_USER_REALNAME, true);
+
+ // TODO now set real name
+ break;
+ case MSG_SET_USER_TOKEN:
+ // TODO
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
+ break;
+ }
+ if(!isset($msg["tokenstring"])) {
+ msg_send($cl_queue, MSG_SET_USER_TOKEN, false);
+ break;
+ }
+
+ global $myga;
+ msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->setUserKey($username, $passcode));
+
+ // TODO now set token
+ break;
+ case MSG_SET_USER_TOKEN_TYPE:
+ // TODO
+ if(!isset($msg["username"])) {
+ msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
+ break;
+ }
+ if(!isset($msg["tokentype"])) {
+ msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, false);
+ break;
+ }
+
+ $username = $msg["username"];
+ $tokentype = $msg["tokentype"];
+ global $myga;
+ msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, $myga->setTokenType($username, $tokentype));
+
+ // TODO now set token
+ break;
+
}
}
}
class GAAuthClient {
function setUserToken($username, $token) {
+ 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);
}
function setUserPass($username, $password) {
+ 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);
}
function authUserPass($username, $password) {
+ 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);
}
function deleteUser($username) {
+ 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);
}
function setUserRealName($username, $realname) {
+ 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);
}
- function authUser($username, $passcode) {
+ function authUserToken($username, $passcode) {
global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
echo "message received?\n";
print_r($msg);
- return false;
+ return $msg;
}
function addUser($username) {
echo "message received?\n";
print_r($msg);
- return false;
+ return $msg;
+
+ }
+
+ 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;
+ }
+
+ 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["username"] = $username;
+
}
}
define("MSG_SET_USER_PASSWORD", 5);
define("MSG_SET_USER_REALNAME", 6);
define("MSG_SET_USER_TOKEN", 7);
+define("MSG_SET_USER_TOKEN_TYPE", 8);
if(file_exists("../../lib/ga4php.php")) require_once("../../lib/ga4php.php");
if(file_exists("../lib/ga4php.php")) require_once("../lib/ga4php.php");
$myAC = new GAAuthClient();
+/*
+define("MSG_AUTH_USER_TOKEN", 1);
+define("MSG_ADD_USER_TOKEN", 2);
+define("MSG_DELETE_USER", 3);
+define("MSG_AUTH_USER_PASSWORD", 4);
+define("MSG_SET_USER_PASSWORD", 5);
+define("MSG_SET_USER_REALNAME", 6);
+define("MSG_SET_USER_TOKEN", 7);
+define("MSG_SET_USER_TOKEN_TYPE", 8);
+
+ */
if(!isset($argv[1])) {
- echo "Usage: ".$argv[0]." add|auth username passcode\n";
+ echo "Usage: ".$argv[0]." command username [args]\n";
+ echo "\tadd: add <username> - returns token code url\n";
+ echo "\tauth: auth <username> <passcode> - returns 0/1 for pass/fail\n";
+ echo "\tdelete: delete <username> - deletes user\n";
+ echo "\tauthpass: authpass <username> <password> - returns 0/1 for pass/fail\n";
+ echo "\tsetpass: setpass <username> <password> - sets a password for a user (x to remove pass)\n";
+ echo "\tsetname: setname <username> <realname> - sets the real name for a user\n";
+ echo "\tsettoken: settoken <username> <tokenkey> - sets the key (hex) for a token\n";
+ echo "\tsettype: settype <username> <tokentype> - sets a token type for a user\n";
return 0;
}
case "add":
$myAC->addUser($argv[2]);
break;
+ case "delete":
+ break;
+ case "authpass":
+ break;
+ case "setpass":
+ break;
+ case "setname":
+ break;
+ case "settoken":
+ break;
+ case "settype":
+ break;
}
?>
\ No newline at end of file