Location: PHPKode > projects > PHPMyServer > server/modules/ups/index.php4.php
<?PHP
//
// PHPMyServer - A PHP System Information Script - Old project name was PHPMyStats
// http://www.phpmyserver.com/
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// $Id: index.php/index.php4.php/index.php5.php/etc ,v 2.6 13-08-2005 16:30 precision Exp $
//
// Date in $Id is as DD-MM-YY

//PHPMyServer - XML Server v2.6
//Build version:
//  split version at the DOT, before the DOT is the CORE version, AFTER the DOT is de RELEASE
//Every new release will get an higher number, so when i released version 2 of the script for the 126523st time, its version v2.126523

//Copyright 2004-2005 by KingOfDos Intra/Extra/Internet WebServices
//http://www.phpmyserver.com
//http://www.kingofdos.com
//http://www.kingofdos.com

class pmsmod_ups {

	var $module;

	//Constructor
	function pmsmod_ups() {
		if (function_exists('pmsFuncStatic'))
			$this->func=& pmsFuncStatic();

		$this->module = array();

		//Compatible versions of PHPMyServer for this module
		$this->module['compatible_version'] = array(
			'03d21b594c8a1b5831a7101c10df7b83',
		'02f1051414bda3eb39439ce2c998abca'
		);

		

	
		//Information
		include 'info_data.php';
		$this->module['information'] = $val;
		$this->module['return_data'] = array();
		
		
		//XML Server - IP / Name of this connection (external)
		if (
			$data_status = explode("\n",$this->func->shell_mexec('.\\ups\\reg.exe query HKLM\\System\\CurrentControlSet\\Services\\UPS\\Start')) AND //Execute REG command
			!eregi('unable to find the specified registry key',$data_status[0]) AND //NOT unable to find
			preg_match("!REG_DWORD	Start	([0-4])!",$data_status[0],$data_status_ret) AND //Get the status from dword
			is_numeric($data_status_ret[1]) AND //Is numeric
			$data_status_ret[1]==2 //Service starts automaticly
		) {


			$data = explode("\n",$this->func->shell_mexec('.\\ups\\reg.exe query HKLM\\System\\CurrentControlSet\\Services\\UPS\\Status'));
			//print_r($data); exit;
		
			if (!eregi('unable to find the specified registry key',$data[0])) {
				//print_r($data);exit;
				//print_r($data);
				for($data_cnt=0;$data_cnt<=count($data)-1;$data_cnt++) {
					//if (preg_match("!SerialNumber	(.*)!",$data[$data_cnt],$data_ret))
					//	$this->module['return_data']['serial_number'] = $data_ret[1];
						
					//if (preg_match("!FirmwareRev	(.*)!",$data[$data_cnt],$data_ret))
					//	$this->module['return_data']['firmware_rev'] = $data_ret[1];
						
					if (preg_match("!UtilityPowerStatus	(.*)!",$data[$data_cnt],$data_ret))
						$this->module['return_data']['utility_power_status'] = (is_numeric($data_ret[1]) AND $data_ret[1]==1)?'Power':((is_numeric($data_ret[1]) AND $data_ret[1]==2)?'Battery':'Unknown');

					if (preg_match("!TotalUPSRuntime	(.*)!",$data[$data_cnt],$data_ret))
						$this->module['return_data']['total_ups_runtime'] = (is_numeric($data_ret[1]))?$data_ret[1].' minutes':'Unknown';
						
					if (preg_match("!BatteryStatus	(.*)!",$data[$data_cnt],$data_ret))
						$this->module['return_data']['battery_helth'] = (is_numeric($data_ret[1]) AND $data_ret[1]==0)?'Unknown':((is_numeric($data_ret[1]) AND $data_ret[1]==1)?'Good':'Replace');
					
					if (preg_match("!BatteryCapacity	(.*)!",$data[$data_cnt],$data_ret))
						$this->module['return_data']['battery_capicity'] = (is_numeric($data_ret[1]) AND $data_ret[1]<=100 AND $data_ret[1]>=0)?$data_ret[1].'%':'Unknown';
						
					if (preg_match("!CommStatus	(.*)!",$data[$data_cnt],$data_ret))
						$this->module['return_data']['comm_status'] = (is_numeric($data_ret[1]) AND $data_ret[1]==1)?'Connected':'Failed';
				}
				
				$this->module['return_data']['comm_port'] = 'COM1';
				//exit;
		
			}
		}
		
		
		
		
		
		
		//For every OS, when there is no data, return this.		
		if (count($this->module['return_data'])==0) {
			$this->module['return_data']['battery_helth'] = 'Unknown';
			$this->module['return_data']['battery_capicity'] = 'Unknown';
			$this->module['return_data']['comm_status'] = 'Unknown';
			//$this->module['return_data']['firmware_rev'] = 0;
			//$this->module['return_data']['serial_number'] = 'Unknown';
			$this->module['return_data']['total_ups_runtime'] = 'Unknown';
			$this->module['return_data']['utility_power_status'] = 'Unknown';
			$this->module['return_data']['comm_port'] = 'Unknown';
		}
		
	}

	//Returner
	function pmsmod_return() {
		return $this->module;
	}
}

?>
Return current item: PHPMyServer