Pull fix from branch_1_1
[freeradius.git] / dialup_admin / htdocs / user_accounting.php3
1 <?php
2 require('../conf/config.php3');
3 ?>
4 <html>
5 <?php
6 require('../lib/functions.php3');
7 require('../lib/sql/functions.php3');
8 require('../lib/attrshow.php3');
9
10 if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php3"))
11         include_once("../lib/sql/drivers/$config[sql_type]/functions.php3");
12 else{
13         echo <<<EOM
14 <title>subscription analysis for $login</title>
15 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
16 <link rel="stylesheet" href="style.css">
17 </head>
18 <body>
19 <center>
20 <b>Could not include SQL library functions. Aborting</b>
21 </body>
22 </html>
23 EOM;
24         exit();
25 }
26
27 $now = time();
28 $now_str = ($now_str != '') ? "$now_str" : date($config[sql_date_format],$now + 86400);
29 $prev_str = ($prev_str != '') ? "$prev_str" : date($config[sql_date_format], $now - 604800 );
30 $num = 0;
31 $pagesize = ($pagesize) ? $pagesize : 10;
32 if (!is_numeric($pagesize) && $pagesize != 'all')
33         $pagesize = 10;
34 $limit = ($pagesize == 'all') ? '' : "$pagesize";
35 $selected[$pagesize] = 'selected';
36 $order = ($order != '') ? $order : $config[general_accounting_info_order];
37 if ($order != 'desc' && $order != 'asc')
38         $order = 'desc';
39 $selected[$order] = 'selected';
40 $now_str = da_sql_escape_string($now_str);
41 $prev_str = da_sql_escape_string($prev_str);
42
43 unset($da_name_cache);
44 if (isset($_SESSION['da_name_cache']))
45         $da_name_cache = $_SESSION['da_name_cache'];
46
47
48 echo <<<EOM
49 <head>
50 <title>subscription analysis for $login</title>
51 <meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
52 <link rel="stylesheet" href="style.css">
53 </head>
54 <body>
55 <center>
56 <table border=0 width=550 cellpadding=0 cellspacing=0>
57 <tr valign=top>
58 <td align=center><img src="images/title2.gif"></td>
59 </tr>
60 </table>
61 <table border=0 width=400 cellpadding=0 cellspacing=2>
62 EOM;
63
64 include("../html/user_toolbar.html.php3");
65
66 print <<<EOM
67 </table>
68 <br>
69 <table border=0 width=840 cellpadding=1 cellspacing=1>
70 <tr valign=top>
71 <td width=65%></td>
72 <td bgcolor="black" width=35%>
73         <table border=0 width=100% cellpadding=2 cellspacing=0>
74         <tr bgcolor="#907030" align=right valign=top><th>
75         <font color="white">Subscription Analysis for $login</font>&nbsp;
76         </th></tr>
77         </table>
78 </td></tr>
79 <tr bgcolor="black" valign=top><td colspan=2>
80         <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
81         <tr><td>
82 <b>$prev_str</b> up to <b>$now_str</b>
83 EOM;
84 ?>
85
86 <p>
87         <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
88         <tr bgcolor="#d0ddb0">
89         <th>#</th>
90 <?php
91 for($i=1;$i<=9;$i++){
92         if ($acct_attrs['ua']["$i"] != '')
93                 echo "<th>" . $acct_attrs['ua']["$i"] . "</th>\n";
94 }
95 $sql_extra_query = '';
96 if ($config[sql_accounting_extra_query] != '')
97         $sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
98 ?>
99         </tr>
100
101 <?php
102 $link = @da_sql_pconnect($config);
103 if ($link){
104         $search = @da_sql_query($link,$config,
105         "SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_accounting_table]
106         WHERE username = '$login' AND acctstarttime <= '$now_str'
107         AND acctstarttime >= '$prev_str' $sql_extra_query " . da_sql_limit($limit,1,$config) .
108         " ORDER BY acctstarttime $order " . da_sql_limit($limit,2,$config). " ;");
109         if ($search){
110                 while( $row = @da_sql_fetch_array($search,$config) ){
111                         $tr_color='white';
112                         $num++;
113                         $acct_type = "$row[framedprotocol]/$row[nasporttype]";
114                         if ($acct_type == '')
115                                 $acct_type = '-';
116                         $acct_logedin = $row[acctstarttime];
117                         $acct_sessiontime = $row[acctsessiontime];
118                         $acct_sessiontime_sum += $acct_sessiontime;
119                         $acct_sessiontime = time2str($acct_sessiontime);
120                         $acct_ip = $row[framedipaddress];
121                         if ($acct_ip == '')
122                                 $acct_ip = '-';
123                         $acct_upload = $row[acctinputoctets];
124                         $acct_upload_sum += $acct_upload;
125                         $acct_upload = bytes2str($acct_upload);
126                         $acct_download = $row[acctoutputoctets];
127                         $acct_download_sum += $acct_download;
128                         $acct_download = bytes2str($acct_download);
129                         $acct_server = $row[nasipaddress];
130                         if ($acct_server != ''){
131                                 $acct_server = $da_name_cache[$row[nasipaddress]];
132                                 if (!isset($acct_server)){
133                                         $acct_server = @gethostbyaddr($row[nasipaddress]);
134                                         if (!isset($da_name_cache) && $config[general_use_session] == 'yes'){
135                                                 $da_name_cache[$row[nasipaddress]] = $acct_server;
136                                                 session_register('da_name_cache');
137                                         }
138                                         else
139                                                 $da_name_cache[$row[nasipaddress]] = $acct_server;
140                                 }
141                         }
142                         else
143                                 $acct_server = '-';
144                         $acct_server = "$acct_server:$row[nasportid]";
145                         $acct_terminate_cause = "$row[acctterminatecause]";
146                         if ($acct_terminate_cause == '')
147                                 $acct_terminate_cause = '-';
148                         if (ereg('Login-Incorrect',$acct_terminate_cause) ||
149                                 ereg('Multiple-Logins', $acct_terminate_cause) || ereg('Invalid-User',$acct_terminate_cause))
150                                 $tr_color='#ffe8e0';
151                         $acct_callerid = "$row[callingstationid]";
152                         if ($acct_callerid == '')
153                                 $acct_callerid = '-';
154                         echo <<<EOM
155                         <tr align=center bgcolor="$tr_color">
156                                 <td>$num</td>
157 EOM;
158                                 if ($acct_attrs[ua][1] != '') echo "<td>$acct_type</td>\n";
159                                 if ($acct_attrs[ua][2] != '') echo "<td>$acct_logedin</td>\n";
160                                 if ($acct_attrs[ua][3] != '') echo "<td>$acct_sessiontime</td>\n";
161                                 if ($acct_attrs[ua][4] != '') echo "<td>$acct_ip</td>\n";
162                                 if ($acct_attrs[ua][5] != '') echo "<td>$acct_upload</td>\n";
163                                 if ($acct_attrs[ua][6] != '') echo "<td>$acct_download</td>\n";
164                                 if ($acct_attrs[ua][7] != '') echo "<td>$acct_server</td>\n";
165                                 if ($acct_attrs[ua][8] != '') echo "<td>$acct_terminate_cause</td>\n";
166                                 if ($acct_attrs[ua][9] != '') echo "<td>$acct_callerid</td>\n";
167                         echo "</tr>\n";
168                 }
169                 $acct_sessiontime_sum = time2str($acct_sessiontime_sum);
170                 $acct_upload_sum = bytes2str($acct_upload_sum);
171                 $acct_download_sum = bytes2str($acct_download_sum);
172         }
173         else
174                 echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
175 }
176 else
177         echo "<b>Could not connect to SQL database</b><br>\n";
178 $colspan = 3;
179 if ($acct_attrs[ua][1] == '')
180         $colspan--;
181 if ($acct_attrs[ua][2] == '')
182         $colspan--;
183 echo <<<EOM
184                         <tr bgcolor="lightyellow">
185                         <td colspan=$colspan align="right">Page Total</td>
186 EOM;
187                                 if ($acct_attrs[ua][3] != '') echo "<td align=\"center\"><b>$acct_sessiontime_sum</td>\n";
188                                 if ($acct_attrs[ua][4] != '') echo "<td>&nbsp;</td>\n";
189                                 if ($acct_attrs[ua][5] != '') echo "<td align=\"right\" nowrap><b>$acct_upload_sum</td>\n";
190                                 if ($acct_attrs[ua][6] != '') echo "<td align=\"right\" nowrap><b>$acct_download_sum</td>\n";
191                                 if ($acct_attrs[ua][7] != '') echo "<td>&nbsp;</td>\n";
192                                 if ($acct_attrs[ua][8] != '') echo "<td>&nbsp;</td>\n";
193                                 if ($acct_attrs[ua][9] != '') echo "<td>&nbsp;</td>\n";
194 ?>
195                                 </tr>
196         </table>
197 <tr><td>
198 <hr>
199 <tr><td align="center">
200         <form action="user_accounting.php3" method="get" name="master">
201         <table border=0>
202                 <tr><td colspan=6></td>
203                         <td rowspan=3 valign="bottom">
204                                 <small>
205                                 the <b>from</b> date matches any login after the 00:00 that day,
206                                 and the <b>to</b> date any login before the 23:59 that day.
207                                 the default values shown are the <b>current week</b>.
208                         </td>
209                 </tr>
210                 <tr valign="bottom">
211                         <td><small><b>user</td><td><small><b>from date</td><td><small><b>to date</td><td><small><b>pagesize</td><td><b>order</td>
212         <tr valign="middle"><td>
213 <?php
214         echo <<<EOM
215 <input type="text" name="login" size="11" value="$login"></td>
216 <td><input type="text" name="prev_str" size="11" value="$prev_str"></td>
217 <td><input type="text" name="now_str" size="11" value="$now_str"></td>
218 <td><select name="pagesize">
219 <option $selected[5] value="5" >05
220 <option $selected[10] value="10">10
221 <option $selected[15] value="15">15
222 <option $selected[20] value="20">20
223 <option $selected[40] value="40">40
224 <option $selected[80] value="80">80
225 <option $selected[all] value="all">all
226 </select>
227 </td>
228 <td><select name="order">
229 <option $selected[asc] value="asc">older first
230 <option $selected[desc] value="desc">recent first
231 </select>
232 </td>
233 EOM;
234 ?>
235
236 <td><input type="submit" class=button value="show"></td></tr>
237 </table></td></tr></form>
238 </table>
239 </tr>
240 </table>
241 </body>
242 </html>