fixed a minor thing with the hotp skew
[ga4php.git] / authserver / authd / authd.php
index 5fdb3e1..2474b3a 100644 (file)
@@ -41,21 +41,32 @@ if($pid == -1) {
                                echo "Call to auth user token\n";
                                // minimal checking, we leav it up to authenticateUser to do the real
                                // checking
-                               if(!isset($msg["user"])) $msg["user"] = "";
+                               if(!isset($msg["username"])) $msg["username"] = "";
                                if(!isset($msg["passcode"])) $msg["passcode"] = "";
-                               $username = $msg["user"];
+                               $username = $msg["username"];
                                $passcode = $msg["passcode"];
                                global $myga;
-                               msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $myga->authenticateUser($username, $passcode));
+                               $authval = $myga->authenticateUser($username, $passcode);
+                               msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $authval);
                                break;
                        case MSG_ADD_USER_TOKEN:
                                echo "Call to add user token\n";
                                if(!isset($msg["username"])) {
                                        msg_send($cl_queue, MSG_ADD_USER_TOKEN, false); 
                                } else {
-                                       $username = $msg["username"];                           
+                                       $username = $msg["username"];
+                                       $tokentype="HOTP";
+                                       if(isset($msg["tokentype"])) {
+                                               $tokentype="HOTP";
+                                       }
+                                       $hexkey = "";
+                                       if(isset($msg["hexkey"])) {
+                                               $hexkey = $msg["hexkey"];
+                                       }
                                        global $myga;
-                                       msg_send($cl_queue, MSG_ADD_USER_TOKEN, $myga->setUser($username));
+                                       $myga->setUser($username, $tokentype, "", $hexkey);
+                                       
+                                       msg_send($cl_queue, MSG_ADD_USER_TOKEN, $myga->createUrl($username));
                                }
                                break;
                        case MSG_DELETE_USER:
@@ -67,6 +78,7 @@ if($pid == -1) {
                                        global $myga;
                                        msg_send($cl_queue, MSG_DELETE_USER, $myga->deleteUser($username));
                                }
+                               break;
                        case MSG_AUTH_USER_PASSWORD:
                                // TODO
                                echo "Call to auth user pass\n";
@@ -144,7 +156,6 @@ if($pid == -1) {
                                $username = $msg["username"];
                                $realname = $msg["realname"];
                                $sql = "update users set users_realname='$realname' where users_username='$username'";
-                               echo "sql: $sql\n";
                                $dbo = getDatabase();
                                
                                $dbo->query($sql);
@@ -166,7 +177,8 @@ if($pid == -1) {
                                }
                                
                                global $myga;
-                               msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->setUserKey($username, $passcode));
+                               $myga->setUserKey($username, $passcode);
+                               msg_send($cl_queue, MSG_SET_USER_TOKEN, $myga->createUrl($username));
                                
                                // TODO now set token 
                                break;                  
@@ -188,10 +200,39 @@ if($pid == -1) {
                                msg_send($cl_queue, MSG_SET_USER_TOKEN_TYPE, $myga->setTokenType($username, $tokentype));
                                
                                // TODO now set token 
-                               break;                  
+                               break;
+                       case MSG_GET_USERS:
+                               // TODO this needs to be better
+                               $sql = "select * from users";
+                               
+                               $dbo = getDatabase();
+                               $res = $dbo->query($sql);
+                               
+                               $users = "";
+                               $i = 0;
+                               foreach($res as $row) {
+                                       $users[$i]["username"] = $row["users_username"];
+                                       $users[$i]["realname"] = $row["users_realname"];
+                                       if($row["users_password"]!="") {
+                                               $users[$i]["haspass"] = true;
+                                       } else {
+                                               $users[$i]["haspass"] = false;
+                                       }
+                                       echo "user: ".$users[$i]["username"]." has tdata: \"".$row["users_tokendata"]."\"\n";
+                                       if($row["users_tokendata"]!="") {
+                                               $users[$i]["hastoken"] = true;
+                                       } else {
+                                               $users[$i]["hastoken"] = false;
+                                       }
+                                       $i++; 
+                               }
+                               msg_send($cl_queue, MSG_GET_USERS, $users);
+                               
+                               // TODO now set token 
+                               break;
                                
                }               
        }       
 }
 
-?>
\ No newline at end of file
+?>