[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 // phpSysInfo - A PHP System Information Script 3 // http://phpsysinfo.sourceforge.net/ 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 2 7 // of the License, or (at your option) any later version. 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // You should have received a copy of the GNU General Public License 13 // along with this program; if not, write to the Free Software 14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 // $Id: common_functions.php 21228 2006-04-06 13:52:08Z ralfbecker $ 16 // HTML/XML Comment 17 function created_by () 18 { 19 global $VERSION; 20 return "<!--\n\tCreated By: phpSysInfo - $VERSION\n\thttp://phpsysinfo.sourceforge.net/\n-->\n\n"; 21 } 22 // usefull during development 23 // error_reporting(E_ALL | E_NOTICE); 24 25 // print out the bar graph 26 // $value as full percentages 27 // $maximim as current maximum 28 // $b as scale factor 29 // $type as filesystem type 30 function create_bargraph ($value, $maximum, $b, $type = "") 31 { 32 global $webpath; 33 34 $textdir = direction(); 35 36 $imgpath = $webpath . 'templates/' . TEMPLATE_SET . '/images/'; 37 $maximum == 0 ? $barwidth = 0 : $barwidth = round((100 / $maximum) * $value) * $b; 38 $red = 90 * $b; 39 $yellow = 75 * $b; 40 41 if (!file_exists(APP_ROOT . "/templates/" . TEMPLATE_SET . "/images/nobar_left.gif")) { 42 if ($barwidth == 0) { 43 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_' . $textdir['left'] . '.gif" alt="">' 44 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_middle.gif" width="1" alt="">' 45 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_' . $textdir['right'] . '.gif" alt="">'; 46 } elseif (file_exists(APP_ROOT . "/templates/" . TEMPLATE_SET . "/images/yellowbar_left.gif") && $barwidth > $yellow && $barwidth < $red) { 47 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'yellowbar_' . $textdir['left'] . '.gif" alt="">' 48 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'yellowbar_middle.gif" width="' . $barwidth . '" alt="">' 49 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'yellowbar_' . $textdir['right'] . '.gif" alt="">'; 50 } elseif (($barwidth < $red) || ($type == "iso9660") || ($type == "CDFS")) { 51 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_' . $textdir['left'] . '.gif" alt="">' 52 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_middle.gif" width="' . $barwidth . '" alt="">' 53 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_' . $textdir['right'] . '.gif" alt="">'; 54 } else { 55 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_' . $textdir['left'] . '.gif" alt="">' 56 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_middle.gif" width="' . $barwidth . '" alt="">' 57 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_' . $textdir['right'] . '.gif" alt="">'; 58 } 59 } else { 60 if ($barwidth == 0) { 61 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_' . $textdir['left'] . '.gif" alt="">' 62 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_middle.gif" width="' . (100 * $b) . '" alt="">' 63 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_' . $textdir['right'] . '.gif" alt="">'; 64 } elseif (file_exists(APP_ROOT . "/templates/" . TEMPLATE_SET . "/images/yellowbar_left.gif") && $barwidth > $yellow && $barwidth < $red) { 65 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'yellowbar_' . $textdir['left'] . '.gif" alt="">' 66 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'yellowbar_middle.gif" width="' . $barwidth . '" alt="">' 67 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_middle.gif" width="' . ((100 * $b) - $barwidth) . '" alt="">' 68 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_' . $textdir['right'] . '.gif" alt="">'; 69 } elseif (($barwidth < $red) || $type == "iso9660" || ($type == "CDFS")) { 70 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_' . $textdir['left'] . '.gif" alt="">' 71 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'bar_middle.gif" width="' . $barwidth . '" alt="">' 72 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_middle.gif" width="' . ((100 * $b) - $barwidth) . '" alt="">' 73 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_' . $textdir['right'] . '.gif" alt="">'; 74 } elseif ($barwidth == (100 * $b)) { 75 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_' . $textdir['left'] . '.gif" alt="">' 76 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_middle.gif" width="' . (100 * $b) . '" alt="">' 77 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_' . $textdir['right'] . '.gif" alt="">'; 78 } else { 79 return '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_' . $textdir['left'] . '.gif" alt="">' 80 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'redbar_middle.gif" width="' . $barwidth . '" alt="">' 81 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_middle.gif" width="' . ((100 * $b) - $barwidth) . '" alt="">' 82 . '<img height="' . BAR_HEIGHT . '" src="' . $imgpath . 'nobar_' . $textdir['right'] . '.gif" alt="">'; 83 } 84 } 85 } 86 87 function create_bargraph_grad( $value, $maximum, $b, $type = "" ) { 88 global $webpath; 89 90 $maximum == 0 ? $barwidth = 0 : $barwidth = round((100 / $maximum) * $value); 91 $startColor = '0ef424'; // green 92 $endColor = 'ee200a'; // red 93 if ($barwidth > 100) { 94 $barwidth = 0; 95 } 96 97 return '<img height="' . BAR_HEIGHT . '" width="300" src="' . $webpath . 'includes/indicator.php?height=' . BAR_HEIGHT . '&percent=' . $barwidth . '&color1=' . $startColor . '&color2=' . $endColor . '" alt="">'; 98 } 99 100 function direction() { 101 global $text_dir; 102 103 if(!isset($text_dir) || $text_dir == "ltr") { 104 $result['direction'] = "ltr"; 105 $result['left'] = "left"; 106 $result['right'] = "right"; 107 } else { 108 $result['direction'] = "rtl"; 109 $result['left'] = "right"; 110 $result['right'] = "left"; 111 } 112 113 return $result; 114 } 115 116 // Find a system program. Do path checking 117 function find_program ($program) 118 { 119 global $addpaths; 120 121 $path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin'); 122 123 if( isset($addpaths) && is_array($addpaths) ) { 124 array_merge( $path, $addpaths ); 125 } 126 127 if (function_exists("is_executable")) { 128 while ($this_path = current($path)) { 129 if (is_executable("$this_path/$program")) { 130 return "$this_path/$program"; 131 } 132 next($path); 133 } 134 } else { 135 return strpos($program, '.exe'); 136 } ; 137 138 return; 139 } 140 // Execute a system program. return a trim()'d result. 141 // does very crude pipe checking. you need ' | ' for it to work 142 // ie $program = execute_program('netstat', '-anp | grep LIST'); 143 // NOT $program = execute_program('netstat', '-anp|grep LIST'); 144 function execute_program ($programname, $args = '', $booErrorRep = true ) 145 { 146 global $error; 147 $buffer = ''; 148 $program = find_program($programname); 149 150 if (!$program) { 151 if( $booErrorRep ) { 152 $error->addError( 'find_program(' . $programname . ')', 'program not found on the machine', __LINE__, __FILE__); 153 } 154 return; 155 } 156 157 // see if we've gotten a |, if we have we need to do patch checking on the cmd 158 if ($args) { 159 $args_list = split(' ', $args); 160 for ($i = 0; $i < count($args_list); $i++) { 161 if ($args_list[$i] == '|') { 162 $cmd = $args_list[$i + 1]; 163 $new_cmd = find_program($cmd); 164 $args = ereg_replace("\| $cmd", "| $new_cmd", $args); 165 } 166 } 167 } 168 // we've finally got a good cmd line.. execute it 169 if ($fp = popen("($program $args > /dev/null) 3>&1 1>&2 2>&3", 'r')) { 170 while (!feof($fp)) { 171 $buffer .= fgets($fp, 4096); 172 } 173 pclose($fp); 174 $buffer = trim($buffer); 175 if (!empty($buffer)) { 176 if( $booErrorRep ) { 177 $error->addError( $program, $buffer, __LINE__, __FILE__); 178 } 179 } 180 } 181 if ($fp = popen("$program $args", 'r')) { 182 $buffer = ""; 183 while (!feof($fp)) { 184 $buffer .= fgets($fp, 4096); 185 } 186 pclose($fp); 187 } 188 $buffer = trim($buffer); 189 return $buffer; 190 } 191 192 // A helper function, when passed a number representing KB, 193 // and optionally the number of decimal places required, 194 // it returns a formated number string, with unit identifier. 195 function format_bytesize ($kbytes, $dec_places = 2) 196 { 197 global $text; 198 $spacer = ' '; 199 if ($kbytes > 1048576) { 200 $result = sprintf('%.' . $dec_places . 'f', $kbytes / 1048576); 201 $result .= $spacer . $text['gb']; 202 } elseif ($kbytes > 1024) { 203 $result = sprintf('%.' . $dec_places . 'f', $kbytes / 1024); 204 $result .= $spacer . $text['mb']; 205 } else { 206 $result = sprintf('%.' . $dec_places . 'f', $kbytes); 207 $result .= $spacer . $text['kb']; 208 } 209 return $result; 210 } 211 212 function get_gif_image_height($image) 213 { 214 // gives the height of the given GIF image, by reading it's LSD (Logical Screen Discriptor) 215 // by Edwin Meester aka MillenniumV3 216 // Header: 3bytes Discription 217 // 3bytes Version 218 // LSD: 2bytes Logical Screen Width 219 // 2bytes Logical Screen Height 220 // 1bit Global Color Table Flag 221 // 3bits Color Resolution 222 // 1bit Sort Flag 223 // 3bits Size of Global Color Table 224 // 1byte Background Color Index 225 // 1byte Pixel Aspect Ratio 226 // Open Image 227 $fp = fopen($image, 'rb'); 228 // read Header + LSD 229 $header_and_lsd = fread($fp, 13); 230 fclose($fp); 231 // calc Height from Logical Screen Height bytes 232 $result = ord($header_and_lsd{8}) + ord($header_and_lsd{9}) * 255; 233 return $result; 234 } 235 236 // Check if a string exist in the global $hide_mounts. 237 // Return true if this is the case. 238 function hide_mount($mount) { 239 global $hide_mounts; 240 if (isset($hide_mounts) && is_array($hide_mounts) && in_array($mount, $hide_mounts)) { 241 return true; 242 } 243 else { 244 return false; 245 } 246 } 247 248 function uptime($timestamp) { 249 global $text; 250 $uptime = ''; 251 252 $min = $timestamp / 60; 253 $hours = $min / 60; 254 $days = floor($hours / 24); 255 $hours = floor($hours - ($days * 24)); 256 $min = floor($min - ($days * 60 * 24) - ($hours * 60)); 257 258 if ($days != 0) { 259 $uptime .= $days. " " . $text['days'] . " "; 260 } 261 262 if ($hours != 0) { 263 $uptime .= $hours . " " . $text['hours'] . " "; 264 } 265 266 $uptime .= $min . " " . $text['minutes']; 267 return $uptime; 268 } 269 270 //Replace some chars which are not valid in xml with iso-8859-1 encoding 271 function replace_specialchars(&$xmlstring) { 272 $xmlstring = str_replace( chr(174), "(R)", $xmlstring ); 273 $xmlstring = str_replace( chr(169), "(C)", $xmlstring ); 274 } 275 276 // find duplicate entrys and count them, show this value befor the duplicated name 277 function finddups( $arrInput ) { 278 $buffer = array_count_values($arrInput); 279 foreach ($buffer as $key => $value) { 280 if( $value > 1 ) { 281 $result[] = "(" . $value . "x) " . $key; 282 } else { 283 $result[] = $key; 284 } 285 } 286 return $result; 287 } 288 289 function rfts( $strFileName, $intLines = 0, $intBytes = 4096, $booErrorRep = true ) { 290 global $error; 291 $strFile = ""; 292 $intCurLine = 1; 293 294 if( file_exists( $strFileName ) ) { 295 if( $fd = fopen( $strFileName, 'r' ) ) { 296 while( !feof( $fd ) ) { 297 $strFile .= fgets( $fd, $intBytes ); 298 if( $intLines <= $intCurLine && $intLines != 0 ) { 299 break; 300 } else { 301 $intCurLine++; 302 } 303 } 304 fclose( $fd ); 305 } else { 306 if( $booErrorRep ) { 307 $error->addError( 'fopen(' . $strFileName . ')', 'file can not read by phpsysinfo', __LINE__, __FILE__ ); 308 } 309 return "ERROR"; 310 } 311 } else { 312 if( $booErrorRep ) { 313 $error->addError( 'file_exists(' . $strFileName . ')', 'the file does not exist on your machine', __LINE__, __FILE__ ); 314 } 315 return "ERROR"; 316 } 317 318 return $strFile; 319 } 320 321 function gdc( $strPath, $booErrorRep = true ) { 322 global $error; 323 $arrDirectoryContent = array(); 324 325 if( is_dir( $strPath ) ) { 326 if( $handle = opendir( $strPath ) ) { 327 while( ( $strFile = readdir( $handle ) ) !== false ) { 328 if( $strFile != "." && $strFile != ".." && $strFile != "CVS" ) { 329 $arrDirectoryContent[] = $strFile; 330 } 331 } 332 closedir( $handle ); 333 } else { 334 if( $booErrorRep ) { 335 $error->addError( 'opendir(' . $strPath . ')', 'directory can not be read by phpsysinfo', __LINE__, __FILE__ ); 336 } 337 } 338 } else { 339 if( $booErrorRep ) { 340 $error->addError( 'is_dir(' . $strPath . ')', 'directory does not exist on your machine', __LINE__, __FILE__ ); 341 } 342 } 343 344 return $arrDirectoryContent; 345 } 346 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |