5 if(isset($_REQUEST["action"])) {
6 switch($_REQUEST["action"]) {
8 unlink("/tmp/gadata.sqlite");
15 if(file_exists("/tmp/gadata.sqlite")) {
17 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
18 } catch(PDOException $exep) {
19 error_log("execpt on db open");
23 $dbobject = new PDO("sqlite:/tmp/gadata.sqlite");
24 } catch(PDOException $exep) {
25 error_log("execpt on db open");
27 $sql = 'CREATE TABLE "users" ("users_id" INTEGER PRIMARY KEY AUTOINCREMENT,"users_username" TEXT,"users_fullname" TEXT,"users_tokendata" TEXT);';
28 $dbobject->query($sql);
32 require_once("tokenstore.php");
34 $ga = new myGoogleAuth();
41 <h1>Example Page for GA4PHP</h1>
42 <a href="index.php">home</a><br>
45 error_log("start switch");
46 if(isset($_REQUEST["action"])) {
47 switch($_REQUEST["action"]) {
49 $username = $_REQUEST["username"];
50 $fullname = $_REQUEST["fullname"];
51 $pr = preg_match('/^[a-zA-Z0-9@\.]+$/',"$username");
53 if(strlen($username)<3) {
54 echo "<font color=\"red\">Sorry, username must be at least 3 chars</font>";
56 echo "<font color=\"red\">Sorry, username can only contain a-z, A-Z, 0-9 @ and .</font>";
58 //$key = $ga->setUser($username, "", $ttype);
59 //$keyinhex = $ga->helperb322hex($key);
60 //$url = urlencode($ga->createURL($username, $key, $ttype));
61 //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)";
62 $sql = "insert into users values (NULL, '$username', '$fullname', '0')";
63 $dbobject->query($sql);
67 case "provisiontoken":
68 error_log("in provision");
69 $username = $_REQUEST["username"];
70 $ttype = $_REQUEST["ttype"];
71 $key = $ga->setUser($username, "", $ttype);
72 $keyinhex = $ga->helperb322hex($key);
73 $url = urlencode($ga->createURL($username, $key, $ttype));
74 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";
77 $username = $_REQUEST["username"];
78 $code = $_REQUEST["code"];
79 if($ga->authenticateUser($username, $code)) {
80 echo "<font color=\"green\">Passed!</font>";
82 echo "<font color=\"red\">Failed!</font>";
86 $username = $_REQUEST["username"];
87 $code1 = $_REQUEST["code1"];
88 $code2 = $_REQUEST["code2"];
89 if($ga->resyncCode($username, $code1, $code2)) {
90 echo "<font color=\"green\">Passed!</font>";
92 echo "<font color=\"red\">Failed!</font>";
103 <tr><th>Username</th><th>FullName</th></tr>
105 $res = $dbobject->query("select * from users");
106 foreach($res as $row) {
107 $username = $row["users_username"];
108 $fullname = $row["users_fullname"];
109 echo "<tr><th>$username</th><th>$fullname</th></tr>";
114 <h2>Destroy the DB</h2>
115 <a href="index.php?action=destroy">This is not UNDOABLE - but this is a test system, so you dont care</a>
117 <h2>Create a User:</h2>
118 <form method="post" action="index.php?action=createuser">
119 Username: <input type="text" name="username"><br>
120 Full Name: <input type="text" name="fullname"><br>
121 <input type="submit" name="go" value="go"><br>
128 <h2>Provision Token</h2>
129 <form method="post" action="index.php?action=provisiontoken">
130 Username: <select name="username">
132 $res = $ga->getUsers();
133 foreach($res as $row) {
134 echo "<option value=\"".$row."\">".$row."</option>";
138 Type: <select name="ttype"><option value="HOTP">HOTP</option><option value="TOTP">TOTP</option></select><br>
139 <input type="submit" name="go" value="go"><br>
147 <form method="post" action="index.php?action=authuser">
148 Username: <select name="username">
150 $res = $ga->getUsers();
151 foreach($res as $row) {
152 echo "<option value=\"".$row."\">".$row."</option>";
156 Code: <input type="text" name="code"><br>
157 <input type="submit" name="go" value="go"><br>
164 <h2>Resync Code (only valid for HOTP codes)</h2>
165 <form method="post" action="index.php?action=resync">
166 Username: <select name="username">
168 $res = $ga->getUsers();
169 foreach($res as $row) {
170 echo "<option value=\"".$row."\">".$row."</option>";
174 Code one: <input type="text" name="code1"><br>
175 Code two: <input type="text" name="code2"><br>
176 <input type="submit" name="go" value="go"><br>