Пример #1
0
 public function __construct(Linfo $linfo)
 {
     $this->linfo = $linfo;
     $this->_LinfoError = Errors::Singleton();
     $this->_CallExt = new CallExt();
     $this->_CallExt->setSearchPaths(array('/usr/bin', '/usr/local/bin', '/sbin', '/usr/local/sbin'));
 }
Пример #2
0
 public function work()
 {
     $t = new Timer('libvirt extension');
     if (!extension_loaded('libvirt')) {
         Errors::add('libvirt extension', 'Libvirt PHP extension not installed');
         $this->res = false;
         return;
     }
     if (!$this->connect()) {
         Errors::add('libvirt extension', 'Failed connecting');
         return;
     }
     if (!($doms = libvirt_list_domains($this->connection))) {
         Errors::add('libvirt extension', 'Failed getting domain list');
         $this->res = false;
         return;
     }
     foreach ($doms as $name) {
         if (!($domain = libvirt_domain_lookup_by_name($this->connection, $name))) {
             continue;
         }
         if (!($info = libvirt_domain_get_info($domain)) || !is_array($info)) {
             continue;
         }
         $info['autostart'] = libvirt_domain_get_autostart($domain);
         if ($info['autostart'] == 1) {
             $info['autostart'] = 'Yes';
         } elseif ($info['autostart'] == 0) {
             $info['autostart'] = 'No';
         } else {
             $info['autostart'] = 'N/A';
         }
         $info['nets'] = array();
         $nets = @libvirt_domain_get_interface_devices($domain);
         foreach ($nets as $key => $net) {
             if (!is_numeric($key)) {
                 continue;
             }
             $info['nets'][] = $net;
         }
         $info['storage'] = array();
         foreach ((array) @libvirt_domain_get_disk_devices($domain) as $blockName) {
             if (!is_string($blockName)) {
                 continue;
             }
             // Sometime device exists but libvirt fails to get more docs. just settle for device name
             if (!($blockInfo = @libvirt_domain_get_block_info($domain, $blockName)) || !is_array($blockInfo)) {
                 $info['storage'][] = array('device' => $blockName);
                 continue;
             }
             if (isset($blockInfo['partition']) && !isset($blockInfo['file'])) {
                 $blockInfo['file'] = $blockInfo['partition'];
             }
             $info['storage'][] = $blockInfo;
         }
         $this->VMs[$name] = $info;
     }
     $this->res = true;
 }
Пример #3
0
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     $this->LinfoError = Errors::Singleton();
     $this->connectionSettings = $settings['utorrent_connection'];
     $this->regexFilters = isset($settings['utorrent_filter']) && is_array($settings['utorrent_filter']) ? $settings['utorrent_filter'] : array();
     $this->hideName = isset($settings['utorrent_hide_name']) ? !empty($settings['utorrent_hide_name']) : false;
 }
Пример #4
0
 /**
  * localize important stuff.
  * @param Linfo $linfo
  */
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     // Localize error handler
     $this->_LinfoError = Errors::Singleton();
     // Should we hide mac addresses, to prevent stuff like mac address spoofing?
     $this->_hide_mac = array_key_exists('dnsmasq_hide_mac', $settings) ? (bool) $settings['dnsmasq_hide_mac'] : false;
     // Find leases file
     $this->_leases_file = isset($settings['dnsmasq_leases']) && is_file($settings['dnsmasq_leases']) ? $settings['dnsmasq_leases'] : Common::locateActualPath(array('/var/lib/libvirt/dnsmasq/default.leases'));
 }
Пример #5
0
 /**
  * localize important stuff.
  * @param Linfo $linfo
  */
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     // Localize error handler
     $this->_LinfoError = Errors::Singleton();
     // Should we hide mac addresses, to prevent stuff like mac address spoofing?
     $this->_hide_mac = array_key_exists('dhcpd3_hide_mac', $settings) ? (bool) $settings['dhcpd3_hide_mac'] : false;
     // Find leases file
     $this->_leases_file = Common::locateActualPath(array('/var/lib/dhcp/dhcpd.leases', '/var/lib/dhcp3/dhcpd.leases', '/var/lib/dhcpd/dhcpd.leases', '/var/state/dhcp/dhcpd.leases', '/var/db/dhcpd/dhcpd.leases', '/var/db/dhcpd.leases'));
 }
Пример #6
0
 /**
  * Constructor. Localizes settings.
  *
  * @param array $settings of linfo settings
  * @throws FatalException
  */
 public function __construct($settings)
 {
     // Localize settings
     $this->settings = $settings;
     // Localize error handler
     $this->error = Errors::Singleton();
     // Make sure we have what we need
     if (!is_dir('/sys') || !is_dir('/proc')) {
         throw new FatalException('This needs access to /proc and /sys to work.');
     }
 }
Пример #7
0
 protected function __construct($settings)
 {
     // Localize settings
     $this->settings = $settings;
     // Localize error handler
     $this->error = Errors::Singleton();
     // Exec running
     $this->exec = new CallExt();
     // Get dmesg
     $this->loadDmesg();
 }
Пример #8
0
 /**
  * Constructor. Localizes settings.
  *
  * @param array $settings of linfo settings
  * @throws FatalException
  */
 public function __construct($settings)
 {
     // Localize settings
     $this->settings = $settings;
     // Localize error handler
     $this->error = Errors::Singleton();
     // Get WMI instance
     $this->wmi = new COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
     if (!is_object($this->wmi)) {
         throw new FatalException('This needs access to WMI. Please enable DCOM in php.ini and allow the current user to access the WMI DCOM object.');
     }
 }
Пример #9
0
 /**
  * localize important stuff.
  * @param Linfo $linfo
  */
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     // Classes we need
     $this->_CallExt = new CallExt();
     $this->_CallExt->setSearchPaths(array('/usr/bin', '/usr/local/bin'));
     $this->_LinfoError = Errors::Singleton();
     // Transmission specific settings
     $this->_auth = array_key_exists('transmission_auth', $settings) ? (array) $settings['transmission_auth'] : array();
     $this->_host = array_key_exists('transmission_host', $settings) ? (array) $settings['transmission_host'] : array();
     // Path to home dir folder
     $this->_folder = array_key_exists('transmission_folder', $settings) && is_dir($settings['transmission_folder']) && is_readable($settings['transmission_folder']) ? $settings['transmission_folder'] : false;
 }
Пример #10
0
 private function _call()
 {
     // Time this
     $t = new Timer('Samba Status extension');
     // Deal with calling it
     try {
         $result = $this->_CallExt->exec('smbstatus');
     } catch (Exception $e) {
         // messed up somehow
         Errors::add('Samba Status Extension', $e->getMessage());
         $this->_res = false;
         // Don't bother going any further
         return false;
     }
     // Split it into lines
     $lines = explode("\n", $result);
     // Store temp stuff here
     $connections = array();
     $services = array();
     $files = array();
     $current_location = false;
     // Parse
     for ($i = 0, $num = count($lines); $i < $num; ++$i) {
         // Deal with pointlessness appropriately
         $lines[$i] = trim($lines[$i]);
         // Is this pointless?
         if ($lines[$i] == '' || preg_match('/^\\-+$/', $lines[$i])) {
             continue;
         } elseif (preg_match('/^PID\\s+Username\\s+Group\\s+Machine$/', $lines[$i])) {
             $current_location = 'c';
         } elseif ($current_location == 'c' && preg_match('/^(\\d+)\\s+(\\w+)\\s+(\\w+)\\s+(\\S+)\\s+\\(([^)]+)\\)$/', $lines[$i], $connection_match)) {
             $connections[] = array('pid' => $connection_match[1], 'username' => $connection_match[2], 'group' => $connection_match[3], 'hostname' => $connection_match[4], 'ip' => $connection_match[5]);
         } elseif (preg_match('/^Service\\s+pid\\s+machine\\s+Connected at$/', $lines[$i])) {
             $current_location = 's';
         } elseif ($current_location == 's' && preg_match('/^(\\w+)\\s+(\\d+)\\s+(\\S+)\\s+([a-zA-z]+ [a-zA-Z]+ \\d+ \\d+:\\d+:\\d+ \\d+)$/', $lines[$i], $service_match)) {
             $services[] = array('service' => $service_match[1], 'pid' => $service_match[2], 'machine' => $service_match[3], 'date' => strtotime($service_match[4]));
         } elseif (preg_match('/^Pid\\s+Uid\\s+DenyMode\\s+Access\\s+R\\/W\\s+Oplock\\s+SharePath\\s+Name\\s+Time$/', $lines[$i])) {
             $current_location = 'f';
         } elseif ($current_location == 'f' && preg_match('/^(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\S+)\\s+([A-Z]+)\\s+([A-Z+]+)\\s+(\\S+)\\s+(.+)\\s+([a-zA-Z]+ [a-zA-Z]+ \\d+ \\d+:\\d+:\\d+ \\d+)$/', $lines[$i], $file_match)) {
             $files[] = array('pid' => $file_match[1], 'uid' => $file_match[2], 'deny_mode' => $file_match[3], 'access' => $file_match[4], 'rw' => $file_match[5], 'oplock' => $file_match[6], 'share' => $file_match[7], 'filename' => $file_match[8], 'date' => strtotime($file_match[9]));
         }
     }
     // Give result
     $this->_res = array('connections' => $connections, 'services' => $services, 'files' => $files);
     // Success
     return true;
 }
Пример #11
0
 /**
  * Constructor.
  * @param $usb_file
  * @param $pci_file
  */
 public function __construct($usb_file, $pci_file)
 {
     // Localize paths to the ids files
     $this->_pci_file = $pci_file;
     $this->_usb_file = $usb_file;
     // Prefer json, but check for it
     $this->_use_json = function_exists('json_encode') && function_exists('json_decode');
     // Allow the same web root to be used for multiple insances of linfo, across multiple machines using
     // nfs or whatever, and to have a different cache file for each
     $sys_id = is_readable('/proc/sys/kernel/hostname') ? '_' . substr(md5(Common::getContents('/proc/sys/kernel/hostname')), 0, 10) : '_x';
     // Path to the cache file
     $this->_cache_file = dirname(dirname(dirname(__DIR__))) . '/cache/ids_cache' . $sys_id . ($this->_use_json ? '.json' : '');
     // Load contents of cache
     $this->_populate_cache();
     // Might need these
     $this->exec = new CallExt();
     $this->exec->setSearchPaths(array('/sbin', '/bin', '/usr/bin', '/usr/local/bin', '/usr/sbin'));
     $this->error = Errors::Singleton();
 }
Пример #12
0
 private function _call()
 {
     // Time this
     $t = new Timer('CUPS extension');
     // Deal with calling it
     try {
         $result = $this->_CallExt->exec('lpstat', '-p -o -l');
     } catch (Exception $e) {
         // messed up somehow
         Errors::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' => Common::byteConvert($queue_match[5]));
         }
     }
     // Save result lset
     $this->_res = array('printers' => $printers, 'queue' => $queue);
     // Apparent success
     return true;
 }
Пример #13
0
 public function work()
 {
     $info =& $this->linfo->getInfo();
     // Make sure this is an array
     $info['Temps'] = (array) $info['Temps'];
     // Time this
     $t = new Timer(self::EXTENSION_NAME . ' Extension');
     // Deal with calling it
     try {
         $result = $this->_CallExt->exec('ipmitool', ' sdr');
     } catch (Exception $e) {
         // messed up somehow
         Errors::add(self::EXTENSION_NAME . ' Extension', $e->getMessage());
         return;
     }
     // Match it up
     if (!preg_match_all('/^([^|]+)\\| ([\\d\\.]+ (?:Volts|degrees [CF]))\\s+\\| ok$/m', $result, $matches, PREG_SET_ORDER)) {
         return;
     }
     // Go through with it
     foreach ($matches as $m) {
         // Separate them by normal spaces
         $v_parts = explode(' ', trim($m[2]));
         // Deal with the type of it
         switch ($v_parts[1]) {
             case 'Volts':
                 $unit = 'v';
                 break;
             case 'degrees':
                 $unit = $v_parts[2];
                 break;
             default:
                 $unit = '';
                 break;
         }
         // Save this one
         $info['Temps'][] = array('path' => 'N/A', 'name' => trim($m[1]), 'temp' => $v_parts[0], 'unit' => $unit);
     }
 }
Пример #14
0
 /**
  * Deal with it.
  */
 private function _call()
 {
     // Time this
     $t = new Timer('dhcpd3 leases extension');
     // We couldn't find leases file?
     if ($this->_leases_file === false) {
         Errors::add('dhcpd3 leases extension', 'couldn\'t find leases file');
         $this->_res = false;
         return;
     }
     // Get contents
     $contents = Common::getContents($this->_leases_file, false);
     // Couldn't?
     if ($contents === false) {
         Errors::add('dhcpd3 leases extension', 'Error getting contents of leases file');
         $this->_res = false;
         return;
     }
     // All dates in the file are in UTC format. Attempt finding out local time zone to convert UTC to local.
     // This prevents confusing the hell out of people.
     $do_date_conversion = false;
     $local_timezone = false;
     // Make sure we have what we need. Stuff this requires doesn't exist on certain php installations
     if (function_exists('date_default_timezone_get') && class_exists('DateTime') && class_exists('DateTimeZone')) {
         // I only want this called once, hence value stored here. It also might fail
         $local_timezone = @date_default_timezone_get();
         // Make sure it didn't fail
         if ($local_timezone !== false && is_string($local_timezone)) {
             $do_date_conversion = true;
         }
         // Say we'll allow conversion later on
     }
     // Get it into lines
     $lines = explode("\n", $contents);
     // Store temp entries here
     $curr = false;
     // Parse each line, while ignoring certain useless'ish values
     // I'd do a single preg_match_all() using multiline regex, but the values in each lease block are inconsistent. :-/
     for ($i = 0, $num_lines = count($lines); $i < $num_lines; ++$i) {
         // Kill padding whitespace
         $lines[$i] = trim($lines[$i]);
         // Last line in entry
         if ($lines[$i] == '}') {
             // Have we a current entry to save?
             if (is_array($curr)) {
                 $this->_leases[] = $curr;
             }
             // Make it empty for next time
             $curr = false;
         } elseif (preg_match('/^lease (\\d+\\.\\d+\\.\\d+\\.\\d+) \\{$/', $lines[$i], $m)) {
             $curr = array('ip' => $m[1]);
         } elseif ($curr && preg_match('/^starts \\d+ (\\d+\\/\\d+\\/\\d+ \\d+:\\d+:\\d+);$/', $lines[$i], $m)) {
             // Get it in unix time stamp for prettier formatting later and easier tz offset conversion
             $curr['lease_start'] = strtotime($m[1]);
             // Handle offset conversion
             if ($do_date_conversion) {
                 // This handy class helps out with timezone offsets. Pass it original date, not unix timestamp
                 $d = new DateTime($m[1], new DateTimeZone($local_timezone));
                 $offset = $d->getOffset();
                 // If ofset looks good, deal with it
                 if (is_numeric($offset) && $offset != 0) {
                     $curr['lease_start'] += $offset;
                 }
             }
         } elseif ($curr && preg_match('/^ends \\d+ (\\d+\\/\\d+\\/\\d+ \\d+:\\d+:\\d+);$/', $lines[$i], $m)) {
             // Get it in unix time stamp for prettier formatting later and easier tz offset conversion
             $curr['lease_end'] = strtotime($m[1]);
             // Handle offset conversion
             if ($do_date_conversion) {
                 // This handy class helps out with timezone offsets. Pass it original date, not unix timestamp
                 $d = new DateTime($m[1], new DateTimeZone($local_timezone));
                 $offset = $d->getOffset();
                 // If ofset looks good, deal with it
                 if (is_numeric($offset) && $offset != 0) {
                     $curr['lease_end'] += $offset;
                 }
             }
             // Is this old?
             // The file seems to contain all leases since the dhcpd server was started for the first time
             if (time() > $curr['lease_end']) {
                 // Kill current entry and ignore any following parts of this lease
                 $curr = false;
                 // Jump out right now
                 continue;
             }
         } elseif (!$this->_hide_mac && $curr && preg_match('/^hardware ethernet (\\w+:\\w+:\\w+:\\w+:\\w+:\\w+);$/', $lines[$i], $m)) {
             $curr['mac'] = $m[1];
         } elseif ($curr && preg_match('/^client\\-hostname "([^"]+)";$/', $lines[$i], $m)) {
             $curr['hostname'] = $m[1];
         }
     }
 }
Пример #15
0
    public function output()
    {
        $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 = $info['OS'] == '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">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>' . $appName . ' - ' . $info['HostName'] . '</title>
	<link href="./layout/favicon.ico" type="image/x-icon" rel="shortcut icon">
	<link href="./layout/' . $theme_css . '" rel="stylesheet">' . ($show_icons ? '
	<link href="./layout/icons.css" rel="stylesheet">' : '') . '
	<script src="./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="./layout/old_ie.css" type="text/css" rel="stylesheet">
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="./layout/mobile.css" media="screen and (max-width: 640px)">
</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($this->linfo->getLocalDir() . 'layout/icons/os_' . $os_icon . '.gif') || file_exists($this->linfo->getLocalDir() . '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($this->linfo->getLocalDir() . 'layout/icons/distro_' . $distro_icon . '.gif') || file_exists($this->linfo->getLocalDir() . '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']) && $info['UpTime']) {
            $core[] = array($lang['uptime'], $info['UpTime']['text'] . (isset($info['UpTime']['bootedTimestamp']) && $info['UpTime']['bootedTimestamp'] ? '; booted ' . date($settings['dates'], $info['UpTime']['bootedTimestamp']) : ''));
        }
        // Hostname
        if (!empty($settings['show']['hostname'])) {
            $core[] = array($lang['hostname'], $info['HostName']);
        }
        //Web server
        if (!empty($settings['show']['webservice'])) {
            $core[] = array($lang['webservice'], $info['webService']);
        }
        //Php version
        if (!empty($settings['show']['phpversion'])) {
            $core[] = array($lang['phpversion'], $info['phpVersion']);
        }
        // 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'], self::generateBarChart($info['cpuUsage']));
        }
        // System Load
        if (!empty($settings['show']['load'])) {
            $core[] = array($lang['load'], implode(' ', (array) $info['Load']));
        }
        // 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']);
        }
        // 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: 12%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
				</colgroup>
				<tr>
					<th>' . $lang['type'] . '</th>
					<th>' . $lang['size'] . '</th>
					<th>' . $lang['used'] . '</th>
					<th>' . $lang['free'] . '</th>
					<th>' . $lang['percent_used'] . '</th>
				</tr>
				<tr>
					<td>' . $info['RAM']['type'] . '</td>
					<td>' . Common::byteConvert($info['RAM']['total']) . '</td>
					<td>' . Common::byteConvert($info['RAM']['total'] - $info['RAM']['free']) . '</td>
					<td>' . Common::byteConvert($info['RAM']['free']) . '</td>
					<td>' . self::generateBarChart(round(($info['RAM']['total'] - $info['RAM']['free']) * 100 / $info['RAM']['total'])) . '</td>
				</tr>';
            $have_swap = isset($info['RAM']['swapFree']) || isset($info['RAM']['swapTotal']);
            if ($have_swap && !empty($info['RAM']['swapTotal'])) {
                // 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>' . Common::byteConvert(@$info['RAM']['swapTotal']) . '</td>
						<td>' . Common::byteConvert(@$info['RAM']['swapTotal'] - $info['RAM']['swapFree']) . '</td>
						<td>' . Common::byteConvert(@$info['RAM']['swapFree']) . '</td>
						<td>' . self::generateBarChart(round(($info['RAM']['swapTotal'] - $info['RAM']['swapFree']) * 100 / $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="4">
								<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>' . Common::byteConvert($swap['size']) . '</td>
											<td>' . Common::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 network_devices">
			<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>' . Common::byteConvert($stats['sent']['bytes']) . '</td>
					<td>' . Common::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>' . self::generateBarChart((int) $bat['percentage'], $bat['percentage'] > -1 ? $bat['percentage'] . '%' : 'N/A') . '</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'] ? Common::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>' . $lang['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'] ? Common::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']) . ' - ' . Common::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 filesystem_mounts">
	<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'];
                        }
                    } elseif (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>' . Common::byteConvert($mount['size']) . '</td>
					<td>' . Common::byteConvert($mount['used']) . ($mount['used_percent'] !== false ? ' <span class="perc">(' . $mount['used_percent'] . '%)</span>' : '') . '</td>
					<td>' . Common::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>' . Common::byteConvert($total_size) . '</td>
			<td>' . Common::byteConvert($total_used) . '</td>
			<td>' . Common::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 drives">
	<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']) && Errors::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 (Errors::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 (Timer::getResults() as $result) {
                echo '
				<tr>
					<td>' . $result['id'] . '</td>
					<td>' . round($result['duration'], 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>';
    }
Пример #16
0
 public function getHD()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new Timer('Drives');
     }
     // Use system profiler to get info
     try {
         $res = $this->exec->exec('diskutil', ' list');
     } catch (Exception $e) {
         Errors::add('Linfo drives', 'Error using `diskutil list` to get drives');
         return array();
     }
     // Get it into lines
     $lines = explode("\n", $res);
     // Keep drives here
     $drives = array();
     // Work on tmp drive here
     $tmp = false;
     for ($i = 0, $num_lines = count($lines); $i < $num_lines; ++$i) {
         // A drive or partition entry
         if (preg_match('/^\\s+(\\d+):\\s+([a-zA-Z0-9\\_]+)\\s+([\\s\\w]*) \\*?(\\d+(?:\\.\\d+)? [A-Z])B\\s+([a-z0-9]+)/', $lines[$i], $m)) {
             // Get size sorted out
             $size_parts = explode(' ', $m[4]);
             switch ($size_parts[1]) {
                 case 'K':
                     $size = $size_parts[0] * 1000;
                     break;
                 case 'M':
                     $size = $size_parts[0] * 1000000;
                     break;
                 case 'G':
                     $size = $size_parts[0] * 1000000000;
                     break;
                 case 'T':
                     $size = $size_parts[0] * 1000000000000;
                     break;
                 case 'P':
                     $size = $size_parts[0] * 1000000000000000;
                     break;
                 default:
                     $size = false;
                     break;
             }
             // A drive?
             if ($m[1] == 0) {
                 // Finish prior drive
                 if (is_array($tmp)) {
                     $drives[] = $tmp;
                 }
                 // Try getting the name
                 $drive_name = false;
                 // I'm pessimistic
                 try {
                     $drive_res = $this->exec->exec('diskutil', ' info /dev/' . $m[5]);
                     if (preg_match('/^\\s+Device \\/ Media Name:\\s+(.+)/m', $drive_res, $drive_m)) {
                         $drive_name = $drive_m[1];
                     }
                 } catch (Exception $e) {
                 }
                 // Start this one off
                 $tmp = array('name' => $drive_name, 'vendor' => 'Unknown', 'device' => '/dev/' . $m[5], 'reads' => false, 'writes' => false, 'size' => $size, 'partitions' => array());
             } elseif ($m[1] > 0) {
                 // Save it
                 $tmp['partitions'][] = array('size' => $size, 'name' => '/dev/' . $m[5]);
             }
         }
     }
     // Save a drive
     if (is_array($tmp)) {
         $drives[] = $tmp;
     }
     // Give
     return $drives;
 }
Пример #17
0
 protected function runExtensions()
 {
     $this->info['extensions'] = array();
     if (!array_key_exists('extensions', $this->settings) || count($this->settings['extensions']) == 0) {
         return;
     }
     // Go through each enabled extension
     foreach ((array) $this->settings['extensions'] as $ext => $enabled) {
         // Is it really enabled?
         if (empty($enabled)) {
             continue;
         }
         // Anti hack
         if (!preg_match('/^[a-z0-9-_]+$/i', $ext)) {
             Errors::add('Extension Loader', 'Not going to load "' . $ext . '" extension as only characters allowed in name are letters/numbers/-_');
             continue;
         }
         // Support older config files with lowercase
         if (preg_match('/^[a-z]/', $ext)) {
             $ext = ucfirst($ext);
         }
         // Try loading our class..
         try {
             $reflector = new ReflectionClass('\\Linfo\\Extension\\' . $ext);
             $ext_class = $reflector->newInstance($this);
         } catch (ReflectionException $e) {
             Errors::add('Extension Loader', 'Cannot instantiate class for "' . $ext . '" extension: ' . $e->getMessage());
             continue;
         }
         // Deal with it
         $ext_class->work();
         // Does this edit the $info directly, instead of creating a separate output table type thing?
         if (!$reflector->hasConstant('LINFO_INTEGRATE')) {
             // Result
             $result = $ext_class->result();
             // Save result if it's good
             if ($result != false) {
                 $this->info['extensions'][$ext] = $result;
             }
         }
     }
 }
Пример #18
0
    public function output()
    {
        $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 = $info['OS'] == '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">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>' . $appName . ' - ' . $info['HostName'] . '</title>
    <meta name="generator" content="' . $appName . ' (' . $version . ')">
    <meta name="author" content="Joseph Gillotti &amp; friends">

    <style>
    body{font-family:arial,sans-serif;background-color:#fff;color:#000;font-size:12px}a{color:#666}a:hover{color:#000}table{border-collapse:collapse;width:100%}table th{font-weight:normal;color:#444}table th,table td{border-right:1px solid #c3c3c3;border-left:1px solid #c3c3c3;border-bottom:1px solid #c3c3c3;padding:4px;background-color:#eee}table tr th,table tr.alt td{background-color:#ddd}.infoTable{margin:10px 5px 10px 5px;clear:both;box-shadow:none}.infoTable h2{margin:0;padding:5px;color:#fff;text-shadow:#2665a7 1px 1px 1px;border:1px solid #4a8fd6;background-color:#5c9ada}.infoTable,.infoTable h2{border-top-left-radius:3px;border-top-right-radius:3px;-moz-border-radius-topleft:3px;-moz-border-radius-topright:3px}.infoTable.collapsed{border-bottom-left-radius:4px;border-bottom-right-radius:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-bottomright:4px}.collapsed h2{border-bottom-left-radius:3px;border-bottom-right-radius:3px;-moz-border-radius-bottomleft:3px;-moz-border-radius-bottomright:3px}.collapsed table{display:none}#foot{margin:15px 0px 20px 15px;color:#444;float:left}#foot_time{margin:15px 15px 20px 0px;color:#444;float:right;vertical-align:bottom}h1{font-size:1.6em;margin:0;padding:0}h2{font-size:1.2em;margin:0}.col2{overflow:hidden}.col2 .col{float:left;width:50%}#info .center{text-align:center}td.none{text-align:center;font-size:12px;padding:10px;color:#666}span.perc,span.faded{color:#666}span.caption{font-size:90%}td ul{margin:0;padding:0}td ul li{list-style-type:square;padding:0;margin-left:15px;margin-top:0;margin-bottom:0;margin-right:0}.raid_normal{color:green}.raid_spare{color:blue}.raid_failed{color:red}.raid_unknown{color:purple}.margin_auto{margin:auto}table.mini{padding:0;font-size:90%;border-collapse:collapse}table.mini th,table.mini td{margin:0;padding:0;border:none}table.mini th{background-color:inherit;color:#444}.net_up{color:green}.net_down{color:red}.net_unknown{color:purple}#errorList,#timerList{font-size:75%;margin-top:15px;margin-bottom:15px}.bar_chart{position:relative;margin:auto}.smaller_bar_chart{padding-bottom:2px}.smaller_bar_chart .bar_text{text-align:left !important}.bar_inner{border-radius:2px;-moz-border-radius:2px;min-height:18px;background-color:#b7cce2}.bar_text{position:absolute;line-height:18px;font-size:12px;text-indent:2px;text-align:center;width:100%}.new_bar_outer{position:relative;margin:auto;background-color:inherit}.new_bar_text{z-index:2;position:relative;padding:2px;text-align:center;color:#000}.new_bar_bg{border-radius:2px;-moz-border-radius:2px;z-index:1;height:100%;position:absolute;display:block;background-color:#b7cce2}.new_bar_left .new_bar_text{text-align:left}.alt .bar_inner,.alt .new_bar_bg{background-color:#96b4d5}.service_up{color:green}.service_down{color:maroon}.service_zombie{color:orange}span.toggler{line-height:24px;color:#8abdf2;float:right;font-family:"Courier New";cursor:pointer;font-weight:bold;font-size:1.4em;padding-top:0.2em;padding-right:0.4em}.infoTable span.toggler:hover{color:#fff}#header{padding:5px 0px 5px 5px}#header:before{float:left;content:url("icons/logo.png");display:inline-block;margin-right:10px}.subtitle{color:#999;font-size:12px}.time{padding:5px 15px 0px 0px;color:#999;float:right;text-align:right}.col2_side{overflow:hidden}.col2_side_left{float:left;width:80%}.col2_side_right{float:left;width:20%}

        @media only screen and (max-width: 640px) {
        .col2 .col{width:100%}.infoTable{margin:0px 0px 5px 0px}#header{padding:0px 0px 5px 2px}.filesystem_mounts table th:nth-child(2),.filesystem_mounts table td:nth-child(2),.filesystem_mounts table th:nth-child(3),.filesystem_mounts table td:nth-child(3),.filesystem_mounts table th:nth-child(4),.filesystem_mounts table td:nth-child(4),.network_devices table th:nth-child(2),.network_devices table td:nth-child(2),.drives table th:nth-child(2),.drives table td:nth-child(2),.drives table th:nth-child(3),.drives table td:nth-child(3){display:none}#foot_time{margin:0}#foot{margin:5px 5px 0px 5px}
        }
    </style>
</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($this->linfo->getLocalDir() . 'layout/icons/os_' . $os_icon . '.gif') || file_exists($this->linfo->getLocalDir() . '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($this->linfo->getLocalDir() . 'layout/icons/distro_' . $distro_icon . '.gif') || file_exists($this->linfo->getLocalDir() . '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']) && $info['UpTime']) {
            $core[] = array($lang['uptime'], $info['UpTime']['text'] . (isset($info['UpTime']['bootedTimestamp']) && $info['UpTime']['bootedTimestamp'] ? '; booted ' . date($settings['dates'], $info['UpTime']['bootedTimestamp']) : ''));
        }
        // Hostname
        if (!empty($settings['show']['hostname'])) {
            $core[] = array($lang['hostname'], $info['HostName']);
        }
        //Web server
        if (!empty($settings['show']['webservice'])) {
            $core[] = array($lang['webservice'], $info['webService']);
        }
        //Php version
        if (!empty($settings['show']['phpversion'])) {
            $core[] = array($lang['phpversion'], $info['phpVersion']);
        }
        // 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'], self::generateBarChart($info['cpuUsage']));
        }
        // System Load
        if (!empty($settings['show']['load'])) {
            $core[] = array($lang['load'], implode(' ', (array) $info['Load']));
        }
        // 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']);
        }
        // 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: 12%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
					<col style="width: 23%;" />
				</colgroup>
				<tr>
					<th>' . $lang['type'] . '</th>
					<th>' . $lang['size'] . '</th>
					<th>' . $lang['used'] . '</th>
					<th>' . $lang['free'] . '</th>
					<th>' . $lang['percent_used'] . '</th>
				</tr>
				<tr>
					<td>' . $info['RAM']['type'] . '</td>
					<td>' . Common::byteConvert($info['RAM']['total']) . '</td>
					<td>' . Common::byteConvert($info['RAM']['total'] - $info['RAM']['free']) . '</td>
					<td>' . Common::byteConvert($info['RAM']['free']) . '</td>
					<td>' . self::generateBarChart(round(($info['RAM']['total'] - $info['RAM']['free']) * 100 / $info['RAM']['total'])) . '</td>
				</tr>';
            $have_swap = isset($info['RAM']['swapFree']) || isset($info['RAM']['swapTotal']);
            if ($have_swap && !empty($info['RAM']['swapTotal'])) {
                // 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>' . Common::byteConvert(@$info['RAM']['swapTotal']) . '</td>
						<td>' . Common::byteConvert(@$info['RAM']['swapTotal'] - $info['RAM']['swapFree']) . '</td>
						<td>' . Common::byteConvert(@$info['RAM']['swapFree']) . '</td>
						<td>' . self::generateBarChart(round(($info['RAM']['swapTotal'] - $info['RAM']['swapFree']) * 100 / $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="4">
								<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>' . Common::byteConvert($swap['size']) . '</td>
											<td>' . Common::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 network_devices">
			<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>' . Common::byteConvert($stats['sent']['bytes']) . '</td>
					<td>' . Common::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>' . self::generateBarChart((int) $bat['percentage'], $bat['percentage'] > -1 ? $bat['percentage'] . '%' : 'N/A') . '</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'] ? Common::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>' . $lang['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'] ? Common::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']) . ' - ' . Common::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 filesystem_mounts">
	<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'];
                        }
                    } elseif (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>' . Common::byteConvert($mount['size']) . '</td>
					<td>' . Common::byteConvert($mount['used']) . ($mount['used_percent'] !== false ? ' <span class="perc">(' . $mount['used_percent'] . '%)</span>' : '') . '</td>
					<td>' . Common::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>' . Common::byteConvert($total_size) . '</td>
			<td>' . Common::byteConvert($total_used) . '</td>
			<td>' . Common::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 drives">
	<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']) && Errors::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 (Errors::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 (Timer::getResults() as $result) {
                echo '
				<tr>
					<td>' . $result['id'] . '</td>
					<td>' . round($result['duration'], 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>

</body>
</html>';
    }
Пример #19
0
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     $this->Errors = Errors::Singleton();
     $this->connectionSettings = $settings['libvirt_connection'];
 }
Пример #20
0
 /**
  * Deal with it.
  */
 private function _call()
 {
     // Time this
     $t = new Timer('Transmission extension');
     // Deal with stats, if possible
     if ($this->_folder && ($stats_contents = Common::getContents($this->_folder . 'stats.json', false)) && $stats_contents != false) {
         $stats_vals = @json_decode($stats_contents, true);
         if (is_array($stats_vals)) {
             $this->_stats = $stats_vals;
         }
     }
     // Deal with calling it
     try {
         // Start up args
         $args = '';
         // Specifc host/port?
         if (array_key_exists('server', $this->_host) && array_key_exists('port', $this->_host) && is_numeric($this->_host['port'])) {
             $args .= ' \'' . $this->_host['server'] . '\':' . $this->_host['port'];
         }
         // We need some auth?
         if (array_key_exists('user', $this->_auth) && array_key_exists('pass', $this->_auth)) {
             $args .= ' --auth=\'' . $this->_auth['user'] . '\':\'' . $this->_auth['pass'] . '\'';
         }
         // Rest of it, including result
         $result = $this->_CallExt->exec('transmission-remote', $args . ' -l');
     } catch (Exception $e) {
         // messed up somehow
         Errors::add('Transmission extension: ', $e->getMessage());
         $this->_res = false;
         // Don't bother going any further
         return;
     }
     $this->_res = true;
     // Get first line
     $first_line = reset(explode("\n", $result, 1));
     // Invalid host?
     if (strpos($first_line, 'Couldn\'t resolve host name') !== false) {
         Errors::add('Transmission extension: Invalid Host');
         $this->_res = false;
         return;
     }
     // Invalid auth?
     if (strpos($first_line, '401: Unauthorized') !== false) {
         Errors::add('Transmission extension: Invalid Authentication');
         $this->_res = false;
         return;
     }
     // Match teh torrents!
     if (preg_match_all('/^\\s+(\\d+)\\*?\\s+(\\d+)\\%\\s+(\\d+\\.\\d+ \\w+|None)\\s+((?:\\d+ )?\\w+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+|None)\\s+(Up & Down|Seeding|Idle|Stopped)\\s+(.+)$/m', $result, $matches, PREG_SET_ORDER) > 0) {
         // Use this to sort them
         $sort_done = array();
         $sort_ratio = array();
         $sort_name = array();
         // Save the matches
         for ($i = 0, $num = count($matches); $i < $num; ++$i) {
             // Save this one
             $this->_torrents[$i] = array('id' => $matches[$i][1], 'done' => $matches[$i][2], 'have' => $matches[$i][3], 'eta' => $matches[$i][4], 'up' => $matches[$i][5] * 1024, 'down' => $matches[$i][6] * 1024, 'ratio' => $matches[$i][7], 'state' => $matches[$i][8], 'torrent' => $matches[$i][9]);
             // Use this for sorting
             $sort_done[$i] = (int) $matches[$i][2];
             $sort_ratio[$i] = (double) $matches[$i][7];
             $sort_name[$i] = $matches[$i][9];
         }
         // Sort
         array_multisort($sort_done, SORT_DESC, $sort_ratio, SORT_DESC, $sort_name, SORT_ASC, $this->_torrents);
     }
 }
Пример #21
0
    private function _call()
    {
        // Time this
        $t = new Timer('apcaccess Extension');
        // Deal with calling it
        try {
            $result = $this->_CallExt->exec('apcaccess');
        } catch (Exception $e) {
            // messed up somehow
            Errors::add('apcaccess Extension', $e->getMessage());
            $this->_res = false;
            // Don't bother going any further
            return false;
        }
        // Store them here
        $this->_res = array();
        // Get name
        if (preg_match('/^UPSNAME\\s+:\\s+(.+)$/m', $result, $m)) {
            $this->_res['name'] = $m[1];
        }
        // Get model
        if (preg_match('/^MODEL\\s+:\\s+(.+)$/m', $result, $m)) {
            $this->_res['model'] = $m[1];
        }
        // Get battery voltage
        if (preg_match('/^BATTV\\s+:\\s+(\\d+\\.\\d+)/m', $result, $m)) {
            $this->_res['volts'] = $m[1];
        }
        // Get charge percentage, and get it cool
        if (preg_match('/^BCHARGE\\s+:\\s+(\\d+(?:\\.\\d+)?)/m', $result, $m)) {
            $charge = (int) $m[1];
            $this->_res['charge'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: ' . (int) $charge . '%;">
							<div class="bar_text">
								' . ($charge ? $charge . '%' : '?') . '
							</div>
						</div>
					</div>
			';
        }
        // Get time remaning
        if (preg_match('/^TIMELEFT\\s+:\\s+([\\d\\.]+)/m', $result, $m)) {
            $this->_res['time_left'] = Common::secondsConvert($m[1] * 60);
        }
        // Get status
        if (preg_match('/^STATUS\\s+:\\s+([A-Z]+)/m', $result, $m)) {
            $this->_res['status'] = $m[1] == 'ONBATT' ? 'On Battery' : ucfirst(strtolower($m[1]));
        }
        // Load percentage looking cool
        if (preg_match('/^LOADPCT\\s+:\\s+(\\d+\\.\\d+)/m', $result, $m)) {
            $load = (int) $m[1];
            $this->_res['load'] = '
					<div class="bar_chart">
						<div class="bar_inner" style="width: ' . (int) $load . '%;">
							<div class="bar_text">
								' . ($load ? $load . '%' : '?') . '
							</div>
						</div>
					</div>
			';
        }
        // Attempt getting wattage
        if (isset($load) && preg_match('/^NOMPOWER\\s+:\\s+(\\d+)/m', $result, $m)) {
            $watts = (int) $m['1'];
            $this->_res['watts_used'] = $load * round($watts / 100);
        } else {
            $this->_res['watts_used'] = false;
        }
        // Apparent success
        return true;
    }
Пример #22
0
 private function _fetchPciIdsPciConf()
 {
     try {
         $pciconf = $this->exec->exec('pciconf', '-l');
     } catch (Exception $e) {
         Errors::add('Linfo Core', 'Error using `pciconf -l` to get hardware info');
         return;
     }
     if (preg_match_all('/^.+chip=0x([a-z0-9]{4})([a-z0-9]{4})/m', $pciconf, $devs, PREG_SET_ORDER) == 0) {
         return;
     }
     foreach ($devs as $dev) {
         $this->_pci_entries[$dev[2]][$dev[1]] = 1;
     }
 }
Пример #23
0
 public function work()
 {
     $t = new Timer('utorrent extension');
     $this->res = false;
     if (!extension_loaded('curl')) {
         Errors::add('utorrent extension', 'Curl PHP extension not installed');
         return;
     }
     if (!isset($this->connectionSettings['host']) || !isset($this->connectionSettings['port']) || !isset($this->connectionSettings['user'])) {
         Errors::add('utorrent extension', 'Missing $setting[\'utorrent_connection\'] details in config..');
         return;
     }
     $token_url = sprintf(self::TOKEN_URL, $this->connectionSettings['host'], $this->connectionSettings['port']);
     // Start up our curl session to be used for both requests. It is going to store the cookies utorrent
     // uses
     $curl = curl_init();
     // For curl to actually process cokies we need to give it a filename. This should be filed as a
     // bug to curl, especially since something like /dev/null works
     $this->cookiefile = tempnam('/tmp', 'linfo_utorrent');
     curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $this->connectionSettings['user'] . ':', CURLOPT_COOKIEJAR => $this->cookiefile ?: '/dev/null'));
     // Get token
     curl_setopt($curl, CURLOPT_URL, $token_url);
     $result = curl_exec($curl);
     if (preg_match('/\\>([^<]+)\\</', $result, $m)) {
         $token = $m[1];
     } else {
         Errors::add('utorrent extension', 'Failed parsing token');
         $this->cleanup();
         return;
     }
     // Get list of torrents? Do our best to forge this (ajax) request
     curl_setopt_array($curl, array(CURLOPT_HTTPHEADER => array('X-Requested-With: XMLHttpRequest', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Firefox/28.0', 'Host: ' . $this->connectionSettings['host'] . ($this->connectionSettings['port'] != 80 ? ':' . $this->connectionSettings['port'] : ''), 'Referer: http://' . $this->connectionSettings['host'] . ($this->connectionSettings['port'] != 80 ? ':' . $this->connectionSettings['port'] : '') . '/gui/web/index.html')));
     $list_url = sprintf(self::LIST_URL, $this->connectionSettings['host'], $this->connectionSettings['port'], $token, '1');
     curl_setopt($curl, CURLOPT_URL, $list_url);
     $result = curl_exec($curl);
     if (!($response = @json_decode($result, true))) {
         Errors::add('utorrent extension', 'Failed parsing json object');
         $this->cleanup();
         return;
     }
     // Not going to be needing curl again
     curl_close($curl);
     if (!isset($response['torrents']) || !is_array($response['torrents'])) {
         Errors::add('utorrent extension', 'torrents array key not found in json response object');
         $this->cleanup();
         return;
     }
     $torrent_names = array();
     $torrent_states = array();
     foreach ($response['torrents'] as $torrent_src) {
         $torrent = array();
         foreach (self::$torrent_keys as $key => $index) {
             $torrent[$key] = $torrent_src[$index];
         }
         foreach ($this->regexFilters as $regex) {
             if (preg_match($regex, $torrent['TORRENT_NAME'])) {
                 continue 2;
             }
         }
         $this->torrents[] = $torrent;
         $torrent_names[] = $torrent['TORRENT_NAME'];
         $torrent_states[] = $torrent['TORRENT_STATUS_MESSAGE'];
         $this->stats['downloaded'] += $torrent['TORRENT_DOWNLOADED'];
         $this->stats['uploaded'] += $torrent['TORRENT_UPLOADED'];
     }
     // Sort by state and then name ascending (show downloading/etc first)
     array_multisort($torrent_states, SORT_ASC, $torrent_names, SORT_ASC, $this->torrents);
     $this->res = true;
     $this->cleanup();
 }
Пример #24
0
 public function tearDown()
 {
     Errors::clear();
 }
Пример #25
0
 /**
  * getSoundCards.
  * 
  * @return array of soundcards
  */
 public function getSoundCards()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new Timer('Sound cards');
     }
     // This should be it
     $file = '/proc/asound/cards';
     // eh?
     if (!is_file($file)) {
         Errors::add('Linux sound card detector', '/proc/asound/cards does not exist');
     }
     // Get contents and parse
     $contents = Common::getContents($file);
     // Parse
     if (preg_match_all('/^\\s*(\\d+)\\s\\[[\\s\\w]+\\]:\\s(.+)$/m', $contents, $matches, PREG_SET_ORDER) == 0) {
         return array();
     }
     // eh?
     $cards = array();
     // Deal with results
     foreach ($matches as $card) {
         $cards[] = array('number' => $card[1], 'card' => $card[2]);
     }
     // Give cards
     return $cards;
 }
Пример #26
0
 private function _call()
 {
     // Time this
     $t = new Timer('Truecrypt Extension');
     // Deal with calling it
     try {
         $result = $this->_CallExt->exec('truecrypt', '-l -v');
     } catch (Exception $e) {
         // messed up somehow
         Errors::add('Truecrypt Extension', $e->getMessage());
         $this->_res = false;
         // Don't bother going any further
         return false;
     }
     // Store them here
     $this->_res = array();
     // Current one
     $curr = false;
     // Lines of output
     $lines = explode("\n", $result);
     // Go through each line
     for ($i = 0, $num = count($lines); $i < $num; ++$i) {
         // Extract juicy info
         if (!preg_match('/^([^:]+): ([^$]+)$/', $lines[$i], $line_match)) {
             continue;
         }
         // Decide what to do with that
         switch ($line_match[1]) {
             // It starts here
             case 'Slot':
                 if ($curr === false) {
                     $curr = array('slot' => $line_match[2]);
                 } elseif (is_array($curr)) {
                     $this->_res[] = $curr;
                     $curr = false;
                 }
                 break;
                 // Volume.
             // Volume.
             case 'Volume':
                 if (is_array($curr)) {
                     $curr['volume'] = $line_match[2];
                 }
                 break;
                 // Virtual device
             // Virtual device
             case 'Virtual Device':
                 if (is_array($curr)) {
                     $curr['virtual_device'] = $line_match[2];
                 }
                 break;
                 // Where it might be mounted
             // Where it might be mounted
             case 'Mount Directory':
                 if (is_array($curr)) {
                     $curr['mount_directory'] = $line_match[2];
                 }
                 break;
                 // Size of it
             // Size of it
             case 'Size':
                 if (is_array($curr)) {
                     $curr['size'] = $line_match[2];
                 }
                 break;
                 // Is it read only?
             // Is it read only?
             case 'Read-Only':
                 if (is_array($curr)) {
                     $curr['read_only'] = $line_match[2];
                 }
                 break;
                 // We deliberately ignore most keys for security reasons
             // We deliberately ignore most keys for security reasons
             default:
                 continue;
                 break;
         }
     }
     // Save a remaining one
     if (is_array($curr) && count($curr) > 0) {
         $this->_res[] = $curr;
     }
     // Apparent success
     return true;
 }
Пример #27
0
 public function __construct(Linfo $linfo)
 {
     $settings = $linfo->getSettings();
     $this->_LinfoError = Errors::Singleton();
     $this->_servers = (array) $settings['soldat_servers'];
 }
Пример #28
0
 public function getProcessStats()
 {
     // Time?
     if (!empty($this->settings['timer'])) {
         $t = new Timer('Process Stats');
     }
     // We'll return this after stuffing it with useful info
     $result = array('exists' => true, 'totals' => array('running' => 0, 'zombie' => 0, 'sleeping' => 0, 'stopped' => 0), 'proc_total' => 0, 'threads' => false);
     // Use ps
     try {
         // Get it
         $ps = $this->exec->exec('ps', 'ax');
         // Match them
         preg_match_all('/^\\s*\\d+\\s+[\\w?]+\\s+([A-Z])\\S*\\s+.+$/m', $ps, $processes, PREG_SET_ORDER);
         // Get total
         $result['proc_total'] = count($processes);
         // Go through
         foreach ($processes as $process) {
             switch ($process[1]) {
                 case 'S':
                 case 'I':
                     $result['totals']['sleeping']++;
                     break;
                 case 'Z':
                     $result['totals']['zombie']++;
                     break;
                 case 'R':
                 case 'D':
                 case 'O':
                     $result['totals']['running']++;
                     break;
                 case 'T':
                     $result['totals']['stopped']++;
                     break;
             }
         }
     } catch (Exception $e) {
         Errors::add('Linfo Core', 'Error using `ps` to get process info');
     }
     // Give
     return $result;
 }
Пример #29
0
 public function getNet()
 {
     $nets = array();
     // ifconfig for nics/statuses
     try {
         $ifconfig = $this->exec->exec('ifconfig', '-a');
     } catch (Exception $e) {
         Errors::add('Solaris Core', 'Failed running ifconfig -a.');
         return array();
     }
     foreach (explode("\n", $ifconfig) as $line) {
         if (!preg_match('/^([^:]+):[^<]+<([^>]+)>/', trim($line), $m)) {
             continue;
         }
         $nic = $m[1];
         $flags = explode(',', strtolower($m[2]));
         if (isset($nets[$nic])) {
             continue;
         }
         $type = null;
         if (in_array('loopback', $flags)) {
             $type = 'Loopback';
         }
         $nets[$nic] = array('recieved' => array('bytes' => null, 'packets' => null, 'errors' => null), 'sent' => array('bytes' => null, 'bytes' => null, 'errors' => null), 'state' => in_array('up', $flags) ? 'up' : 'Unknown', 'type' => $type);
     }
     // kstat for more stats
     foreach (explode("\n", $this->kstat['link:0:']) as $line) {
         if (!preg_match('/^([^:]+):(\\S+)\\s+(\\S+)/', trim($line), $m)) {
             continue;
         }
         list(, $nic, $key, $value) = $m;
         if (!isset($nets[$nic])) {
             continue;
         }
         $cur_nic =& $nets[$nic];
         switch ($key) {
             case 'ipackets64':
                 $cur_nic['recieved']['packets'] = $value;
                 break;
             case 'opackets64':
                 $cur_nic['sent']['packets'] = $value;
                 break;
             case 'rbytes64':
                 $cur_nic['recieved']['bytes'] = $value;
                 break;
             case 'obytes64':
                 $cur_nic['sent']['bytes'] = $value;
                 break;
         }
     }
     // dladm for more stats...
     try {
         $dladm = $this->exec->exec('dladm', 'show-link');
         foreach (explode("\n", $dladm) as $line) {
             if (!preg_match('/^(\\S+)\\s+(\\S+)\\s+\\d+\\s+(\\S+)/', $line, $m)) {
                 continue;
             }
             if (!isset($nets[$m[1]])) {
                 continue;
             }
             if (!$nets[$m[1]]['type'] && $m[2] == 'phys') {
                 $nets[$m[1]]['type'] = 'Physical';
             }
             if (!$nets[$m[1]]['state'] || $nets[$m[1]]['state'] == 'unknown') {
                 $nets[$m[1]]['state'] = $m[3];
             }
         }
     } catch (Exception $e) {
         Errors::add('Solaris Core', 'Failed running dladm show-link.');
         return array();
     }
     return $nets;
 }