3420623532501d54812d6727b9f04857672bc41f
[freeradius.git] / dialup_admin / htdocs / user_admin.php3
1 <html>
2 <head>
3 <?php
4 require('../conf/config.php3');
5 require('../lib/functions.php3');
6 require('../lib/defaults.php3');
7
8 $date = strftime('%A, %e %B %Y, %T %Z');
9
10 if (is_file("../lib/$config[general_lib_type]/user_info.php3")){
11         include("../lib/$config[general_lib_type]/user_info.php3");
12         if ($user_exists == 'no'){
13                 echo <<<EOM
14 <title>user information page</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 <form action="user_admin.php3" method=get>
20 <b>User Name&nbsp;&nbsp;</b>
21 <input type="text" size=10 name="login" value="$login">
22 <b>&nbsp;&nbsp;does not exist</b><br>
23 <input type=submit class=button value="Show User">
24 </body>
25 </html>
26 EOM;
27                 exit();
28         }
29 }
30
31 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
32         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
33 else{
34         echo <<<EOM
35 <title>user information page</title>
36 <link rel="stylesheet" href="style.css">
37 </head>
38 <body bgcolor="#80a040" background="images/greenlines1.gif" link="black" alink="black">
39 <center>
40 <b>Could not include SQL library functions. Aborting</b>
41 </body>
42 </html>
43 EOM;
44         exit();
45 }
46
47 $monthly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'];
48 $monthly_limit = ($monthly_limit) ? $monthly_limit : $config[counter_default_monthly];
49 $weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'];
50 $weekly_limit = ($weekly_limit) ? $weekly_limit : $config[counter_default_weekly];
51 $daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'];
52 $daily_limit = ($daily_limit) ? $daily_limit : $config[counter_default_daily];
53 $session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'];
54 $session_limit = ($session_limit) ? $session_limit : 'none';
55 $remaining = 'unlimited time';
56 $log_color = 'green';
57
58 $now = time();
59 $week = $now - 604800;
60 $now_str = date("$config[sql_date_format]",$now + 86400);
61 $week_str = date("$config[sql_date_format]",$week);
62 $day = date('w');
63 $week_start = date($config[sql_date_format],$now - ($day)*86400);
64 $today = $day;
65 $now_tmp = $now;
66 for ($i = $day; $i >-1; $i--){
67         $days[$i] = date($config[sql_date_format],$now_tmp);
68         $now_tmp -= 86400;
69 }
70 $day++;
71 //$now -= ($day * 86400);
72 $now -= 604800;
73 $now += 86400;
74 for ($i = $day; $i <= 6; $i++){
75         $days[$i] = date($config[sql_date_format],$now);
76 //      $now -= 86400;
77         $now += 86400;
78 }
79
80 $daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
81 $extra_msg = '';
82 $used = array('-','-','-','-','-','-','-');
83
84 $link = @da_sql_pconnect($config);
85 if ($link){
86         $search = @da_sql_query($link,$config,
87         "SELECT sum(AcctSessionTime),sum(AcctInputOctets),sum(AcctOutputOctets),
88         avg(AcctSessionTime),avg(AcctInputOctets),avg(AcctOutputOctets),COUNT(*) FROM
89         $config[sql_accounting_table] WHERE UserName = '$login'
90         AND AcctStopTime >= '$week_str' AND AcctStopTime <= '$now_str';");
91         if ($search){
92                 $row = @da_sql_fetch_array($search,$config);
93                 $tot_time = time2str($row['sum(AcctSessionTime)']);
94                 $tot_input = bytes2str($row['sum(AcctInputOctets)']);
95                 $tot_output = bytes2str($row['sum(AcctOutputOctets)']);
96                 $avg_time = time2str($row['avg(AcctSessionTime)']);
97                 $avg_input = bytes2str($row['avg(AcctInputOctets)']);
98                 $avg_output = bytes2str($row['avg(AcctOutputOctets)']);
99                 $tot_conns = $row['COUNT(*)'];
100         }
101         for($i = 0; $i <=6; $i++){
102                 if ($days[$i] == '')
103                         continue;
104                 $search = @da_sql_query($link,$config,
105                 "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE
106                 UserName = '$login' AND AcctStopTime LIKE '$days[$i]%';");
107                 if ($search){
108                         $row = @da_sql_fetch_array($search,$config);
109                         $used[$i] = $row['sum(AcctSessionTime)'];
110                         if ($daily_limit != 'none' && $used[$i] > $daily_limit)
111                                 $used[$i] = "<font color=red>" . time2str($used[$i]) . "</font>";
112                         else
113                                 $used[$i] = time2str($used[$i]);
114                         if ($today == $i){
115                                 $daily_used = $row['sum(AcctSessionTime)'];
116                                 if ($daily_limit != 'none'){
117                                         $remaining = $daily_limit - $daily_used;
118                                         if ($remaining <=0)
119                                                 $remaining = 0;
120                                         $log_color = ($remaining) ? 'green' : 'red';
121                                         if (!$remaining)
122                                                 $extra_msg = '(Out of daily quota)';
123                                 }
124                                 $daily_used = time2str($daily_used);
125                                 if ($daily_limit != 'none' && !$remaining)
126                                         $daily_used = "<font color=red>$daily_used</font>";
127                         }
128                 }
129         }
130         $search = @da_sql_query($link,$config,
131         "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE
132         UserName = '$login' AND AcctStopTime >= '$week_start' AND
133         AcctStopTime <= '$now_str';");
134         if ($search){
135                 $row = @da_sql_fetch_array($search,$config);
136                 $weekly_used = $row['sum(AcctSessionTime)'];
137                 if ($weekly_limit != 'none'){
138                         $tmp = $weekly_limit - $weekly_used;
139                         if ($tmp <=0){
140                                 $tmp = 0;
141                                 $extra_msg .= '(Out of weekly quota)';
142                         }
143                         if ($remaining > $tmp)
144                                 $remaining = $tmp;
145                         $log_color = ($remaining) ? 'green' : 'red';
146                 }
147                 $weekly_used = time2str($weekly_used);
148                 if ($weekly_limit != 'none' && !$tmp)
149                         $weekly_used = "<font color=red>$weekly_used</font>";
150         }
151         $search = @da_sql_query($link,$config,
152         "SELECT * FROM $config[sql_accounting_table]
153         WHERE UserName = '$login' AND AcctStopTime = '0'
154         ORDER BY AcctStartTime DESC LIMIT 1;");
155         if ($search){
156                 if (@da_sql_num_rows($search,$config)){
157                         $logged_now = 1;
158                         $row = @da_sql_fetch_array($search,$config);
159                         $lastlog_time = $row['AcctStartTime'];
160                         $lastlog_server_ip = $row['NASIPAddress'];
161                         $lastlog_server_port = $row['NASPortId'];
162                         $lastlog_session_time = date2timediv($lastlog_time);
163                         if ($daily_limit != 'none'){
164                                 $remaining = $remaining - $lastlog_session_time;
165                                 if ($remaining < 0)
166                                         $remaining = 0;
167                                 $log_color = ($remaining) ? 'green' : 'red'; 
168                         }
169                         $lastlog_session_time_jvs = 1000 * $lastlog_session_time;
170                         $lastlog_session_time = time2strclock($lastlog_session_time);
171                         $lastlog_client_ip = $row['FramedIPAddress'];   
172                         $lastlog_server_name = gethostbyaddr($lastlog_server_ip);
173                         $lastlog_client_name = gethostbyaddr($lastlog_client_ip);
174                         $lastlog_input = $row['AcctInputOctets'];
175                         if ($lastlog_input)
176                                 $lastlog_input = bytes2str($lastlog_input);
177                         else
178                                 $lastlog_input = 'not available';
179                         $lastlog_output = $row['AcctOutputOctets'];
180                         if ($lastlog_output)
181                                 $lastlog_input = bytes2str($lastlog_output);
182                         else
183                                 $lastlog_output = 'not available';
184                 }
185         }
186         if (! $logged_now){
187                 $search = @da_sql_query($link,$config,
188                 "SELECT * FROM $config[sql_accounting_table]
189                 WHERE UserName = '$login' AND AcctSessionTime != '0'
190                 ORDER BY AcctStopTime DESC LIMIT 1;");
191                 if ($search){
192                         if (@da_sql_num_rows($search,$config)){
193                                 $row = @da_sql_fetch_array($search,$config);
194                                 $lastlog_time = $row['AcctStartTime'];
195                                 $lastlog_server_ip = $row['NASIPAddress'];
196                                 $lastlog_server_port = $row['NASPortId'];
197                                 $lastlog_session_time = time2str($row['AcctSessionTime']);
198                                 $lastlog_client_ip = $row['FramedIPAddress'];   
199                 $lastlog_server_name = ($lastlog_server_ip != '') ? gethostbyaddr($lastlog_server_ip) : '-';
200                 $lastlog_client_name = ($lastlog_client_ip != '') ? gethostbyaddr($lastlog_client_ip) : '-';
201                                 $lastlog_input = $row['AcctInputOctets'];
202                                 $lastlog_input = bytes2str($lastlog_input);
203                                 $lastlog_output = $row['AcctOutputOctets'];
204                                 $lastlog_output = bytes2str($lastlog_output);
205                         }
206                         else
207                                 $not_known = 1;
208                 }
209         }
210 }
211
212 $monthly_limit = (is_numeric($monthly_limit)) ? time2str($monthly_limit) : $monthly_limit;
213 $weekly_limit = (is_numeric($weekly_limit)) ? time2str($weekly_limit) : $weekly_limit;
214 $daily_limit = (is_numeric($daily_limit)) ? time2str($daily_limit) : $daily_limit;
215 $session_limit = (is_numeric($session_limit)) ? time2str($session_limit) : $session_limit;
216 $remaining = (is_numeric($remaining)) ? time2str($remaining) : $remaining;
217
218 if ($item_vals['Dialup-Access'][0] == 'FALSE')
219         $msg =<<<EON
220 <font color=red><b> The user account is locked </b></font>
221 EON;
222 else
223         $msg =<<<EON
224 user can login for <font color="$log_color"> <b>$remaining $extra_msg</font>
225 EON;
226 $lock_msg = $item_vals['Dialup-Lock-Msg'][0];
227 if ($lock_msg != '')
228         $descr =<<<EON
229 <font color=red><b>$lock_msg </b</font>
230 EON;
231 else
232         $descr = '-';
233
234 $expiration = $default_vals['Expiration'];
235 if ($item_vals['Expiration'][0] != '')
236         $expiration = $item_vals['Expiration'][0];
237 if ($expiration != ''){
238         $expiration = strtotime($expiration);
239         if ($expiration != -1 && $expiration < time())
240                 $descr = <<<EOM
241 <font color=red><b>User Account has expired</b></font>
242 EOM;
243 }
244
245 require('../html/user_admin.html.php3');