Radius clients
[ga4php.git] / authserver / www / admin.php
1 <?php
2 /*
3  * This is the web component of the GA4PHP radius server. This web app should be able to configure freeradius and itself.
4  * 
5  * This app will try to do the following:
6  * 1) initialise tokens
7  * 2) pull accounts from some backend (such as AD)
8  * 3) allow users to self-enroll.
9  * 
10  * I wonder if we can store data in the backend database itself? that would be interesting
11  * then user admin would be less disconnected. I.e. if a user was deleted from AD, their token
12  * data should disappear with them.
13  */
14 require_once("admin_actions.php");
15
16 // the logged in component
17 if($loggedin) {
18 ?>
19 <h1>GAAS Manager</h1>
20 Welcome to the Google Authenticator Authentication Server Manager Application - <a href="?showhelp">Show Help</a><br>
21
22 <?php 
23 if(isset($_REQUEST["message"])) {
24         echo "<font color=\"green\">".$_REQUEST["message"]."</font>";
25
26 if(isset($_REQUEST["error"])) {
27         echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
28
29
30
31 if(isset($_REQUEST["showhelp"])) {
32         echo "<hr>";
33         ?>
34 On this page, you create users and manage their tokens and passwords. A few notes,<br>
35 <li> Passwords are *ONLY* for this page, if you assign a password to a user they can login here
36 and edit anyone, including you
37 <li> OTK/One-Time-Keys are the QRcode for provisioning a GA token, it can only be viewed once
38 and once viewed is deleted. If you need a new one, you need to re-create a key.
39 <li> TOTP tokens are time based tokens that change every 30 seconds, HOTP tokens are event tokens
40 that change everytime they are used or generated
41 <li> In the OTK, the "Get (User URL)" link is a link you can send to a user to retrieve their key
42         <?php 
43
44
45 if(isset($_REQUEST["edituser"])) {
46         $username = $_REQUEST["edituser"];
47 ?>
48
49 <h2>Editing user, <?php echo $username ?></h2><br>
50 <form method="post" action="?action=edituser&username=<?php echo $username ?>">
51 <input type="hidden" name="original_real" value="<?php echo $_REQUEST["realname"] ?>">
52 <table>
53 <tr><td>Real Name:</td><td><input type="text" name="realname" value="<?php echo $_REQUEST["realname"] ?>"></td></tr>
54 <tr><td>Password:</td><td><input type="password" name="password"></td></tr>
55 <tr><td>Confirm Password:</td><td><input type="password" name="password_conf"></td></tr>
56 </table>
57 <input type="submit" value="Update">
58 </form>
59 <?php
60 if($myAC->getUserTokenType($username)=="HOTP") {
61 ?> 
62 <form method="post" action="?action=synctoken&username=<?php echo $username?>">
63 <h3>Resync Tokens</h3>
64 <table>
65 <tr><td>Token One</td><td><input type="text" name="tokenone"></td></tr>
66 <tr><td>Token Two</td><td><input type="text" name="tokentwo"></td></tr>
67 </table>
68 <input type="submit" value="Sync">
69 </form>
70 <?php
71 }
72 ?> 
73
74 <form method="post" action="?action=customtoken&username=<?php echo $username ?>">
75 <h3>Custom Tokens</h3><br>
76 For assiging in a user-created or hardware tokens.<br>
77 If you assign a token this way, any previous token is removed and forever gone.<br>
78 Token Key (hex) <input type="text" name="tokenkey"><br>
79 Token Type 
80 <select name="tokentype">
81 <option value="HOTP">HOTP</option>
82 <option value="TOTP">TOTP</option>
83 </select><br>
84 <input type="submit" value="Set">
85 </form>
86 <?php
87 } else if(isset($_REQUEST["editclient"])) {
88 ?>
89 this page is for editing radius clients, it doesnt exist yet.. What you need to do is delete the client and re-add it... go <a href="admin.php">back</a>
90 </html>
91 <?php 
92 } else {
93 ?>
94 <hr><h2>Users</h2>
95 <table border="1">
96 <tr><th>Username</th><th>RealName</th><th>Has Password?</th><th>Has Token?</th><th>One Time Key</th><th>Delete</th></tr>
97 <?php
98 $users = $myAC->getUsers();
99 foreach($users as $user) {
100         $username = $user["username"];
101         
102         if($user["realname"] == "") $realname = "";
103         else $realname = $user["realname"];
104         
105         if($user["haspass"]) $haspass = "Yes <a href=\"?action=deletepass&username=$username\">Delete Password</a>";
106         else $haspass = "No";
107         
108         if($user["otk"]=="deleted") $otk = "OTK Was Not Picked Up";
109         else if($user["otk"]!="") $otk = "<a href=\"?action=getotk&username=$username&otk=".$user["otk"]."\">Get (admin)</a> <a href=\"index.php?gettoken&username=$username&otkid=".$user["otk"]."\">Get (User URL)</a>";
110         else $otk = "Already Claimed";
111         
112         if($user["hastoken"]) $hastoken = "Yes <a href=\"?action=recreatehotptoken&username=$username\">Re-Create (HOTP)</a> <a href=\"?action=recreatetotptoken&username=$username\">Re-Create (TOTP)</a> <a href=\"?action=deletetoken&username=$username\">Delete</a>";
113         else {
114                 $hastoken = "No <a href=\"?action=recreatehotptoken&username=$username\">Create (HOTP)</a> <a href=\"?action=recreatetotptoken&username=$username\">Create (TOTP)</a>";
115                 if($user["otk"]!="deleted")$otk = "No Token Exists";
116         }
117         
118         $delete = "<a href=\"?action=delete&username=$username\">Delete</a>";
119         
120         echo "<tr>";
121         echo "<td><a href=\"?edituser=$username&realname=$realname\">$username</a></td><td>$realname</td><td>$haspass</td>";
122         echo "<td>$hastoken</td><td>$otk</td><td>$delete</td><tr></form>";
123 }
124 ?>
125 </table><br>
126 <form method="post" action="?action=createuser">Create User(s) - Enter a comma seperated list of usernames: <input type="text" name="username" size="120"> <input type="submit" value="Create"></form>
127
128 <?php
129
130
131 if(isset($_REQUEST["action"])) if($_REQUEST["action"] == "getotk") {
132         $username = $_REQUEST["username"];
133         $otk = $_REQUEST["otk"];
134         echo "<hr>Got One Time Key for user $username, this one-time-key can only be retrieved once, after that it is deleted<br>";
135         echo "<img src=\"?action=getotkimg&username=$username&otk=$otk\" alt=\"one time key error\"><br>";
136
137
138 ?>
139 <hr><h2>Radius Clients</h2>
140 <table border="1">
141 <tr><th>Name</th><th>IP Address</th><th>Description</th><th>Delete</th></tr>
142 <?php
143 $msg = $myAC->getRadiusClients();
144 foreach($msg as $client) {
145         if($client["desc"]=="") $desc = "no description set";
146         else $desc = $client["desc"];
147         $clientname = $client["name"];
148         $clientip = $client["ip"];
149         echo "<tr><td><a href=\"?editclient=$clientname\">$clientname</a></td><td>$clientip</td><td>$desc</td><td><a href=\"?action=deleteradclient&clientname=$clientname\">Delete</a></td></tr>";
150 }
151 ?>
152 </table>
153 <br>
154 <h3>Add a Radius Client</h3>
155 <form method="post" action="?action=addradclient">
156 <table>
157 <tr><td>Client Name</td><td><input type="text" name="clientname"></td></tr>
158 <tr><td>Client IP</td><td><input type="text" name="clientip"></td></tr>
159 <tr><td>Client Secret</td><td><input type="text" name="clientsecret"></td></tr>
160 <tr><td>Client Description</td><td><input type="text" name="clientdesc"></td></tr>
161 </table>
162 <input type="submit" name="go" value="add">
163 </form>
164 <hr><a href="?action=logout">Logout</a> <a href="admin.php">Home</a>
165
166 <?php 
167 } // edit users
168
169 } else {
170         
171         
172         
173         
174         
175         
176         
177         
178         
179         
180         // Login page
181 ?>
182 <h1>GAAS Manager Login</h1>
183 <?php
184 if(isset($_REQUEST["message"])) {
185         echo "<font color=\"green\">".$_REQUEST["message"]."</font>";
186
187 if(isset($_REQUEST["error"])) {
188         echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
189
190 ?>
191 <form method="post" action="?action=login">
192 <table>
193 <tr><td>Username</td><td><input type="text" name="username"></td></tr>
194 <tr><td>Password</td><td><input type="password" name="password"></td></tr>
195 <tr><td><input type="submit" value="Go"></td></tr>
196 </table>
197 </form>
198 <?php
199 } //loggedin
200 ?>