/**
  * fill the private content var
  */
 public function __construct()
 {
     parent::__construct();
     if (PSI_OS == 'WINNT') {
         $_wmi = null;
         // don't set this params for local connection, it will not work
         $strHostname = '';
         $strUser = '';
         $strPassword = '';
         try {
             // initialize the wmi object
             $objLocator = new COM('WbemScripting.SWbemLocator');
             if ($strHostname == "") {
                 $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI');
             } else {
                 $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword);
             }
         } catch (Exception $e) {
             $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
         }
         if ($_wmi) {
             $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
         }
     }
 }
 function sysinfo()
 {
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     // initialize the wmi object
     $objLocator = new COM("WbemScripting.SWbemLocator");
     if ($strHostname == "") {
         $this->wmi = $objLocator->ConnectServer();
     } else {
         $this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "{$strHostname}\$strUser", $strPassword);
     }
 }
Exemple #3
0
 /**
  * Create a new wmi instance.
  *
  * @param	string	$host		Host name or IP address to connect to
  * @param	string	$username	Local host user with rights to query WMI; normally a local admin
  * @param	string	$password	Password of local user account
  * @return	void				New wmi object
  */
 public function __construct($host = null, $username = null, $password = null)
 {
     $wmiLocator = new COM('WbemScripting.SWbemLocator');
     try {
         $this->connection = $wmiLocator->ConnectServer($host, 'root\\CIMV2', $username, $password);
         $this->connection->Security_->impersonationLevel = 3;
     } catch (Exception $e) {
         // -2147352567 means that we're unable to connect to the local host with a username and password.
         // Attempt connection again passing null values for username and password.
         if ($e->getCode() == '-2147352567') {
             $this->connection = $wmiLocator->ConnectServer($host, 'root\\CIMV2', null, null);
             $this->connection->Security_->impersonationLevel = 3;
         }
     }
 }
 /**
  * build the global Error object and create the WMI connection
  */
 public function __construct()
 {
     parent::__construct();
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     // initialize the wmi object
     $objLocator = new COM('WbemScripting.SWbemLocator');
     if ($strHostname == "") {
         $this->_wmi = $objLocator->ConnectServer();
     } else {
         $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
     }
     $this->_getCodeSet();
 }
 /**
  * Connects to a registry and returns a registry instance.
  *
  * @param string $host     The host name or IP address of the computer whose registry to connect
  *                         to. Defaults to the local computer.
  * @param string $username The user name to use to access the registry.
  * @param string $password The password to use to access the registry.
  *
  * @return Registry
  */
 public static function connect($host = '.', $username = null, $password = null)
 {
     // create a WMI connection
     $swbemLocator = new \COM('WbemScripting.SWbemLocator', null, CP_UTF8);
     $swbemService = $swbemLocator->ConnectServer($host, 'root\\default', $username, $password);
     $swbemService->Security_->ImpersonationLevel = 3;
     // initialize registry provider
     $handle = new RegistryHandle($swbemService->Get('StdRegProv'));
     return new static($handle);
 }
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM('WbemScripting.SWbemLocator');
                     $wmi = $objLocator->ConnectServer('', 'root\\CIMv2');
                     $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'ProcessId'));
                     foreach ($process_wmi as $process) {
                         $this->_filecontent[] = array(strtolower(trim($process['Caption'])), trim($process['ProcessId']));
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) {
                     if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) {
                         $processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES);
                     } else {
                         $processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES);
                     }
                     if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX === true) {
                         foreach ($processes as $process) {
                             CommonFunctions::executeProgram("pgrep", "-n -x " . $process, $buffer, PSI_DEBUG);
                             if (strlen($buffer) > 0) {
                                 $this->_filecontent[] = array($process, $buffer);
                             }
                         }
                     } else {
                         foreach ($processes as $process) {
                             CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
                             if (strlen($buffer) > 0) {
                                 $this->_filecontent[] = array($process, $buffer);
                             }
                         }
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
             $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($processes as $process) {
                 $ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
                 if (count($ps) == 2) {
                     $this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini");
             break;
     }
 }
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM("WbemScripting.SWbemLocator");
                     $wmi = $objLocator->ConnectServer();
                     $os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
                     foreach ($os_wmi as $os) {
                         $memtotal = $os->TotalVisibleMemorySize * 1024;
                     }
                     $process_wmi = $wmi->InstancesOf('Win32_Process');
                     foreach ($process_wmi as $process) {
                         if (strlen(trim($process->CommandLine)) > 0) {
                             $ps = trim($process->CommandLine);
                         } else {
                             $ps = trim($process->Caption);
                         }
                         if (trim($process->ProcessId) != 0) {
                             $memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
                             //ParentProcessId
                             //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they
                             //only identify a process for the lifetime of that process. It is possible that the process identified by
                             //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also
                             //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can
                             //use the CreationDate property to determine whether the specified parent was created after the process
                             //represented by this Win32_Process instance was created.
                             //=> subtrees of processes may be missing (WHAT TODO?!?)
                             $this->_filecontent[] = trim($process->ProcessId) . " " . trim($process->ParentProcessId) . " " . $memusage . " " . $ps;
                         }
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG);
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
             break;
     }
     if (PSI_OS != 'WINNT') {
         if (trim($buffer) != "") {
             $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             unset($this->_filecontent[0]);
         } else {
             $this->_filecontent = array();
         }
     }
 }
 /**
  * build the global Error object and create the WMI connection
  */
 public function __construct()
 {
     parent::__construct();
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     try {
         // initialize the wmi object
         $objLocator = new COM('WbemScripting.SWbemLocator');
         if ($strHostname == "") {
             $this->_wmi = $objLocator->ConnectServer();
         } else {
             $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
         }
     } catch (Exception $e) {
         $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
     }
     $this->_getCodeSet();
 }
Exemple #9
0
 /**
  * fill the private content var
  */
 public function __construct()
 {
     parent::__construct();
     $_wmi = null;
     // don't set this params for local connection, it will not work
     $strHostname = '';
     $strUser = '';
     $strPassword = '';
     try {
         // initialize the wmi object
         $objLocator = new COM('WbemScripting.SWbemLocator');
         if ($strHostname == "") {
             $_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor');
         } else {
             $_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor', $strHostname . '\\' . $strUser, $strPassword);
         }
     } catch (Exception $e) {
         $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
     }
     if ($_wmi) {
         $this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
     }
 }
 /**
  * fill the private content var
  */
 public function __construct()
 {
     parent::__construct();
     $_wmi = null;
     try {
         // initialize the wmi object
         $objLocator = new COM('WbemScripting.SWbemLocator');
         $_wmi = $objLocator->ConnectServer('', 'root\\OpenHardwareMonitor');
     } catch (Exception $e) {
         $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
     }
     if ($_wmi) {
         $this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
     }
 }
 /**
  * fill the private content var
  */
 public function __construct()
 {
     parent::__construct();
     if (PSI_OS == 'WINNT') {
         $_wmi = null;
         try {
             // initialize the wmi object
             $objLocator = new COM('WbemScripting.SWbemLocator');
             $_wmi = $objLocator->ConnectServer('', 'root\\WMI');
         } catch (Exception $e) {
             $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
         }
         if ($_wmi) {
             $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
         }
     }
 }
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_PSSTATUS_ACCESS) {
         case 'command':
             if (PHP_OS == 'WINNT') {
                 $objLocator = new COM("WbemScripting.SWbemLocator");
                 $wmi = $objLocator->ConnectServer();
                 $process_wmi = $wmi->InstancesOf('Win32_Process');
                 foreach ($process_wmi as $process) {
                     $this->_filecontent[] = array(trim($process->Caption), trim($process->ProcessId));
                 }
             } else {
                 $processes = preg_split("/([\\s]+)?,([\\s]+)?/", PSI_PLUGIN_PSSTATUS_PROCESSES, -1, PREG_SPLIT_NO_EMPTY);
                 foreach ($processes as $process) {
                     CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[] = array($process, trim($buffer));
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
             $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($processes as $process) {
                 $ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
                 if (count($ps) == 2) {
                     $this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in psstatus.config.php");
             break;
     }
 }
Exemple #13
0
 public function readEventLogs($host, $domain, $service)
 {
     // Get credentials.
     $account = $this->options['account'];
     $password = $this->options['password'];
     $WbemLocator = new \COM("WbemScripting.SWbemLocator");
     $WbemServices = $WbemLocator->ConnectServer($host, 'root\\cimv2', $account, $password);
     $WbemServices->Security_->ImpersonationLevel = 3;
     $events = $WbemServices->ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and type = 'Error' and TimeWritten > '2016'");
     foreach ($events as $event) {
         echo $event->category . '<br>';
         echo $event->computerName . '<br>';
         echo $event->eventCode . '<br>';
         echo $event->message . '<br>';
         echo $event->recordNumber . '<br>';
         echo $event->sourceName . '<br>';
         echo $event->timeWritten . '<br>';
         echo $event->type . '<br>';
         echo $event->user . '<br>';
         echo '<hr>';
     }
     die;
     /**   Wscript.Echo "Category: " & objEvent.Category & VBNewLine _
         & "Computer Name: " & objEvent.ComputerName & VBNewLine _
         & "Event Code: " & objEvent.EventCode & VBNewLine _
         & "Message: " & objEvent.Message & VBNewLine _
         & "Record Number: " & objEvent.RecordNumber & VBNewLine _
         & "Source Name: " & objEvent.SourceName & VBNewLine _
         & "Time Written: " & objEvent.TimeWritten & VBNewLine _
         & "Event Type: " & objEvent.Type & VBNewLine _
         & "User: " & objEvent.User
     Next
       * 
       */
     die('ok');
 }
Exemple #14
0
function sys_windows()
{
    if (PHP_VERSION >= 5) {
        $objLocator = new COM("WbemScripting.SWbemLocator");
        $wmi = $objLocator->ConnectServer();
        $prop = $wmi->get("Win32_PnPEntity");
    } else {
        return false;
    }
    //CPU
    $cpuinfo = GetWMI($wmi, "Win32_Processor", array("Name", "L2CacheSize", "NumberOfCores"));
    $res['cpu']['num'] = $cpuinfo[0]['NumberOfCores'];
    if (null == $res['cpu']['num']) {
        $res['cpu']['num'] = 1;
    }
    /*
    
    	for ($i=0;$i<$res['cpu']['num'];$i++)
    	{
    
    		$res['cpu']['model'] .= $cpuinfo[0]['Name']."<br />";
    
    		$res['cpu']['cache'] .= $cpuinfo[0]['L2CacheSize']."<br />";
    
    	}*/
    $cpuinfo[0]['L2CacheSize'] = ' (' . $cpuinfo[0]['L2CacheSize'] . ')';
    if ($res['cpu']['num'] == 1) {
        $x1 = '';
    } else {
        $x1 = ' ×' . $res['cpu']['num'];
    }
    $res['cpu']['model'] = $cpuinfo[0]['Name'] . $cpuinfo[0]['L2CacheSize'] . $x1;
    // SYSINFO
    $sysinfo = GetWMI($wmi, "Win32_OperatingSystem", array('LastBootUpTime', 'TotalVisibleMemorySize', 'FreePhysicalMemory', 'Caption', 'CSDVersion', 'SerialNumber', 'InstallDate'));
    $sysinfo[0]['Caption'] = iconv('GBK', 'UTF-8', $sysinfo[0]['Caption']);
    $sysinfo[0]['CSDVersion'] = iconv('GBK', 'UTF-8', $sysinfo[0]['CSDVersion']);
    $res['win_n'] = $sysinfo[0]['Caption'] . " " . $sysinfo[0]['CSDVersion'] . " 序列号:{$sysinfo[0]['SerialNumber']} 于" . date('Y年m月d日H:i:s', strtotime(substr($sysinfo[0]['InstallDate'], 0, 14))) . "安装";
    //UPTIME
    $res['uptime'] = $sysinfo[0]['LastBootUpTime'];
    $sys_ticks = 3600 * 8 + time() - strtotime(substr($res['uptime'], 0, 14));
    $min = $sys_ticks / 60;
    $hours = $min / 60;
    $days = floor($hours / 24);
    $hours = floor($hours - $days * 24);
    $min = floor($min - $days * 60 * 24 - $hours * 60);
    if ($days !== 0) {
        $res['uptime'] = $days . "天";
    }
    if ($hours !== 0) {
        $res['uptime'] .= $hours . "小时";
    }
    $res['uptime'] .= $min . "分钟";
    //MEMORY
    $res['memTotal'] = round($sysinfo[0]['TotalVisibleMemorySize'] / 1024, 2);
    $res['memFree'] = round($sysinfo[0]['FreePhysicalMemory'] / 1024, 2);
    $res['memUsed'] = $res['memTotal'] - $res['memFree'];
    //上面两行已经除以1024,这行不用再除了
    $res['memPercent'] = round($res['memUsed'] / $res['memTotal'] * 100, 2);
    $swapinfo = GetWMI($wmi, "Win32_PageFileUsage", array('AllocatedBaseSize', 'CurrentUsage'));
    // LoadPercentage
    $loadinfo = GetWMI($wmi, "Win32_Processor", array("LoadPercentage"));
    $res['loadAvg'] = $loadinfo[0]['LoadPercentage'];
    return $res;
}
Exemple #15
0
 public function AdapterAction()
 {
     // Get credentials from config.
     $config = $this->getServiceLocator()->get('Config')['cobalt'];
     $account = $config['account'];
     $password = $config['password'];
     $host = $config['test_host'];
     // hostname or IP address
     $WbemLocator = new \COM("WbemScripting.SWbemLocator");
     $WbemServices = $WbemLocator->ConnectServer($host, 'root\\cimv2', $account, $password);
     $WbemServices->Security_->ImpersonationLevel = 3;
     $adapter = $WbemServices->ExecQuery("Select * from Win32_NetworkAdapterConfiguration");
     return array('adapter' => $adapter);
 }
Exemple #16
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM("WbemScripting.SWbemLocator");
                     $wmi = $objLocator->ConnectServer();
                     $os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
                     foreach ($os_wmi as $os) {
                         $memtotal = $os->TotalVisibleMemorySize * 1024;
                     }
                     $process_wmi = $wmi->InstancesOf('Win32_Process');
                     foreach ($process_wmi as $process) {
                         if (strlen(trim($process->CommandLine)) > 0) {
                             $ps = trim($process->CommandLine);
                         } else {
                             $ps = trim($process->Caption);
                         }
                         if (trim($process->ProcessId) != 0) {
                             $memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
                             //ParentProcessId
                             //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they
                             //only identify a process for the lifetime of that process. It is possible that the process identified by
                             //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also
                             //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can
                             //use the CreationDate property to determine whether the specified parent was created after the process
                             //represented by this Win32_Process instance was created.
                             //=> subtrees of processes may be missing (WHAT TODO?!?)
                             $this->_filecontent[] = trim($process->ProcessId) . " " . trim($process->ParentProcessId) . " " . $memusage . " " . $ps;
                         }
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG);
                 if ((PSI_OS == 'Linux' || PSI_OS == 'Android') && !preg_match("/^[^\n]+\n.+/", $buffer)) {
                     //alternative method if no data
                     if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
                         $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
                         $totalmem = 0;
                         foreach ($bufe as $buf) {
                             if (preg_match('/^MemTotal:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                                 $totalmem = $ar_buf[1];
                                 break;
                             }
                         }
                         $buffer = "  PID  PPID %MEM COMMAND\n";
                         $processlist = glob('/proc/*/status', GLOB_NOSORT);
                         if (($total = count($processlist)) > 0) {
                             natsort($processlist);
                             //first sort
                             $prosess = array();
                             foreach ($processlist as $processitem) {
                                 //second sort
                                 $process[] = $processitem;
                             }
                             $buf = "";
                             for ($i = 0; $i < $total; $i++) {
                                 if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
                                     if ($totalmem != 0 && preg_match('/^VmRSS:\\s+(\\d+)\\s+kB/m', $buf, $tmppmem)) {
                                         $pmem = round(100 * $tmppmem[1] / $totalmem, 1);
                                     } else {
                                         $pmem = 0;
                                     }
                                     $name = null;
                                     if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i]) - 6) . "cmdline", $namebuf, 0, 4096, false)) {
                                         $name = str_replace(chr(0), ' ', trim($namebuf));
                                     }
                                     if (preg_match('/^Pid:\\s+(\\d+)/m', $buf, $tmppid) && preg_match('/^PPid:\\s+(\\d+)/m', $buf, $tmpppid) && preg_match('/^Name:\\s+(.+)/m', $buf, $tmpargs)) {
                                         $pid = $tmppid[1];
                                         $ppid = $tmpppid[1];
                                         $args = $tmpargs[1];
                                         if ($name !== null) {
                                             if ($name !== "") {
                                                 $args = $name;
                                             } else {
                                                 $args = "[" . $args . "]";
                                             }
                                         }
                                         $buffer .= $pid . " " . $ppid . " " . $pmem . " " . $args . "\n";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
             break;
     }
     if (PSI_OS != 'WINNT') {
         if (trim($buffer) != "") {
             $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             unset($this->_filecontent[0]);
         } else {
             $this->_filecontent = array();
         }
     }
 }
Exemple #17
0
 /**
  * Constructor to access to wmi database.
  */
 public function __construct()
 {
     if (!class_exists('COM')) {
         $this->_wmi = null;
     } else {
         // initialize the wmi object
         $objLocator = new COM('WbemScripting.SWbemLocator');
         $this->_wmi = $objLocator->ConnectServer();
     }
 }
Exemple #18
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 $_cim = null;
                 //root\CIMv2
                 $_wmi = null;
                 //root\WMI
                 // don't set this params for local connection, it will not work
                 $strHostname = '';
                 $strUser = '';
                 $strPassword = '';
                 try {
                     // initialize the wmi object
                     $objLocatorCIM = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $_cim = $objLocatorCIM->ConnectServer();
                     } else {
                         $_cim = $objLocatorCIM->ConnectServer($strHostname, 'root\\CIMv2', $strHostname . '\\' . $strUser, $strPassword);
                     }
                     // initialize the wmi object
                     $objLocatorWMI = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI');
                     } else {
                         $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword);
                     }
                 } catch (Exception $e) {
                     $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
                 }
                 $buffer_info = '';
                 $buffer_state = '';
                 $bufferWB = CommonFunctions::getWMI($_cim, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry'));
                 if (sizeof($bufferWB) > 0) {
                     $capacity = '';
                     if (isset($bufferWB[0]['EstimatedChargeRemaining'])) {
                         $capacity = $bufferWB[0]['EstimatedChargeRemaining'];
                     }
                     if (isset($bufferWB[0]['BatteryStatus'])) {
                         switch ($bufferWB[0]['BatteryStatus']) {
                             case 1:
                                 $batstat = 'Discharging';
                                 break;
                             case 2:
                                 $batstat = 'AC connected';
                                 break;
                             case 3:
                                 $batstat = 'Fully Charged';
                                 break;
                             case 4:
                                 $batstat = 'Low';
                                 break;
                             case 5:
                                 $batstat = 'Critical';
                                 break;
                             case 6:
                                 $batstat = 'Charging';
                                 break;
                             case 7:
                                 $batstat = 'Charging and High';
                                 break;
                             case 8:
                                 $batstat = 'Charging and Low';
                                 break;
                             case 9:
                                 $batstat = 'Charging and Critical';
                                 break;
                             case 10:
                                 $batstat = 'Undefined';
                                 break;
                             case 11:
                                 $batstat = 'Partially Charged';
                                 break;
                             default:
                                 $batstat = '';
                         }
                         if ($batstat != '') {
                             $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n";
                         }
                     }
                     $techn = '';
                     if (isset($bufferWB[0]['Chemistry'])) {
                         switch ($bufferWB[0]['Chemistry']) {
                             case 1:
                                 $techn = 'Other';
                                 break;
                             case 2:
                                 $techn = 'Unknown';
                                 break;
                             case 3:
                                 $techn = 'PbAc';
                                 break;
                             case 4:
                                 $techn = 'NiCd';
                                 break;
                             case 5:
                                 $techn = 'NiMH';
                                 break;
                             case 6:
                                 $techn = 'Li-ion';
                                 break;
                             case 7:
                                 $techn = 'Zinc-air';
                                 break;
                             case 8:
                                 $techn = 'Li-poly';
                                 break;
                         }
                     }
                     $bufferWPB = CommonFunctions::getWMI($_cim, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity', 'FullChargeCapacity'));
                     if (isset($bufferWPB[0]['DesignVoltage'])) {
                         $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $bufferWPB[0]['DesignVoltage'] * 1000 . "\n";
                     }
                     // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6
                     if (($techn == '' || $techn == 'Unknown') && isset($bufferWPB[0]['Chemistry'])) {
                         switch ($bufferWPB[0]['Chemistry']) {
                             case 1:
                                 $techn = 'Other';
                                 break;
                             case 2:
                                 $techn = 'Unknown';
                                 break;
                             case 3:
                                 $techn = 'PbAc';
                                 break;
                             case 4:
                                 $techn = 'NiCd';
                                 break;
                             case 5:
                                 $techn = 'NiMH';
                                 break;
                             case 6:
                                 $techn = 'Li-ion';
                                 break;
                             case 7:
                                 $techn = 'Zinc-air';
                                 break;
                             case 8:
                                 $techn = 'Li-poly';
                                 break;
                         }
                     }
                     if ($techn != '') {
                         $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n";
                     }
                     $bufferBS = CommonFunctions::getWMI($_wmi, 'BatteryStatus', array('RemainingCapacity', 'Voltage'));
                     if (sizeof($bufferBS) > 0) {
                         if (isset($bufferBS[0]['RemainingCapacity']) && $bufferBS[0]['RemainingCapacity'] > 0) {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $bufferBS[0]['RemainingCapacity'] * 1000 . "\n";
                             $capacity = '';
                         }
                         if (isset($bufferBS[0]['Voltage']) && $bufferBS[0]['Voltage'] > 0) {
                             $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferBS[0]['Voltage'] * 1000 . "\n";
                         } elseif (isset($bufferWB[0]['DesignVoltage'])) {
                             $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferWB[0]['DesignVoltage'] * 1000 . "\n";
                         }
                     }
                     if (!isset($bufferWPB[0]['FullChargeCapacity'])) {
                         $bufferBFCC = CommonFunctions::getWMI($_wmi, 'BatteryFullChargedCapacity', array('FullChargedCapacity'));
                         if (sizeof($bufferBFCC) > 0 && isset($bufferBFCC[0]['FullChargedCapacity'])) {
                             $bufferWPB[0]['FullChargeCapacity'] = $bufferBFCC[0]['FullChargedCapacity'];
                         }
                     }
                     if (isset($bufferWPB[0]['FullChargeCapacity'])) {
                         $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL=' . $bufferWPB[0]['FullChargeCapacity'] * 1000 . "\n";
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['FullChargeCapacity'] * 10) . "\n");
                         }
                         if (isset($bufferWPB[0]['DesignCapacity']) && $bufferWPB[0]['DesignCapacity'] != 0) {
                             $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n";
                         }
                     } elseif (isset($bufferWPB[0]['DesignCapacity'])) {
                         $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n";
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['DesignCapacity'] * 10) . "\n");
                         }
                     } else {
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n";
                         }
                     }
                     $bufferBCC = CommonFunctions::getWMI($_wmi, 'BatteryCycleCount', array('CycleCount'));
                     if (sizeof($bufferBCC) > 0 && isset($bufferBCC[0]['CycleCount']) && $bufferBCC[0]['CycleCount'] > 0) {
                         $buffer_info .= 'POWER_SUPPLY_CYCLE_COUNT=' . $bufferBCC[0]['CycleCount'] . "\n";
                     }
                 }
             } elseif (PSI_OS == 'Darwin') {
                 $buffer_info = '';
                 $buffer_state = '';
                 CommonFunctions::executeProgram('ioreg', '-w0 -l -n AppleSmartBattery -r', $buffer_info, false);
             } elseif (PSI_OS == 'FreeBSD') {
                 $buffer_info = '';
                 $buffer_state = '';
                 CommonFunctions::executeProgram('acpiconf', '-i batt', $buffer_info, false);
             } else {
                 $buffer_info = '';
                 $buffer_state = '';
                 $bat_name = PSI_PLUGIN_BAT_DEVICE;
                 $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/info', $buffer_info, 0, 4096, false);
                 $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/state', $buffer_state, 0, 4096, false);
                 if (!$rfts_bi && !$rfts_bs) {
                     $buffer_info = '';
                     $buffer_state = '';
                     if (!CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, false)) {
                         if (CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, false)) {
                             $bat_name = 'battery';
                         } else {
                             CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                             // Once again but with debug
                         }
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_min_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_max_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CHARGE_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CHARGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/capacity', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/technology', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/status', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_temp', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_vol', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/health', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1;
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info);
             CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS");
             break;
     }
     $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
     $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY);
 }
Exemple #19
0
            }
        } else {
            // On other systems, like Ubuntu, there's file with the Olsen time right inside it.
            $timezone = @file_get_contents('/etc/timezone');
            if (! strlen($timezone)) {
                $timezone = $default;
            }
        }
        if ((string) $timezone === '') {
            $timezone = $default;
        }
    }

    if ((string) php_uname('s') == 'Windows NT') {
        $wbem_locator = new COM('WbemScripting.SWbemLocator');
        $wbem_services = $wbem_locator->ConnectServer('.', 'root\\cimv2');
        $zones = $wbem_services->ExecQuery('Select * from Win32_TimeZone');
        foreach ($zones as $zone) {
            $wmi_zone_offset = (int) $zone->Bias * 60;
            $wmi_caption = strtok($zone->Caption, ' ');
            $wmi_location = strtok('|');
        }
        // Attempt to match based on the offset and part of the WMI string in the Caption field
        foreach (timezone_abbreviations_list() as $timezone_abbr) {
            foreach ($timezone_abbr as $entry) {
                if ((int) $entry['offset'] === (int) $wmi_zone_offset and strpos($entry['timezone_id'], $wmi_location) !== false) {
                    $timezone = trim($entry['timezone_id']);
                }
            }
        }
        if ((string) $timezone === '') {
Exemple #20
0
<?php

//header('Content-Type: text/plain');
$WbemAuthenticationLevelPktPrivacy = 6;
$get_sid = new Variant("", VT_BSTR);
$get_user = new Variant("", VT_BSTR);
$get_domain = new Variant("", VT_BSTR);
$user = '******';
$password = "******";
$arrComputers = array('192.168.1.10');
foreach ($arrComputers as $strComputer) {
    $obj = new COM('WbemScripting.SWbemLocator');
    $obj->Security_->ImpersonationLevel = 3;
    $obj->Security_->AuthenticationLevel = $WbemAuthenticationLevelPktPrivacy;
    $wmi = $obj->ConnectServer($strComputer, '/root/cimv2', $user, $password);
    //Use the second method below if no CLI computer is given
    //$wmi = new COM('winmgmts:{impersonationLevel=impersonate}!//' . $strComputer . '/root/cimv2');      //Use local computer
    $colItems = $wmi->ExecQuery("SELECT * FROM Win32_Bios");
    foreach ($colItems as $colItem) {
        echo "BuildNumber: " . $colItem->BuildNumber . "<br />";
        echo "Caption: " . $colItem->Caption . "<br />";
        echo "CodeSet: " . $colItem->CodeSet . "<br />";
        echo "CurrentLanguage: " . $colItem->CurrentLanguage . "<br />";
        echo "Description: " . $colItem->Description . "<br />";
        echo "IdentificationCode: " . $colItem->IdentificationCode . "<br />";
    }
    $get_sid = new Variant("", VT_BSTR);
    $strUser = new Variant("", VT_BSTR);
    $strDomain = new Variant("", VT_BSTR);
    $colItems = $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'");
    foreach ($colItems as $colItem) {
 public function __construct($computer = ".", $user = null, $password = null)
 {
     $this->Computer = $computer;
     // Get class constants ; this is useful for the GetValue() method, which takes a root key and key path
     // that must be mapped to a string like "\\rootkey\keypath"
     $reflector = new \ReflectionClass(__CLASS__);
     self::$ClassConstants = $reflector->getConstants();
     // Get OS architecture
     if (self::$OsArchitecture === null) {
         self::$OsArchitecture = self::GetOsArchitecture();
     }
     // Check if we need to connect to a local or remote registry
     if ($computer !== "." && $computer !== "localhost") {
         $locator = new \COM("WbemScripting.SWbemLocator");
         $this->WmiInstance = $locator->ConnectServer($computer, "root/default:StdRegProv", $user, $password);
     } else {
         $this->WmiInstance = new \COM(str_ireplace("{Computer}", $computer, self::REGISTRY_STANDARD_OBJECT));
     }
 }
<?php

$live = "live";
$dead = "de";
$server = $_GET['server'];
$service = $_GET['service'];
$computer = 'OMUKCTX02';
// echo $server;
// echo $service;
$objLocator = new COM("WbemScripting.SWbemLocator");
$objService = $objLocator->ConnectServer($server, $computer, 'RNAdmin', 'Woodstock2020');
$services = $objService->execquery("SELECT *\nFROM Win32_Service WHERE Name = '{$service}' and State = 'Running'");
// echo $services->count;  // used to test if condition
if ($services->count > 0) {
    echo $live;
} else {
    echo $dead;
}
?>


?>
Exemple #23
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) {
         case 'command':
             if (PSI_OS == 'Android') {
                 CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                 $buffer_state = '';
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/capacity', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_temp', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_vol', $buffer1, 1, 4096, false)) {
                     if ($buffer1 < 100000) {
                         // uV or mV detection
                         $buffer1 = $buffer1 * 1000;
                     }
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/voltage_max_design', $buffer1, 1, 4096, false)) {
                     if ($buffer1 < 100000) {
                         // uV or mV detection
                         $buffer1 = $buffer1 * 1000;
                     }
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n";
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/technology', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/status', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/health', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1;
                 }
             } elseif (PSI_OS == 'WINNT') {
                 // don't set this params for local connection, it will not work
                 $strHostname = '';
                 $strUser = '';
                 $strPassword = '';
                 try {
                     // initialize the wmi object
                     $objLocator = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $this->_wmi = $objLocator->ConnectServer();
                     } else {
                         $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
                     }
                 } catch (Exception $e) {
                     $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
                 }
                 $buffer_info = '';
                 $buffer_state = '';
                 $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry'));
                 $capacity = '';
                 if (isset($buffer[0]['EstimatedChargeRemaining'])) {
                     $capacity = $buffer[0]['EstimatedChargeRemaining'];
                 }
                 if (isset($buffer[0]['DesignVoltage'])) {
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . 1000 * $buffer[0]['DesignVoltage'] . "\n";
                 }
                 if (isset($buffer[0]['BatteryStatus'])) {
                     switch ($buffer[0]['BatteryStatus']) {
                         case 1:
                             $batstat = 'Discharging';
                             break;
                         case 2:
                             $batstat = 'AC connected';
                             break;
                         case 3:
                             $batstat = 'Fully Charged';
                             break;
                         case 4:
                             $batstat = 'Low';
                             break;
                         case 5:
                             $batstat = 'Critical';
                             break;
                         case 6:
                             $batstat = 'Charging';
                             break;
                         case 7:
                             $batstat = 'Charging and High';
                             break;
                         case 8:
                             $batstat = 'Charging and Low';
                             break;
                         case 9:
                             $batstat = 'Charging and Critical';
                             break;
                         case 10:
                             $batstat = 'Undefined';
                             break;
                         case 11:
                             $batstat = 'Partially Charged';
                             break;
                         default:
                             $batstat = '';
                     }
                     if ($batstat != '') {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n";
                     }
                 }
                 $techn = '';
                 if (isset($buffer[0]['Chemistry'])) {
                     switch ($buffer[0]['Chemistry']) {
                         case 1:
                             $techn = 'Other';
                             break;
                         case 2:
                             $techn = 'Unknown';
                             break;
                         case 3:
                             $techn = 'PbAc';
                             break;
                         case 4:
                             $techn = 'NiCd';
                             break;
                         case 5:
                             $techn = 'NiMH';
                             break;
                         case 6:
                             $techn = 'Li-ion';
                             break;
                         case 7:
                             $techn = 'Zinc-air';
                             break;
                         case 8:
                             $techn = 'Li-poly';
                             break;
                     }
                 }
                 $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity'));
                 if (isset($buffer[0]['DesignVoltage'])) {
                     $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . 1000 * $buffer[0]['DesignVoltage'] . "\n";
                 }
                 // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6
                 if (($techn == '' || $techn == 'Unknown') && isset($buffer[0]['Chemistry'])) {
                     switch ($buffer[0]['Chemistry']) {
                         case 1:
                             $techn = 'Other';
                             break;
                         case 2:
                             $techn = 'Unknown';
                             break;
                         case 3:
                             $techn = 'PbAc';
                             break;
                         case 4:
                             $techn = 'NiCd';
                             break;
                         case 5:
                             $techn = 'NiMH';
                             break;
                         case 6:
                             $techn = 'Li-ion';
                             break;
                         case 7:
                             $techn = 'Zinc-air';
                             break;
                         case 8:
                             $techn = 'Li-poly';
                             break;
                     }
                 }
                 if ($techn != '') {
                     $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n";
                 }
                 if (isset($buffer[0]['DesignCapacity'])) {
                     $buffer_info .= 'design capacity:' . $buffer[0]['DesignCapacity'];
                     if ($capacity != '') {
                         $buffer_state .= 'remaining capacity:' . round($capacity * $buffer[0]['DesignCapacity'] / 100);
                     }
                 } else {
                     if ($capacity != '') {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n";
                     }
                 }
             } else {
                 $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/info', $buffer_info, 0, 4096, false);
                 $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/state', $buffer_state, 0, 4096, false);
                 if (!$rfts_bi && !$rfts_bs) {
                     CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                     $buffer_state = '';
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_min_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/capacity', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/technology', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/status', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info);
             CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS");
             break;
     }
     $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
     $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY);
 }
Exemple #24
0
 public function __construct()
 {
     // initialize the wmi object
     $objLocator = new COM('WbemScripting.SWbemLocator');
     $this->_wmi = $objLocator->ConnectServer();
 }
Exemple #25
0
     $form_data['fqdn'] = ".";
 }
 $computers = explode(",", $form_data['fqdn']);
 $logfilequery = "Select * from Win32_NTEventLogFile";
 $query = "Select * from Win32_NTLogEvent";
 foreach ($computers as $computer) {
     $computer = trim($computer);
     if ($computer == "." or empty($form_data['user']) and empty($form_data['pass'])) {
         $objWMIService = new COM("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy,(Security)}!//" . $computer . "\\root\\cimv2");
     } else {
         $obj = new COM('WbemScripting.SWbemLocator');
         $obj->Security_->ImpersonationLevel = 3;
         /* http://msdn.microsoft.com/en-us/library/windows/desktop/aa393787%28v=vs.85%29.aspx */
         $obj->Security_->AuthenticationLevel = 6;
         /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms695984%28v=vs.85%29.aspx */
         $objWMIService = $obj->ConnectServer($computer, '/root/cimv2', $form_data['user'], $form_data['pass']);
     }
     $logFileDetails = $objWMIService->ExecQuery($logfilequery, 'WQL', 48);
     $logfiles_array = array();
     foreach ($logFileDetails as $logFileDetail) {
         $logfiles_array[] = $logFileDetail->LogFileName;
     }
     foreach ($logfiles_array as $logfilename) {
         $colItems = $objWMIService->ExecQuery("Select * from Win32_NTLogEvent WHERE LogFile = '" . $logfilename . "'", 'WQL', 48);
         $x = 0;
         $total = 0;
         $query = "BEGIN TRANSACTION; ";
         foreach ($colItems as $objItem) {
             foreach ($snorm as $key => $value) {
                 if ($x == 0) {
                     ${"norm_query_" . $value} = "BEGIN TRANSACTION;";
Exemple #26
0
 /**
  * @return \COM
  */
 protected function getWMI()
 {
     if ($this->wmiConnection === null) {
         $wmiLocator = new \COM('WbemScripting.SWbemLocator');
         try {
             $this->wmiConnection = $wmiLocator->ConnectServer($this->wmiHost, 'root\\CIMV2', $this->wmiUsername, $this->wmiPassword);
             $this->wmiConnection->Security_->impersonationLevel = 3;
         } catch (\Exception $e) {
             if ($e->getCode() == '-2147352567') {
                 $this->wmiConnection = $wmiLocator->ConnectServer($this->wmiHosthost, 'root\\CIMV2', null, null);
                 $this->wmiConnection->Security_->impersonationLevel = 3;
             }
         }
     }
     return $this->wmiConnection;
 }
Exemple #27
0
<?php

//header('Content-Type: text/plain');
//$wbemFlagReturnImmediately=0x10;
//$wbemFlagForwardOnly=0x20;
//$WbemAuthenticationLevelPktPrivacy=6;
$arrComputers = array(".");
$get_sid = new Variant("", VT_BSTR);
$get_user = new Variant("", VT_BSTR);
$get_domain = new Variant("", VT_BSTR);
// $user = $argv[1];
// $password = $argv[2];
// $arrComputers = explode($argv[3], ",");
foreach ($arrComputers as $strComputer) {
    $obj = new COM('WbemScripting.SWbemLocator');
    $wmi = $obj->ConnectServer($strComputer, '/root/cimv2');
    //Use the second method below if no CLI computer is given
    //$wmi = new COM('winmgmts:{impersonationLevel=impersonate}!//' . $strComputer . '/root/cimv2');      //Use local computer
    $colItems = $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'");
    foreach ($colItems as $colItem) {
        if ($colItem != null) {
            echo "Explorer is running as " . "\r\n";
            $colItem->GetOwner($get_user, $get_domain);
            echo "    " . $get_domain . "\\" . $get_user . "\r\n";
        } else {
            echo "explorer is not running" . "\r\n";
        }
    }
}