Esempio n. 1
0
File: nodeinfo.php Progetto: rzt/lms
function NodeStats($id, $dt) {
	global $DB;
	if ($stats = $DB->GetRow('SELECT SUM(download) AS download, SUM(upload) AS upload 
			    FROM stats WHERE nodeid=? AND dt>?', array($id, time() - $dt))) {
		list($result['download']['data'], $result['download']['units']) = setunits($stats['download']);
		list($result['upload']['data'], $result['upload']['units']) = setunits($stats['upload']);
		$result['downavg'] = $stats['download'] * 8 / 1000 / $dt;
		$result['upavg'] = $stats['upload'] * 8 / 1000 / $dt;
	}
	return $result;
}
Esempio n. 2
0
            	    FROM stats
		    LEFT JOIN nodes ON (nodeid = nodes.id)
		    WHERE ownerid = ? AND dt >= ? AND dt < ?', array($customer, $from, $to))) {
    for ($i = 1; $i <= date('t', $from); $i++) {
        $stats[$i]['date'] = mktime(0, 0, 0, $month, $i, $year);
    }
    foreach ($list as $row) {
        $day = date('j', $row['dt']);
        $stats[$day]['download'] += $row['download'];
        $stats[$day]['upload'] += $row['upload'];
    }
    for ($i = 1; $i <= date('t', $from); $i++) {
        $stats[$i]['upavg'] = $stats[$i]['upload'] * 8 / 1000 / 86400;
        //kbit/s
        $stats[$i]['downavg'] = $stats[$i]['download'] * 8 / 1000 / 86400;
        //kbit/s
        $listdata['upload'] += $stats[$i]['upload'];
        $listdata['download'] += $stats[$i]['download'];
        $listdata['upavg'] += $stats[$i]['upavg'];
        $listdata['downavg'] += $stats[$i]['downavg'];
        list($stats[$i]['upload'], $stats[$i]['uploadunit']) = setunits($stats[$i]['upload']);
        list($stats[$i]['download'], $stats[$i]['downloadunit']) = setunits($stats[$i]['download']);
    }
    $listdata['upavg'] = $listdata['upavg'] / date('t', $from);
    $listdata['downavg'] = $listdata['downavg'] / date('t', $from);
    list($listdata['upload'], $listdata['uploadunit']) = setunits($listdata['upload']);
    list($listdata['download'], $listdata['downloadunit']) = setunits($listdata['download']);
}
$SMARTY->assign('stats', $stats);
$SMARTY->assign('listdata', $listdata);
clearheader();
Esempio n. 3
0
function Traffic($from = 0, $to = 0, $net = 0, $customerid = 0, $order = '', $limit = 0)
{
    global $DB, $LMS;
    // period
    $fromdate = intval($from);
    $todate = intval($to);
    $delta = $todate - $fromdate ? $todate - $fromdate : 1;
    $dt = "( dt >= {$fromdate} AND dt < {$todate} ) ";
    // nets
    if ($net) {
        $params = $LMS->GetNetworkParams($net);
        $params['address']++;
        $params['broadcast']--;
        $net = ' AND (( ipaddr > ' . $params['address'] . ' AND ipaddr < ' . $params['broadcast'] . ')
			OR ( ipaddr_pub > ' . $params['address'] . ' AND ipaddr_pub < ' . $params['broadcast'] . ')) ';
    } else {
        $net = '';
    }
    // order
    switch ($order) {
        case 'nodeid':
            $order = ' ORDER BY nodeid';
            break;
        case 'download':
            $order = ' ORDER BY download DESC';
            break;
        case 'upload':
            $order = ' ORDER BY upload DESC';
            break;
        case 'name':
            $order = ' ORDER BY name';
            break;
        case 'ip':
            $order = ' ORDER BY ipaddr';
            break;
    }
    // limits
    if ($limit > 0) {
        $limit = ' LIMIT ' . intval($limit);
    } else {
        $limit = '';
    }
    // join query from parts
    $query = 'SELECT nodeid, name, inet_ntoa(ipaddr) AS ip, 
			    sum(upload) as upload, sum(download) as download 
		    FROM stats 
		    LEFT JOIN nodes ON stats.nodeid = nodes.id 
		    WHERE ' . $dt . $net . ($customerid ? ' AND ownerid = ' . intval($customerid) : '') . ' GROUP BY nodeid, name, ipaddr' . $order . $limit;
    // get results
    if ($traffic = $DB->GetAll($query)) {
        $downloadsum = 0;
        $uploadsum = 0;
        foreach ($traffic as $idx => $row) {
            $traffic['upload']['data'][] = $row['upload'];
            $traffic['download']['data'][] = $row['download'];
            $traffic['upload']['avg'][] = $row['upload'] * 8 / ($delta * 1000);
            $traffic['download']['avg'][] = $row['download'] * 8 / ($delta * 1000);
            $traffic['upload']['name'][] = $row['name'] ? $row['name'] : trans('unknown') . ' (ID: ' . $row['nodeid'] . ')';
            $traffic['download']['name'][] = $row['name'] ? $row['name'] : trans('unknown') . ' (ID: ' . $row['nodeid'] . ')';
            $traffic['upload']['ipaddr'][] = $row['ip'];
            $traffic['download']['nodeid'][] = $row['nodeid'];
            $traffic['upload']['nodeid'][] = $row['nodeid'];
            $traffic['download']['ipaddr'][] = $row['ip'];
            $downloadsum += $row['download'];
            $uploadsum += $row['upload'];
        }
        $traffic['upload']['sum']['data'] = $uploadsum;
        $traffic['download']['sum']['data'] = $downloadsum;
        $traffic['upload']['avgsum'] = $uploadsum * 8 / ($delta * 1000);
        $traffic['download']['avgsum'] = $downloadsum * 8 / ($delta * 1000);
        // get maximum data from array
        $maximum = max($traffic['download']['data']);
        if ($maximum < max($traffic['upload']['data'])) {
            $maximum = max($traffic['upload']['data']);
        }
        if ($maximum == 0) {
            // do not need divide by zero
            $maximum = 1;
        }
        // make data for bars drawing
        $x = 0;
        foreach ($traffic['download']['data'] as $data) {
            $traffic['download']['bar'][] = round($data * 150 / $maximum);
            list($traffic['download']['data'][$x], $traffic['download']['unit'][$x]) = setunits($data);
            $x++;
        }
        $x = 0;
        foreach ($traffic['upload']['data'] as $data) {
            $traffic['upload']['bar'][] = round($data * 150 / $maximum);
            list($traffic['upload']['data'][$x], $traffic['upload']['unit'][$x]) = setunits($data);
            $x++;
        }
        //set units for data
        list($traffic['download']['sum']['data'], $traffic['download']['sum']['unit']) = setunits($traffic['download']['sum']['data']);
        list($traffic['upload']['sum']['data'], $traffic['upload']['sum']['unit']) = setunits($traffic['upload']['sum']['data']);
    }
    return $traffic;
}
Esempio n. 4
0
        die;
    }
}
if (!isset($_GET['id'])) {
    $SESSION->redirect('?' . $SESSION->get('backto'));
}
$message = $LMS->GetMessage($_GET['id']);
if ($message['userid']) {
    $message['username'] = $LMS->GetUserName($message['userid']);
}
if ($message['customerid']) {
    $message['customername'] = $LMS->GetCustomerName($message['customerid']);
}
if (sizeof($message['attachments'])) {
    foreach ($message['attachments'] as $key => $val) {
        list($size, $unit) = setunits(@filesize($CONFIG['rt']['mail_dir'] . sprintf("/%06d/%06d/%s", $message['ticketid'], $message['id'], $val['filename'])));
        $message['attachments'][$key]['size'] = $size;
        $message['attachments'][$key]['unit'] = $unit;
    }
}
if ($message['inreplyto']) {
    $reply = $LMS->GetMessage($message['inreplyto']);
    $message['inreplytoid'] = $reply['subject'];
}
if (!$message['customerid'] && !$message['userid'] && !$message['mailfrom']) {
    $message['requestor'] = $DB->GetOne('SELECT requestor FROM rttickets WHERE id=?', array($message['ticketid']));
}
$layout['pagetitle'] = trans('Ticket Review');
$SESSION->save('backto', $_SERVER['QUERY_STRING']);
$SMARTY->assign('message', $message);
$SMARTY->display('rtmessageview.html');
Esempio n. 5
0
        die;
    }
}
if (!isset($_GET['id'])) {
    $SESSION->redirect('?' . $SESSION->get('backto'));
}
$message = $LMS->GetMessage($_GET['id']);
if ($message['userid']) {
    $message['username'] = $LMS->GetUserName($message['userid']);
}
if ($message['customerid']) {
    $message['customername'] = $LMS->GetCustomerName($message['customerid']);
}
if (sizeof($message['attachments'])) {
    foreach ($message['attachments'] as $key => $val) {
        list($size, $unit) = setunits(@filesize(ConfigHelper::getConfig('rt.mail_dir') . sprintf("/%06d/%06d/%s", $message['ticketid'], $message['id'], $val['filename'])));
        $message['attachments'][$key]['size'] = $size;
        $message['attachments'][$key]['unit'] = $unit;
    }
}
if ($message['inreplyto']) {
    $reply = $LMS->GetMessage($message['inreplyto']);
    $message['inreplytoid'] = $reply['subject'];
}
if (!$message['customerid'] && !$message['userid'] && !$message['mailfrom']) {
    $message['requestor'] = $DB->GetOne('SELECT requestor FROM rttickets WHERE id=?', array($message['ticketid']));
}
$layout['pagetitle'] = trans('Ticket Review');
$SESSION->save('backto', $_SERVER['QUERY_STRING']);
$SMARTY->assign('message', $message);
$SMARTY->display('rt/rtmessageview.html');
Esempio n. 6
0
    public function GetNodeSessions($nodeid)
    {
        $nodesessions = $this->DB->GetAll('SELECT INET_NTOA(ipaddr) AS ipaddr, mac, start, stop,
		download, upload, terminatecause, type
		FROM nodesessions WHERE nodeid = ? ORDER BY stop DESC LIMIT ' . intval(ConfigHelper::getConfig('phpui.nodesession_limit', 10)), array($nodeid));
        if (!empty($nodesessions)) {
            foreach ($nodesessions as $idx => $session) {
                list($number, $unit) = setunits($session['download']);
                $nodesessions[$idx]['download'] = round($number, 2) . ' ' . $unit;
                list($number, $unit) = setunits($session['upload']);
                $nodesessions[$idx]['upload'] = round($number, 2) . ' ' . $unit;
                $nodesessions[$idx]['duration'] = uptimef($session['stop'] - $session['start']);
            }
        }
        return $nodesessions;
    }
Esempio n. 7
0
function handle_file_uploads($elemid, &$error)
{
    $tmpdir = $tmppath = '';
    $fileupload = array();
    if (isset($_POST['fileupload'])) {
        $fileupload = $_POST['fileupload'];
        $tmpdir = $fileupload[$elemid . '-tmpdir'];
        if (empty($tmpdir)) {
            $tmpdir = uniqid('lms-fileupload-');
            $tmppath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tmpdir;
            if (is_dir($tmppath) || !@mkdir($tmppath)) {
                $tmpdir = '';
            }
        } elseif (preg_match('/^lms-fileupload-[0-9a-f]+$/', $tmpdir)) {
            $tmppath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tmpdir;
            if (!file_exists($tmppath)) {
                @mkdir($tmppath);
            }
        } else {
            $tmpdir = '';
        }
        if (isset($_GET['ajax'])) {
            $files = array();
            if (isset($_FILES[$elemid])) {
                foreach ($_FILES[$elemid]['name'] as $fileidx => $filename) {
                    if (preg_match('/(\\.\\.|\\/)/', $filename)) {
                        continue;
                    }
                    if (!empty($filename)) {
                        if (is_uploaded_file($_FILES[$elemid]['tmp_name'][$fileidx]) && $_FILES[$elemid]['size'][$fileidx]) {
                            $files[] = array('name' => $filename, 'tmp_name' => $_FILES[$elemid]['tmp_name'][$fileidx], 'type' => $_FILES[$elemid]['type'][$fileidx], 'size' => $_FILES[$elemid]['size'][$fileidx]);
                        } else {
                            // upload errors
                            if (isset($error[$elemid])) {
                                $error[$elemid] .= "\n";
                            } else {
                                $error[$elemid] = '';
                            }
                            switch ($_FILES[$elemid]['error'][$fileidx]) {
                                case 1:
                                case 2:
                                    $error[$elemid] .= trans('File is too large: $a', $filename);
                                    break;
                                case 3:
                                    $error[$elemid] .= trans('File upload has finished prematurely: $a', $filename);
                                    break;
                                case 4:
                                    $error[$elemid] .= trans('Path to file was not specified: $a', $filename);
                                    break;
                                default:
                                    $error[$elemid] .= trans('Problem during file upload: $a', $filename);
                                    break;
                            }
                        }
                    }
                }
            }
            if ($error && isset($error[$elemid])) {
                $result = array('error' => $error[$elemid]);
            } else {
                if (isset($fileupload) && !empty($tmpdir)) {
                    $files2 = array();
                    foreach ($files as &$file) {
                        unset($file2);
                        if (isset($fileupload[$elemid])) {
                            foreach ($fileupload[$elemid] as &$file2) {
                                if ($file['name'] == $file2['name']) {
                                    continue 2;
                                }
                            }
                        }
                        if (!file_exists($tmppath . DIRECTORY_SEPARATOR . $file['name'])) {
                            @move_uploaded_file($file['tmp_name'], $tmppath . DIRECTORY_SEPARATOR . $file['name']);
                            unset($file['tmp_name']);
                        }
                        $files2[] = $file;
                    }
                    unset($file);
                    $files = $files2;
                    unset($files2, $file2);
                }
                $result = array('error' => '', 'tmpdir' => $tmpdir, 'files' => $files);
            }
            header('Content-type: application/json');
            print json_encode($result);
            die;
        } elseif (isset($fileupload[$elemid])) {
            foreach ($fileupload[$elemid] as &$file) {
                list($size, $unit) = setunits($file['size']);
                $file['sizestr'] = sprintf("%.02f", $size) . ' ' . $unit;
            }
            unset($file);
            ${$elemid} = $fileupload[$elemid];
        }
    }
    return compact('fileupload', 'tmppath', $elemid);
}
Esempio n. 8
0
function Traffic($from = 0, $to = 0, $owner = 0, $order = '')
{
    global $LMS, $DB;
    if ($owner) {
        $owner = ' AND ownerid = ' . $owner;
    }
    // period
    if (is_array($from)) {
        $fromdate = mktime($from['Hour'], $from['Minute'], 0, $from['Month'], $from['Day'], $from['Year']);
    } else {
        $fromdate = $from;
    }
    if (is_array($to)) {
        $todate = mktime($to['Hour'], $to['Minute'], 59, $to['Month'], $to['Day'], $to['Year']);
    } else {
        $todate = $to;
    }
    $delta = $todate - $fromdate ? $todate - $fromdate : 1;
    if ($from || $to) {
        $dt = " AND ( dt >= {$fromdate} AND dt <= {$todate} )";
    }
    // order
    switch ($order) {
        case 'nodeid':
            $order = ' ORDER BY nodeid';
            break;
        case 'download':
            $order = ' ORDER BY download DESC';
            break;
        case 'upload':
            $order = ' ORDER BY upload DESC';
            break;
        case 'name':
            $order = ' ORDER BY name';
            break;
        case 'ip':
            $order = ' ORDER BY ipaddr';
            break;
    }
    // join query from parts
    $query = 'SELECT nodeid, name, inet_ntoa(ipaddr) AS ip, sum(upload) as upload, sum(download) as download 
		    FROM stats 
		    LEFT JOIN nodes ON stats.nodeid=nodes.id 
		    WHERE 1=1 ' . ($dt ? $dt : '') . ($owner ? $owner : '') . ' GROUP BY nodeid, name, ipaddr ' . $order;
    // get results
    if ($traffic = $LMS->DB->GetAll($query)) {
        $downloadsum = 0;
        $uploadsum = 0;
        foreach ($traffic as $idx => $row) {
            $traffic['upload']['data'][] = $row['upload'];
            $traffic['download']['data'][] = $row['download'];
            $traffic['upload']['name'][] = $row['name'] ? $row['name'] : 'nieznany (ID: ' . $row['nodeid'] . ')';
            $traffic['download']['name'][] = $row['name'] ? $row['name'] : 'nieznany (ID: ' . $row['nodeid'] . ')';
            $traffic['upload']['ipaddr'][] = $row['ip'];
            $traffic['download']['nodeid'][] = $row['nodeid'];
            $traffic['upload']['nodeid'][] = $row['nodeid'];
            $traffic['download']['ipaddr'][] = $row['ip'];
            $downloadsum += $row['download'];
            $uploadsum += $row['upload'];
            $traffic['upload']['avg'][] = $row['upload'] * 8 / ($delta * 1000);
            $traffic['download']['avg'][] = $row['download'] * 8 / ($delta * 1000);
        }
        $traffic['upload']['sum']['data'] = $uploadsum;
        $traffic['download']['sum']['data'] = $downloadsum;
        $traffic['upload']['avgsum'] = $uploadsum * 8 / ($delta * 1000);
        $traffic['download']['avgsum'] = $downloadsum * 8 / ($delta * 1000);
        // get maximum data from array
        $maximum = max($traffic['download']['data']);
        if ($maximum < max($traffic['upload']['data'])) {
            $maximum = max($traffic['upload']['data']);
        }
        if ($maximum == 0) {
            // do not need divide by zero
            $maximum = 1;
        }
        // make data for bars drawing
        $x = 0;
        foreach ($traffic['download']['data'] as $data) {
            $down = round($data * 150 / $maximum);
            $traffic['download']['bar'][] = $down ? $down : 1;
            list($traffic['download']['data'][$x], $traffic['download']['unit'][$x]) = setunits($data);
            $x++;
        }
        $x = 0;
        foreach ($traffic['upload']['data'] as $data) {
            $up = round($data * 150 / $maximum);
            $traffic['upload']['bar'][] = $up ? $up : 1;
            list($traffic['upload']['data'][$x], $traffic['upload']['unit'][$x]) = setunits($data);
            $x++;
        }
        //set units for data
        list($traffic['download']['sum']['data'], $traffic['download']['sum']['unit']) = setunits($traffic['download']['sum']['data']);
        list($traffic['upload']['sum']['data'], $traffic['upload']['sum']['unit']) = setunits($traffic['upload']['sum']['data']);
    }
    return $traffic;
}
Esempio n. 9
0
    public function GetNodeSessions($nodeid)
    {
        $nodesessions = $this->DB->GetAll('SELECT INET_NTOA(ipaddr) AS ipaddr, mac, start, stop, download, upload
			FROM nodesessions WHERE nodeid = ? ORDER BY stop DESC LIMIT 10', array($nodeid));
        if (!empty($nodesessions)) {
            foreach ($nodesessions as $idx => $session) {
                list($number, $unit) = setunits($session['download']);
                $nodesessions[$idx]['download'] = round($number, 2) . ' ' . $unit;
                list($number, $unit) = setunits($session['upload']);
                $nodesessions[$idx]['upload'] = round($number, 2) . ' ' . $unit;
                $nodesessions[$idx]['duration'] = uptimef($session['stop'] - $session['start']);
            }
        }
        return $nodesessions;
    }
Esempio n. 10
0
            } else {
                $filtervalue = '';
            }
            break;
    }
}
$nodesessions = $DB->GetAll('SELECT s.*, c.name, c.lastname FROM nodesessions s
	LEFT JOIN nodes n ON n.id = s.nodeid
	LEFT JOIN customers c ON c.id = s.customerid
	WHERE ' . implode(' AND ', $where) . '
	ORDER BY s.start DESC LIMIT 5000');
if (!empty($nodesessions)) {
    foreach ($nodesessions as &$session) {
        list($number, $unit) = setunits($session['download']);
        $session['download'] = round($number, 2) . ' ' . $unit;
        list($number, $unit) = setunits($session['upload']);
        $session['upload'] = round($number, 2) . ' ' . $unit;
        $session['duration'] = $session['stop'] ? uptimef($session['stop'] - $session['start']) : '-';
    }
}
$pagelimit = ConfigHelper::getConfig('phpui.nodesession_pagelimit', 100);
$page = !isset($_GET['page']) ? 1 : intval($_GET['page']);
$listdata['total'] = count($nodesessions);
if (($page - 1) * $pagelimit > $listdata['total']) {
    $page = 1;
}
$SMARTY->assign('listdata', $listdata);
$SMARTY->assign('pagelimit', $pagelimit);
$SMARTY->assign('start', ($page - 1) * $pagelimit);
$SMARTY->assign('page', $page);
$SMARTY->assign('filtertype', $filtertype);