added hardware token add/list methods.
[ga4php.git] / gaas / lib / gaasdMessages.php
index 5115759..8e5aff5 100644 (file)
@@ -89,6 +89,7 @@ function gaasInitServer_server($msg)
                confSetVal("ad.clientdef", $adclientdef);
                confSetVal("ad.admindef", $adadmindef);
                confSetVal("backend", "AD");
+               confSetVal("defaulttokentype", "TOTP");
                
                $initState = true;
                $backEnd = "AD";
@@ -172,8 +173,38 @@ function gaasProvisionUser_server($msg)
 {
        
        // function userInGroup($user, $domain, $adlogin, $adpass, $group)
+       echo "in provision user\n";
+       print_r($msg);
+       $dttype = confGetVal("defaulttokentype");
+       if($dttype != "HOTP" && $dttype != "TOTP") {
+               echo "default token type not set, setting to TOTP\n";
+               confSetVal("defaulttokentype", "TOTP");
+               $dttype = "TOTP";
+       }
+       if($msg["tokentype"] == "") {
+               $ttype = confGetVal("defaulttokentype");
+       } else {
+               $ttype = $msg["tokentype"];
+       }
+       if($ttype != "HOTP" && $ttype != "TOTP") {
+               echo "using default token type, $dttype because user entered value of $ttype doesnt make sense\n";
+               $ttype = $dttype;
+       }
+       $tkey = $msg["tokenkey"];
        if(confGetVal("backend") == "AD") {
-               userInGroup($msg["username"], confGetVal("ad.domain"), confGetVal("ad.user", $adlogin), confGetVal("ad.pass"), confGetVal("ad.clientdef"));
+               if(userInGroup($msg["username"], confGetVal("ad.domain"), confGetVal("ad.user"), confGetVal("ad.pass"), confGetVal("ad.clientdef"))) {
+                       $myga = new gaasdGA();
+                       
+                       // TODO - figure out how to deal with the token origin - i.e. software/hardware
+                       if($msg["origin"] == "hardware") {
+                               echo "want a hardware token, but i dont know how to do this yet\n";
+                       } else {
+                               echo "using software token\n";
+                               $myga->setUser($msg["username"], $ttype, "", $tkey);
+                       }
+               } else {
+                       echo "User not in client group\n";
+               }
        } else {
                // internal db
        }
@@ -182,6 +213,54 @@ function gaasProvisionUser_server($msg)
        return true;
 }
 
+// TODO error check/ value check
+function gaasAddHardwareToken_server($msg)
+{
+       $tokenid = $msg["tokenid"];
+       $tokenkey = $msg["tokenkey"];
+       $tokentype = $msg["tokentype"];
+       
+       //"hardwaretokens" ("tok_id" INTEGER PRIMARY KEY AUTOINCREMENT,"tok_name" TEXT, "tok_key" TEXT, "tok_type" TEXT);';
+       print_r($msg);
+       $db = getDB();
+       $sql = "insert into hardwaretokens values (NULL, '$tokenid', '$tokenkey', '$tokentype')";
+       echo "Sql is $sql\n";
+       $ret = $db->query($sql);
+       if($ret) return true;
+       else return false;
+       
+}
+
+
+function gaasGetHardwareTokens_server($msg)
+{
+       $db = getDB();
+       
+       $sql = "select tok_name, tok_type from hardwaretokens";
+       $ret = $db->query($sql);
+       
+       $toks = "";
+       $i = 0;
+       foreach($ret as $row) {
+               $toks[$i]["name"] = $row["tok_name"];
+               $toks[$i]["type"] = $row["tok_type"];
+               $i++;
+       }
+       
+       return $toks;
+}
+
+
+function gaasAssignToken_server($msg)
+{
+       if(!isset($msg["tokenid"])) return false;
+       
+       // now, we check the username is in the client gorup
+       // now we check the token id is valid in the hardware db.
+       
+       // then we assign to the user
+}
+
 function gaasGetUsers_server($msg)
 {
        $haveTokens = $msg["havetokens"];