X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=authserver%2Fauthd%2Fauthd.php;h=bd102671f08be372522e883e8dc04d7f7de3a6c3;hp=afe3883aeb30a3182e2c3d50325cf54eb669c7cd;hb=34cbcba6d0f7c0a92c849545712cc5ce7ec03f97;hpb=07e42724b584df5d317a72b0e0ed1bafbc744b8f diff --git a/authserver/authd/authd.php b/authserver/authd/authd.php index afe3883..bd10267 100644 --- a/authserver/authd/authd.php +++ b/authserver/authd/authd.php @@ -49,6 +49,34 @@ if($pid == -1) { $authval = $myga->authenticateUser($username, $passcode); msg_send($cl_queue, MSG_AUTH_USER_TOKEN, $authval); break; + + case MSG_GET_OTK_PNG: + if(!isset($msg["username"])) { + msg_send($cl_queue, MSG_GET_OTK_PNG, false); + } else { + $username = $msg["username"]; + $sql = "select users_otk from users where users_username='$username'"; + $dbo = getDatabase(); + $res = $dbo->query($sql); + $otk = ""; + foreach($res as $row) { + $otk = $row["users_otk"]; + } + + if($otk == "") { + msg_send($cl_queue, MSG_GET_OTK_PNG, false); + } else { + $hand = fopen("otks/$otk.png", "rb"); + $data = fread($hand, filesize("otks/$otk.png")); + fclose($hand); + msg_send($cl_queue, MSG_GET_OTK_PNG, $data); + unlink("otks/$otk.png"); + $sql = "update users set users_otk='' where users_username='$username'"; + $dbo->query($sql); + } + } + + break; case MSG_ADD_USER_TOKEN: echo "Call to add user token\n"; if(!isset($msg["username"])) { @@ -66,7 +94,16 @@ if($pid == -1) { global $myga; $myga->setUser($username, $tokentype, "", $hexkey); - msg_send($cl_queue, MSG_ADD_USER_TOKEN, $myga->createUrl($username)); + $url = $myga->createUrl($username); + mkdir("otks"); + $otk = generateRandomString(); + system("qrencode -o otks/$otk.png $url"); + + $sql = "update users set users_otk='$otk' where users_username='$username'"; + $dbo = getDatabase(); + $res = $dbo->query($sql); + + msg_send($cl_queue, MSG_ADD_USER_TOKEN, true); } break; case MSG_DELETE_USER: