Subversion Repositories ALCASAR

Rev

Rev 1805 | Rev 2817 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?php
//gestion de la langue
if (is_file("../lib/langues.php"))
        include("../lib/langues.php");

if(!isset($selected['5'])) $selected['5'] = '';
if(!isset($selected['10'])) $selected['10'] = '';
if(!isset($selected['15'])) $selected['15'] = '';
if(!isset($selected['20'])) $selected['20'] = '';
if(!isset($selected['40'])) $selected['40'] = '';
if(!isset($selected['80'])) $selected['80'] = '';
if(!isset($selected['all'])) $selected['all'] = '';
if(!isset($selected['asc'])) $selected['asc'] = '';
if(!isset($selected['desc'])) $selected['desc'] = '';

require('/etc/freeradius-web/config.php');
require('../lib/functions.php');
require('../lib/sql/functions.php');
require('../lib/attrshow.php');
if (is_file("../lib/$config[general_lib_type]/user_info.php"))
        include("../lib/$config[general_lib_type]/user_info.php");

if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
        include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
else{
        echo <<<EOM
<html>
<head>
<title>User accounting</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<center>
<b>Could not include SQL library functions. Aborting</b>
</body>
</html>
EOM;
        exit();
}

$now = time();
$now_str = (isset($now_str) && $now_str != '') ? "$now_str" : date($config['sql_date_format'],$now + 86400);
$prev_str = (isset($prev_str) && $prev_str != '') ? "$prev_str" : date($config['sql_date_format'], $now - 604800 );
$num = 0;
$pagesize = (isset($pagesize) && $pagesize) ? $pagesize : 10;
if (!is_numeric($pagesize) && $pagesize != 'all')
        $pagesize = 10;
$limit = ($pagesize == 'all') ? '' : "$pagesize";
$selected[$pagesize] = 'selected';
$order = (isset($order) && $order != '') ? $order : $config['general_accounting_info_order'];
if ($order != 'desc' && $order != 'asc')
        $order = 'desc';
$selected[$order] = 'selected';

$link = da_sql_pconnect($config);
$now_str = da_sql_escape_string($link, $now_str);
$prev_str = da_sql_escape_string($link, $prev_str);

unset($da_name_cache);
if (isset($_SESSION['da_name_cache']))
        $da_name_cache = $_SESSION['da_name_cache'];


echo <<<EOM
<html>
<head>
<title>User accounting</title>
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><th>$l_users_managment</th></tr>
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1"
height="2"></td></tr>
</TABLE>
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
<tr bgcolor="#666666"><td>
<TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
<tr><td valign="middle" align="left">
<center>
<table border=0 width=640 cellpadding=0 cellspacing=2>
EOM;

include("../html/user_toolbar.html.php");

print <<<EOM
</table>
<br>
<table border=0 width=720 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=400></td>
<td bgcolor="black">
        <table border=0 width=100% cellpadding=2 cellspacing=0>
        <tr bgcolor="#907030" align=right valign=top><th>
        <font color="white">$l_user : $login ($cn)</font>
        </th></tr>
        </table>
</td></tr>
<tr bgcolor="black" valign=top><td colspan=2>
        <table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
        <tr><td>
Dates : <b>$prev_str</b> to <b>$now_str</b>
EOM;
?>
<p>
        <table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
        <tr bgcolor="#d0ddb0">
        <td><b>#</b></td>
<?php
for($i=1;$i<=9;$i++){
        if (isset($acct_attrs['ua']["$i"]) && ($acct_attrs['ua']["$i"] != '') && ($acct_attrs['ua']["$i"] != 'server') && ($acct_attrs['ua']["$i"] != 'callerid'))
                echo "<td><b>" . $acct_attrs['ua']["$i"] . "</b></td>\n";
}
$sql_extra_query = '';
if (isset($config['sql_accounting_extra_query']) && $config['sql_accounting_extra_query'] != '')
        $sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
?>
        </tr>

<?php
if ($link){
        $search = da_sql_query($link,$config,
        "SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_accounting_table]
        WHERE username = '$login' AND acctstarttime <= '$now_str'
        AND acctstarttime >= '$prev_str' $sql_extra_query " . da_sql_limit($limit,1,$config) .
        " ORDER BY acctstarttime $order " . da_sql_limit($limit,2,$config). " ;");
        if ($search){
                $acct_sessiontime_sum = 0;
                $acct_upload_sum = 0;
                $acct_download_sum = 0;
                while( $row = da_sql_fetch_array($search,$config) ){
                        $num++;
                        $acct_type = "$row[framedprotocol]/$row[nasporttype]";
                        if ($acct_type == '')
                                $acct_type = '-';
                        $acct_logedin = $row['acctstarttime'];
                        $acct_sessiontime = $row['acctsessiontime'];
                        $acct_sessiontime_sum += $acct_sessiontime;
                        $acct_sessiontime = time2str($acct_sessiontime);
                        $acct_ip = $row['framedipaddress'];
                        if ($acct_ip == '')
                                $acct_ip = '-';
                        $acct_upload = $row['acctinputoctets'];
                        $acct_upload_sum += $acct_upload;
                        $acct_upload = bytes2str($acct_upload);
                        $acct_download = $row['acctoutputoctets'];
                        $acct_download_sum += $acct_download;
                        $acct_download = bytes2str($acct_download);
                        $acct_server = $row['nasipaddress'];
                        if ($acct_server != ''){
                                $acct_server = (isset($da_name_cache)) ? $da_name_cache[$row['nasipaddress']] : null;
                                if (!isset($acct_server)){
                                        $acct_server = gethostbyaddr($row['nasipaddress']);
                                        if (!isset($da_name_cache) && $config['general_use_session'] == 'yes'){
                                                $da_name_cache[$row['nasipaddress']] = $acct_server;
                                                session_register('da_name_cache');
                                        }
                                        else
                                                $da_name_cache[$row['nasipaddress']] = $acct_server;
                                }
                        }
                        else
                                $acct_server = '-';
                        $acct_server = "$acct_server:$row[nasportid]";
                        $acct_terminate_cause = "$row[acctterminatecause]";
                        if ($acct_terminate_cause == '')
                                $acct_terminate_cause = '-';
                        if (preg_match('/Login-Incorrect/',$acct_terminate_cause) ||
                                preg_match('/Multiple-Logins/', $acct_terminate_cause) || preg_match('/Invalid-User/',$acct_terminate_cause))
                        $acct_callerid = "$row[callingstationid]";
                        if (!isset($acct_callerid) || $acct_callerid == '')
                                $acct_callerid = '-';
                        echo <<<EOM
                        <tr align=center>
                                <td>$num</td>
EOM;
                                if (isset($acct_attrs['ua'][1]) && $acct_attrs['ua'][1] != '') echo "<td>$acct_type</td>\n";
                                if (isset($acct_attrs['ua'][2]) && $acct_attrs['ua'][2] != '') echo "<td>$acct_logedin</td>\n";
                                if (isset($acct_attrs['ua'][3]) && $acct_attrs['ua'][3] != '') echo "<td>$acct_sessiontime</td>\n";
                                if (isset($acct_attrs['ua'][4]) && $acct_attrs['ua'][4] != '') echo "<td>$acct_ip</td>\n";
                                if (isset($acct_attrs['ua'][5]) && $acct_attrs['ua'][5] != '') echo "<td>$acct_upload</td>\n";
                                if (isset($acct_attrs['ua'][6]) && $acct_attrs['ua'][6] != '') echo "<td>$acct_download</td>\n";
//                              if (isset($acct_attrs['ua'][7]) && $acct_attrs[ua][7] != '') echo "<td>$acct_server</td>\n";
                                if (isset($acct_attrs['ua'][8]) && $acct_attrs['ua'][8] != '') echo "<td>$acct_terminate_cause</td>\n";
//                              if (isset($acct_attrs['ua'][9]) && $acct_attrs[ua][9] != '') echo "<td>$acct_callerid</td>\n";
                        echo "</tr>\n";
                }
                $acct_sessiontime_sum = (isset($acct_sessiontime_sum)) ? time2str($acct_sessiontime_sum) : "0 seconds";
                $acct_upload_sum = (isset($acct_upload_sum)) ? bytes2str($acct_upload_sum) : "0.00 KBs";
                $acct_download_sum = (isset($acct_download_sum)) ? bytes2str($acct_download_sum) : "0.00 KBs";
        }
        else
                echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
}
else
        echo "<b>Could not connect to SQL database</b><br>\n";
$colspan = 3;
if (!isset($acct_attrs['ua'][1]) || $acct_attrs['ua'][1] == ''){
        $colspan--;}
if (!isset($acct_attrs['ua'][2]) || $acct_attrs['ua'][2] == ''){
        $colspan--;}
echo <<<EOM
                        <tr bgcolor="lightyellow" align="center">
                        <td colspan=$colspan><b>Total</b></td>
EOM;
                                if (isset($acct_attrs['ua'][3]) && $acct_attrs['ua'][3] != '') echo "<td><b>$acct_sessiontime_sum</b></td>\n";
                                if (isset($acct_attrs['ua'][4]) && $acct_attrs['ua'][4] != '') echo "<td>&nbsp;</td>\n";
                                if (isset($acct_attrs['ua'][5]) && $acct_attrs['ua'][5] != '') echo "<td><b>$acct_upload_sum</b></td>\n";
                                if (isset($acct_attrs['ua'][6]) && $acct_attrs['ua'][6] != '') echo "<td><b>$acct_download_sum</b></td>\n";
//                              if (isset($acct_attrs['ua'][7]) && $acct_attrs['ua'][7] != '') echo "<td>&nbsp;</td>\n";
                                if (isset($acct_attrs['ua'][8]) && $acct_attrs['ua'][8] != '') echo "<td>&nbsp;</td>\n";
//                              if (isset($acct_attrs['ua'][9]) && $acct_attrs['ua'][9] != '') echo "<td>&nbsp;</td>\n";
?>
                                </tr>
        </table>
<tr><td>
<hr>
<tr><td align="center">
        <form action="user_accounting.php" method="get" name="master">
        <table border=0>
                <tr><td colspan=6></td>
                </tr>
                <tr valign="bottom">
        <td><?php echo "$l_user";?></td><td>from</td><td>to</td><td>nbr./page</td><td>order</td>
        <tr valign="middle"><td>
<?php
        echo <<<EOM
<input type="text" name="login" size="11" value="$login"></td>
<td><input type="text" name="prev_str" size="11" value="$prev_str"></td>
<td><input type="text" name="now_str" size="11" value="$now_str"></td>
<td><select name="pagesize">
<option $selected[5] value="5" >05
<option $selected[10] value="10">10
<option $selected[15] value="15">15
<option $selected[20] value="20">20
<option $selected[40] value="40">40
<option $selected[80] value="80">80
<option $selected[all] value="all">tous
</select>
</td>
<td><select name="order">
<option $selected[asc] value="asc">older first
<option $selected[desc] value="desc">recent first
</select>
</td>
EOM;
?>

<td><input type="submit" class=button value="show"></td></tr>
</table></td></tr></form>
</table>
</tr>
</table>
</TD></TR>
</TABLE>
</td></tr>
</TABLE>
</body>
</html>