private function _call()
 {
     // Time this
     $t = new LinfoTimerStart('CUPS extension');
     // Deal with calling it
     try {
         $result = $this->_CallExt->exec('lpstat', '-p -o -l');
     } catch (CallExtException $e) {
         // messed up somehow
         $this->_LinfoError->add('CUPS Extension', $e->getMessage());
         $this->_res = false;
         // Don't bother going any further
         return false;
     }
     // Split it into lines
     $lines = explode("\n", $result);
     // Hold temporarily values here
     $printers = array();
     $queue = array();
     $begin_queue_list = false;
     // Go through it line by line
     for ($i = 0, $num = count($lines); $i < $num; $i++) {
         // So regexes don't break on endlines
         $lines[$i] = trim($lines[$i]);
         // If there are no entries, don't waste time and end here
         if ($lines[$i] == 'no entries') {
             break;
         } elseif (preg_match('/^printer (.+) is idle\\. (.+)$/', $lines[$i], $printers_match) == 1) {
             $printers[] = array('name' => str_replace('_', ' ', $printers_match[1]), 'status' => $printers_match[2]);
         } elseif (preg_match('/^(.+)+ is (ready|ready and printing|not ready)$/', $lines[$i], $printers_match) == 1) {
             $printers[] = array('name' => str_replace('_', ' ', $printers_match[1]), 'status' => $printers_match[2]);
         } elseif (preg_match('/^Rank\\s+Owner\\s+Job\\s+File\\(s\\)\\s+Total Size$/', $lines[$i])) {
             $begin_queue_list = true;
         } elseif ($begin_queue_list && preg_match('/^([a-z0-9]+)\\s+(\\S+)\\s+(\\d+)\\s+(.+)\\s+(\\d+) bytes$/', $lines[$i], $queue_match)) {
             $queue[] = array('rank' => $queue_match[1], 'owner' => $queue_match[2], 'job' => $queue_match[3], 'files' => $queue_match[4], 'size' => LinfoCommon::byteConvert($queue_match[5]));
         }
     }
     // Save result lset
     $this->_res = array('printers' => $printers, 'queue' => $queue);
     // Apparent success
     return true;
 }
 public function draw()
 {
     // Gain access to translations
     $lang = $this->linfo->getLang();
     // And info
     $this->linfo->scan();
     $info = $this->linfo->getInfo();
     // Say we're called more than once. Kill previous remnants
     if (count($this->_windows) > 0) {
         $this->_kill_windows();
     }
     // Get dimensions and give lovely header text
     $fullscreen = ncurses_newwin(0, 0, 0, 0);
     ncurses_wrefresh($fullscreen);
     ncurses_getmaxyx($fullscreen, $x, $y);
     ncurses_mvwaddstr($fullscreen, 0, 0, 'Generated by ' . $this->linfo->getAppName() . ' (' . $this->linfo->getVersion() . ') on ' . date('m/d/Y @ h:i:s A (T)'));
     ncurses_wrefresh($fullscreen);
     $this->_max_dims = array($x, $y);
     // Some important windows
     $core_wins = array(array('name' => $lang['core'], 'content' => array(array($lang['os'], $info['OS']), array_key_exists('Distro', $info) ? array($lang['distro'], $info['Distro']['name'] . ($info['Distro']['version'] ? ' ' . $info['Distro']['version'] : '')) : false, array($lang['kernel'], $info['Kernel']), array_key_exists('Model', $info) && !empty($info['Model']) ? array($lang['model'], $info['Model']) : false, array($lang['uptime'], str_ireplace(array(' ', 'days', 'minutes', 'hours', 'seconds'), array('', 'd', 'm', 'h', 's'), reset(explode(';', $info['UpTime'])))), array($lang['hostname'], $info['HostName']), array_key_exists('CPUArchitecture', $info) ? array($lang['cpu_arch'], $info['CPUArchitecture']) : false, array($lang['load'], implode(' ', (array) $info['Load'])))), array('name' => $lang['memory'], 'content' => array(array($lang['size'], LinfoCommon::byteConvert($info['RAM']['total'])), array($lang['used'], LinfoCommon::byteConvert($info['RAM']['total'] - $info['RAM']['free'])), array($lang['free'], LinfoCommon::byteConvert($info['RAM']['free'])))));
     // Show them
     $h = 1;
     foreach ($core_wins as $win) {
         list($width, $height) = $this->_window_with_lines($win['name'], $win['content'], $h, 0);
         $h += $height + 1;
     }
     // Makeshift event loop
     while (true) {
         // Die on input
         $getch = ncurses_getch();
         if ($getch > 0 && $getch == 113) {
             $this->__destruct();
             echo "\nEnding at your request.\n";
             exit(0);
         }
         // Stop temporariy
         ncurses_napms(1000);
         // Call ourselves
         $this->draw();
     }
 }
 public function result()
 {
     if (!$this->res) {
         return false;
     }
     $rows[] = array('type' => 'header', 'columns' => array('VM Name', 'Status', 'RAM Allocation', 'CPUs', 'CPU Time', 'Block Storage'));
     foreach ($this->VMs as $name => $info) {
         $disks = array();
         foreach ($info['storage'] as $disk) {
             $disks[] = $disk['device'] . (isset($disk['file']) && isset($disk['capacity']) ? ': ' . $disk['file'] . ' (' . LinfoCommon::byteConvert($disk['capacity'], 2) . ')' : '');
         }
         $rows[] = array('type' => 'values', 'columns' => array($name, $info['state'] == 1 ? '<span style="color: green;">On</span>' : '<span style="color: maroon;">Off</span>', LinfoCommon::byteConvert($info['memory'] * 1024, 2), $info['nrVirtCpu'], $info['cpuUsed'] ? $info['cpuUsed'] : 'N/A', $disks ? implode('<br />', $disks) : 'None'));
     }
     // Give it off
     return array('root_title' => 'libvirt Virtual Machines', 'rows' => $rows);
 }
    public function htmlOut()
    {
        $lang = $this->linfo->getLang();
        $settings = $this->linfo->getSettings();
        $info = $this->linfo->getInfo();
        $appName = $this->linfo->getAppName();
        $version = $this->linfo->getVersion();
        // Fun icons
        $show_icons = array_key_exists('icons', $settings) ? !empty($settings['icons']) : true;
        $os_icon = defined('IS_WINDOWS') ? 'windows' : strtolower(str_replace(' ', '', current(explode('(', $info['OS']))));
        $distro_icon = $info['OS'] == 'Linux' && is_array($info['Distro']) && $info['Distro']['name'] ? strtolower(str_replace(' ', '', $info['Distro']['name'])) : false;
        // Start compressed output buffering. Try to not do this if we've had errors or otherwise already outputted stuff
        if ((!function_exists('error_get_last') || !error_get_last()) && (!isset($settings['compress_content']) || $settings['compress_content'])) {
            ob_start(function_exists('ob_gzhandler') ? 'ob_gzhandler' : null);
        }
        // See if we have a specific theme file installed
        if (isset($settings['theme']) && strpos($settings['theme'], '..') === false && file_exists('layout/theme_' . $settings['theme'] . '.css')) {
            $theme_css = 'theme_' . $settings['theme'] . '.css';
        } elseif (($settings['theme'] = 'default') && file_exists('layout/theme_' . $settings['theme'] . '.css')) {
            $theme_css = 'theme_' . $settings['theme'] . '.css';
        } else {
            $theme_css = 'styles.css';
        }
        // Proceed to letting it all out
        echo '<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>' . $appName . ' - ' . $info['HostName'] . '</title>
	<link href="' . LINFO_WEB_PATH . 'layout/favicon.ico" type="image/x-icon" rel="shortcut icon">
	<link href="' . LINFO_WEB_PATH . 'layout/' . $theme_css . '" rel="stylesheet">' . ($show_icons ? '
	<link href="' . LINFO_WEB_PATH . 'layout/icons.css" rel="stylesheet">' : '') . '
	<script src="' . LINFO_WEB_PATH . 'layout/scripts.min.js"></script>
	<meta name="generator" content="' . $appName . ' (' . $version . ')">
	<meta name="author" content="Joseph Gillotti &amp; friends">
	<!--[if lt IE 8]>
	<link href="' . LINFO_WEB_PATH . 'layout/old_ie.css" type="text/css" rel="stylesheet">
	<![endif]-->
</head>
<body id="info">
<div id="header">
	<h1>' . $info['HostName'] . '</h1>
	<div class="subtitle">' . $lang['header'] . '</div>
</div>
<div class="col2">
	<div class="col">
		<div class="infoTable">
			<h2>' . $lang['core'] . '</h2>
			<table>';
        // Linfo Core. Decide what to show.
        $core = array();
        // OS? (with icon, if we have it)
        if (!empty($settings['show']['os'])) {
            $core[] = array($lang['os'], ($show_icons && (file_exists(LINFO_LOCAL_PATH . 'layout/icons/os_' . $os_icon . '.gif') || file_exists(LINFO_LOCAL_PATH . 'layout/icons/os_' . $os_icon . '.png')) ? '<span class="icon icon_os_' . $os_icon . '"></span>' : '') . $info['OS']);
        }
        // Distribution? (with icon, if we have it)
        if (!empty($settings['show']['distro']) && array_key_exists('Distro', $info) && is_array($info['Distro'])) {
            $core[] = array($lang['distro'], ($show_icons && $distro_icon && (file_exists(LINFO_LOCAL_PATH . 'layout/icons/distro_' . $distro_icon . '.gif') || file_exists(LINFO_LOCAL_PATH . 'layout/icons/distro_' . $distro_icon . '.png')) ? '<span class="icon icon_distro_' . $distro_icon . '"></span>' : '') . $info['Distro']['name'] . ($info['Distro']['version'] ? ' - ' . $info['Distro']['version'] : ''));
        }
        // Virtualization
        if (!empty($settings['show']['virtualization']) && isset($info['virtualization']) && !empty($info['virtualization'])) {
            $vmval = false;
            if ($info['virtualization']['type'] == 'guest') {
                $vmval = '<span class="icon icon_vm_' . str_replace('/', '_', strtolower($info['virtualization']['method'])) . '"></span>' . $info['virtualization']['method'] . ' ' . $lang['guest'];
            } elseif ($info['virtualization']['type'] == 'host') {
                $vmval = '<span class="icon icon_vm_' . str_replace('/', '_', strtolower($info['virtualization']['method'])) . '"></span>' . $info['virtualization']['method'] . ' ' . $lang['host'];
            }
            if ($vmval) {
                $core[] = array($lang['virtualization'], $vmval);
            }
        }
        // Kernel
        if (!empty($settings['show']['kernel'])) {
            $core[] = array($lang['kernel'], $info['Kernel']);
        }
        // Model?
        if (!empty($settings['show']['model']) && array_key_exists('Model', $info) && !empty($info['Model'])) {
            $core[] = array($lang['model'], $info['Model']);
        }
        // IP
        if (!isset($settings['show']['ip']) || !empty($settings['show']['ip'])) {
            $core[] = array($lang['accessed_ip'], $info['AccessedIP']);
        }
        // Uptime
        if (!empty($settings['show']['uptime'])) {
            $core[] = array($lang['uptime'], $info['UpTime']);
        }
        // Hostname
        if (!empty($settings['show']['hostname'])) {
            $core[] = array($lang['hostname'], $info['HostName']);
        }
        // The CPUs
        if (!empty($settings['show']['cpu'])) {
            $cpus = array();
            foreach ((array) $info['CPU'] as $cpu) {
                $cpu_html = (array_key_exists('Vendor', $cpu) && !empty($cpu['Vendor']) ? $cpu['Vendor'] . ' - ' : '') . $cpu['Model'] . (array_key_exists('MHz', $cpu) ? $cpu['MHz'] < 1000 ? ' (' . $cpu['MHz'] . ' MHz)' : ' (' . round($cpu['MHz'] / 1000, 3) . ' GHz)' : '') . (array_key_exists('usage_percentage', $cpu) ? ' (' . $cpu['usage_percentage'] . '%)' : '');
                if (array_key_exists('usage_percentage', $cpu)) {
                    $cpu_html = '<div class="new_bar_left" style="margin-top: 3px; margin-bottom: 3px;">' . self::generateBarChart($cpu['usage_percentage'], $cpu_html) . '</div>';
                } else {
                    $cpu_html .= '<br>';
                }
                $cpus[] = $cpu_html;
            }
            $core[] = array('CPUs (' . count($info['CPU']) . ')', implode('', $cpus));
        }
        // CPU Usage?
        if (!empty($settings['cpu_usage']) && isset($info['cpuUsage']) && $info['cpuUsage'] !== false) {
            $core[] = array($lang['cpu_usage'], $info['cpuUsage'] . '%');
        }
        // CPU architecture. Permissions goes hand in hand with normal CPU
        if (!empty($settings['show']['cpu']) && array_key_exists('CPUArchitecture', $info)) {
            $core[] = array($lang['cpu_arch'], $info['CPUArchitecture']);
        }
        // System Load
        if (!empty($settings['show']['load'])) {
            $core[] = array($lang['load'], implode(' ', (array) $info['Load']));
        }
        // We very well may not have process stats
        if (!empty($settings['show']['process_stats']) && $info['processStats']['exists']) {
            // Different os' have different keys of info
            $proc_stats = array();
            // Load the keys
            if (array_key_exists('totals', $info['processStats']) && is_array($info['processStats']['totals'])) {
                foreach ($info['processStats']['totals'] as $k => $v) {
                    $proc_stats[] = $k . ': ' . number_format($v);
                }
            }
            // Total as well
            $proc_stats[] = 'total: ' . number_format($info['processStats']['proc_total']);
            // Show them
            $core[] = array($lang['processes'], implode('; ', $proc_stats));
            // We might not have threads
            if ($info['processStats']['threads'] !== false) {
                $core[] = array($lang['threads'], number_format($info['processStats']['threads']));
            }
        }
        // Users with active shells
        if (!empty($settings['show']['numLoggedIn']) && array_key_exists('numLoggedIn', $info) && $info['numLoggedIn']) {
            $core[] = array($lang['numLoggedIn'], $info['numLoggedIn']);
        }
        // Show
        foreach ($core as $val) {
            echo '
				<tr>
					<th>' . $val[0] . '</th>
					<td>' . $val[1] . '</td>
				</tr>
				';
        }
        echo '
			</table>
		</div>';
        // Show memory?
        if (!empty($settings['show']['ram'])) {
            echo '
		<div class="infoTable">
			<h2>' . $lang['memory'] . '</h2>
			<table>
				<colgroup>
					<col style="width: 10%;" />
					<col style="width: 30%;" />
					<col style="width: 30%;" />
					<col style="width: 30%;" />
				</colgroup>
				<tr>
					<th>' . $lang['type'] . '</th>
					<th>' . $lang['free'] . '</th>
					<th>' . $lang['used'] . '</th>
					<th>' . $lang['size'] . '</th>
				</tr>
				<tr>
					<td>' . $info['RAM']['type'] . '</td>
					<td>' . LinfoCommon::byteConvert($info['RAM']['free']) . '</td>
					<td>' . LinfoCommon::byteConvert($info['RAM']['total'] - $info['RAM']['free']) . '</td>
					<td>' . LinfoCommon::byteConvert($info['RAM']['total']) . '</td>
				</tr>';
            $have_swap = isset($info['RAM']['swapFree']) || isset($info['RAM']['swapTotal']);
            if ($have_swap) {
                // Show detailed swap info?
                $show_detailed_swap = is_array($info['RAM']['swapInfo']) && count($info['RAM']['swapInfo']) > 0;
                echo '
					<tr>
						<td' . ($show_detailed_swap ? ' rowspan="2"' : '') . '>Swap</td>
						<td>' . LinfoCommon::byteConvert(@$info['RAM']['swapFree']) . '</td>
						<td>' . LinfoCommon::byteConvert(@$info['RAM']['swapTotal'] - $info['RAM']['swapFree']) . '</td>
						<td>' . LinfoCommon::byteConvert(@$info['RAM']['swapTotal']) . '</td>
					</tr>';
                // As in we have at least one swap device present. Show them.
                if ($show_detailed_swap) {
                    echo '
						<tr>
							<td colspan="3">
								<table class="mini center">
									<colgroup>
										<col style="width: 25%;" />
										<col style="width: 25%;" />
										<col style="width: 25%;" />
										<col style="width: 25%;" />
									</colgroup>
									<tr>
										<th>' . $lang['device'] . '</th>
										<th>' . $lang['type'] . '</th>
										<th>' . $lang['size'] . '</th>
										<th>' . $lang['used'] . '</th>
									</tr>';
                    foreach ($info['RAM']['swapInfo'] as $swap) {
                        echo '
										<tr>
											<td>' . $swap['device'] . '</td>
											<td>' . ucfirst($swap['type']) . '</td>
											<td>' . LinfoCommon::byteConvert($swap['size']) . '</td>
											<td>' . LinfoCommon::byteConvert($swap['used']) . '</td>
										</tr>
										';
                    }
                    echo '
								</table>
							</td>
						</tr>';
                }
            }
            echo '
			</table>
		</div>';
        }
        // Network Devices?
        if (!empty($settings['show']['network'])) {
            $show_type = array_key_exists('nic_type', $info['contains']) ? $info['contains']['nic_type'] : true;
            $show_speed = array_key_exists('nic_port_speed', $info['contains']) ? $info['contains']['nic_port_speed'] : true;
            echo '
		<div class="infoTable">
			<h2>' . $lang['network_devices'] . '</h2>
			<table>
				<tr>
					<th>' . $lang['device_name'] . '</th>' . ($show_type ? '
					<th>' . $lang['type'] . '</th>' : '') . ($show_speed ? '
					<th>' . $lang['port_speed'] . '</th>' : '') . '
					<th>' . $lang['amount_sent'] . '</th>
					<th>' . $lang['amount_received'] . '</th>
					<th>' . $lang['state'] . '</th>
				</tr>';
            if (count($info['Network Devices']) > 0) {
                foreach ($info['Network Devices'] as $device => $stats) {
                    echo '
				<tr>
					<td>' . $device . '</td>' . ($show_type ? '
					<td>' . $stats['type'] . '</td>' : '') . ($show_speed ? '
					<td>' . (isset($stats['port_speed']) && $stats['port_speed'] !== false ? $stats['port_speed'] . 'Mb/s' : '') . '</td>' : '') . '
					<td>' . LinfoCommon::byteConvert($stats['sent']['bytes']) . '</td>
					<td>' . LinfoCommon::byteConvert($stats['recieved']['bytes']) . '</td>
					<td class="net_' . $stats['state'] . '">' . ucfirst($stats['state']) . '</td>
				</tr>';
                }
            } else {
                echo '<tr><td colspan="5" class="none">' . $lang['none_found'] . '</td></tr>';
            }
            echo '
			</table>
		</div>';
        }
        // Show temps?
        if (!empty($settings['show']['temps']) && count($info['Temps']) > 0) {
            echo '
		<div class="infoTable">
			<h2>' . $lang['temps_voltages'] . '</h2>
			<table>
				<tr><th>' . $lang['path'] . '</th><th>' . $lang['device'] . '</th><th>' . $lang['value'] . '</th></tr>
				';
            if (count($info['Temps']) > 0) {
                foreach ($info['Temps'] as $stat) {
                    echo '
					<tr>
						<td>' . $stat['path'] . '</td>
						<td>' . $stat['name'] . '</td>
						<td>' . (array_key_exists('bar', $stat) && $stat['bar'] && $stat['unit'] == '%' ? '<div class="bar_chart">
								<div class="bar_inner" style="width: ' . $stat['temp'] . '%;">
									<div class="bar_text">
										' . ($stat['temp'] > -1 ? $stat['temp'] : '?') . '%
									</div>
								</div>
							</div>
							' : $stat['temp'] . ' ' . $stat['unit']) . '</td>
					</tr>
					';
                }
            } else {
                echo '<tr><td colspan="3" class="none">' . $lang['none_found'] . '</td></tr>';
            }
            echo '
			</table>
		</div>';
        }
        // Show battery?
        if (!empty($settings['show']['battery']) && count($info['Battery']) > 0) {
            echo '
		<div class="infoTable">
			<h2>' . $lang['batteries'] . '</h2>
			<table>
				<tr><th>' . $lang['device'] . '</th><th>' . $lang['state'] . '</th><th>' . $lang['charge'] . ' %</th></tr>
				';
            foreach ($info['Battery'] as $bat) {
                echo '
					<tr>
						<td>' . $bat['device'] . '</td>
						<td>' . $bat['state'] . '</td>
						<td>
							<div class="bar_chart">
								<div class="bar_inner" style="width: ' . (int) $bat['percentage'] . '%;">
									<div class="bar_text">
										' . ($bat['percentage'] > -1 ? $bat['percentage'] : '?') . '
									</div>
								</div>
							</div>
						
						</td>
					</tr>
					';
            }
            echo '
			</table>
		</div>';
        }
        // Show services?
        if (!empty($settings['show']['services']) && count($info['services']) > 0) {
            echo '
		<div class="infoTable">
			<h2>' . $lang['services'] . '</h2>
			<table>
				<tr>
					<th>' . $lang['service'] . '</th><th>' . $lang['state'] . '</th><th>' . $lang['pid'] . '</th><th>Threads</th><th>' . $lang['memory_usage'] . '</th>
				</tr>
				';
            // Show them
            foreach ($info['services'] as $service => $state) {
                $state_parts = explode(' ', $state['state'], 2);
                echo '
				<tr>
					<td>' . $service . '</td>
					<td>
						<span class="service_' . strtolower($state_parts[0]) . '">' . $state_parts[0] . '</span>
						' . (array_key_exists(1, $state_parts) ? self::fadedText($state_parts[1]) . '</span>' : '') . '</td>
					<td>' . $state['pid'] . '</td>
					<td>', $state['threads'] ? $state['threads'] : '?', '</td>
					<td>', $state['memory_usage'] ? LinfoCommon::byteConvert($state['memory_usage']) : '?', '</td>
				</tr>
			';
            }
            echo '
			</table>
		</div>';
        }
        echo '
	</div>
	<div class="col">';
        // Show hardware?
        if (!empty($settings['show']['devices'])) {
            // Don't show vendor?
            $show_vendor = array_key_exists('hw_vendor', $info['contains']) ? $info['contains']['hw_vendor'] === false ? false : true : true;
            echo '
		<div class="infoTable">
			<h2>' . $lang['hardware'] . '</h2>
			<table>
				<tr>
					<th>' . $lang['type'] . '</th>
					', $show_vendor ? '<th>' . $lang['vendor'] . '</th>' : '', '
					<th>' . $lang['device'] . '</th>
				</tr>
				';
            $num_devs = count($info['Devices']);
            if ($num_devs > 0) {
                for ($i = 0; $i < $num_devs; $i++) {
                    echo '
				<tr>
					<td class="center">' . $info['Devices'][$i]['type'] . '</td>
					', $show_vendor ? '<td>' . ($info['Devices'][$i]['vendor'] ? $info['Devices'][$i]['vendor'] : 'Unknown') . '</td>' : '', '
					<td>' . $info['Devices'][$i]['device'] . '</td>
				</tr>';
                }
            } else {
                echo '<tr><td colspan="3" class="none">' . $lang['none_found'] . '</td></tr>';
            }
            echo '
			</table>
		</div>';
        }
        // Show drives?
        if (!empty($settings['show']['hd'])) {
            // Should we not show the Reads and Writes columns?
            $show_stats = array_key_exists('drives_rw_stats', $info['contains']) ? $info['contains']['drives_rw_stats'] === false ? false : true : true;
            // Or vendor columns?
            $show_vendor = array_key_exists('drives_vendor', $info['contains']) ? $info['contains']['drives_vendor'] === false ? false : true : true;
            echo '
		<div class="infoTable">
			<h2>Drives</h2>
			<table>
				<tr>
					<th>' . $lang['path'] . '</th>
					', $show_vendor ? '<th>' . $lang['vendor'] : '', '</th>
					<th>' . $lang['name'] . '</th>
					', $show_stats ? '<th>' . $lang['reads'] . '</th>
					<th>' . $lang['writes'] . '</th>' : '', '
					<th>' . $lang['size'] . '</th>
				</tr>';
            if (count($info['HD']) > 0) {
                foreach ($info['HD'] as $drive) {
                    echo '
				<tr>
					<td>' . $drive['device'] . '</td>
					', $show_vendor ? '<td>' . ($drive['vendor'] ? $drive['vendor'] : $lang['unknown']) . '</td>' : '', '
					<td>', $drive['name'] ? $drive['name'] : $lang['unknown'], '</td>
					', $show_stats ? '<td>' . ($drive['reads'] !== false ? number_format($drive['reads']) : $lang['unknown']) . '</td>
					<td>' . ($drive['writes'] !== false ? number_format($drive['writes']) : $lang['unknown']) . '</td>' : '', '
					<td>', $drive['size'] ? LinfoCommon::byteConvert($drive['size']) : $lang['unknown'], '</td>
				</tr>';
                    // If we've got partitions for this drive, show them too
                    if (array_key_exists('partitions', $drive) && is_array($drive['partitions']) && count($drive['partitions']) > 0) {
                        echo '
				<tr>
					<td colspan="6">';
                        // Each
                        foreach ($drive['partitions'] as $partition) {
                            echo '
						&#9492; ' . (isset($partition['number']) ? $drive['device'] . $partition['number'] : $partition['name']) . ' - ' . LinfoCommon::byteConvert($partition['size']) . '<br />';
                        }
                        echo '
					</td>
				</tr>
				';
                    }
                }
            } else {
                echo '<tr><td colspan="6" class="none">' . $lang['none_found'] . '</td></tr>';
            }
            echo '
			</table>
		</div>';
        }
        // Show sound card stuff?
        if (!empty($settings['show']['sound']) && count($info['SoundCards']) > 0) {
            echo '
		<div class="infoTable">
			<h2>' . $lang['sound_cards'] . '</h2>
			<table>
				<tr>
					<th>' . $lang['number'] . '</th>
					<th>' . $lang['vendor'] . '</th>
					<th>' . $lang['card'] . '</th>
				</tr>';
            foreach ($info['SoundCards'] as $card) {
                if (empty($card['vendor'])) {
                    $card['vendor'] = 'Unknown';
                }
                echo '
				<tr>
					<td>' . $card['number'] . '</td>
					<td>' . $card['vendor'] . '</td>
					<td>' . $card['card'] . '</td>
				</tr>';
            }
            echo '
			</table>
		</div>
		';
        }
        echo '
	</div>
</div>';
        // Show file system mounts?
        if (!empty($settings['show']['mounts'])) {
            $has_devices = false;
            $has_labels = false;
            $has_types = false;
            foreach ($info['Mounts'] as $mount) {
                if (!empty($mount['device'])) {
                    $has_devices = true;
                }
                if (!empty($mount['label'])) {
                    $has_labels = true;
                }
                if (!empty($mount['devtype'])) {
                    $has_types = true;
                }
            }
            $addcolumns = 0;
            if ($settings['show']['mounts_options']) {
                $addcolumns++;
            }
            if ($has_devices) {
                $addcolumns++;
            }
            if ($has_labels) {
                $addcolumns++;
            }
            if ($has_types) {
                $addcolumns++;
            }
            echo '
<div class="infoTable">
	<h2>' . $lang['filesystem_mounts'] . '</h2>
	<table>
		<tr>';
            if ($has_types) {
                echo '<th>' . $lang['type'] . '</th>';
            }
            if ($has_devices) {
                echo '<th>' . $lang['device'] . '</th>';
            }
            echo '<th>' . $lang['mount_point'] . '</th>';
            if ($has_labels) {
                echo '<th>' . $lang['label'] . '</th>';
            }
            echo '
			<th>' . $lang['filesystem'] . '</th>', $settings['show']['mounts_options'] ? '
			<th>' . $lang['mount_options'] . '</th>' : '', '
			<th>' . $lang['size'] . '</th>
			<th>' . $lang['used'] . '</th>
			<th>' . $lang['free'] . '</th>
			<th style="width: 12%;">' . $lang['percent_used'] . '</th>
		</tr>
		';
            // Calc totals
            $total_size = 0;
            $total_used = 0;
            $total_free = 0;
            // Don't add totals for duplicates. (same filesystem mount twice in different places)
            $done_devices = array();
            // Are there any?
            if (count($info['Mounts']) > 0) {
                // Go through each
                foreach ($info['Mounts'] as $mount) {
                    // Only add totals for this device if we haven't already
                    if (!in_array($mount['device'], $done_devices)) {
                        $total_size += $mount['size'];
                        $total_used += $mount['used'];
                        $total_free += $mount['free'];
                        if (!empty($mount['device'])) {
                            $done_devices[] = $mount['device'];
                        }
                    } else {
                        if (array_key_exists('duplicate_mounts', $settings['show']) && empty($settings['show']['duplicate_mounts'])) {
                            continue;
                        }
                    }
                    // If it's an NFS mount it's likely in the form of server:path (without a trailing slash),
                    // but if the path is just / it likely just shows up as server:,
                    // which is vague. If there isn't a /, add one
                    if (preg_match('/^.+:$/', $mount['device']) == 1) {
                        $mount['device'] .= DIRECTORY_SEPARATOR;
                    }
                    echo '<tr>';
                    if ($has_types) {
                        echo '<td>' . $mount['devtype'] . '</td>';
                    }
                    if ($has_devices) {
                        echo '<td>' . $mount['device'] . '</td>';
                    }
                    echo '<td>' . $mount['mount'] . '</td>';
                    if ($has_labels) {
                        echo '<td>' . $mount['label'] . '</td>';
                    }
                    echo '
					<td>' . $mount['type'] . '</td>', $settings['show']['mounts_options'] ? '
					<td>' . (empty($mount['options']) ? '<em>unknown</em>' : '<ul><li>' . implode('</li><li>', $mount['options']) . '</li></ul>') . '</td>' : '', '
					<td>' . LinfoCommon::byteConvert($mount['size']) . '</td>
					<td>' . LinfoCommon::byteConvert($mount['used']) . ($mount['used_percent'] !== false ? ' <span class="perc">(' . $mount['used_percent'] . '%)</span>' : '') . '</td>
					<td>' . LinfoCommon::byteConvert($mount['free']) . ($mount['free_percent'] !== false ? ' <span class="perc">(' . $mount['free_percent'] . '%)</span>' : '') . '</td>
					<td>
						' . self::generateBarChart((int) $mount['used_percent'], $mount['used_percent'] ? $mount['used_percent'] . '%' : 'N/A') . '
					</td>
				</tr>';
                }
            } else {
                echo '<tr><td colspan="', 6 + $addcolumns, '" class="none">None found</td></tr>';
            }
            // Show totals and finish table
            $total_used_perc = $total_size > 0 && $total_used > 0 ? round($total_used / $total_size, 2) * 100 : 0;
            echo '
		<tr class="alt">
			<td colspan="', 2 + $addcolumns, '">Totals: </td>
			<td>' . LinfoCommon::byteConvert($total_size) . '</td>
			<td>' . LinfoCommon::byteConvert($total_used) . '</td>
			<td>' . LinfoCommon::byteConvert($total_free) . '</td>
			<td>
				' . self::generateBarChart($total_used_perc, $total_used_perc . '%') . '
			</td>
		</tr>
	</table>
</div>';
        }
        // Show RAID Arrays?
        if (!empty($settings['show']['raid']) && count($info['Raid']) > 0) {
            echo '
<div class="infoTable">
	<h2>' . $lang['raid_arrays'] . '</h2>
	<table>
		<colgroup>
			<col style="width: 10%;" />
			<col style="width: 30%;" />
			<col style="width: 10%;" />
			<col style="width: 10%;" />
			<col style="width: 30%;" />
			<col style="width: 10%;" />
		</colgroup>
		<tr>
			<th>' . $lang['name'] . '</th>
			<th>' . $lang['level'] . '</th>
			<th>' . $lang['status'] . '</th>
			<th>' . $lang['size'] . '</th>
			<th>' . $lang['devices'] . '</th>
			<th>' . $lang['active'] . '</th>
		</tr>
		';
            if (count($info['Raid']) > 0) {
                foreach ($info['Raid'] as $raid) {
                    $active = explode('/', $raid['count']);
                    // http://en.wikipedia.org/wiki/Standard_RAID_levels
                    switch ($raid['level']) {
                        case 0:
                            $type = 'Stripe';
                            break;
                        case 1:
                            $type = 'Mirror';
                            break;
                        case 10:
                            $type = 'Mirrored Stripe';
                            break;
                        case 5:
                        case 6:
                            $type = 'Distributed Parity Block-Level Striping';
                            break;
                        default:
                            $type = false;
                            break;
                    }
                    echo '
				<tr>
				<td>' . $raid['device'] . '</td>
				<td>' . $raid['level'] . ($type ? ' <span class="caption">(' . $type . ')</span>' : '') . '</td>
				<td>' . ucfirst($raid['status']) . '</td>
				<td>' . $raid['size'] . '</td>
				<td><table class="mini center margin_auto"><tr><th>' . $lang['device'] . '</th><th>' . $lang['state'] . '</th></tr>';
                    foreach ($raid['drives'] as $drive) {
                        echo '<tr><td>' . $drive['drive'] . '</td><td class="raid_' . $drive['state'] . '">' . ucfirst($drive['state']) . '</td></tr>';
                    }
                    echo '</table></td>
				<td>' . $active[1] . '/' . $active[0] . '</td>
				</tr>
				';
                }
            } else {
                echo '<tr><td colspan="6" class="none">' . $lang['none_found'] . '</td></tr>';
            }
            echo '
	</table>
</div>';
        }
        // Feel like showing errors? Are there any even?
        if (!empty($settings['show_errors']) && LinfoError::Singleton()->num() > 0) {
            echo '
	<div id="errorList" class="infoTable">
		<h2>' . $lang['error_head'] . '</h2>
		<table>
			<tr>
				<th>' . $lang['from_where'] . '</th>
				<th>' . $lang['message'] . '</th>
			</tr>';
            foreach (LinfoError::Singleton()->show() as $error) {
                echo '
				<tr>
					<td>' . $error[0] . '</td>
					<td>' . $error[1] . '</td>
				</tr>
				';
            }
            echo '
		</table>
	</div>
	';
        }
        // Additional extensions
        if (count($info['extensions']) > 0) {
            foreach ($info['extensions'] as $ext) {
                if (is_array($ext) && count($ext) > 0) {
                    // Decide how to show something extra
                    switch (array_key_exists('extra_type', $ext) && !empty($ext['extra_vals']) ? $ext['extra_type'] : false) {
                        // Table with a key->value table to the right of it
                        // Useful for stats or other stuff pertaining to
                        // the main info to the left
                        case 'k->v':
                            echo '
<div class="col2_side">
	<div class="col2_side_left">
	' . self::createTable($ext) . '
	</div>
	<div class="col2_side_right">
		<div class="infoTable">
			<h2>' . $ext['extra_vals']['title'] . '</h2>
			<table>';
                            // Give each value
                            foreach (array_filter($ext['extra_vals']['values']) as $v) {
                                echo '
				<tr>
					<th>' . $v[0] . '</th>
					<td>' . $v[1] . '</td>
				</tr>';
                            }
                            echo '
			</table>
		</div>
	</div>
</div>
						';
                            break;
                            // Nothing extra; just the table
                        // Nothing extra; just the table
                        default:
                            echo self::createTable($ext);
                            break;
                    }
                }
            }
        }
        // Feel like showing timed results?
        if (!empty($settings['timer'])) {
            echo '
	<div id="timerList" class="infoTable">
		<h2>' . $lang['timer'] . '</h2>
		<table>
			<tr>
				<th>' . $lang['area'] . '</th>
				<th>' . $lang['time_taken'] . '</th>
			</tr>';
            foreach (LinfoTimer::Singleton()->getResults() as $result) {
                echo '
				<tr>
					<td>' . $result[0] . '</td>
					<td>' . round($result[1], 3) . ' ' . $lang['seconds'] . '</td>
				</tr>
				';
            }
            echo '
		</table>
	</div>
	';
        }
        echo '
<div id="foot">
	' . sprintf($lang['footer_app'], '<a href="https://github.com/jrgp/linfo"><em>' . $appName . '</em></a> (' . $version . ')', round(microtime(true) - $this->linfo->getTimeStart(), 2)) . '<br>
	<em>' . $appName . '</em> &copy; 2010 &ndash; ' . (date('Y') > 2011 ? date('Y') : 2011) . '
	Joseph Gillotti ' . (date('m/d') == '06/03' ? ' (who turns ' . (date('Y') - 1993) . ' today!)' : '') . '&amp; friends. Source code licensed under GPL.
</div>
<div id="foot_time">
	<br />
	Generated on ' . date($settings['dates']) . '
</div>
<script>Linfo.init()</script>
</body>
</html>';
    }
    /**
     * Return result
     * 
     * @access public
     * @return false on failure|array of the torrents
     */
    public function result()
    {
        // Don't bother if it didn't go well
        if ($this->_res === false) {
            return false;
        }
        // it did; continue
        // Store rows here
        $rows = array();
        // Start showing connections
        $rows[] = array('type' => 'header', 'columns' => array('Torrent', array(1, 'Done', '10%'), 'State', 'Have', 'Uploaded', 'Time Left', 'Ratio', 'Up', 'Down'));
        // No torrents?
        if (count($this->_torrents) == 0) {
            $rows[] = array('type' => 'none', 'columns' => array(array(9, 'None found')));
        } else {
            // Store a total amount of certain torrents here:
            $status_tally = array();
            // As well as uploaded/downloaded
            $status_tally['Downloaded'] = 0;
            $status_tally['Uploaded'] = 0;
            $status_tally['Ratio'] = '';
            // Go through each torrent
            foreach ($this->_torrents as $torrent) {
                // Status count tally
                $status_tally[$torrent['state']] = !array_key_exists($torrent['state'], $status_tally) ? 1 : $status_tally[$torrent['state']] + 1;
                // Make some sense of the have so we can get it into bytes, which we can then have fun with
                $have_bytes = false;
                if ($torrent['have'] != 'None') {
                    $have_parts = explode(' ', $torrent['have'], 2);
                    if (is_numeric($have_parts[0]) && $have_parts[0] > 0) {
                        switch ($have_parts[1]) {
                            case 'TiB':
                                $have_bytes = (double) $have_parts[0] * 1099511627776;
                                break;
                            case 'GiB':
                                $have_bytes = (double) $have_parts[0] * 1073741824;
                                break;
                            case 'MiB':
                                $have_bytes = (double) $have_parts[0] * 1048576;
                                break;
                            case 'KiB':
                                $have_bytes = (double) $have_parts[0] * 1024;
                                break;
                        }
                    }
                }
                // Try getting amount uploaded, based upon ratio and exact amount downloaded above
                $uploaded_bytes = false;
                if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($torrent['ratio']) && $torrent['ratio'] > 0) {
                    $uploaded_bytes = $torrent['ratio'] * $have_bytes;
                }
                // Save amount uploaded/downloaded tally
                if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($uploaded_bytes) && $uploaded_bytes > 0) {
                    $status_tally['Downloaded'] += $have_bytes;
                    $status_tally['Uploaded'] += $uploaded_bytes;
                }
                // Save result
                $rows[] = array('type' => 'values', 'columns' => array(wordwrap(htmlspecialchars($torrent['torrent']), 50, ' ', true), '<div class="bar_chart">
							<div class="bar_inner" style="width: ' . (int) $torrent['done'] . '%;">
								<div class="bar_text">
									' . ($torrent['done'] ? $torrent['done'] . '%' : '0%') . '
								</div>
							</div>
						</div>
						', $torrent['state'], $have_bytes !== false ? LinfoCommon::byteConvert($have_bytes) : $torrent['have'], $uploaded_bytes !== false ? LinfoCommon::byteConvert($uploaded_bytes) : 'None', $torrent['eta'], $torrent['ratio'], LinfoCommon::byteConvert($torrent['up']) . '/s', LinfoCommon::byteConvert($torrent['down']) . '/s'));
            }
            // Finish the size totals
            $status_tally['Ratio'] = $status_tally['Downloaded'] > 0 && $status_tally['Uploaded'] > 0 ? round($status_tally['Uploaded'] / $status_tally['Downloaded'], 2) : 'N/A';
            $status_tally['Downloaded'] = $status_tally['Downloaded'] > 0 ? LinfoCommon::byteConvert($status_tally['Downloaded']) : 'None';
            $status_tally['Uploaded'] = $status_tally['Uploaded'] > 0 ? LinfoCommon::byteConvert($status_tally['Uploaded']) : 'None';
            // Create a row for the tally of statuses
            if (count($status_tally) > 0) {
                // Store list of k: v'ish values here
                $tally_contents = array();
                // Populate that
                foreach ($status_tally as $state => $tally) {
                    $tally_contents[] = "{$state}: {$tally}";
                }
                // Save this final row
                $rows[] = array('type' => 'values', 'columns' => array(array(9, implode(', ', $tally_contents))));
            }
        }
        // Handle stats which might not exist
        if (is_array($this->_stats) && array_key_exists('downloaded-bytes', $this->_stats) && array_key_exists('uploaded-bytes', $this->_stats) && array_key_exists('seconds-active', $this->_stats)) {
            $extra_vals = array('title' => 'Transmission Stats', 'values' => array(array('Total Downloaded', LinfoCommon::byteConvert($this->_stats['downloaded-bytes'])), array('Total Uploaded', LinfoCommon::byteConvert($this->_stats['uploaded-bytes'])), $this->_stats['uploaded-bytes'] > 0 && $this->_stats['downloaded-bytes'] > 0 ? array('Total Ratio', round($this->_stats['uploaded-bytes'] / $this->_stats['downloaded-bytes'], 3)) : false, array('Duration', LinfoCommon::secondsConvert($this->_stats['seconds-active']))));
        } else {
            $extra_vals = false;
        }
        // Give it off
        return array('root_title' => 'Transmission Torrents', 'rows' => $rows, 'extra_type' => 'k->v', 'extra_vals' => $extra_vals);
    }
Exemple #6
0
 /**
  * getRAID 
  * 
  * @access private
  * @return array of raid arrays
  */
 public function getRAID()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new LinfoTimerStart('RAID');
     }
     // Store it here
     $raidinfo = array();
     // mdadm?
     if (array_key_exists('mdadm', (array) $this->settings['raid']) && !empty($this->settings['raid']['mdadm'])) {
         // Try getting contents
         $mdadm_contents = LinfoCommon::getContents('/proc/mdstat', false);
         // No?
         if ($mdadm_contents === false) {
             $this->error->add('Linux softraid mdstat parser', '/proc/mdstat does not exist.');
         }
         // Parse
         @preg_match_all('/(\\S+)\\s*:\\s*(\\w+)\\s*raid(\\d+)\\s*([\\w+\\[\\d+\\] (\\(\\w\\))?]+)\\n\\s+(\\d+) blocks[^[]+\\[(\\d\\/\\d)\\] \\[([U\\_]+)\\]/mi', (string) $mdadm_contents, $match, PREG_SET_ORDER);
         // Store them here
         $mdadm_arrays = array();
         // Deal with entries
         foreach ((array) $match as $array) {
             // Temporarily store drives here
             $drives = array();
             // Parse drives
             foreach (explode(' ', $array[4]) as $drive) {
                 // Parse?
                 if (preg_match('/([\\w\\d]+)\\[\\d+\\](\\(\\w\\))?/', $drive, $match_drive) == 1) {
                     // Determine a status other than normal, like if it failed or is a spare
                     if (array_key_exists(2, $match_drive)) {
                         switch ($match_drive[2]) {
                             case '(S)':
                                 $drive_state = 'spare';
                                 break;
                             case '(F)':
                                 $drive_state = 'failed';
                                 break;
                             case null:
                                 $drive_state = 'normal';
                                 break;
                                 // I'm not sure if there are status codes other than the above
                             // I'm not sure if there are status codes other than the above
                             default:
                                 $drive_state = 'unknown';
                                 break;
                         }
                     } else {
                         $drive_state = 'normal';
                     }
                     // Append this drive to the temp drives array
                     $drives[] = array('drive' => '/dev/' . $match_drive[1], 'state' => $drive_state);
                 }
             }
             // Add record of this array to arrays list
             $mdadm_arrays[] = array('device' => '/dev/' . $array[1], 'status' => $array[2], 'level' => $array[3], 'drives' => $drives, 'size' => LinfoCommon::byteConvert($array[5] * 1024), 'count' => $array[6], 'chart' => $array[7]);
         }
         // Append MD arrays to main raidinfo if it's good
         if (is_array($mdadm_arrays) && count($mdadm_arrays) > 0) {
             $raidinfo = array_merge($raidinfo, $mdadm_arrays);
         }
     }
     // Return info
     return $raidinfo;
 }
 /**
  * @test
  */
 public function byteConvert()
 {
     $this->assertEquals('1000 KiB', LinfoCommon::byteConvert(1024000));
     $this->assertEquals('1 GiB', LinfoCommon::byteConvert(1073741824));
 }
 public function result()
 {
     if (!$this->res) {
         return false;
     }
     $rows[] = array('type' => 'header', 'columns' => array('Torrent/hash' . ($this->hideName ? ' (names hidden)' : ''), 'Size', 'Progress', 'Status', 'Seeds', 'Peers', 'Downloaded', 'Uploaded', 'Ratio', 'Speeds'));
     foreach ($this->torrents as $name => $info) {
         $rows[] = array('type' => 'values', 'columns' => array(($this->hideName ? '' : $info['TORRENT_NAME'] . '<br />') . '<span style="font-size: 80%; font-family: monaco, monospace, courier;">' . $info['TORRENT_HASH'] . '</span>', LinfoCommon::byteConvert($info['TORRENT_SIZE']), LinfoOutput::generateBarChart($info['TORRENT_PROGRESS'] / 10), $info['TORRENT_STATUS_MESSAGE'], $info['TORRENT_SEEDS_CONNECTED'] . '/' . $info['TORRENT_SEEDS_SWARM'], $info['TORRENT_SEEDS_CONNECTED'] . '/' . $info['TORRENT_PEERS_SWARM'], LinfoCommon::byteConvert($info['TORRENT_DOWNLOADED']), LinfoCommon::byteConvert($info['TORRENT_UPLOADED']), $info['TORRENT_RATIO'] > 0 ? round($info['TORRENT_RATIO'] / 1000, 2) ?: '0.0' : '0.0', LinfoCommon::byteConvert($info['TORRENT_DOWNSPEED']) . '/s &darr; ' . LinfoCommon::byteConvert($info['TORRENT_UPSPEED']) . '/s &uarr; '));
     }
     // Give it off
     return array('root_title' => '&micro;Torrent <span style="font-size: 80%;">(' . LinfoCommon::byteConvert($this->stats['downloaded']) . ' &darr; ' . LinfoCommon::byteConvert($this->stats['uploaded']) . ' &uarr; ' . round($this->stats['uploaded'] / $this->stats['downloaded'], 2) . ' ratio)</span>', 'rows' => $rows);
 }