Remember a few things in the user_test page. Also add another configuration file...
[freeradius.git] / dialup_admin / htdocs / user_test.php3
1 <?php
2 require('../conf/config.php3');
3 if (is_file("../lib/$config[general_lib_type]/user_info.php3"))
4         include("../lib/$config[general_lib_type]/user_info.php3");
5
6 if ($login == 'da_server_test'){
7         $login = $config[general_test_account_login];
8         $test_login=1;
9 }
10
11 echo <<<EOM
12 <html>
13 <head>
14 <title>test user $login ($cn)</title>
15 <link rel="stylesheet" href="style.css">
16 </head>
17 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
18 <center>
19 <table border=0 width=550 cellpadding=0 cellspacing=0>
20 <tr valign=top>
21 <td align=center><img src="images/title2.gif"></td>
22 </tr>
23 </table>
24
25 <table border=0 width=400 cellpadding=0 cellspacing=2>
26 EOM;
27
28 if (!$test_login)
29         include("../html/user_toolbar.html.php3");
30
31 print <<<EOM
32 </table>
33
34 <br>
35 <table border=0 width=540 cellpadding=1 cellspacing=1>
36 <tr valign=top>
37 <td width=340></td>
38 <td bgcolor="black" width=200>
39         <table border=0 width=100% cellpadding=2 cellspacing=0>
40         <tr bgcolor="#907030" align=right valign=top><th>
41 EOM;
42
43 if ($test_login){
44         print <<<EOM
45         <font color="white">Radius Server Test Page</font>&nbsp;
46 EOM;
47 }else{
48         print <<<EOM
49         <font color="white">User $login Test Page</font>&nbsp;
50 EOM;
51 }
52 ?>
53         </th></tr>
54         </table>
55 </td></tr>
56 <tr bgcolor="black" valign=top><td colspan=2>
57         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
58         <tr><td>
59
60 <?php
61 if ($server == '')
62         $server = $config[general_radius_server];
63 if ($port == 0)
64         $port = $config[general_radius_server_port];
65 if ($auth_proto == '')
66         $auth_proto = $config[general_radius_server_auth_proto];
67 $selected[$auth_proto] = 'selected';
68
69 if ($test_user == 1){
70         $tmp_file = tempnam("$config[general_tmp_dir]",'DA');
71         $req=file($config[general_auth_request_file]);
72         if ($config[general_ld_library_path] != '')
73                 putenv("LD_LIBRARY_PATH=$config[general_ld_library_path]");
74         $comm = $config[general_radclient_bin] . " $server:$port" . ' auth ' . $config[general_radius_server_secret] 
75                 . ' >' . $tmp_file;
76         $fp = popen("$comm","w");
77         if ($fp){
78                 foreach ($req as $val){
79                         // Ignore comments
80                         if (ereg('^[[:space:]]*#',$val) || ereg('^[[:space:]]*$',$val))
81                                 continue;
82                         fwrite($fp,$val);
83                 }
84                 if ($test_login){
85                         $test=1;
86                         fwrite($fp, "User-Name = \"$config[general_test_account_login]\"\n");
87                         fwrite($fp, "Password = \"$config[general_test_account_password]\"\n");
88                         pclose($fp);
89                 }
90                 else{
91                         fwrite($fp, "User-Name = \"$login\"\n");
92                         if ($auth_proto == 'pap')
93                                 fwrite($fp, "Password = \"$passwd\"\n");
94                         else if ($auth_proto == 'chap')
95                                 fwrite($fp, "CHAP-Password = \"$passwd\"\n");
96                         if (strlen($extra))
97                                 fwrite($fp,$extra);
98                         pclose($fp);
99                 }
100                 $reply = file($tmp_file);
101                 unlink($tmp_file);
102                 $msg = "<b>" . strftime('%A, %e %B %Y, %T %Z') . "</b><br>\n";
103                 $msg .= "<b>Server: </b><i>$server:$port</i><br><br>\n";
104                 if (ereg('code 2', $reply[0]))
105                         $msg .= "<b>Authentication was <font color=green>successful</font>";
106                 else if (ereg('code 3',$reply[0]))
107                         $msg .= "<b>Authentication <font color=red>failed</font>";
108                 else if (ereg('no response from server', $reply[0]))
109                         $msg .= "<b><font color=red>No response from server</font>";
110                 else if (ereg('Connection refused',$reply[0]))
111                         $msg .= "<b><font color=red>Connection was refused</font>";
112                 if ($test_login)
113                         $msg .= "</b><i> (test user $login)</i><br>\n";
114                 else
115                         $msg .= "</b><br>\n";
116                 array_shift($reply);
117                 if (count($reply)){
118                         $msg .= "<br><b>Server response:</b><br>\n";
119                         foreach ($reply as $val){
120                                 $msg .= "<i>$val</i><br>\n";
121                         }
122                 }
123                 if ($test_login){
124                         print <<<EOM
125 $msg
126 <br>
127 </td></tr>
128 </table>
129 </tr>
130 </table>
131 </body>
132 </html>
133 EOM;
134                         exit();
135                 }
136
137         }
138 }
139 ?>
140    <form method=post>
141       <input type=hidden name=login value=<?php print $login ?>>
142       <input type=hidden name=test_user value="0">
143         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
144 <tr>
145 <td align=right bgcolor="#d0ddb0">
146 User Password
147 </td>
148 <td>
149 <input type=password name=passwd value="<?php print $passwd ?>" size=25>
150 </td>
151 </tr>
152 <tr>
153 <td align=right bgcolor="#d0ddb0">
154 Radius Server
155 </td>
156 <td>
157 <input type=text name=server value="<?php print $server ?>" size=25>
158 </td>
159 </tr>
160 <tr>
161 <td align=right bgcolor="#d0ddb0">
162 Radius Server Port
163 </td>
164 <td>
165 <input type=text name=port value="<?php print $port ?>" size=25>
166 </td>
167 </tr>
168 <tr>
169 <td align=right bgcolor="#d0ddb0">
170 Extra Attributes
171 </td>
172 <td>
173 <textarea name="extra" cols="35" wrap="PHYSICAL" rows="4"><?php print $extra ?></textarea>
174 </td>
175 </tr>
176 <tr>
177 <td align=right bgcolor="#d0ddb0">
178 Authentication Protocol
179 </td>
180 <td>
181 <?php
182 echo <<<EOM
183 <select name="auth_proto" editable>
184 <option $selected[pap] value="pap">PAP
185 <option $selected[chap] value="chap">CHAP
186 EOM
187 ?>
188 </select>
189 </td>
190 </tr>
191
192         </table>
193 <br>
194 <input type=submit class=button value="Run Test" OnClick="this.form.test_user.value=1">
195 </form>
196 <?php
197 if ($test_user == 1){
198         echo <<<EOM
199 <br>
200 $msg
201 EOM;
202 }
203 ?>
204         </td></tr>
205 </table>
206 </tr>
207 </table>
208 </body>
209 </html>