public static function network_device_string()
 {
     $network = array();
     if (phodevi::is_macosx()) {
         // TODO: implement
     } else {
         if (phodevi::is_bsd()) {
             foreach (array('dev.em.0.%desc', 'dev.wpi.0.%desc', 'dev.mskc.0.%desc') as $controller) {
                 $pci = phodevi_bsd_parser::read_sysctl($controller);
                 if (!empty($pci)) {
                     array_push($network, $pci);
                 }
             }
         } else {
             if (phodevi::is_windows()) {
                 // TODO: implement
             } else {
                 if (phodevi::is_linux()) {
                     foreach (array('Ethernet controller', 'Network controller') as $controller) {
                         $pci = phodevi_linux_parser::read_pci($controller);
                         if (!empty($pci)) {
                             array_push($network, $pci);
                         }
                     }
                 }
             }
         }
     }
     return implode(' + ', $network);
 }
 public static function read_sensor()
 {
     // Determine current percentage for processor usage
     if (phodevi::is_linux() || phodevi::is_bsd()) {
         $start_load = self::cpu_load_array(-1);
         sleep(1);
         $end_load = self::cpu_load_array(-1);
         for ($i = 0; $i < count($end_load); $i++) {
             $end_load[$i] -= $start_load[$i];
         }
         $percent = ($sum = array_sum($end_load)) == 0 ? 0 : 100 - $end_load[count($end_load) - 1] * 100 / $sum;
     } else {
         if (phodevi::is_solaris()) {
             // TODO: Add support for monitoring load on a per-core basis (through mpstat maybe?)
             $info = explode(' ', pts_strings::trim_spaces(pts_arrays::last_element(explode("\n", trim(shell_exec('sar -u 1 1 2>&1'))))));
             $percent = $info[1] + $info[2];
         } else {
             if (phodevi::is_macosx()) {
                 // CPU usage for user
                 $top = shell_exec('top -n 1 -l 1 2>&1');
                 $top = substr($top, strpos($top, 'CPU usage: ') + 11);
                 $percent = substr($top, 0, strpos($top, '%'));
             } else {
                 $percent = null;
             }
         }
     }
     if (!is_numeric($percent) || $percent < 0 || $percent > 100) {
         $percent = -1;
     }
     return pts_math::set_precision($percent, 2);
 }
 public function read_sensor()
 {
     $net_speed = -1;
     if (phodevi::is_bsd() || phodevi::is_macosx()) {
         $net_speed = $this->network_usage_bsd();
     }
     return pts_math::set_precision($net_speed, 2);
 }
 private function mem_usage()
 {
     if (phodevi::is_linux()) {
         return self::mem_usage_linux();
     } elseif (phodevi::is_macosx() || phodevi::is_bsd()) {
         return self::mem_usage_bsd('MEMORY', 'USED');
     }
 }
 public static function audio_processor_string()
 {
     $audio = null;
     if (phodevi::is_macosx()) {
         // TODO: implement
     } else {
         if (phodevi::is_bsd()) {
             foreach (array('dev.hdac.0.%desc') as $dev) {
                 $dev = phodevi_bsd_parser::read_sysctl($dev);
                 if (!empty($dev)) {
                     $audio = $dev;
                 }
             }
         } else {
             if (phodevi::is_windows()) {
                 // TODO: implement
             } else {
                 if (phodevi::is_linux()) {
                     foreach (pts_file_io::glob('/sys/class/sound/card*/hwC0D*/vendor_name') as $vendor_name) {
                         $card_dir = dirname($vendor_name) . '/';
                         if (!is_readable($card_dir . 'chip_name')) {
                             continue;
                         }
                         $vendor_name = pts_file_io::file_get_contents($vendor_name);
                         $chip_name = pts_file_io::file_get_contents($card_dir . 'chip_name');
                         $audio = $vendor_name . ' ' . $chip_name;
                         if (strpos($chip_name, 'HDMI') !== false || strpos($chip_name, 'DP') !== false) {
                             // If HDMI is in the audio string, likely the GPU-provided audio, so try to find the mainboard otherwise
                             $audio = null;
                         } else {
                             break;
                         }
                     }
                     if ($audio == null) {
                         $audio = phodevi_linux_parser::read_pci('Multimedia audio controller');
                     }
                     if ($audio == null) {
                         $audio = phodevi_linux_parser::read_pci('Audio device');
                     }
                 }
             }
         }
     }
     return $audio;
 }
 public static function read_sensor()
 {
     // Determine the current processor frequency
     $cpu_core = 0;
     // TODO: for now just monitoring the first core
     $info = 0;
     if (phodevi::is_linux()) {
         // First, the ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current
         if (is_file('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq')) {
             $info = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq');
             $info = intval($info) / 1000;
         } else {
             if (is_file('/proc/cpuinfo')) {
                 $cpu_speeds = phodevi_linux_parser::read_cpuinfo('cpu MHz');
                 if (isset($cpu_speeds[0])) {
                     $cpu_core = isset($cpu_speeds[$cpu_core]) ? $cpu_core : 0;
                     $info = intval($cpu_speeds[$cpu_core]);
                 }
             }
         }
     } else {
         if (phodevi::is_solaris()) {
             $info = shell_exec('psrinfo -v | grep MHz');
             $info = substr($info, strrpos($info, 'at') + 3);
             $info = trim(substr($info, 0, strpos($info, 'MHz')));
         } else {
             if (phodevi::is_bsd()) {
                 $info = phodevi_bsd_parser::read_sysctl('dev.cpu.0.freq');
             } else {
                 if (phodevi::is_macosx()) {
                     $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorSpeed');
                     if (($cut_point = strpos($info, ' ')) > 0) {
                         $info = substr($info, 0, $cut_point);
                         $info = str_replace(',', '.', $info);
                     }
                     if ($info < 100) {
                         $info *= 1000;
                     }
                 }
             }
         }
     }
     return pts_math::set_precision($info, 2);
 }
 public function read_sensor()
 {
     // Determine current percentage for core usage
     // Default core to read is the first one (number 0)
     if (phodevi::is_linux() || phodevi::is_bsd()) {
         $percent = $this->cpu_usage_linux_bsd();
     } else {
         if (phodevi::is_solaris()) {
             $percent = $this->cpu_usage_solaris();
         } else {
             if (phodevi::is_macosx()) {
                 $percent = $this->cpu_usage_macosx();
             }
         }
     }
     if (!isset($percent) || !is_numeric($percent) || $percent < 0 || $percent > 100) {
         $percent = -1;
     }
     return pts_math::set_precision($percent, 2);
 }
 public function read_sensor()
 {
     // Determine the current processor frequency
     $frequency = 0;
     if (phodevi::is_linux()) {
         $frequency = $this->cpu_freq_linux();
     } else {
         if (phodevi::is_solaris()) {
             $frequency = $this->cpu_freq_solaris();
         } else {
             if (phodevi::is_bsd()) {
                 $frequency = $this->cpu_freq_bsd();
             } else {
                 if (phodevi::is_macosx()) {
                     $frequency = $this->cpu_freq_macosx();
                 }
             }
         }
     }
     return pts_math::set_precision($frequency, 2);
 }
 public static function sw_operating_system()
 {
     if (!PTS_IS_CLIENT) {
         // TODO: Figure out why this function is sometimes called from OpenBenchmarking.org....
         return false;
     }
     // Determine the operating system release
     if (phodevi::is_linux()) {
         $vendor = phodevi_linux_parser::read_lsb_distributor_id();
         if ($vendor == null) {
             if (is_readable('/etc/os-release')) {
                 $os_release = parse_ini_file('/etc/os-release');
             } else {
                 if (is_readable('/usr/lib/os-release')) {
                     $os_release = parse_ini_file('/usr/lib/os-release');
                 } else {
                     $os_release = null;
                 }
             }
             if (isset($os_release['PRETTY_NAME']) && !empty($os_release['PRETTY_NAME'])) {
                 $vendor = $os_release['PRETTY_NAME'];
             } else {
                 if (isset($os_release['NAME']) && !empty($os_release['NAME'])) {
                     $vendor = $os_release['NAME'];
                 }
             }
         }
     } else {
         if (phodevi::is_hurd()) {
             $vendor = php_uname('v');
         } else {
             $vendor = null;
         }
     }
     $version = phodevi::read_property('system', 'os-version');
     if (!$vendor) {
         $os = null;
         // Try to detect distro for those not supplying lsb_release
         $files = pts_file_io::glob('/etc/*-version');
         for ($i = 0; $i < count($files) && $os == null; $i++) {
             $file = file_get_contents($files[$i]);
             if (trim($file) != null) {
                 $os = substr($file, 0, strpos($file, "\n"));
             }
         }
         if ($os == null) {
             $files = pts_file_io::glob('/etc/*-release');
             for ($i = 0; $i < count($files) && $os == null; $i++) {
                 $file = file_get_contents($files[$i]);
                 if (trim($file) != null) {
                     $proposed_os = substr($file, 0, strpos($file, PHP_EOL));
                     if (strpos($proposed_os, '=') == false) {
                         $os = $proposed_os;
                     }
                 } else {
                     if ($i == count($files) - 1) {
                         $os = ucwords(substr($n = basename($files[$i]), 0, strpos($n, '-')));
                     }
                 }
             }
         }
         if ($os == null && is_file('/etc/release')) {
             $file = file_get_contents('/etc/release');
             $os = substr($file, 0, strpos($file, "\n"));
         }
         if ($os == null && is_file('/etc/palm-build-info')) {
             // Palm / webOS Support
             $os = phodevi_parser::parse_equal_delimited_file('/etc/palm-build-info', 'PRODUCT_VERSION_STRING');
         }
         if ($os == null) {
             if (phodevi::is_windows()) {
                 $os = trim(exec('ver'));
             }
             if (is_file('/etc/debian_version')) {
                 $os = 'Debian ' . php_uname('s') . ' ' . ucwords(pts_file_io::file_get_contents('/etc/debian_version'));
             } else {
                 $os = php_uname('s');
             }
         } else {
             if (strpos($os, ' ') === false) {
                 // The OS string is only one word, likely a problem...
                 if (is_file('/etc/arch-release') && stripos($os, 'Arch') === false) {
                     // On at least some Arch installs (ARM) the file is empty so would have missed above check
                     $os = trim('Arch Linux ' . $os);
                 }
             }
         }
     } else {
         if (stripos($vendor, $version) === false) {
             $os = $vendor . ' ' . $version;
         } else {
             $os = $vendor;
         }
     }
     if (($break_point = strpos($os, ':')) > 0) {
         $os = substr($os, $break_point + 1);
     }
     if (phodevi::is_macosx()) {
         $os = phodevi_osx_parser::read_osx_system_profiler('SPSoftwareDataType', 'SystemVersion');
     }
     if (($break_point = strpos($os, '(')) > 0) {
         $os = substr($os, 0, $break_point);
     }
     $os = trim($os);
     return $os;
 }
 public static function motherboard_string()
 {
     // Returns the motherboard / system model name or number
     $info = null;
     if (phodevi::is_macosx()) {
         $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ModelName');
     } else {
         if (phodevi::is_solaris()) {
             $manufacturer = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Manufacturer', 'SystemInformation,Manufacturer'));
             $product = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Product', 'SystemInformation,Product', 'SystemInformation,Model'));
             if (count($manufacturer) == 1 && count($product) == 1) {
                 $info = $manufacturer[0] . ' ' . $product[0];
             }
         } else {
             if (phodevi::is_bsd()) {
                 $vendor = phodevi_bsd_parser::read_kenv('smbios.system.maker');
                 $product = phodevi_bsd_parser::read_kenv('smbios.system.product');
                 $version = phodevi_bsd_parser::read_kenv('smbios.system.version');
                 // for at least Lenovo ThinkPads this is where it displays ThinkPad model
                 if ($vendor != null && ($product != null || $version != null)) {
                     $info = $vendor . ' ' . $product . ' ' . $version;
                 } else {
                     if (($vendor = phodevi_bsd_parser::read_sysctl('hw.vendor')) != false && ($version = phodevi_bsd_parser::read_sysctl(array('hw.version', 'hw.product'))) != false) {
                         $info = trim($vendor . ' ' . $version);
                     } else {
                         if (($acpi = phodevi_bsd_parser::read_sysctl('dev.acpi.0.%desc')) != false) {
                             $info = trim($acpi);
                         }
                     }
                 }
             } else {
                 if (phodevi::is_linux()) {
                     $vendor = phodevi_linux_parser::read_sys_dmi(array('board_vendor', 'sys_vendor'));
                     $name = phodevi_linux_parser::read_sys_dmi(array('board_name', 'product_name'));
                     $version = phodevi_linux_parser::read_sys_dmi(array('board_version', 'product_version'));
                     if ($vendor != false && $name != false) {
                         $info = strpos($name . ' ', $vendor . ' ') === false ? $vendor . ' ' : null;
                         $info .= $name;
                         if ($version != false && strpos($info, $version) === false && pts_strings::string_only_contains($version, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL)) {
                             $info .= (substr($version, 0, 1) == 'v' ? ' ' : ' v') . $version;
                         }
                     }
                     if (empty($info)) {
                         if ($info == null) {
                             $hw_string = phodevi_linux_parser::read_cpuinfo('Hardware');
                             if (count($hw_string) == 1) {
                                 $info = $hw_string[0];
                             }
                         }
                         $bios_vendor = phodevi_linux_parser::read_sys_dmi('bios_vendor');
                         $bios_version = phodevi_linux_parser::read_sys_dmi('bios_version');
                         if ($bios_vendor != null) {
                             $info = $bios_vendor . ' ' . $bios_version;
                         }
                         if ($info == null) {
                             $hw_string = phodevi_linux_parser::read_cpuinfo('machine');
                             if (count($hw_string) == 1) {
                                 $info = $hw_string[0];
                             }
                         }
                     }
                     if (empty($info)) {
                         $info = phodevi_linux_parser::read_sys_dmi('product_name');
                     }
                     if (empty($info) && is_file('/sys/bus/soc/devices/soc0/machine')) {
                         $info = pts_file_io::file_get_contents('/sys/bus/soc/devices/soc0/machine');
                     }
                     if (empty($info)) {
                         // Works on the MIPS Creator CI20
                         $hardware = phodevi_linux_parser::read_cpuinfo('Hardware');
                         if (!empty($hardware)) {
                             $info = array_pop($hardware);
                         }
                     }
                 } else {
                     if (phodevi::is_windows()) {
                         $info = phodevi_windows_parser::read_cpuz('Mainboard Model', null);
                     }
                 }
             }
         }
     }
     if ((strpos($info, 'Mac ') !== false || strpos($info, 'MacBook') !== false) && strpos($info, 'Apple') === false) {
         $info = 'Apple ' . $info;
     }
     // ensure words aren't repeated (e.g. VMware VMware Virtual and MSI MSI X58M (MS-7593))
     $info = implode(' ', array_unique(explode(' ', $info)));
     return $info;
 }
 public static function chipset_string()
 {
     $info = false;
     if (phodevi::is_macosx()) {
         $sb_vendor = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Vendor');
         $sb_product = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Product');
         if ($sb_product == 'SSD') {
             $sb_product = null;
         }
         if (($cut_point = strpos($sb_product, ' ')) > 0) {
             $sb_product = substr($sb_product, 0, $cut_point);
         }
         // TODO: Can't find Northbridge
         $info = $sb_vendor . ' ' . $sb_product;
     } else {
         if (phodevi::is_windows()) {
             $info = phodevi_windows_parser::read_cpuz('Northbridge', null);
             if ($info != null) {
                 if (($e = strpos($info, 'rev')) !== false) {
                     $info = substr($info, 0, $e);
                 }
                 $info = trim($info);
             }
         } else {
             if (phodevi::is_solaris()) {
                 // Vendor Detection
                 $vendor_possible_udis = array('/org/freedesktop/Hal/devices/pci_0_0/pci_ide_3_2_0', '/org/freedesktop/Hal/devices/pci_0_0/pci_ide_1f_1_1');
                 $info = phodevi_solaris_parser::read_hal_property($vendor_possible_udis, 'info.vendor');
                 // TODO: Northbridge and Southbridge Detection For Solaris
             } else {
                 if (phodevi::is_linux() || phodevi::is_hurd()) {
                     $info = phodevi_linux_parser::read_pci(array('RAM memory', 'Host bridge'));
                     if (count(explode(' ', $info)) == 1) {
                         $bridge = phodevi_linux_parser::read_pci(array('Bridge', 'PCI bridge'));
                         if (!empty($bridge)) {
                             $match = false;
                             $break_words = array('Ethernet', 'PCI', 'High', 'USB');
                             for ($i = 0; $i < count($break_words) && !$match; $i++) {
                                 if (($pos = strpos($bridge, $break_words[$i])) > 0) {
                                     $bridge = trim(substr($bridge, 0, $pos));
                                     $info = $bridge;
                                     $match = true;
                                 }
                             }
                         }
                     }
                     if (!isset($bridge) || !empty($bridge)) {
                         // Attempt to detect Southbridge (if applicable)
                         $southbridge = phodevi_linux_parser::read_pci(array('ISA bridge', 'SATA controller'), false);
                         $southbridge_clean = null;
                         if (($start_cut = strpos($southbridge, '(')) > 0 && ($end_cut = strpos($southbridge, ')', $start_cut + 1)) > 0) {
                             $southbridge_extract = substr($southbridge, $start_cut + 1, $end_cut - $start_cut - 1);
                             if (strpos($southbridge_extract, 'rev') === false) {
                                 $southbridge_extract = explode(' ', $southbridge_extract);
                                 $southbridge_clean = $southbridge_extract[0];
                             } else {
                                 if (($s = strpos($southbridge, 'ICH')) > 0) {
                                     $southbridge_extract = substr($southbridge, $s);
                                     $southbridge_clean = substr($southbridge_extract, 0, strpos($southbridge_extract, ' '));
                                 }
                             }
                         } else {
                             if (($start_cut = strpos($southbridge, 'SB')) !== false) {
                                 $southbridge_extract = substr($southbridge, $start_cut);
                                 $southbridge_clean = substr($southbridge_extract, 0, strpos($southbridge_extract, ' '));
                             }
                         }
                         if (!empty($southbridge_clean) && $southbridge_clean != 'SB') {
                             $info .= ' + ' . $southbridge_clean;
                         }
                     }
                 }
             }
         }
     }
     return $info;
 }
 public static function cpu_model()
 {
     // Returns the processor name / frequency information
     $info = null;
     if (isset(phodevi::$vfs->cpuinfo)) {
         $physical_cpu_ids = phodevi_linux_parser::read_cpuinfo('physical id');
         $physical_cpu_count = count(array_unique($physical_cpu_ids));
         $cpu_strings = phodevi_linux_parser::read_cpuinfo(array('model name', 'Processor', 'cpu', 'cpu model'));
         $cpu_strings_unique = array_unique($cpu_strings);
         if ($physical_cpu_count == 1 || empty($physical_cpu_count)) {
             // Just one processor
             if (isset($cpu_strings[0]) && ($cut = strpos($cpu_strings[0], ' (')) !== false) {
                 $cpu_strings[0] = substr($cpu_strings[0], 0, $cut);
             }
             $info = isset($cpu_strings[0]) ? $cpu_strings[0] : null;
             if (strpos($info, 'ARM') !== false) {
                 if (is_dir('/sys/devices/system/exynos-core/') && stripos($info, 'Exynos') === false) {
                     $info = 'Exynos ' . $info;
                 }
             }
         } else {
             if ($physical_cpu_count > 1 && count($cpu_strings_unique) == 1) {
                 // Multiple processors, same model
                 $info = $physical_cpu_count . ' x ' . $cpu_strings[0];
             } else {
                 if ($physical_cpu_count > 1 && count($cpu_strings_unique) > 1) {
                     // Multiple processors, different models
                     $current_id = -1;
                     $current_string = $cpu_strings[0];
                     $current_count = 0;
                     $cpus = array();
                     for ($i = 0; $i < count($physical_cpu_ids); $i++) {
                         if ($current_string != $cpu_strings[$i] || $i == count($physical_cpu_ids) - 1) {
                             array_push($cpus, $current_count . ' x ' . $current_string);
                             $current_string = $cpu_strings[$i];
                             $current_count = 0;
                         }
                         if ($physical_cpu_ids[$i] != $current_id) {
                             $current_count++;
                             $current_id = $physical_cpu_ids[$i];
                         }
                     }
                     $info = implode(', ', $cpus);
                 }
             }
         }
     } else {
         if (phodevi::is_solaris()) {
             $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('CPUType', '-C');
             if (count($dmi_cpu) == 0) {
                 $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorName');
             }
             if (count($dmi_cpu) > 0) {
                 $info = $dmi_cpu[0];
             } else {
                 $info = trim(shell_exec('dmesg 2>&1 | grep cpu0'));
                 $info = trim(substr($info, strrpos($info, 'cpu0:') + 6));
                 if (empty($info)) {
                     $info = array_pop(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorManufacturer'));
                 }
             }
             //TODO: Add in proper support for reading multiple CPUs, similar to the code from above
             $physical_cpu_count = count(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorSocketType'));
             if ($physical_cpu_count > 1 && !empty($info)) {
                 // TODO: For now assuming when multiple CPUs are installed, that they are of the same type
                 $info = $physical_cpu_count . ' x ' . $info;
             }
         } else {
             if (phodevi::is_bsd()) {
                 $info = phodevi_bsd_parser::read_sysctl('hw.model');
             } else {
                 if (phodevi::is_macosx()) {
                     $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorName');
                 } else {
                     if (phodevi::is_windows()) {
                         $info = phodevi_windows_parser::read_cpuz('Processor 1', 'Name');
                         if (!$info) {
                             $info = getenv('PROCESSOR_IDENTIFIER');
                         }
                     }
                 }
             }
         }
     }
     if (empty($info)) {
         $info = 'Unknown';
     } else {
         if (($strip_point = strpos($info, '@')) > 0) {
             $info = trim(substr($info, 0, $strip_point));
             // stripping out the reported freq, since the CPU could be overclocked, etc
         }
         $info = pts_strings::strip_string($info);
         // It seems Intel doesn't report its name when reporting Pentium hardware
         if (strpos($info, 'Pentium') !== false && strpos($info, 'Intel') === false) {
             $info = 'Intel ' . $info;
         }
         if (substr($info, 0, 5) == 'Intel') {
             $cpu_words = explode(' ', $info);
             $cpu_words_count = count($cpu_words);
             // Convert strings like 'Intel Core i7 M 620' -> 'Intel Core i7 620M' and 'Intel Core i7 X 990' -> 'Intel Core i7 990X' to better reflect Intel product marketing names
             if ($cpu_words_count > 4 && is_numeric($cpu_words[$cpu_words_count - 1]) && strlen($cpu_words[$cpu_words_count - 2]) == 1 && strlen($cpu_words[$cpu_words_count - 3]) == 2) {
                 $cpu_words[$cpu_words_count - 1] .= $cpu_words[$cpu_words_count - 2];
                 unset($cpu_words[$cpu_words_count - 2]);
                 $info = implode(' ', $cpu_words);
             }
         }
     }
     return $info;
 }
 public static function __startup()
 {
     $halt_screensaver = pts_module::read_variable('HALT_SCREENSAVER');
     if (!empty($halt_screensaver) && !pts_strings::string_bool($halt_screensaver) || phodevi::read_property('system', 'display-server') == null) {
         return pts_module::MODULE_UNLOAD;
     }
     if (phodevi::is_macosx()) {
         // Right now there doesn't appear to be a better way to disable OS X screensaver automatically...
         return pts_module::MODULE_UNLOAD;
     }
     // GNOME Screensaver?
     if (($gt = pts_client::executable_in_path('gconftool')) != false || ($gt = pts_client::executable_in_path('gconftool-2')) != false) {
         self::$gnome_gconftool = $gt;
     }
     if (self::$gnome_gconftool != false) {
         $is_gnome_screensaver_enabled = trim(shell_exec(self::$gnome_gconftool . ' -g /apps/gnome-screensaver/idle_activation_enabled 2>&1'));
         if ($is_gnome_screensaver_enabled == 'true') {
             // Stop the GNOME Screensaver
             shell_exec(self::$gnome_gconftool . ' --type bool --set /apps/gnome-screensaver/idle_activation_enabled false 2>&1');
             self::$gnome2_screensaver_halted = true;
         }
         $sleep_display_ac = trim(shell_exec(self::$gnome_gconftool . ' -g /apps/gnome-power-manager/timeout/sleep_display_ac 2>&1'));
         if ($sleep_display_ac != 0) {
             // Don't sleep the display when on AC power
             shell_exec(self::$gnome_gconftool . ' --type int --set /apps/gnome-power-manager/timeout/sleep_display_ac 0 2>&1');
             self::$sleep_display_ac = $sleep_display_ac;
         }
     }
     if (pts_client::executable_in_path('qdbus')) {
         // KDE Screensaver?
         $is_kde_screensaver_enabled = trim(shell_exec('qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.GetActive 2>&1'));
         if ($is_kde_screensaver_enabled == 'true') {
             // Stop the KDE Screensaver
             shell_exec('qdbus org.freedesktop.ScreenSaver  /ScreenSaver SimulateUserActivity 2>&1');
             self::$kde_screensaver_halted = true;
         }
     }
     if (self::$gnome2_screensaver_halted == false && pts_client::executable_in_path('gsettings')) {
         // GNOME 3.x Screensaver?
         $is_gnome3_screensaver_enabled = trim(shell_exec('gsettings get org.gnome.desktop.session idle-delay 2>&1'));
         if (stripos($is_gnome3_screensaver_enabled, 'no such key') === false && pts_strings::last_in_string($is_gnome3_screensaver_enabled) > 0) {
             // Stop the GNOME 3.x Screensaver
             shell_exec('gsettings set org.gnome.desktop.session idle-delay 0 2>&1');
             self::$gnome3_screensaver_halted = pts_strings::last_in_string($is_gnome3_screensaver_enabled);
         }
         // GNOME 3.x Lock-Screen
         $is_gnome3_lockscreen_enabled = trim(shell_exec('gsettings get org.gnome.desktop.lockdown disable-lock-screen 2>&1'));
         if (stripos($is_gnome3_lockscreen_enabled, 'no such key') === false && pts_strings::last_in_string($is_gnome3_lockscreen_enabled) == 'false') {
             // Stop the GNOME 3.x Lock Screen
             shell_exec('gsettings set org.gnome.desktop.lockdown disable-lock-screen true 2>&1');
             self::$gnome3_lockscreen_disabled = true;
         }
         // This GNOME3 GSettings method is deprecated on distributions like GNOME 3.8 with Fedora 19
         $is_gnome3_screensaver_enabled_old = trim(shell_exec('gsettings get org.gnome.desktop.screensaver idle-activation-enabled 2>&1'));
         if ($is_gnome3_screensaver_enabled_old == 'true') {
             // Stop the GNOME 3.x Screensaver
             shell_exec('gsettings set org.gnome.desktop.screensaver idle-activation-enabled false 2>&1');
             self::$gnome3_screensaver_halted_old = true;
         }
         // GNOME 3.x Sleep Dispaly?
         $is_gnome3_sleep = trim(shell_exec('gsettings get org.gnome.settings-daemon.plugins.power sleep-display-ac 2>&1'));
         if ($is_gnome3_sleep > 0) {
             // Stop the GNOME 3.x Display Sleep
             shell_exec('gsettings set org.gnome.settings-daemon.plugins.power sleep-display-ac 0 2>&1');
             self::$sleep_display_ac = $is_gnome3_sleep;
         }
     }
     if (pts_client::executable_in_path('xfconf-query')) {
         $is_xfce_screensaver_enabled = stripos(shell_exec('xfconf-query -c xfce4-session -p /startup/screensaver/enabled 2>&1'), 'false') !== false;
         if ($is_xfce_screensaver_enabled) {
             shell_exec('xfconf-query -c xfce4-session -n -t bool -p /startup/screensaver/enabled -s false 2>&1');
             self::$xfce_screensaver_halted = true;
         }
     }
     if (getenv('DISPLAY') != false && (self::$xset = pts_client::executable_in_path('xset'))) {
         shell_exec('xset s off 2>&1');
     } else {
         if (getenv('DISPLAY') == false && pts_client::executable_in_path('setterm')) {
             shell_exec('setterm -powersave off -blank 0 2>&1');
         }
     }
     if (self::$gnome2_screensaver_halted || self::$gnome3_screensaver_halted || self::$gnome3_screensaver_halted_old || self::$kde_screensaver_halted || self::$xfce_screensaver_halted) {
         self::$screensaver_halted = true;
     }
     if (($xdg = pts_client::executable_in_path('xdg-screensaver')) == false) {
         self::$xdg_screensaver_available = $xdg;
     }
     if ($xscreensaver = pts_client::executable_in_path('xscreensaver-command')) {
         shell_exec($xscreensaver . ' -exit 2>&1');
     }
 }
 public static function memory_capacity()
 {
     // Returns physical memory capacity
     if (isset(phodevi::$vfs->meminfo)) {
         $info = phodevi::$vfs->meminfo;
         $info = substr($info, strpos($info, 'MemTotal:') + 9);
         $info = intval(trim(substr($info, 0, strpos($info, 'kB'))));
         $info = floor($info / 1024);
         if (is_numeric($info) && $info > 950) {
             if ($info > 4608) {
                 $info = ceil($info / 1024) * 1024;
             } else {
                 if ($info > 1536) {
                     $info = ceil($info / 512) * 512;
                 } else {
                     $info = ceil($info / 256) * 256;
                 }
             }
         }
     } else {
         if (phodevi::is_solaris()) {
             $info = shell_exec('prtconf 2>&1 | grep Memory');
             $info = substr($info, strpos($info, ':') + 2);
             $info = substr($info, 0, strpos($info, 'Megabytes'));
         } else {
             if (phodevi::is_bsd()) {
                 $mem_size = phodevi_bsd_parser::read_sysctl('hw.physmem');
                 if ($mem_size == false) {
                     $mem_size = phodevi_bsd_parser::read_sysctl('hw.realmem');
                 }
                 $info = ceil(floor($mem_size / 1048576) / 256) * 256;
             } else {
                 if (phodevi::is_macosx()) {
                     $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'Memory');
                     $info = explode(' ', $info);
                     $info = isset($info[1]) && $info[1] == 'GB' ? $info[0] * 1024 : $info[0];
                 } else {
                     if (phodevi::is_windows()) {
                         $info = phodevi_windows_parser::read_cpuz('Memory Size', null);
                         if ($info != null) {
                             if (($e = strpos($info, ' MBytes')) !== false) {
                                 $info = substr($info, 0, $e);
                             }
                             $info = trim($info);
                         }
                     } else {
                         $info = null;
                     }
                 }
             }
         }
     }
     return $info;
 }
 public static function test_profile_system_compatibility_check(&$test_profile, $report_errors = false)
 {
     $valid_test_profile = true;
     $test_type = $test_profile->get_test_hardware_type();
     $skip_tests = pts_client::read_env('SKIP_TESTS') ? pts_strings::comma_explode(pts_client::read_env('SKIP_TESTS')) : false;
     $skip_test_subsystems = pts_client::read_env('SKIP_TESTING_SUBSYSTEMS') ? pts_strings::comma_explode(strtolower(pts_client::read_env('SKIP_TESTING_SUBSYSTEMS'))) : false;
     $display_driver = phodevi::read_property('system', 'display-driver');
     $gpu = phodevi::read_name('gpu');
     if ($test_profile->is_supported(false) == false) {
         $valid_test_profile = false;
     } else {
         if ($test_type == 'Graphics' && pts_client::read_env('DISPLAY') == false && pts_client::read_env('WAYLAND_DISPLAY') == false && phodevi::is_windows() == false && phodevi::is_macosx() == false) {
             $report_errors && pts_client::$display->test_run_error('No display server was found, cannot run ' . $test_profile);
             $valid_test_profile = false;
         } else {
             if ($test_type == 'Graphics' && in_array($display_driver, array('vesa', 'nv', 'cirrus')) && stripos($gpu, 'LLVM') === false) {
                 // These display drivers end up being in known configurations without 3D hardware support so unless an LLVM-based string is reported as the GPU, don't advertise 3D tests
                 $report_errors && pts_client::$display->test_run_error('3D acceleration support not available, cannot run ' . $test_profile);
                 $valid_test_profile = false;
             } else {
                 if ($test_type == 'Disk' && stripos(phodevi::read_property('system', 'filesystem'), 'SquashFS') !== false) {
                     $report_errors && pts_client::$display->test_run_error('Running on a RAM-based live file-system, cannot run ' . $test_profile);
                     $valid_test_profile = false;
                 } else {
                     if (pts_client::read_env('NO_' . strtoupper($test_type) . '_TESTS') || $skip_tests && (in_array($test_profile, $skip_tests) || in_array($test_type, $skip_tests) || in_array($test_profile->get_identifier(false), $skip_tests) || in_array($test_profile->get_identifier_base_name(), $skip_tests))) {
                         $report_errors && pts_client::$display->test_run_error('Due to a pre-set environmental variable, skipping ' . $test_profile);
                         $valid_test_profile = false;
                     } else {
                         if ($skip_test_subsystems && in_array(strtolower($test_profile->get_test_hardware_type()), $skip_test_subsystems)) {
                             $report_errors && pts_client::$display->test_run_error('Due to a pre-set environmental variable, skipping ' . $test_profile);
                             $valid_test_profile = false;
                         } else {
                             if ($test_profile->is_root_required() && $this->batch_mode && phodevi::is_root() == false) {
                                 $report_errors && pts_client::$display->test_run_error('Cannot run ' . $test_profile . ' in batch mode as root access is required.');
                                 $valid_test_profile = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($valid_test_profile == false && pts_client::read_env('SKIP_ALL_TEST_SUPPORT_CHECKS')) {
         $report_errors && pts_client::$display->test_run_error('SKIP_ALL_TEST_SUPPORT_CHECKS is set for ' . $test_profile . '.');
         $valid_test_profile = true;
     }
     return $valid_test_profile;
 }
 public static function gpu_model()
 {
     // Report graphics processor string
     $info = phodevi_parser::read_glx_renderer();
     $video_ram = phodevi::read_property('gpu', 'memory-capacity');
     if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
         $crossfire_status = phodevi_linux_parser::read_amd_pcsdb('SYSTEM/Crossfire/chain/*,Enable');
         $crossfire_status = pts_arrays::to_array($crossfire_status);
         $crossfire_card_count = 0;
         for ($i = 0; $i < count($crossfire_status); $i++) {
             if ($crossfire_status[$i] == '0x00000001') {
                 $crossfire_card_count += 2;
                 // For now assume each chain is 2 cards, but proper way would be NumSlaves + 1
             }
         }
         $adapters = phodevi_linux_parser::read_amd_graphics_adapters();
         if (count($adapters) > 0) {
             $video_ram = $video_ram > 64 ? ' ' . $video_ram . 'MB' : null;
             // assume more than 64MB of vRAM
             if ($crossfire_card_count > 1 && $crossfire_card_count <= count($adapters)) {
                 $unique_adapters = array_unique($adapters);
                 if (count($unique_adapters) == 1) {
                     if (strpos($adapters[0], 'X2') > 0 && $crossfire_card_count > 1) {
                         $crossfire_card_count -= 1;
                     }
                     $info = $crossfire_card_count . ' x ' . $adapters[0] . $video_ram . ' CrossFire';
                 } else {
                     $info = implode(', ', $unique_adapters) . ' CrossFire';
                 }
             } else {
                 $info = $adapters[0] . $video_ram;
             }
         }
     } else {
         if (phodevi::is_macosx()) {
             $system_profiler_info = implode(' + ', phodevi_osx_parser::read_osx_system_profiler('SPDisplaysDataType', 'ChipsetModel', true));
             if (!empty($system_profiler_info)) {
                 $info = $system_profiler_info;
             }
         } else {
             if (phodevi::is_nvidia_graphics()) {
                 if ($info == null) {
                     if (pts_client::executable_in_path('nvidia-settings')) {
                         $nv_gpus = shell_exec('nvidia-settings -q gpus 2>&1');
                         // TODO: search for more than one GPU
                         $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '[0]'));
                         $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '(') + 1);
                         $nv_gpus = substr($nv_gpus, 0, strpos($nv_gpus, ')'));
                         if (stripos($nv_gpus, 'GeForce') !== false || stripos($nv_gpus, 'Quadro') !== false) {
                             $info = $nv_gpus;
                         }
                     }
                 }
                 $sli_mode = phodevi_parser::read_nvidia_extension('SLIMode');
                 if (!empty($sli_mode) && $sli_mode != 'Off') {
                     $info .= ' SLI';
                 }
             } else {
                 if (phodevi::is_solaris()) {
                     if (($cut = strpos($info, 'DRI ')) !== false) {
                         $info = substr($info, $cut + 4);
                     }
                     if (($cut = strpos($info, ' Chipset')) !== false) {
                         $info = substr($info, 0, $cut);
                     }
                     if ($info == false && isset(phodevi::$vfs->xorg_log)) {
                         $xorg_log = phodevi::$vfs->xorg_log;
                         if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) {
                             $xorg_log = substr($xorg_log, $x + 14);
                             $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                             if (($c = strpos($xorg_log, '[')) || ($c = strpos($xorg_log, '('))) {
                                 $xorg_log = substr($xorg_log, 0, $c);
                             }
                             if (phodevi::is_product_string($xorg_log)) {
                                 $info = $xorg_log;
                             }
                         }
                     }
                 } else {
                     if (phodevi::is_bsd()) {
                         $drm_info = phodevi_bsd_parser::read_sysctl('dev.drm.0.%desc');
                         if (!$drm_info) {
                             $drm_info = phodevi_bsd_parser::read_sysctl('dev.nvidia.0.%desc');
                         }
                         if (!$drm_info) {
                             $agp_info = phodevi_bsd_parser::read_sysctl('dev.agp.0.%desc');
                             if ($agp_info != false) {
                                 $info = $agp_info;
                             }
                         } else {
                             $info = $drm_info;
                         }
                         if ($info == null && isset(phodevi::$vfs->xorg_log)) {
                             $xorg_log = phodevi::$vfs->xorg_log;
                             if (($e = strpos($xorg_log, ' at 01@00:00:0')) !== false) {
                                 $xorg_log = substr($xorg_log, 0, $e);
                                 $info = substr($xorg_log, strrpos($xorg_log, 'Found ') + 6);
                             }
                         }
                     } else {
                         if (phodevi::is_windows()) {
                             $info = phodevi_windows_parser::read_cpuz('Display Adapters', 'Name');
                         }
                     }
                 }
             }
         }
     }
     if (empty($info) || strpos($info, 'Mesa ') !== false || strpos($info, 'Gallium ') !== false) {
         if (phodevi::is_windows() == false) {
             $info_pci = phodevi_linux_parser::read_pci('VGA compatible controller', false);
             if (!empty($info_pci)) {
                 $info = $info_pci;
                 if (strpos($info, 'Intel 2nd Generation Core Family') !== false || strpos($info, 'Gen Core') !== false) {
                     // Try to come up with a better non-generic string
                     $was_reset = false;
                     if (isset(phodevi::$vfs->xorg_log)) {
                         /*
                         $ cat /var/log/Xorg.0.log | grep -i Chipset
                         [     8.421] (II) intel: Driver for Intel Integrated Graphics Chipsets: i810,
                         [     8.421] (II) VESA: driver for VESA chipsets: vesa
                         [     8.423] (II) intel(0): Integrated Graphics Chipset: Intel(R) Sandybridge Mobile (GT2+)
                         [     8.423] (--) intel(0): Chipset: "Sandybridge Mobile (GT2+)"
                         */
                         $xorg_log = phodevi::$vfs->xorg_log;
                         if (($x = strpos($xorg_log, 'Integrated Graphics Chipset: ')) !== false) {
                             $xorg_log = substr($xorg_log, $x + 29);
                             $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                             if (stripos($xorg_log, 'Intel') === false) {
                                 $xorg_log = 'Intel ' . $xorg_log;
                             }
                             // if string is too long, likely not product
                             if (!isset($xorg_log[45])) {
                                 $info = $xorg_log;
                                 $was_reset = true;
                             }
                         } else {
                             if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) {
                                 $xorg_log = substr($xorg_log, $x + 14);
                                 $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                                 if (stripos($xorg_log, 'Intel') === false) {
                                     $xorg_log = 'Intel ' . $xorg_log;
                                 }
                                 // if string is too long, likely not product
                                 if (!isset($xorg_log[45])) {
                                     $info = $xorg_log;
                                     $was_reset = true;
                                 }
                             }
                         }
                     }
                     if ($was_reset == false && isset(phodevi::$vfs->i915_capabilities)) {
                         $i915_caps = phodevi::$vfs->i915_capabilities;
                         if (($x = strpos($i915_caps, 'gen: ')) !== false) {
                             $gen = substr($i915_caps, $x + 5);
                             $gen = substr($gen, 0, strpos($gen, PHP_EOL));
                             if (is_numeric($gen)) {
                                 $info = 'Intel Gen' . $gen;
                                 if (strpos($i915_caps, 'is_mobile: yes') !== false) {
                                     $info .= ' Mobile';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (($start_pos = strpos($info, ' DRI ')) > 0) {
             $info = substr($info, $start_pos + 5);
         }
         if (empty($info) && isset(phodevi::$vfs->xorg_log)) {
             $log_parse = phodevi::$vfs->xorg_log;
             $log_parse = substr($log_parse, strpos($log_parse, 'Chipset') + 8);
             $log_parse = substr($log_parse, 0, strpos($log_parse, 'found'));
             if (strpos($log_parse, '(--)') === false && strlen(str_ireplace(array('ATI', 'NVIDIA', 'VIA', 'Intel'), '', $log_parse)) != strlen($log_parse)) {
                 $info = $log_parse;
             }
         }
         if (empty($info) && is_readable('/sys/class/graphics/fb0/name')) {
             switch (pts_file_io::file_get_contents('/sys/class/graphics/fb0/name')) {
                 case 'omapdrm':
                     $info = 'Texas Instruments OMAP';
                     // The OMAP DRM driver currently is for OMAP2/3/4 hardware
                     break;
                 case 'exynos':
                     $info = 'Samsung EXYNOS';
                     // The Exynos DRM driver
                     break;
                 case 'tegra_fb':
                     $info = 'NVIDIA TEGRA';
                     // The Exynos DRM driver
                     break;
                 default:
                     if (is_file('/dev/mali')) {
                         $info = 'ARM Mali';
                         // One of the ARM Mali models
                     }
                     break;
             }
         }
         if (substr($info, -1) == ')' && ($open_p = strrpos($info, '(')) != false) {
             $end_check = strpos($info, ' ', $open_p);
             $to_check = substr($info, $open_p + 1, $end_check - $open_p - 1);
             // Don't report card revision from PCI info
             if ($to_check == 'rev') {
                 $info = substr($info, 0, $open_p - 1);
             }
         }
     }
     if (($bracket_open = strpos($info, '[')) !== false) {
         // Report only the information inside the brackets if it's more relevant...
         // Mainly with Linux systems where the PCI information is reported like 'nVidia GF104 [GeForce GTX 460]'
         if (($bracket_close = strpos($info, ']', $bracket_open + 1)) !== false) {
             $inside_bracket = substr($info, $bracket_open + 1, $bracket_close - $bracket_open - 1);
             if (stripos($inside_bracket, 'Quadro') !== false || stripos($inside_bracket, 'GeForce') !== false) {
                 $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1);
             } else {
                 if (stripos($inside_bracket, 'Radeon') !== false || stripos($inside_bracket, 'Fire') !== false || stripos($inside_bracket, 'Fusion') !== false) {
                     $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1);
                 }
             }
         }
     }
     if (stripos($info, 'NVIDIA') === false && (stripos($info, 'Quadro') !== false || stripos($info, 'GeForce') !== false)) {
         $info = 'NVIDIA' . ' ' . $info;
     } else {
         if (stripos($info, 'ATI') === false && stripos($info, 'AMD') === false && (stripos($info, 'Radeon') !== false || stripos($info, 'Fire') !== false || stripos($info, 'Fusion') !== false)) {
             // Fire would be for FireGL or FirePro hardware
             $info = 'AMD ' . $info;
         }
     }
     if (phodevi::is_linux() && ($vendor = phodevi_linux_parser::read_pci_subsystem_value('VGA compatible controller')) != null && stripos($info, $vendor) === false && (stripos($info, 'AMD') !== false || stripos($info, 'NVIDIA') !== false)) {
         $info = $vendor . ' ' . $info;
     }
     if ($video_ram > 64 && strpos($info, $video_ram) == false) {
         $info .= ' ' . $video_ram . 'MB';
     }
     $clean_phrases = array('OpenGL Engine');
     $info = str_replace($clean_phrases, null, $info);
     return $info;
 }
 private static function sys_battery_power()
 {
     // Returns power consumption rate in mW
     $rate = -1;
     if (phodevi::is_linux()) {
         $power_now = phodevi_linux_parser::read_sysfs_node('/sys/class/power_supply/*/power_now', 'POSITIVE_NUMERIC', array('status' => 'Discharging'));
         if ($power_now != -1) {
             // sysfs power_now seems to be displayed in microWatts
             $rate = pts_math::set_precision($power_now / 1000, 2);
         }
         if ($rate == -1) {
             $battery = array('/battery/BAT0/state', '/battery/BAT1/state');
             $state = phodevi_linux_parser::read_acpi($battery, 'charging state');
             $power = phodevi_linux_parser::read_acpi($battery, 'present rate');
             $voltage = phodevi_linux_parser::read_acpi($battery, 'present voltage');
             if ($state == 'discharging') {
                 $power_unit = substr($power, strrpos($power, ' ') + 1);
                 $power = substr($power, 0, strpos($power, ' '));
                 if ($power_unit == 'mA') {
                     $voltage_unit = substr($voltage, strrpos($voltage, ' ') + 1);
                     $voltage = substr($voltage, 0, strpos($voltage, ' '));
                     if ($voltage_unit == 'mV') {
                         $rate = round($power * $voltage / 1000);
                     }
                 } else {
                     if ($power_unit == 'mW') {
                         $rate = $power;
                     }
                 }
             }
         }
         if ($rate == -1 && is_file('/sys/class/power_supply/BAT0/voltage_now') && is_file('/sys/class/power_supply/BAT0/current_now')) {
             $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/voltage_now') / 1000;
             $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/current_now') / 1000;
             $power_now = $voltage_now * $current_now / 1000;
             if ($power_now > 1) {
                 $rate = $power_now;
             }
         }
         if ($rate == -1 && is_file('/sys/class/power_supply/BAT1/voltage_now') && is_file('/sys/class/power_supply/BAT1/current_now')) {
             $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/voltage_now') / 1000;
             $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/current_now') / 1000;
             $power_now = $voltage_now * $current_now / 1000;
             if ($power_now > 1) {
                 $rate = $power_now;
             }
         }
     } else {
         if (phodevi::is_macosx()) {
             $amperage = abs(phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Amperage'));
             // in mA
             $voltage = phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Voltage');
             // in mV
             if ($amperage > 0 && $voltage > 0) {
                 $rate = round($amperage * $voltage / 1000);
             } else {
                 if (pts_client::executable_in_path('ioreg')) {
                     $ioreg = trim(shell_exec("ioreg -l | grep LegacyBatteryInfo | cut -d '{' -f 2 | tr -d \\} | tr ',' '=' | awk -F'=' '{print (\$2*\$10/10^22)}' 2>&1"));
                     if (is_numeric($ioreg) && $ioreg > 0) {
                         $rate = $ioreg;
                     }
                 }
             }
         } else {
             if (phodevi::is_solaris()) {
                 $battery = phodevi_solaris_parser::read_hal_property('/org/freedesktop/Hal/devices/pseudo/acpi_drv_0_battery0_0', 'battery.reporting.rate');
                 if (is_numeric($battery)) {
                     $rate = $battery;
                 }
             } else {
                 if (phodevi::is_bsd()) {
                     $battery = phodevi_bsd_parser::read_acpiconf('Present rate');
                     if ($battery && substr($battery, -2) == 'mW') {
                         $rate = substr($battery, 0, strpos($battery, ' '));
                     }
                 }
             }
         }
     }
     return $rate;
 }
 private static function install_packages_on_system($os_packages_to_install)
 {
     // Do the actual installing process of packages using the distribution's package management system
     $vendor_install_file = PTS_EXDEP_PATH . 'scripts/install-' . self::vendor_identifier('installer') . '-packages.sh';
     // Rebuild the array index since some OS package XML tags provide multiple package names in a single string
     $os_packages_to_install = explode(' ', implode(' ', $os_packages_to_install));
     if (is_file($vendor_install_file)) {
         // hook into pts_client::$display here if it's desired
         echo PHP_EOL . 'The following dependencies are needed and will be installed: ' . PHP_EOL . PHP_EOL;
         echo pts_user_io::display_text_list($os_packages_to_install);
         echo PHP_EOL . 'This process may take several minutes.' . PHP_EOL;
         echo shell_exec('sh ' . $vendor_install_file . ' ' . implode(' ', $os_packages_to_install));
     } else {
         if (phodevi::is_macosx() == false) {
             echo 'Distribution install script not found!';
         }
     }
 }
 public static function monitor_string()
 {
     $monitor = null;
     if (phodevi::is_macosx()) {
         $system_profiler = shell_exec('system_profiler SPDisplaysDataType 2>&1');
         $system_profiler = substr($system_profiler, strrpos($system_profiler, 'Displays:'));
         $system_profiler = substr($system_profiler, strpos($system_profiler, "\n"));
         $monitor = trim(substr($system_profiler, 0, strpos($system_profiler, ':')));
         if ($monitor == 'Display Connector') {
             $monitor = null;
         }
     } else {
         if (phodevi::is_nvidia_graphics() && isset(phodevi::$vfs->xorg_log)) {
             $log_parse = phodevi::$vfs->xorg_log;
             $offset = 0;
             $monitor = array();
             /* e.g.
             			$ cat /var/log/Xorg.0.log | grep -i connected
             			[    18.174] (--) NVIDIA(0):     Acer P243W (DFP-0) (connected)
             			[    18.174] (--) NVIDIA(0):     Acer AL2223W (DFP-1) (connected)
             			*/
             while (($monitor_pos = strpos($log_parse, ') (connected)', $offset)) !== false || ($monitor_pos = strpos($log_parse, ') (boot, connected)', $offset)) !== false) {
                 $m = substr($log_parse, 0, $monitor_pos);
                 $m = substr($m, strrpos($m, '): ') + 2);
                 $m = trim(substr($m, 0, strpos($m, ' (')));
                 if (!empty($m) && !isset($m[32]) && isset($m[6])) {
                     array_push($monitor, $m);
                 }
                 $offset = $monitor_pos + 2;
             }
             // technically should be fine reporting multiple of the same monitor
             // but fglrx/catalyst as of late 2013 is in habit of reporting monitors twice
             $monitor = array_unique($monitor);
             $monitor = implode(' + ', $monitor);
         } else {
             if (isset(phodevi::$vfs->xorg_log)) {
                 $log_parse = phodevi::$vfs->xorg_log;
                 $offset = 0;
                 $monitor = array();
                 while (($monitor_name = strpos($log_parse, 'Monitor name:', $offset)) !== false) {
                     $log_parse = substr($log_parse, $monitor_name + 14);
                     $m = trim(substr($log_parse, 0, strpos($log_parse, "\n")));
                     if (!empty($m)) {
                         array_push($monitor, $m);
                     }
                 }
                 // technically should be fine reporting multiple of the same monitor
                 // but fglrx/catalyst as of late 2013 is in habit of reporting monitors twice
                 $monitor = array_unique($monitor);
                 $monitor = implode(' + ', $monitor);
             }
         }
     }
     if ($monitor == null && phodevi::is_linux()) {
         // Attempt to find the EDID over sysfs and then decode it for monitor name (0xFC)
         // For at least Intel DRM drivers there is e.g. /sys/class/drm/card0-HDMI-A-2/edid
         // Also works at least for Radeon DRM driver too
         foreach (glob('/sys/class/drm/*/edid') as $edid_file) {
             $edid_file = pts_file_io::file_get_contents($edid_file);
             if ($edid_file == null) {
                 continue;
             }
             $edid = bin2hex($edid_file);
             $x = 0;
             while ($x = strpos($edid, '00fc', $x)) {
                 // 00fc indicates start of EDID monitor descriptor block
                 $encoded = substr($edid, $x + 4, 36);
                 $edid_monitor_name_block = null;
                 for ($i = 0; $i < strlen($encoded); $i += 2) {
                     $hex = substr($encoded, $i, 2);
                     if ($hex == 15 || $hex == '0a') {
                         break;
                     }
                     $ch = chr(hexdec($hex));
                     $edid_monitor_name_block .= $ch;
                 }
                 $edid_monitor_name_block = trim($edid_monitor_name_block);
                 if (pts_strings::string_only_contains($edid_monitor_name_block, pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_DASH)) {
                     $monitor = $edid_monitor_name_block;
                     break;
                 }
                 $x++;
             }
             if ($monitor != null) {
                 break;
             }
         }
     }
     return empty($monitor) ? false : $monitor;
 }
 public static function display_web_page($URL, $alt_text = null, $default_open = true, $auto_open = false)
 {
     if (pts_client::read_env('DISPLAY') == false && pts_client::read_env('WAYLAND_DISPLAY') == false && phodevi::is_windows() == false && phodevi::is_macosx() == false || defined('PHOROMATIC_PROCESS')) {
         return;
     }
     if ($auto_open == false) {
         $view_results = pts_user_io::prompt_bool_input($alt_text == null ? 'Do you want to view the results in your web browser' : $alt_text, $default_open);
     } else {
         $view_results = true;
     }
     if ($view_results) {
         static $browser = null;
         if ($browser == null) {
             $config_browser = pts_config::read_user_config('PhoronixTestSuite/Options/General/DefaultBrowser', null);
             if ($config_browser != null && (is_executable($config_browser) || ($config_browser = pts_client::executable_in_path($config_browser)))) {
                 $browser = $config_browser;
             } else {
                 if (phodevi::is_windows()) {
                     $windows_browsers = array('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', 'C:\\Program Files\\Internet Explorer\\iexplore.exe');
                     foreach ($windows_browsers as $browser_test) {
                         if (is_executable($browser_test)) {
                             $browser = $browser_test;
                             break;
                         }
                     }
                     if (substr($URL, 0, 1) == '\\') {
                         $URL = 'file:///C:' . str_replace('/', '\\', $URL);
                     }
                 } else {
                     $possible_browsers = array('firefox', 'mozilla', 'x-www-browser', 'open', 'xdg-open', 'iceweasel', 'konqueror', 'epiphany', 'google-chrome');
                     foreach ($possible_browsers as &$b) {
                         if ($b = pts_client::executable_in_path($b)) {
                             $browser = $b;
                             break;
                         }
                     }
                 }
             }
         }
         if ($browser != null) {
             shell_exec($browser . ' "' . $URL . '" 2> /dev/null &');
         } else {
             echo PHP_EOL . 'No Web Browser Found.' . PHP_EOL;
         }
     }
 }
 public static function hdd_string()
 {
     $disks = array();
     if (phodevi::is_macosx()) {
         // TODO: Support reading non-SATA drives and more than one drive
         $capacity = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Capacity');
         $model = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Model');
         if (($cut = strpos($capacity, ' (')) !== false) {
             $capacity = substr($capacity, 0, $cut);
         }
         if (($cut = strpos($capacity, ' ')) !== false) {
             if (is_numeric(substr($capacity, 0, $cut))) {
                 $capacity = floor(substr($capacity, 0, $cut)) . substr($capacity, $cut);
             }
         }
         $capacity = str_replace(' GB', 'GB', $capacity);
         if (!empty($capacity) && !empty($model)) {
             $disks = array($capacity . ' ' . $model);
         }
     } else {
         if (phodevi::is_bsd()) {
             $i = 0;
             do {
                 $disk = phodevi_bsd_parser::read_sysctl('dev.ad.' . $i . '.%desc');
                 if ($disk != false && strpos($disk, 'DVD') === false && strpos($disk, 'ATAPI') === false) {
                     array_push($disks, $disk);
                 }
                 $i++;
             } while (($disk != false || $i < 9) && $i < 128);
             // On some systems, the first drive seems to be at dev.ad.8 rather than starting at dev.ad.0
             if (empty($disks) && pts_client::executable_in_path('camcontrol')) {
                 $camcontrol = trim(shell_exec('camcontrol devlist 2>&1'));
                 foreach (explode(PHP_EOL, $camcontrol) as $line) {
                     if (substr($line, 0, 1) == '<' && ($model_end = strpos($line, '>')) !== false && strpos($line, 'DVD') === false && strpos($line, 'ATAPI') === false) {
                         $disk = self::prepend_disk_vendor(substr($line, 1, $model_end - 1));
                         array_push($disks, $disk);
                     }
                 }
             }
         } else {
             if (phodevi::is_solaris()) {
                 if (is_executable('/usr/ddu/bin/i386/hd_detect')) {
                     $hd_detect = explode(PHP_EOL, trim(shell_exec('/usr/ddu/bin/i386/hd_detect -l 2>&1')));
                     foreach ($hd_detect as $hd_line) {
                         if (isset($hd_line) && ($hd_pos = strpos($hd_line, ':/')) != false) {
                             $disk = trim(substr($hd_line, 0, $hd_pos));
                             $disk = self::prepend_disk_vendor($disk);
                             if ($disk != 'blkdev') {
                                 array_push($disks, $disk);
                             }
                         }
                     }
                 }
             } else {
                 if (phodevi::is_linux()) {
                     $disks_formatted = array();
                     $disks = array();
                     foreach (array_merge(pts_file_io::glob('/sys/block/sd*'), pts_file_io::glob('/sys/block/mmcblk*')) as $sdx) {
                         if (strpos($sdx, 'boot') !== false) {
                             // Don't include devices like /sys/block/mmcblk0boot[0,1] as it's repeat of /sys/block/mmcblk0
                             continue;
                         }
                         if ((is_file($sdx . '/device/name') || is_file($sdx . '/device/model')) && is_file($sdx . '/size')) {
                             $disk_size = pts_file_io::file_get_contents($sdx . '/size');
                             $disk_model = pts_file_io::file_get_contents($sdx . (is_file($sdx . '/device/model') ? '/device/model' : '/device/name'));
                             $disk_removable = pts_file_io::file_get_contents($sdx . '/removable');
                             if ($disk_removable == '1') {
                                 // Don't count removable disks
                                 continue;
                             }
                             $disk_size = round($disk_size * 512 / 1000000000) . 'GB';
                             $disk_model = self::prepend_disk_vendor($disk_model);
                             if (strpos($disk_model, $disk_size . ' ') === false && strpos($disk_model, ' ' . $disk_size) === false && $disk_size != '1GB') {
                                 $disk_model = $disk_size . ' ' . $disk_model;
                             }
                             if ($disk_size > 0) {
                                 array_push($disks_formatted, $disk_model);
                             }
                         }
                     }
                     for ($i = 0; $i < count($disks_formatted); $i++) {
                         if (!empty($disks_formatted[$i])) {
                             $times_found = 1;
                             for ($j = $i + 1; $j < count($disks_formatted); $j++) {
                                 if ($disks_formatted[$i] == $disks_formatted[$j]) {
                                     $times_found++;
                                     $disks_formatted[$j] = '';
                                 }
                             }
                             $disk = ($times_found > 1 ? $times_found . ' x ' : null) . $disks_formatted[$i];
                             array_push($disks, $disk);
                         }
                     }
                 }
             }
         }
     }
     if (count($disks) == 0) {
         $root_disk_size = ceil(disk_total_space('/') / 1073741824);
         $pts_disk_size = ceil(disk_total_space(pts_client::test_install_root_path()) / 1073741824);
         if ($pts_disk_size > $root_disk_size) {
             $root_disk_size = $pts_disk_size;
         }
         if ($root_disk_size > 1) {
             $disks = $root_disk_size . 'GB';
         } else {
             $disks = null;
         }
     } else {
         $disks = implode(' + ', $disks);
     }
     return $disks;
 }