First commit 18/08/2000
This commit is contained in:
112
otros/includes/common_functions.php
Normal file
112
otros/includes/common_functions.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
//
|
||||
// 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.2 2001/08/03 18:45:55 precision Exp $
|
||||
|
||||
|
||||
// So that stupid warnings do not appear when we stats files that do not exist.
|
||||
error_reporting(5);
|
||||
|
||||
|
||||
// print out the bar graph
|
||||
function create_bargraph ($percent, $a, $b)
|
||||
{
|
||||
if ($percent == 0) {
|
||||
return '<img height="' . BAR_HEIGHT . '" src="templates/' . TEMPLATE_SET . '/images/bar_left.gif" alt="">'
|
||||
. '<img src="templates/' . TEMPLATE_SET . '/images/bar_middle.gif" height="' . BAR_HEIGHT . '" width="1" alt="">'
|
||||
. '<img src="templates/' . TEMPLATE_SET . '/images/bar_right.gif" height="' . BAR_HEIGHT . '" alt="">';
|
||||
} else if ($percent < 90) {
|
||||
return '<img height="' . BAR_HEIGHT . '" src="templates/' . TEMPLATE_SET . '/images/bar_left.gif" alt="">'
|
||||
. '<img src="templates/' . TEMPLATE_SET . '/images/bar_middle.gif" height="' . BAR_HEIGHT . '" width="' . ($a * $b) . '" alt="">'
|
||||
. '<img height="' . BAR_HEIGHT . '" src="templates/' . TEMPLATE_SET . '/images/bar_right.gif" alt="">';
|
||||
} else {
|
||||
return '<img height="' . BAR_HEIGHT . '" src="templates/' . TEMPLATE_SET . '/images/redbar_left.gif" alt="">'
|
||||
. '<img src="templates/' . TEMPLATE_SET . '/images/redbar_middle.gif" height="' . BAR_HEIGHT . '" width="' . ($a * $b) . '" alt="">'
|
||||
. '<img height="' . BAR_HEIGHT . '" src="templates/' . TEMPLATE_SET . '/images/redbar_right.gif" alt="">';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Execute a system function. Do path checking
|
||||
// return a trim()'d result.
|
||||
function execute_program ($program, $args)
|
||||
{
|
||||
$path = array( '/bin/', '/sbin/', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
|
||||
$buffer = '';
|
||||
|
||||
while ($this_path = current($path)) {
|
||||
if (is_executable("$this_path/$program")) {
|
||||
if ($fp = popen("$this_path/$program $args", 'r')) {
|
||||
while (!feof($fp)) {
|
||||
$buffer .= fgets($fp, 4096);
|
||||
}
|
||||
return trim($buffer);
|
||||
}
|
||||
}
|
||||
next($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// function that emulate the compat_array_keys function of PHP4
|
||||
// for PHP3 compatability
|
||||
function compat_array_keys ($arr)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
while (list($key, $val) = each($arr)) {
|
||||
$result[] = $key;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
// function that emulates the compat_in_array function of PHP4
|
||||
// for PHP3 compatability
|
||||
function compat_in_array ($value, $arr)
|
||||
{
|
||||
while (list($key,$val) = each($arr)) {
|
||||
if ($value == $val) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 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.
|
||||
function format_bytesize ($kbytes, $dec_places = 2)
|
||||
{
|
||||
global $text;
|
||||
if ($kbytes > 1048576) {
|
||||
$result = sprintf('%.' . $dec_places . 'f', $kbytes / 1048576);
|
||||
$result .= ' '.$text['gb'];
|
||||
} elseif ($kbytes > 1024) {
|
||||
$result = sprintf('%.' . $dec_places . 'f', $kbytes / 1024);
|
||||
$result .= ' '.$text['mb'];
|
||||
} else {
|
||||
$result = sprintf('%.' . $dec_places . 'f', $kbytes);
|
||||
$result .= ' '.$text['kb'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user