Source for file common_functions.php
Documentation is available at common_functions.php
/***************************************************************************
* Copyright (C) 2006 by phpSysInfo - A PHP System Information Script *
* http://phpsysinfo.sourceforge.net/ *
* 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: common_functions.php,v 1.55 2007/02/20 19:20:20 bigmichi1 Exp $
// usefull during development
if( isset
($showerrors) &&
$showerrors ) {
return "<!--\n\tCreated By: phpSysInfo - " .
$VERSION .
"\n\thttp://phpsysinfo.sourceforge.net/\n-->\n";
// print out the bar graph
// $value as full percentages
// $maximim as current maximum
// $type as filesystem type
$imgpath =
$webpath .
'templates/' .
TEMPLATE_SET .
'/images/';
$maximum ==
0 ?
$barwidth =
0 :
$barwidth =
round((100 /
$maximum) *
$value) *
$b;
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_middle.gif" width="1">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_' .
$textdir['right'] .
'.gif">';
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'yellowbar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'yellowbar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'yellowbar_' .
$textdir['right'] .
'.gif">';
} elseif ( ( $barwidth <
$red ) ||
( $type ==
"iso9660" ) ||
( $type ==
"CDFS" ) ) {
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_' .
$textdir['right'] .
'.gif">';
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_' .
$textdir['right'] .
'.gif">';
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_middle.gif" width="' .
( 100 *
$b ) .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_' .
$textdir['right'] .
'.gif">';
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'yellowbar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'yellowbar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_middle.gif" width="' .
( ( 100 *
$b ) -
$barwidth ) .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_' .
$textdir['right'] .
'.gif">';
} elseif ( ( $barwidth <
$red ) ||
( $type ==
"iso9660" ) ||
( $type ==
"CDFS" ) ) {
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'bar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_middle.gif" width="' .
( ( 100 *
$b ) -
$barwidth ) .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_' .
$textdir['right'] .
'.gif">';
} elseif ( $barwidth ==
( 100 *
$b ) ) {
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_middle.gif" width="' .
( 100 *
$b ) .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_' .
$textdir['right'] .
'.gif">';
return '<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_' .
$textdir['left'] .
'.gif">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'redbar_middle.gif" width="' .
$barwidth .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_middle.gif" width="' .
( ( 100 *
$b ) -
$barwidth ) .
'">'
.
'<img height="' .
BAR_HEIGHT .
'" alt="" src="' .
$imgpath .
'nobar_' .
$textdir['right'] .
'.gif">';
$maximum ==
0 ?
$barwidth =
0 :
$barwidth =
round( ( 100 /
$maximum ) *
$value );
$startColor =
'0ef424'; // green
$endColor =
'ee200a'; // red
return '<img height="' .
BAR_HEIGHT .
'" width="300" src="' .
$webpath .
'includes/indicator.php?height=' .
BAR_HEIGHT .
'&percent=' .
$barwidth .
'&color1=' .
$startColor .
'&color2=' .
$endColor .
'" alt="">';
if( ! isset
( $text_dir ) ||
( $text_dir ==
"ltr" ) ) {
$arrResult['direction'] =
"ltr";
$arrResult['left'] =
"left";
$arrResult['right'] =
"right";
$arrResult['direction'] =
"rtl";
$arrResult['left'] =
"right";
$arrResult['right'] =
"left";
// Find a system program. Do path checking
$arrPath =
array( '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin' );
if( isset
( $addpaths ) &&
is_array( $addpaths ) ) {
foreach ( $arrPath as $strPath ) {
$strProgrammpath =
$strPath .
"/" .
$strProgram;
return strpos( $strProgram, '.exe' );
// Execute a system program. return a trim()'d result.
// does very crude pipe checking. you need ' | ' for it to work
// ie $program = execute_program('netstat', '-anp | grep LIST');
// NOT $program = execute_program('netstat', '-anp|grep LIST');
function execute_program ($strProgramname, $strArgs =
'', $booErrorRep =
true ) {
$error->addError( 'find_program(' .
$strProgramname .
')', 'program not found on the machine', __LINE__
, __FILE__
);
// see if we've gotten a |, if we have we need to do patch checking on the cmd
$arrArgs =
split( ' ', $strArgs );
for( $i =
0; $i <
count( $arrArgs ); $i++
) {
if ( $arrArgs[$i] ==
'|' ) {
$strCmd =
$arrArgs[$i +
1];
$strArgs =
ereg_replace( "\| " .
$strCmd, "| " .
$strNewcmd, $strArgs );
// no proc_open() below php 4.3
0 =>
array("pipe", "r"), // stdin is a pipe that the child will read from
1 =>
array("pipe", "w"), // stdout is a pipe that the child will write to
2 =>
array("pipe", "w") // stderr is a pipe that the child will write to
$process =
proc_open( $strProgram .
" " .
$strArgs, $descriptorspec, $pipes );
while( !feof( $pipes[1] ) ) {
$strBuffer .=
fgets( $pipes[1], 1024 );
while( !feof( $pipes[2] ) ) {
$strError .=
fgets( $pipes[2], 1024 );
if( $fp =
popen( "(" .
$strProgram .
" " .
$strArgs .
" > /dev/null) 3>&1 1>&2 2>&3", 'r' ) ) {
$strError .=
fgets( $fp, 4096 );
$strError =
trim( $strError );
if( $fp =
popen( $strProgram .
" " .
$strArgs, 'r' ) ) {
$strBuffer .=
fgets( $fp, 4096 );
$return_value =
pclose( $fp );
$strError =
trim( $strError );
$strBuffer =
trim( $strBuffer );
if( ! empty( $strError ) ||
$return_value <>
0 ) {
$error->addError( $strProgram, $strError .
"\nReturn value: " .
$return_value, __LINE__
, __FILE__
);
// A helper function, when passed a number representing KB,
// and optionally the number of decimal places required,
// it returns a formated number string, with unit identifier.
if( $intKbytes >
1048576 ) {
$strResult =
sprintf( '%.' .
$intDecplaces .
'f', $intKbytes /
1048576 );
$strResult .=
$strSpacer .
$text['gb'];
} elseif( $intKbytes >
1024 ) {
$strResult =
sprintf( '%.' .
$intDecplaces .
'f', $intKbytes /
1024);
$strResult .=
$strSpacer .
$text['mb'];
$strResult =
sprintf( '%.' .
$intDecplaces .
'f', $intKbytes );
$strResult .=
$strSpacer .
$text['kb'];
$strResult =
$intHz .
" Mhz";
$strResult =
round( $intHz /
1000, 2 ) .
" GHz";
// gives the height of the given GIF image, by reading it's LSD (Logical Screen Discriptor)
// by Edwin Meester aka MillenniumV3
//2bytes Logical Screen Width
// 2bytes Logical Screen Height
// 1bit Global Color Table Flag
// 3bits Color Resolution
// 3bits Size of Global Color Table
// 1byte Background Color Index
// 1byte Pixel Aspect Ratio
$fp =
fopen( $image, 'rb' );
$strHeaderandlsd =
fread( $fp, 13 );
// calc Height from Logical Screen Height bytes
$intResult =
ord( $strHeaderandlsd{8} ) +
ord( $strHeaderandlsd{9} ) *
255;
// Check if a string exist in the global $hide_mounts.
// Return true if this is the case.
if( isset
( $hide_mounts ) &&
is_array( $hide_mounts ) &&
in_array( $strMount, $hide_mounts ) ) {
// Check if a string exist in the global $hide_fstypes.
// Return true if this is the case.
if( isset
( $hide_fstypes ) &&
is_array( $hide_fstypes ) &&
in_array( $strFSType, $hide_fstypes ) ) {
function uptime( $intTimestamp ) {
$intMin =
$intTimestamp /
60;
$intHours =
$intMin /
60;
$intDays =
floor( $intHours /
24 );
$intHours =
floor( $intHours -
( $intDays *
24 ) );
$intMin =
floor( $intMin -
( $intDays *
60 *
24 ) -
( $intHours *
60 ) );
$strUptime .=
$intDays.
" " .
$text['days'] .
" ";
$strUptime .=
$intHours .
" " .
$text['hours'] .
" ";
$strUptime .=
$intMin .
" " .
$text['minutes'];
//Replace some chars which are not valid in xml with iso-8859-1 encoding
$arrReplace =
array( "(R)", "(C)", "ae", "oe", "ue", "Oe", "Ue", "Ae" );
$strXml =
str_replace( $arrSearch, $arrReplace, $strXml );
// find duplicate entrys and count them, show this value befor the duplicated name
foreach( $arrBuffer as $strKey =>
$intValue) {
$arrResult[] =
"(" .
$intValue .
"x) " .
$strKey;
function rfts( $strFileName, $intLines =
0, $intBytes =
4096, $booErrorRep =
true ) {
if( $fd =
fopen( $strFileName, 'r' ) ) {
$strFile .=
fgets( $fd, $intBytes );
if( $intLines <=
$intCurLine &&
$intLines !=
0 ) {
$error->addError( 'fopen(' .
$strFileName .
')', 'file can not read by phpsysinfo', __LINE__
, __FILE__
);
$error->addError( 'file_exists(' .
$strFileName .
')', 'the file does not exist on your machine', __LINE__
, __FILE__
);
function gdc( $strPath, $booErrorRep =
true ) {
$arrDirectoryContent =
array();
if( $handle =
opendir( $strPath ) ) {
while( ( $strFile =
readdir( $handle ) ) !==
false ) {
if( $strFile !=
"." &&
$strFile !=
".." &&
$strFile !=
"CVS" ) {
$arrDirectoryContent[] =
$strFile;
$error->addError( 'opendir(' .
$strPath .
')', 'directory can not be read by phpsysinfo', __LINE__
, __FILE__
);
$error->addError( 'is_dir(' .
$strPath .
')', 'directory does not exist on your machine', __LINE__
, __FILE__
);
return $arrDirectoryContent;
global $temperatureformat, $text, $error;
$floatFahrenheit =
$floatTempC *
1.8 +
32;
$strResult .=
round( $floatFahrenheit ) .
$text['degreeF'];
$strResult .=
round( $floatTempC ) .
$text['degreeC'];
$floatFahrenheit =
$floatTempC *
1.8 +
32;
$strResult .=
round( $floatFahrenheit ) .
$text['degreeF'];
$strResult .=
round( $floatTempC ) .
$text['degreeC'];
$floatFahrenheit =
$floatTempC *
1.8 +
32;
$strResult .=
round( $floatTempC ) .
$text['degreeC'];
$strResult .=
round( $floatFahrenheit ) .
$text['degreeF'];
$error->addError( 'temperature(' .
$floatTempC .
')', 'wrong or unspecified temperature format', __LINE__
, __FILE__
);
Documentation generated on Mon, 06 Feb 2012 01:10:27 +0100 by phpDocumentor 1.4.0