import from HEAD:
[freeradius.git] / dialup_admin / htdocs / failed_logins.php3
1 <?php
2 require('../conf/config.php3');
3 require('../lib/attrshow.php3');
4 ?>
5 <html>
6 <?php
7
8 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
9         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
10 else{
11         echo <<<EOM
12 <title>Failed logins</title>
13 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
14 <link rel="stylesheet" href="style.css">
15 </head>
16 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
17 <center>
18 <b>Could not include SQL library functions. Aborting</b>
19 </body>
20 </html>
21 EOM;
22         exit();
23 }
24
25 $now = time();
26 if ($last == 0)
27         $last = ($config[general_most_recent_fl]) ? $config[general_most_recent_fl] : 5;
28 $start = $now - ($last*60);
29 $now_str = date($config[sql_full_date_format],$now);
30 $prev_str = date($config[sql_full_date_format],$start);
31
32 $now_str = da_sql_escape_string($now_str);
33 $prev_str = da_sql_escape_string($prev_str);
34
35 $pagesize = ($pagesize) ? $pagesize : 10;
36 if (!is_numeric($pagesize) && $pagesize != 'all')
37         $pagesize = 10;
38 $limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize";
39 $selected[$pagesize] = 'selected';
40 $order = ($order != '') ? $order : $config[general_accounting_info_order];
41 if ($order != 'desc' && $order != 'asc')
42         $order = 'desc';
43 $selected[$order] = 'selected';
44 if ($callerid != ''){
45         $callerid = da_sql_escape_string($callerid);
46         $callerid_str = "AND callingstationid = '$callerid'";
47 }
48 if ($server != '' && $server != 'all'){
49         $server = da_sql_escape_string($server);
50         $server_str = "AND nasipaddress = '$server'";
51 }
52
53 ?>
54
55 <head>
56 <title>Failed Logins</title>
57 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
58 <link rel="stylesheet" href="style.css">
59 </head>
60 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
61 <center>
62 <table border=0 width=550 cellpadding=0 cellspacing=0>
63 <tr valign=top>
64 <td align=center><img src="images/title2.gif"></td>
65 </tr>
66 </table>
67 <table border=0 width=400 cellpadding=0 cellspacing=2>
68 </table>
69 <br>
70 <table border=0 width=840 cellpadding=1 cellspacing=1>
71 <tr valign=top>
72 <td width=65%></td>
73 <td bgcolor="black" width=35%>
74         <table border=0 width=100% cellpadding=2 cellspacing=0>
75         <tr bgcolor="#907030" align=right valign=top><th>
76         <font color="white">Failed Logins</font>&nbsp;
77         </th></tr>
78         </table>
79 </td></tr>
80 <tr bgcolor="black" valign=top><td colspan=2>
81         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
82         <tr><td>
83 <?php
84 echo <<<EOM
85 <b>$prev_str</b> up to <b>$now_str</b>
86 EOM;
87 ?>
88
89 <p>
90         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
91         <tr bgcolor="#d0ddb0">
92         <th>#</th><th>login</th>
93 <?php
94 if ($acct_attrs['fl'][2] != '') echo "<th>" . $acct_attrs['fl'][2] . "</th>\n";
95 if ($acct_attrs['fl'][7] != '') echo "<th>" . $acct_attrs['fl'][7] . "</th>\n";
96 if ($acct_attrs['fl'][8] != '') echo "<th>" . $acct_attrs['fl'][8] . "</th>\n";
97 if ($acct_attrs['fl'][9] != '') echo "<th>" . $acct_attrs['fl'][9] . "</th>\n";
98 $sql_extra_query = '';
99 if ($config[sql_accounting_extra_query] != '')
100         $sql_extra_query = sql_xlat($config[sql_accounting_extra_query],$login,$config);
101 ?>
102         </tr>
103
104 <?php
105 $link = @da_sql_pconnect($config);
106 if ($link){
107         $search = @da_sql_query($link,$config,
108         "SELECT acctstoptime,username,nasipaddress,nasportid,acctterminatecause,callingstationid
109         FROM $config[sql_accounting_table]
110         WHERE acctstoptime <= '$now_str' AND acctstoptime >= '$prev_str'
111         AND (acctterminatecause LIKE 'Login-Incorrect%' OR
112         acctterminatecause LIKE 'Invalid-User%' OR
113         acctterminatecause LIKE 'Multiple-Logins%') $callerid_str $server_str $sql_extra_query
114         ORDER BY acctstoptime $order $limit;");
115         if ($search){
116                 while( $row = @da_sql_fetch_array($search,$config) ){
117                         $num++;
118                         $acct_login = $row[username];
119                         if ($acct_login == '')
120                                 $acct_login = '-';
121                         else
122                                 $acct_login = "<a href=\"user_admin.php3?login=$acct_login\" title=\"Edit user $acct_login\">$acct_login</a>";
123                         $acct_time = $row[acctstoptime];
124                         $acct_server = $row[nasipaddress];
125                         if ($acct_server != ''){
126                                 $acct_server = $da_name_cache[$acct_server];
127                                 if (!isset($acct_server)){
128                                         $acct_server = $row[nasipaddress];
129                                         $acct_server = @gethostbyaddr($acct_server);
130                                         if (!isset($da_name_cache) && $config[general_use_session] == 'yes'){
131                                                 $da_name_cache[$row[nasipaddress]] = $acct_server;
132                                                 session_register('da_name_cache');
133                                         }
134                                         else
135                                                 $da_name_cache[$row[nasipaddress]] = $acct_server;
136                                 }
137                         }
138                         else
139                                 $acct_server = '-';
140                         $acct_server = "$acct_server:$row[nasportid]";
141                         $acct_terminate_cause = "$row[acctterminatecause]";
142                         if ($acct_terminate_cause == '')
143                                 $acct_terminate_cause = '-';
144                         $acct_callerid = "$row[callingstationid]";
145                         if ($acct_callerid == '')
146                                 $acct_callerid = '-';
147                         echo <<<EOM
148                         <tr align=center bgcolor="white">
149                                 <td>$num</td>
150                                 <td>$acct_login</td>
151 EOM;
152                                 if ($acct_attrs['fl'][2] != '') echo "<td>$acct_time</td>\n";
153                                 if ($acct_attrs['fl'][2] != '') echo "<td>$acct_server</td>\n";
154                                 if ($acct_attrs['fl'][2] != '') echo "<td>$acct_terminate_cause</td>\n";
155                                 if ($acct_attrs['fl'][2] != '') echo "<td>$acct_callerid</td>\n";
156                                 echo "</tr>\n";
157                 }
158         }
159         else
160                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
161 }
162 else
163         echo "<b>Could not connect to SQL database</b><br>\n";
164 echo <<<EOM
165         </table>
166 <tr><td>
167 <hr>
168 <tr><td align="left">
169         <form action="failed_logins.php3" method="get" name="master">
170         <table border=0>
171                 <tr valign="bottom">
172                         <td><small><b>time back (mins)</td><td><small><b>pagesize</td><td><small><b>caller id</td><td><b>order</td>
173         <tr valign="middle"><td>
174 <input type="text" name="last" size="11" value="$last"></td>
175 <td><select name="pagesize">
176 <option $selected[5] value="5" >05
177 <option $selected[10] value="10">10
178 <option $selected[15] value="15">15
179 <option $selected[20] value="20">20
180 <option $selected[40] value="40">40
181 <option $selected[80] value="80">80
182 <option $selected[all] value="all">all
183 </select>
184 </td>
185 <td>
186 <input type="text" name="callerid" size="11" value="$callerid"></td>
187 <td><select name="order">
188 <option $selected[asc] value="asc">older first
189 <option $selected[desc] value="desc">recent first
190 </select>
191 </td>
192 EOM;
193 ?>
194
195 <td><input type="submit" class=button value="show"></td></tr>
196 <tr><td>
197 <b>On Access Server:</b>
198 </td></tr><tr><td>
199 <select name="server">
200 <?php
201 foreach ($nas_list as $nas){
202         $name = $nas[name];
203         $servers[$name] = $nas[ip];
204 }
205 ksort($servers);
206 foreach ($servers as $name => $ip){
207         if ($server == $ip)
208                 echo "<option selected value=\"$ip\">$name\n";
209         else
210                 echo "<option value=\"$ip\">$name\n";
211 }
212 if ($server == '' || $server == 'all')
213         echo "<option selected value=\"all\">all\n";
214 else
215         echo "<option value=\"all\">all\n";
216 ?>
217 </select>
218 </td></tr>
219 </table></td></tr></form>
220 </table>
221 </tr>
222 </table>
223 </body>
224 </html>