Freeradius users script added
[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 delete the user and re-create.
39         <?php 
40
41
42 if(isset($_REQUEST["edituser"])) {
43         $username = $_REQUEST["edituser"];
44 ?>
45
46 <h2>Editing user, <?php echo $username ?></h2><br>
47 <form method="post" action="?action=edituser&username=<?php echo $username ?>">
48 <input type="hidden" name="original_real" value="<?php echo $_REQUEST["realname"] ?>">
49 <table>
50 <tr><td>Real Name:</td><td><input type="text" name="realname" value="<?php echo $_REQUEST["realname"] ?>"></td></tr>
51 <tr><td>Password:</td><td><input type="password" name="password"></td></tr>
52 <tr><td>Confirm Password:</td><td><input type="password" name="password_conf"></td></tr>
53 </table>
54 <input type="submit" value="Update">
55 </form>
56 <form method="post" action="?action=customtoken&username=<?php echo $username ?>">
57 <h3>Custom Tokens - doesnt work yet</h3><br>
58 For assiging in a user-created or hardware tokens<br>
59 Token Key (hex) <input type="text" name="tokenkey"><br>
60 Token Type 
61 <select name="tokentype">
62 <option value="HOTP">HOTP</option>
63 <option value="TOTP">TOTP</option>
64 </select><br>
65 <input type="submit" value="Set">
66 </form>
67 <?php
68 } else {
69 ?>
70 <hr><h2>Users</h2>
71 <table border="1">
72 <tr><th>Username</th><th>RealName</th><th>Has Password?</th><th>Has Token?</th><th>One Time Key</th><th>Delete</th></tr>
73 <?php
74 $users = $myAC->getUsers();
75 foreach($users as $user) {
76         $username = $user["username"];
77         
78         if($user["realname"] == "") $realname = "";
79         else $realname = $user["realname"];
80         
81         if($user["haspass"]) $haspass = "Yes <a href=\"?action=deletepass&username=$username\">Delete Password</a>";
82         else $haspass = "No";
83         
84         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>";
85         else $hastoken = "No <a href=\"?action=recreatehotptoken&username=$username\">Create (hotp)</a> <a href=\"?action=recreatetotptoken&username=$username\">Create (totp)</a>";
86         
87         if($user["otk"]!="") $otk = "<a href=\"?action=getotk&username=$username&otk=".$user["otk"]."\">Get</a>";
88         else $otk = "Already Claimed";
89         
90         $delete = "<a href=\"?action=delete&username=$username\">Delete</a>";
91         
92         echo "<tr>";
93         echo "<td><a href=\"?edituser=$username&realname=$realname\">$username</a></td><td>$realname</td><td>$haspass</td>";
94         echo "<td>$hastoken</td><td>$otk</td><td>$delete</td><tr></form>";
95 }
96 ?>
97 </table><br>
98 <form method="post" action="?action=createuser">Create User(s) - Enter a comma seperated list of names: <input type="text" name="username" size="120"> <input type="submit" value="Create"></form>
99
100 <?php
101
102
103 if(isset($_REQUEST["action"])) if($_REQUEST["action"] == "getotk") {
104         $username = $_REQUEST["username"];
105         $otk = $_REQUEST["otk"];
106         echo "<hr>Got One Time Key for user $username, this one-time-key can only be retrieved once, after that it is deleted<br>";
107         echo "<img src=\"?action=getotkimg&username=$username&otk=$otk\" alt=\"one time key error\"><br>";
108
109
110 ?>
111 <hr><h2>Radius Clients</h2>
112 Not yet implemented
113
114 <hr><a href="?action=logout">Logout</a> <a href="admin.php">Home</a>
115
116 <?php 
117 } // edit users
118
119 } else {
120         
121         
122         
123         
124         
125         
126         
127         
128         
129         
130         // Login page
131 ?>
132 <h1>GAAS Manager Login</h1>
133 <?php
134 if(isset($_REQUEST["message"])) {
135         echo "<font color=\"green\">".$_REQUEST["message"]."</font>";
136
137 if(isset($_REQUEST["error"])) {
138         echo "<font color=\"red\">".$_REQUEST["error"]."</font>";
139
140 ?>
141 <form method="post" action="?action=login">
142 <table>
143 <tr><td>Username</td><td><input type="text" name="username"></td></tr>
144 <tr><td>Password</td><td><input type="password" name="password"></td></tr>
145 <tr><td><input type="submit" value="Go"></td></tr>
146 </table>
147 </form>
148 <?php
149 } //loggedin
150 ?>