Use the User-Password attribute instead of Password in user_test.php3
[freeradius.git] / dialup_admin / htdocs / user_admin.php3
1 <?php
2 require('../conf/config.php3');
3 ?>
4 <html>
5 <head>
6 <?php
7 require('../lib/functions.php3');
8 require('../lib/defaults.php3');
9 $date = strftime('%A, %e %B %Y, %T %Z');
10
11 if (is_file("../lib/$config[general_lib_type]/user_info.php3")){
12         include("../lib/$config[general_lib_type]/user_info.php3");
13         if ($user_exists == 'no'){
14                 echo <<<EOM
15 <title>user information page</title>
16 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
17 <link rel="stylesheet" href="style.css">
18 </head>
19 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
20 <center>
21 <form action="user_admin.php3" method=get>
22 <b>User Name&nbsp;&nbsp;</b>
23 <input type="text" size=10 name="login" value="$login">
24 <b>&nbsp;&nbsp;does not exist</b><br>
25 <input type=submit class=button value="Show User">
26 </body>
27 </html>
28 EOM;
29                 exit();
30         }
31 }
32
33 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
34         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
35 else{
36         echo <<<EOM
37 <title>user information page</title>
38 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
39 <link rel="stylesheet" href="style.css">
40 </head>
41 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
42 <center>
43 <b>Could not include SQL library functions. Aborting</b>
44 </body>
45 </html>
46 EOM;
47         exit();
48 }
49
50 $monthly_limit = ($item_vals['Max-Monthly-Session'][0] != '') ? $item_vals['Max-Monthly-Session'][0] : $default_vals['Max-Monthly-Session'][0];
51 $monthly_limit = ($monthly_limit) ? $monthly_limit : $config[counter_default_monthly];
52 $weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'][0];
53 $weekly_limit = ($weekly_limit) ? $weekly_limit : $config[counter_default_weekly];
54 $daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'][0];
55 $daily_limit = ($daily_limit) ? $daily_limit : $config[counter_default_daily];
56 $session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'][0];
57 $session_limit = ($session_limit) ? $session_limit : 'none';
58 $remaining = 'unlimited time';
59 $log_color = 'green';
60
61 $now = time();
62 $week = $now - 604800;
63 $now_str = date("$config[sql_date_format]",$now + 86400);
64 $week_str = date("$config[sql_date_format]",$week);
65 $day = date('w');
66 $week_start = date($config[sql_date_format],$now - ($day)*86400);
67 $month_start = date($config[sql_date_format],$now - date('j')*86400);
68 $today = $day;
69 $now_tmp = $now;
70 for ($i = $day; $i >-1; $i--){
71         $days[$i] = date($config[sql_date_format],$now_tmp);
72         $now_tmp -= 86400;
73 }
74 $day++;
75 //$now -= ($day * 86400);
76 $now -= 604800;
77 $now += 86400;
78 for ($i = $day; $i <= 6; $i++){
79         $days[$i] = date($config[sql_date_format],$now);
80 //      $now -= 86400;
81         $now += 86400;
82 }
83
84 $daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
85 $extra_msg = '';
86 $used = array('-','-','-','-','-','-','-');
87
88 $link = @da_sql_pconnect($config);
89 if ($link){
90         $search = @da_sql_query($link,$config,
91         "SELECT sum(AcctSessionTime),sum(AcctInputOctets),sum(AcctOutputOctets),
92         avg(AcctSessionTime),avg(AcctInputOctets),avg(AcctOutputOctets),COUNT(*) FROM
93         $config[sql_accounting_table] WHERE UserName = '$login'
94         AND AcctStartTime >= '$week_str' AND AcctStartTime <= '$now_str';");
95         if ($search){
96                 $row = @da_sql_fetch_array($search,$config);
97                 $tot_time = time2str($row['sum(AcctSessionTime)']);
98                 $tot_input = bytes2str($row['sum(AcctInputOctets)']);
99                 $tot_output = bytes2str($row['sum(AcctOutputOctets)']);
100                 $avg_time = time2str($row['avg(AcctSessionTime)']);
101                 $avg_input = bytes2str($row['avg(AcctInputOctets)']);
102                 $avg_output = bytes2str($row['avg(AcctOutputOctets)']);
103                 $tot_conns = $row['COUNT(*)'];
104         }
105         else
106                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
107         $search = @da_sql_query($link,$config,
108         "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE UserName = '$login'
109         AND AcctStartTime >= '$week_start' AND AcctStartTime <= '$now_str';");
110         if ($search){
111                 $row = @da_sql_fetch_array($search,$config);
112                 $weekly_used = $row['sum(AcctSessionTime)'];
113         }
114         else
115                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
116         if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
117                 $search = @da_sql_query($link,$config,
118                 "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE UserName = '$login'
119                 AND AcctStartTime >= '$month_start' AND AcctStartTime <= '$now_str';");
120                 if ($search){
121                         $row = @da_sql_fetch_array($search,$config);
122                         $monthly_used = $row['sum(AcctSessionTime)'];
123                 }
124                 else
125                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
126         }
127         $search = @da_sql_query($link,$config,
128         "SELECT COUNT(*) FROM $config[sql_accounting_table] WHERE UserName = '$login'
129         AND AcctStopTime >= '$week_str' AND AcctStopTime <= '$now_str'
130         AND (AcctTerminateCause LIKE 'Login-Incorrect%' OR
131         AcctTerminateCause LIKE 'Invalid-User%' OR
132         AcctTerminateCause LIKE 'Multiple-Logins%');");
133         if ($search){
134                 $row = @da_sql_fetch_array($search,$config);
135                 $tot_badlogins = $row['COUNT(*)'];
136         }
137         else
138                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
139         for($i = 0; $i <=6; $i++){
140                 if ($days[$i] == '')
141                         continue;
142                 $search = @da_sql_query($link,$config,
143                 "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE
144                 UserName = '$login' AND AcctStopTime >= '$days[$i] 00:00:00'
145                 AND AcctStopTime <= '$days[$i] 23:59:59';");
146                 if ($search){
147                         $row = @da_sql_fetch_array($search,$config);
148                         $used[$i] = $row['sum(AcctSessionTime)'];
149                         if ($daily_limit != 'none' && $used[$i] > $daily_limit)
150                                 $used[$i] = "<font color=red>" . time2str($used[$i]) . "</font>";
151                         else
152                                 $used[$i] = time2str($used[$i]);
153                         if ($today == $i){
154                                 $daily_used = $row['sum(AcctSessionTime)'];
155                                 if ($daily_limit != 'none'){
156                                         $remaining = $daily_limit - $daily_used;
157                                         if ($remaining <=0)
158                                                 $remaining = 0;
159                                         $log_color = ($remaining) ? 'green' : 'red';
160                                         if (!$remaining)
161                                                 $extra_msg = '(Out of daily quota)';
162                                 }
163                                 $daily_used = time2str($daily_used);
164                                 if ($daily_limit != 'none' && !$remaining)
165                                         $daily_used = "<font color=red>$daily_used</font>";
166                         }
167                 }
168                 else
169                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
170         }
171         if ($weekly_limit != 'none'){
172                 $tmp = $weekly_limit - $weekly_used;
173                 if ($tmp <=0){
174                         $tmp = 0;
175                         $extra_msg .= '(Out of weekly quota)';
176                 }
177                 if (!is_numeric($remaining))
178                         $remaining = $tmp;
179                 if ($remaining > $tmp)
180                         $remaining = $tmp;
181                 $log_color = ($remaining) ? 'green' : 'red';
182         }
183         $weekly_used = time2str($weekly_used);
184         if ($weekly_limit != 'none' && !$tmp)
185                 $weekly_used = "<font color=red>$weekly_used</font>";
186
187         if ($monthly_limit != 'none'){
188                 $tmp = $monthly_limit - $monthly_used;
189                 if ($tmp <=0){
190                         $tmp = 0;
191                         $extra_msg .= '(Out of monthly quota)';
192                 }
193                 if (!is_numeric($remaining))
194                         $remaining = $tmp;
195                 if ($remaining > $tmp)
196                         $remaining = $tmp;
197                 $log_color = ($remaining) ? 'green' : 'red';
198         }
199         if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
200                 $monthly_used = time2str($monthly_used);
201                 if ($monthly_limit != 'none' && !$tmp)
202                         $monthly_used = "<font color=red>$monthly_used</font>";
203         }
204         if ($session_limit != 'none'){
205                 if (!is_numeric($remaining))
206                         $remaining = $session_limit;
207                 if ($remaining > $session_limit)
208                         $remaining = $session_limit;
209         }
210
211         $search = @da_sql_query($link,$config,
212         "SELECT * FROM $config[sql_accounting_table]
213         WHERE UserName = '$login' AND AcctStopTime IS NULL
214         ORDER BY AcctStartTime DESC LIMIT 1;");
215         if ($search){
216                 if (@da_sql_num_rows($search,$config)){
217                         $logged_now = 1;
218                         $row = @da_sql_fetch_array($search,$config);
219                         $lastlog_time = $row['AcctStartTime'];
220                         $lastlog_server_ip = $row['NASIPAddress'];
221                         $lastlog_server_port = $row['NASPortId'];
222                         $lastlog_session_time = date2timediv($lastlog_time,0);
223                         if ($daily_limit != 'none'){
224                                 $remaining = $remaining - $lastlog_session_time;
225                                 if ($remaining < 0)
226                                         $remaining = 0;
227                                 $log_color = ($remaining) ? 'green' : 'red'; 
228                         }
229                         $lastlog_session_time_jvs = 1000 * $lastlog_session_time;
230                         $lastlog_session_time = time2strclock($lastlog_session_time);
231                         $lastlog_client_ip = $row['FramedIPAddress'];   
232                         $lastlog_server_name = @gethostbyaddr($lastlog_server_ip);
233                         $lastlog_client_name = @gethostbyaddr($lastlog_client_ip);
234                         $lastlog_callerid = $row['CallingStationId'];
235                         if ($lastlog_callerid == '')
236                                 $lastlog_callerid = 'not available';
237                         $lastlog_input = $row['AcctInputOctets'];
238                         if ($lastlog_input)
239                                 $lastlog_input = bytes2str($lastlog_input);
240                         else
241                                 $lastlog_input = 'not available';
242                         $lastlog_output = $row['AcctOutputOctets'];
243                         if ($lastlog_output)
244                                 $lastlog_input = bytes2str($lastlog_output);
245                         else
246                                 $lastlog_output = 'not available';
247                 }
248         }
249         else
250                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
251         if (! $logged_now){
252                 $search = @da_sql_query($link,$config,
253                 "SELECT * FROM $config[sql_accounting_table]
254                 WHERE UserName = '$login' AND AcctSessionTime != '0'
255                 ORDER BY AcctStopTime DESC LIMIT 1;");
256                 if ($search){
257                         if (@da_sql_num_rows($search,$config)){
258                                 $row = @da_sql_fetch_array($search,$config);
259                                 $lastlog_time = $row['AcctStartTime'];
260                                 $lastlog_server_ip = $row['NASIPAddress'];
261                                 $lastlog_server_port = $row['NASPortId'];
262                                 $lastlog_session_time = time2str($row['AcctSessionTime']);
263                                 $lastlog_client_ip = $row['FramedIPAddress'];   
264                 $lastlog_server_name = ($lastlog_server_ip != '') ? @gethostbyaddr($lastlog_server_ip) : '-';
265                 $lastlog_client_name = ($lastlog_client_ip != '') ? @gethostbyaddr($lastlog_client_ip) : '-';
266                                 $lastlog_callerid = $row['CallingStationId'];
267                                 if ($lastlog_callerid == '')
268                                         $lastlog_callerid = 'not available';
269                                 $lastlog_input = $row['AcctInputOctets'];
270                                 $lastlog_input = bytes2str($lastlog_input);
271                                 $lastlog_output = $row['AcctOutputOctets'];
272                                 $lastlog_output = bytes2str($lastlog_output);
273                         }
274                         else
275                                 $not_known = 1;
276                 }
277                 else
278                         echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
279         }
280 }
281 else
282         echo "<b>Could not connect to SQL database</b><br>\n";
283
284 $monthly_limit = (is_numeric($monthly_limit)) ? time2str($monthly_limit) : $monthly_limit;
285 $weekly_limit = (is_numeric($weekly_limit)) ? time2str($weekly_limit) : $weekly_limit;
286 $daily_limit = (is_numeric($daily_limit)) ? time2str($daily_limit) : $daily_limit;
287 $session_limit = (is_numeric($session_limit)) ? time2str($session_limit) : $session_limit;
288 $remaining = (is_numeric($remaining)) ? time2str($remaining) : $remaining;
289
290 if ($item_vals['Dialup-Access'][0] == 'FALSE' || (!isset($item_vals['Dialup-Access'][0]) && $attrmap['Dialup-Access'] != '' && $attrmap['Dialup-Access'] != 'none'))
291         $msg =<<<EON
292 <font color=red><b> The user account is locked </b></font>
293 EON;
294 else
295         $msg =<<<EON
296 user can login for <font color="$log_color"> <b>$remaining $extra_msg</font>
297 EON;
298 $lock_msg = $item_vals['Dialup-Lock-Msg'][0];
299 if ($lock_msg != '')
300         $descr =<<<EON
301 <font color=red><b>$lock_msg </b</font>
302 EON;
303 else
304         $descr = '-';
305
306 $expiration = $default_vals['Expiration'][0];
307 if ($item_vals['Expiration'][0] != '')
308         $expiration = $item_vals['Expiration'][0];
309 if ($expiration != ''){
310         $expiration = strtotime($expiration);
311         if ($expiration != -1 && $expiration < time())
312                 $descr = <<<EOM
313 <font color=red><b>User Account has expired</b></font>
314 EOM;
315 }
316
317 require('../html/user_admin.html.php3');