Created a provisioning example
[ga4php.git] / example / provisioning / index.php
1 <?php 
2 /*
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
6  * 
7  */
8
9 // Require our php libraries
10 require_once("token.php");
11 require_once("dbfunctions.php");
12 require_once("input.php");
13
14 // now lets get an instance of our class
15 $myga = new myGA();
16 global $myga;
17
18 // this part of the page resonds to user input
19 processInput();
20 ?>
21
22 <html>
23 <h1>Welcome to GA Provisioning!</h1>
24
25 <?php 
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>";
29 }
30 if(isset($_REQUEST["failure"])) {
31         echo "<br><font color=\"red\">".$_REQUEST["failure"]."</font><br>";
32 }
33 ?>
34
35 <hr>
36
37
38
39 <h2>Users</h2>
40 <table border="1">
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>
42 <?php
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
46 // you do it.
47 $db = getDatabase();
48 $result = $db->query("select * from users");
49 foreach($result as $row) {
50         if($myga->hasToken($row["users_username"])) {
51                 $hastoken = "Yes";
52                 $type = $myga->getTokenType($row["users_username"]);
53                 if($type == "HOTP") {
54                         $type = "- Counter Based";
55                 } else {
56                         $type = "- Time Based";
57                 }
58                 $hexkey = $myga->getKey($row["users_username"]);
59                 $b32key = $myga->helperhex2b32($hexkey);
60                 
61                 $url = urlencode($myga->createURL($row["users_username"]));
62                 $keyurl = "<img src=\"http://chart.apis.google.com/chart?cht=qr&chl=$url&chs=100x100\">";
63                 
64         }
65         else {
66                 $b32key = "";
67                 $hexkey = "";
68                 $type = "";
69                 $hastoken = "no";
70                 $keyurl = "";
71         }
72         
73         
74         // now we generate the qrcode for the user
75         
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>";
77 }
78 closeDatabase($db);
79 ?>
80 </table>
81 Create a User:
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">
86 </form>
87
88
89 <hr>
90
91
92
93 <h2>Create Token</h2>
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">
97 <?php
98 // here we list the users again for a select clause
99 $db = getDatabase();
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";
104         
105         $username = $row["users_username"];
106         
107         echo "<option value=\"$username\">$username $hastoken</option>";
108 }
109 closedatabase($db);
110 ?>
111 </select>
112 <br>
113 Token Type
114 <select name="tokentype">
115 <option value="HOTP">Counter Based</option>
116 <option value="TOTP">Time Based</option>
117 </select>
118 <input type="submit" name="Add" value="Add">
119 </form>
120
121 <hr>
122 <h2>Test Authentication</h2>
123 <form method="post" action="?action=auth">
124 User:<select name="user">
125 <?php
126 // here we list the users again for a select clause
127 $db = getDatabase();
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";
132         
133         $username = $row["users_username"];
134         
135         echo "<option value=\"$username\">$username $hastoken</option>";
136 }
137 closedatabase($db);
138 ?>
139 <input type="text" name="tokencode">
140 <input type="submit" name="Auth" value="Auth">
141 </select>
142
143
144 <pre>
145 <?php 
146
147 print_r($myga->internalGetData("asdf"));
148 ?>
149 </pre>
150
151 </html>