Cześć
do stats wstawiam tym skryptem co kiedyć od Ciebie kupiłem
#v+
while (!feof($fh)) {
$line = trim(fgets($fh));
$cols = explode('|', $line);
if (!in_array(count($cols), array(7, 11, 12)))
continue;
$datetokens = sscanf($cols[0], '%d-%d-%d-%d.%d.%d.%d');
if (count($datetokens) != 7)
continue;
$dt = mktime($datetokens[3], $datetokens[4], $datetokens[5],
$datetokens[1], $datetokens[2], $datetokens[0]);
$oper = $cols[1];
$tag = $cols[2];
$ip = $cols[3];
$mac = $cols[4];
$nasip = $cols[5];
$nasid = $cols[6];
$terminatecause = '';
$download = $upload = 0;
if (count($cols) > 7) {
$download = $cols[7] * $full32bit + $cols[8];
$upload = $cols[9] * $full32bit + $cols[10];
if (count($cols) > 11)
$terminatecause = $cols[11];
}
if (isset($sessions[$tag]))
$session = $sessions[$tag];
else
$session = $DB->GetRow('SELECT * FROM nodesessions WHERE tag = ?',
array($tag));
if ($session) {
$prev_download = $session['download'];
$prev_upload = $session['upload'];
if (count($cols) == 7) {
$download = $prev_download;
$upload = $prev_upload;
}
$session['stop'] = $dt;
$session['mac'] = $mac;
$session['download'] = $download;
$session['upload'] = $upload;
$session['terminatecause'] = $terminatecause;
} else {
$prev_download = 0;
$prev_upload = 0;
if (count($cols) == 7)
$download = $upload = 0;
$session = $DB->GetRow('SELECT ownerid AS customerid,
n.id AS nodeid,
ipaddr, mac FROM vmacs n
WHERE n.ipaddr = ?', array(ip_long($ip)));
$session['start'] = $session['stop'] = $dt;
$session['mac'] = $mac;
$session['download'] = $download;
$session['upload'] = $upload;
$session['tag'] = $tag;
$session['terminatecause'] = $terminatecause;
$DB->BeginTrans();
$DB->Execute('INSERT INTO nodesessions (customerid, nodeid, ipaddr,
mac, start, stop, download, upload, tag, terminatecause,type) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,1)',
array_values($session));
$session['id'] = $DB->GetLastInsertID('nodesessions');
$DB->CommitTrans();
}
//$session['nasip'] = $nasip;
//$session['nasid'] = $nasid;
$sessions[$tag] = $session;
$delta_download = $download - $prev_download;
$delta_upload = $upload - $prev_upload;
if ($delta_download < 0)
$delta_download = 0;
if ($delta_upload < 0)
$delta_upload = 0;
if ($delta_download > 0 || $delta_upload > 0) {
//if ($DB->GetOne('SELECT dt FROM stats WHERE nodeid = ? AND dt = ?', array($session['nodeid'], $dt)))
// continue;
$delta_download = sprintf("%.0f", $delta_download);
$delta_upload = sprintf("%.0f", $delta_upload);
//printf("nodeid=%d dt=%d upload=%s download=%s sessionid=%d\n", $session['nodeid'], $dt, $delta_upload,
// $delta_download, $session['id']);
$DB->Execute('INSERT INTO stats (nodeid, dt, upload, download, nodesessionid)
VALUES(?, ?, ?, ?, ?)',
array($session['nodeid'], $dt, $delta_upload,
$delta_download, $session['id']));
}
}
fclose($fh);
unlink($accounting_file);
#-