3 require_once("../lib/lib.php");
4 require_once("tokenstore.php");
6 $ga = new GoogleAuthenticator("myGetData", "mySetData");
8 if(isset($_REQUEST["action"])) {
9 switch($_REQUEST["action"]) {
11 unlink("/tmp/gadata.sqlite");
16 // create/connect a db
19 if(file_exists("/tmp/gadata.sqlite")) {
21 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
22 } catch(PDOException $exep) {
23 error_log("execpt on db open");
27 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
28 } catch(PDOException $exep) {
29 error_log("execpt on db open");
31 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT,"users_tokentype" TEXT,"users_tokenkey" TEXT,"users_tokencounter" integer);';
32 $dbobject->query($sql);
38 <h1>Example Page for GA4PHP</h1>
39 <a href="index.php">home</a><br>
42 if(isset($_REQUEST["action"])) {
43 switch($_REQUEST["action"]) {
45 $username = $_REQUEST["username"];
46 $pr = preg_match('/^[a-zA-Z0-9@\.]+$/',"$username");
48 if(strlen($username)<3) {
49 echo "<font color=\"red\">Sorry, username must be at least 3 chars</font>";
51 echo "<font color=\"red\">Sorry, username can only contain a-z, A-Z, 0-9 @ and .</font>";
53 //$key = $ga->setUser($username, "", $ttype);
54 //$keyinhex = $ga->helperb322hex($key);
55 //$url = urlencode($ga->createURL($username, $key, $ttype));
56 //echo "QRCode for user \"$username\" is <img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=120x120\"> or type in $key (google authenticator) or $keyinhex (for most other otp's)";
57 $sql = "insert into users values (NULL, '$username', 'TOTP', 'ASDF', '0')";
58 $dbobject->query($sql);
62 case "provisiontoken":
63 $username = $_REQUEST["username"];
64 $ttype = $_REQUEST["ttype"];
65 $key = $ga->setUser($username, "", $ttype);
66 $keyinhex = $ga->helperb322hex($key);
67 $url = urlencode($ga->createURL($username, $key, $ttype));
68 echo "QRCode for user \"$username\" is <img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=420x420\"> or type in $key (google authenticator) or $keyinhex (for most other otp's), $ttype";
71 $username = $_REQUEST["username"];
72 $code = $_REQUEST["code"];
73 if($ga->authenticateUser($username, $code)) {
74 echo "<font color=\"green\">Passed!</font>";
76 echo "<font color=\"red\">Failed!</font>";
80 $username = $_REQUEST["username"];
81 $code1 = $_REQUEST["code1"];
82 $code2 = $_REQUEST["code2"];
83 if($ga->resyncCode($username, $code1, $code2)) {
84 echo "<font color=\"green\">Passed!</font>";
86 echo "<font color=\"red\">Failed!</font>";
95 <h2>Destroy the DB</h2>
96 <a href="index.php?action=destroy">This is UNDOABLE - but this is a test system, so you dont care</a>
97 <h2>Create a User:</h2>
98 <form method="post" action="index.php?action=createuser">
99 Username: <input type="text" name="username"><br>
100 <input type="submit" name="go" value="go"><br>
103 <h2>Provision Token</h2>
104 <form method="post" action="index.php?action=provisiontoken">
105 Username: <select name="username">
107 $res = $ga->getUserList();
108 foreach($res as $row) {
109 echo "<option value=\"".$row."\">".$row."</option>";
113 Type: <select name="ttype"><option value="HOTP">HOTP</option><option value="TOTP">TOTP</option></select><br>
114 <input type="submit" name="go" value="go"><br>
118 <form method="post" action="index.php?action=authuser">
119 Username: <select name="username">
121 $res = $ga->getUserList();
122 foreach($res as $row) {
123 echo "<option value=\"".$row."\">".$row."</option>";
127 Code: <input type="text" name="code"><br>
128 <input type="submit" name="go" value="go"><br>
131 <h2>Resync Code (only valid for HOTP codes)</h2>
132 <form method="post" action="index.php?action=resync">
133 Username: <select name="username">
135 $res = $ga->getUserList();
136 foreach($res as $row) {
137 echo "<option value=\"".$row."\">".$row."</option>";
141 Code one: <input type="text" name="code1"><br>
142 Code two: <input type="text" name="code2"><br>
143 <input type="submit" name="go" value="go"><br>