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