Location: PHPKode > projects > PHPMyServer > server/modules/generic_information/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_generic_information {

	var $module;

	function UptimePagefile() {
		$val = array();
		//Windows
		if ($this->func->OSIsWindows() AND file_exists('c:\pagefile.sys')){ // when file exists
			$tmp["uptimediffrent"] = time() - filemtime('c:\pagefile.sys'); //gets the filetime of file
			$tmp["uptimedays"] = floor($tmp["uptimediffrent"] / (24 * 3600));
			$tmp["uptimediffrent"] = $tmp["uptimediffrent"] - ($tmp["uptimedays"] * (24 * 3600));
			$tmp["uptimehours"] = floor($tmp["uptimediffrent"] / (3600));
			$tmp["uptimediffrent"] = $tmp["uptimediffrent"] - ($tmp["uptimehours"] * (3600));
			$tmp["uptimeminutes"] = floor($tmp["uptimediffrent"] / (60));
			$tmp["uptimediffrent"] = $tmp["uptimediffrent"] - ($tmp["uptimeminutes"] * 60);
			$tmp["uptimeseconds"] = $tmp["uptimediffrent"];
			$val['uptime_words'] = $tmp["uptimedays"] . ' days, ' . $tmp["uptimehours"] . ' hours, ' . $tmp["uptimeminutes"] . ' minutes and ' . $tmp["uptimeseconds"] . ' seconds';
			$val['uptime_since'] = strtotime($tmp["uptimedays"].' days '.$tmp["uptimehours"].' hours '.$tmp["uptimeminutes"].' minutes '.$tmp["uptimeseconds"].' seconds ago');
		} else
			$val = array('uptime_words'=>'NO-LINUX','uptime_since'=>'NO-LINUX');
		return $val;
	}



	function UptimeExe() {
		$val = '';
		$since = '';
		//Windows
		if ($this->func->OSIsWindows() AND file_exists("generic_information\\uptime.exe") AND $explFile = $this->func->shell_mexec("generic_information\\uptime.exe")){
			// Based on Microsoft's uptime tool: http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/winntas/downloads/uptime.asp
			// Made by TweakBoy - user on http://gahering.tweakers.net
			$tmp['uptime'] = explode("\n", $explFile);
			$tmp['uptime'] = explode(" ", $tmp['uptime'][0]);
			$data = $tmp['uptime'][5] . " days, ";
			$data .= $tmp['uptime'][7] . " hours, ";
			$data .= $tmp['uptime'][9] . " minutes and ";
			$data .= $tmp['uptime'][11] . " seconds";
			$val = $data;
			$since = strtotime($tmp['uptime'][5].' days '.$tmp['uptime'][7].' hours '.$tmp['uptime'][9].' minutes '.$tmp['uptime'][11].' seconds ago');
		} elseif (!$this->func->OSIsWindows()) {
			// ---------------------------------------------------- Uptime
			if ($fd = implode("", file('/proc/uptime'))){ // When the command uptime returns an value
				$tmp = explode(" ", $fd);
				$tmp["min"] = $tmp[0] / 60;
				$tmp["hours"] = $tmp["min"] / 60;
				$tmp["days"] = floor($tmp["hours"] / 24);
				$tmp["hours"] = floor($tmp["hours"] - ($tmp["days"] * 24));
				$tmp["min"] = floor($tmp["min"] - ($tmp["days"] * 60 * 24) - ($tmp["hours"] * 60));
				$tmp["sec"] = floor($tmp[0] - ($tmp["days"] * 60 * 60 * 24) - ($tmp["hours"] * 60 * 60) - ($tmp["min"]) * 60);
				$val = "";
				$sin = '';
				if(!empty($tmp["days"])){
					$val .= $tmp["days"] . " days, "; //return that value
					$sin .= $tmp['days'].' days ';
				}
				if(!empty($tmp["hours"])){
					$val .= $tmp["hours"] . " hours, "; //return that value
					$sin .= $tmp['hours'] . ' hours ';
				}
				if(!empty($tmp["min"])){
					$val .= $tmp["min"] . " minutes and "; //return that value
					$sin .= $tmp['min'] . ' minutes ';
				}
				$val .= $tmp["sec"] . " seconds"; //return that value
				$sin .= $tmp['sec'] . ' seconds';
				
				$since = strtotime($sin.' ago');
			}
		}
		
		return array('uptime_words'=>$val,'uptime_since'=>$since);
	}




	function OSVersion() {
		$val = '';
		//Windows AND 1/2e Linux
		if ($this->func->OSIsWindowS()) {
			if (isset($_SERVER["OS"]) AND eregi("nt",$_SERVER["OS"]) AND !$this->func->shell_mexec("ver"))
				$val = "Microsoft Windows NT";
			elseif ($winver = $this->func->shell_mexec("ver")) {
				$winver = explode('[',$winver); //don't show the exact version (security, so hackers can't see your weakness)
				$val = trim($winver[0]); //returns the operatingsystem
			} else
				$val = "N/A";
		} else {
			if (($tmp["server_os"] = $this->func->shell_mexec("uname -s")) && ($tmp["server_os1"] = $this->func->shell_mexec("uname -r")))
				$val = $tmp["server_os"] . " [" . $tmp["server_os1"] . " ]";
			else
				$val = "N/A";
		}
		return $val;
	}




	function WebVersion() {
		$val = '';
		//Windows AND Linux
		if (ereg("php", strtolower($_SERVER["SERVER_SOFTWARE"])))
			$val = $_SERVER["SERVER_SOFTWARE"]; //return the server software
		elseif (isset($_SERVER) AND isset($_SERVER["SERVER_SOFTWARE"]))
			$val = $_SERVER["SERVER_SOFTWARE"] . " / PHP " . phpversion(); //return the server software with php version
		else
			$val = "N/A";
		return $val;
	}



	function AdminMail() {
		$val = '';
		//Windows AND Linux
		if (isset($_SERVER) AND isset($_SERVER["SERVER_ADMIN"]))
			$val = $_SERVER["SERVER_ADMIN"];
		elseif (isset($_ENV) AND isset($_ENV["SERVER_ADMIN"]))
			$val = $_ENV["SERVER_ADMIN"];
		else
			$val = 'N/A';
		return $val;
	}






	//Constructor
	function pmsmod_generic_information() {
		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();
		
		$this->module['return_data']['timestamp'] = time();
		
		if ($valex = $this->UptimeExe()) {
			$this->module['return_data']['uptime_words'] = $valex['uptime_words'];
			$this->module['return_data']['uptime_since'] = $valex['uptime_since'];
		} else {
			$this->module['return_data']['uptime_words'] = '';
			$this->module['return_data']['uptime_since'] = '';
		}
		
		if ($valpa = $this->UptimePagefile()) {
			$this->module['return_data']['uptime_page_words'] = $valpa['uptime_words'];
			$this->module['return_data']['uptime_page_since'] = $valpa['uptime_since'];
		} else {
			$this->module['return_data']['uptime_page_words'] = '';
			$this->module['return_data']['uptime_page_since'] = '';
		}
		$this->module['return_data']['os'] = $this->OSVersion();
		$this->module['return_data']['webserver'] = $this->WebVersion();
		$this->module['return_data']['admin'] = $this->AdminMail();
	}

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

?>
Return current item: PHPMyServer