jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [check.php] - Blame information for rev 84

 

Line No. Rev Author Line
11simandl<?php
2 // get some basics...
3 $php_version = phpversion();
4 $mem_allowed = ini_get("memory_limit");
5 $php_os = php_uname();
613simandl 
7 $mem_warning = "";
8 $mem_allowed_int = return_bytes($mem_allowed);
9 if(($mem_allowed_int>0) && ($mem_allowed_int < 32000000)) { $mem_warning='You should increase this value to at least 32M. '; }
10 
111simandl // capture the PHP "General Info" table
12 ob_start();
13 phpinfo(INFO_GENERAL);
14 $s = ob_get_contents();
15 ob_end_clean();
16 
17 // <tr><td class="e">System </td><td class="v">Windows NT BLINKYZERO 6.0 build 6000 </td></tr>
18 // since preg_* are potentially missing, we'll have to do this without regexps.
19 foreach (explode("\n",$s) as $line)
20 {
21 $line = str_replace('<tr><td class="e">','',$line);
22 $line = str_replace('</td></tr>','',$line);
23 $line = str_replace(' </td><td class="v">',' => ',$line);
24 $sep_pos = strpos($line," => ");
25 if($sep_pos!==FALSE)
26 {
27 // by here, it should be a straight "name => value"
28 $name = substr($line,0,$sep_pos);
29 $value = substr($line,$sep_pos+4);
30 $php_general[$name] = $value;
31 }
32 }
33 
34 $ini_file = $php_general['Configuration File (php.ini) Path'];
35 $extra_ini = php_ini_scanned_files();
3613simandl if($extra_ini != '')
37 { $extra_ini = "The following additional ini files were read: $extra_ini"; }
38 else { $extra_ini = "There were no additional ini files, according to PHP."; }
39 
40 $gdversion = "";
41 $gdbuiltin=FALSE;
42 $gdstring = "";
43 if(function_exists('gd_info'))
44 {
45 $gdinfo = gd_info();
46 $gdversion=$gdinfo['GD Version'];
47 if(strpos($gdversion,"bundled") !== FALSE)
48 {
49 $gdbuiltin=TRUE;
50 $gdstring="This PHP uses the 'bundled' GD library, which doesn't have alpha-blending bugs. That's good!\n";
51 }
52 else
53 {
54 $gdstring="This PHP uses the system GD library, which MIGHT have alpha-blending bugs. Check that you have at least GD 2.0.34 installed, if you see problems with weathermap segfaulting.\n";
55 }
56 }
57 else
58 {
59 $gdstring = "The gdinfo() function is not available, which means that either the GD extension is not available, not enabled, or not installed.\n";
60 }
61 
621simandl if(isset($argv))
63 {
64 $environment = "CLI";
6513simandl print "\n----------------------------------------------------\nWeathermap Pre-Install Checker\n\n";
661simandl print "This script checks for some common problems with your PHP and server\nenvironment that may stop Weathermap or the Editor from working.\n\n";
6713simandl print "NOTE: You should run this script as both a web page AND from the\ncommand-line, as the environment can be different in each.\n";
68 print "\nThis is the PHP version that is responsible for \n* creating maps from the Cacti poller\n* the command-line weathermap tool\n\n";
691simandl print "PHP Basics\n----------\n";
7013simandl print wordwrap("This is PHP Version $php_version running on \"$php_os\" with a memory_limit of '$mem_allowed'. $mem_warning\n");
711simandl print "\nThe php.ini file was $ini_file\n$extra_ini\n\n";
7213simandl print "";
731simandl print "PHP Functions\n-------------\n";
7413simandl print "Some parts of Weathermap need special support in your PHP\ninstallation to work.\n\n";
75 print wordwrap($gdstring)."\n";
761simandl }
77 else
78 {
79 $environment = "web";
80?>
81<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
82<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
83<head>
84 <title>Weathermap Pre-Install Checker</title>
85 <style>
86 body { font-family: Lucida Grande,Arial,sans-serif; font-size: 10pt; }
87 p {margin-bottom: 10px; margin-top: 10px;}
88 table { margin: 20px;}
89 .critical { width: 400px; padding: 10px; background: #fee; border: 1px solid #f88; padding-left: 20px; background-image: left no-repeat url(images/exclamation.png); }
90 .noncritical { width: 400px; padding: 10px; background: #ffe; border: 1px solid #fb8; }
91 .ok { width: 400px; padding: 10px; background: #efe; border: 1px solid #8f8; }
92 </style>
93</head>
94<body>
95 
96 <h1>Weathermap Pre-install Checker</h1>
97 
98 <p>This page checks for some common problems with your PHP and server environment that may stop Weathermap or the Editor from working.</p>
99 <p>NOTE: You should run this script as a web page AND from the command-line, as the environment can be different in each.</p>
10013simandl <h2>PHP Basics</h2><p>This is the PHP version that is responsible for<ul>
101 <li>The web-based editor<li>Building maps with Rebuild Now from Cacti</ul></p>
102 <p>This is PHP Version <?php echo $php_version ?> running on "<?php echo $php_os ?>" with a memory_limit of '<?php echo $mem_allowed ?>'. <?php echo $mem_warning ?></p>
1031simandl <p>The php.ini file was <?php echo $ini_file ?></p>
104 <p><?php echo $extra_ini ?></p>
105 <h2>PHP Functions</h2>
106 <p>Some parts of Weathermap need special support in your PHP installation to work.</p>
10713simandl <?php echo $gdstring; ?>
1081simandl <table>
109<?php
110 }
111 
112 $critical=0;
113 $noncritical=0;
11413simandl 
115 
1161simandl 
117 # critical, what-it-affects, what-it-is
118 $functions = array('imagepng' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
119 'imagecreatetruecolor' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
120 'imagealphablending' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
121 'imageSaveAlpha' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
122 'preg_match'=> array(TRUE,FALSE,'configuration reading','provided by the "pcre" extension') ,
123 'imagecreatefrompng' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
124 
125 'imagecreatefromjpeg' => array(FALSE,FALSE,'JPEG input support for ICON and BACKGROUND','an optional part of the GD library and the "gd" PHP extension'),
126 'imagecreatefromgif' => array(FALSE,FALSE,'GIF input support for ICON and BACKGROUND','an optional part of the GD library and the "gd" PHP extension'),
127 'imagejpeg' => array(FALSE,FALSE,'JPEG output support','an optional part of the GD library and the "gd" PHP extension'),
128 'imagegif' => array(FALSE,FALSE,'GIF output support','an optional part of the GD library and the "gd" PHP extension'),
129 'imagecopyresampled' => array(FALSE,FALSE,'Thumbnail creation in the Cacti plugin','an optional part of the GD library and the "gd" PHP extension'),
130 'imagettfbbox' => array(FALSE,FALSE,'TrueType font support','an optional part of the GD library and the "gd" PHP extension'),
131 'memory_get_usage' => array(FALSE,TRUE,'memory-usage debugging','not supported on all PHP versions and platforms')
132 );
133 
134 $results=array();
135 
13613simandl if($environment == 'CLI')
137 {
138 // Console_Getopt is only needed by the CLI tool.
139 $included = @include_once 'Console/Getopt.php';
140 
141 if($included != 1)
142 {
143 $noncritical++;
144 print wordwrap("The Console_Getopt PEAR module is not available. The CLI weathermap tool will not run without it (that may not be a problem, if you only intend to use Cacti).\n\n");
145 }
146 else
147 {
148 print wordwrap("The Console_Getopt PEAR module is available. That's good!\n\n");
149 }
150 
151 }
152 
1531simandl foreach ($functions as $function=>$details)
154 {
155 $exists = ""; $notes="";
156 if($environment=='web') print "<tr><td align=right>$function()</td>";
157 
158 if(function_exists($function))
159 {
160 $exists = "YES";
161 if($environment=='web') print "<td><img alt=\"YES\" src=\"images/tick.png\" /></td>";
162 }
163 else
164 {
165 $exists = "NO";
166 if($details[0])
167 {
168 $notes .= "CRITICAL. ";
169 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/exclamation.png\" /><b>CRITICAL</b> ";
170 $critical++;
171 } else {
172 if(!$details[1])
173 {
174 $notes .= "Non-Critical. ";
175 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/cross.png\" /><i>non-critical</i> ";
176 $noncritical++;
177 }
178 else
179 {
180 $notes .= "Minor. ";
181 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/cross.png\" /><i>minor</i> ";
182 }
183 }
184 $explanation = "This is required for ".$details[2].". It is ".$details[3].".";
185 $notes .= $explanation;
186 
187 if($environment=='web') print "$explanation</td>";
188 }
189 if($environment=='web') print "</tr>\n";
190 else
191 {
192 $wnotes = wordwrap($notes,50);
193 $lines = split("\n",$wnotes);
194 $i=0;
195 foreach ($lines as $noteline)
196 {
197 if($i==0)
198 {
199 print sprintf("%20s %5s %-52s\n",$function,$exists,$noteline);
200 $i++;
201 }
202 else
203 {
204 print sprintf("%20s %5s %-52s\n","","",$noteline);
205 $i++;
206 }
207 }
208 }
209 }
210 
211 if($environment=='web') print "</table>";
212 
213 if( ($critical + $noncritical) > 0)
214 {
215 if($environment=='web')
216 {
217 print "<p>If these functions are not found, you may need to <ul><li>check that the 'extension=' line for that extension is uncommented in your php.ini file (then restart your webserver), or<li>install the extension, if it isn't installed already</ul>";
218 }
219 else
220 {
221 print "\nIf these functions are not found, you may need to\n * check that the 'extension=' line for that extension is uncommented in\n your php.ini file (then restart your webserver), or\n * install the extension, if it isn't installed already\n\n";
222 }
223 
224 print wordwrap("The details of how this is done will depend on your operating system, and on where you installed (or compiled) your PHP from originally. Usually, you would install an RPM, or other package on Linux systems, a port on *BSD, or a DLL on Windows. If you build PHP from source, you need to add extra options to the './configure' line. Consult your PHP documention for more information.\n");
225 if($environment=='web') print "</p>";
226 }
227 
228 if($environment=="CLI") print "\n---------------------------------------------------------------------\n";
229 
230 if($critical>0)
231 {
232 if($environment=='web') print "<div class=\"critical\">";
233 print wordwrap("There are problems with your PHP or server environment that will stop Weathermap from working. You need to correct this issues if you wish to use Weathermap.\n");
234 if($environment=='web') print "</div>";
235 }
236 else
237 {
238 if($noncritical>0)
239 {
24013simandl if($environment=='web') print "<div class=\"noncritical\">";
2411simandl print wordwrap("Some features of Weathermap will not be available to you, due to lack of support in your PHP installation. You can still proceed with Weathermap though.\n");
24213simandl if($environment=='web') print "</div>";
2431simandl 
244 }
245 else
246 {
24713simandl if($environment=='web') print "<div class=\"ok\">";
248 print wordwrap("OK! Your PHP and server environment *seems* to have support for ALL of the Weathermap features. Make sure you have run this script BOTH as a web page and from the CLI to be sure, however.\n");
249 if($environment=='web') print "</div>";
2501simandl 
251 }
252 }
25313simandl if($environment=='web') print "</body></html>";
254 
255 function return_bytes($val) {
256 $val = trim($val);
257 if($val != '')
258 {
259 $last = strtolower($val{strlen($val)-1});
260 switch($last) {
261 // The 'G' modifier is available since PHP 5.1.0
262 case 'g':
263 $val *= 1024;
264 case 'm':
265 $val *= 1024;
266 case 'k':
267 $val *= 1024;
268 }
269 }
270 else
271 {
272 $val = 0;
273 }
274 
275 return $val;
276}
2771simandl?>

Powered by WebSVN 2.2.1