3 * This example is simply an example of how a provisioning page may look
4 * which includes such funcationality as createing users, initialising their
5 * data, create a token for them, testing the token and resyncing it as needed
9 // Require our php libraries
10 require_once("token.php");
11 require_once("dbfunctions.php");
12 require_once("input.php");
14 // now lets get an instance of our class
18 // this part of the page resonds to user input
23 <h1>Welcome to GA Provisioning!</h1>
26 // in this part of the code we look for "success" or "fail" things
27 if(isset($_REQUEST["success"])) {
28 echo "<br><font color=\"green\">".$_REQUEST["success"]."</font><br>";
30 if(isset($_REQUEST["failure"])) {
31 echo "<br><font color=\"red\">".$_REQUEST["failure"]."</font><br>";
41 <tr><th>Username/Login</th><th>Fullname</th><th>Has Token?</th><th>Key</th><th>Base 32 Key</th><th>Hex Key</th></tr>
43 // now we get our list of users - this part of the page just has a list of users
44 // and the ability to create new ones. This isnt really in the scope of the
45 // GA4PHP, but for this example, we need to be able to create users, so heres where
48 $result = $db->query("select * from users");
49 foreach($result as $row) {
50 if($myga->hasToken($row["users_username"])) {
52 $type = $myga->getTokenType($row["users_username"]);
54 $type = "- Counter Based";
56 $type = "- Time Based";
58 $hexkey = $myga->getKey($row["users_username"]);
59 $b32key = $myga->helperhex2b32($hexkey);
61 $url = urlencode($myga->createURL($row["users_username"]));
62 $keyurl = "<img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=100x100\">";
74 // now we generate the qrcode for the user
76 echo "<tr><td>".$row["users_username"]."</td><td>".$row["users_fullname"]."</td><td>$hastoken $type</td><td>$keyurl</td><td>$b32key</td><td>$hexkey</td></tr>";
82 <form method="post" action="?action=createuser">
83 Username/login: <input type="text" name="username">
84 Full Name: <input type="text" name="fullname">
85 <input type="submit" name="Add" value="Add">
94 This form allows you to provision a token for the user<br>
95 <form method="post" action="?action=provision">
96 User:<select name="user">
98 // here we list the users again for a select clause
100 $result = $db->query("select * from users");
101 foreach($result as $row) {
102 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
103 else $hastoken = "- No token";
105 $username = $row["users_username"];
107 echo "<option value=\"$username\">$username $hastoken</option>";
114 <select name="tokentype">
115 <option value="HOTP">Counter Based</option>
116 <option value="TOTP">Time Based</option>
118 <input type="submit" name="Add" value="Add">
122 <h2>Test Authentication</h2>
123 <form method="post" action="?action=auth">
124 User:<select name="user">
126 // here we list the users again for a select clause
128 $result = $db->query("select * from users");
129 foreach($result as $row) {
130 if($myga->hasToken($row["users_username"])) $hastoken = "- Has a token";
131 else $hastoken = "- No token";
133 $username = $row["users_username"];
135 echo "<option value=\"$username\">$username $hastoken</option>";
139 <input type="text" name="tokencode">
140 <input type="submit" name="Auth" value="Auth">
147 print_r($myga->internalGetData("asdf"));