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