jablonka.czprosek.czf

weathermap

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

 

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 
3485simandl $ini_file = $php_general['Loaded Configuration File'];
351simandl $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";
5585simandl $gdstring .= "You can test for this specific fault by running check-gdbug.php\n";
5613simandl }
57 }
58 else
59 {
60 $gdstring = "The gdinfo() function is not available, which means that either the GD extension is not available, not enabled, or not installed.\n";
61 }
62 
631simandl if(isset($argv))
64 {
65 $environment = "CLI";
6613simandl print "\n----------------------------------------------------\nWeathermap Pre-Install Checker\n\n";
671simandl 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";
6813simandl 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";
69 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";
701simandl print "PHP Basics\n----------\n";
7113simandl print wordwrap("This is PHP Version $php_version running on \"$php_os\" with a memory_limit of '$mem_allowed'. $mem_warning\n");
721simandl print "\nThe php.ini file was $ini_file\n$extra_ini\n\n";
7313simandl print "";
741simandl print "PHP Functions\n-------------\n";
7513simandl print "Some parts of Weathermap need special support in your PHP\ninstallation to work.\n\n";
7685simandl print wordwrap($gdstring)."\n";
771simandl }
78 else
79 {
80 $environment = "web";
81?>
82<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
83<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
84<head>
85 <title>Weathermap Pre-Install Checker</title>
8685simandl <style type="text/css">
87 body { font-family: 'Lucida Grande',Arial,sans-serif; font-size: 10pt; }
881simandl p {margin-bottom: 10px; margin-top: 10px;}
89 table { margin: 20px;}
9085simandl .critical { width: 400px; padding: 10px; background: #fee; border: 1px solid #f88; padding-left: 20px; background: left no-repeat url(images/exclamation.png); }
911simandl .noncritical { width: 400px; padding: 10px; background: #ffe; border: 1px solid #fb8; }
92 .ok { width: 400px; padding: 10px; background: #efe; border: 1px solid #8f8; }
93 </style>
94</head>
95<body>
96 
97 <h1>Weathermap Pre-install Checker</h1>
98 
99 <p>This page checks for some common problems with your PHP and server environment that may stop Weathermap or the Editor from working.</p>
100 <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>
10185simandl <h2>PHP Basics</h2><p>This is the PHP version that is responsible for</p><ul>
102 <li>The web-based editor</li><li>Building maps with Rebuild Now from Cacti</li></ul>
10313simandl <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>
1041simandl <p>The php.ini file was <?php echo $ini_file ?></p>
105 <p><?php echo $extra_ini ?></p>
106 <h2>PHP Functions</h2>
107 <p>Some parts of Weathermap need special support in your PHP installation to work.</p>
10813simandl <?php echo $gdstring; ?>
1091simandl <table>
110<?php
111 }
112 
113 $critical=0;
114 $noncritical=0;
11513simandl 
116 
1171simandl 
118 # critical, what-it-affects, what-it-is
119 $functions = array('imagepng' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
120 'imagecreatetruecolor' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
121 'imagealphablending' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
122 'imageSaveAlpha' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
123 'preg_match'=> array(TRUE,FALSE,'configuration reading','provided by the "pcre" extension') ,
124 'imagecreatefrompng' => array(TRUE,FALSE,'all of Weathermap','part of the GD library and the "gd" PHP extension'),
125 
126 'imagecreatefromjpeg' => array(FALSE,FALSE,'JPEG input support for ICON and BACKGROUND','an optional part of the GD library and the "gd" PHP extension'),
127 'imagecreatefromgif' => array(FALSE,FALSE,'GIF input support for ICON and BACKGROUND','an optional part of the GD library and the "gd" PHP extension'),
128 'imagejpeg' => array(FALSE,FALSE,'JPEG output support','an optional part of the GD library and the "gd" PHP extension'),
129 'imagegif' => array(FALSE,FALSE,'GIF output support','an optional part of the GD library and the "gd" PHP extension'),
13085simandl # 'imagefilter' => array(FALSE, FALSE, 'colorizing icons','a special function of the PHP-supplied GD library ONLY (not the external GD library'.($gdbuiltin?'':' that you are using').')'),
131 'imagecopyresampled' => array(FALSE,FALSE,'Thumbnail creation in the Cacti plugin','an optional part of the GD library and the "gd" PHP extension'),
1321simandl 'imagettfbbox' => array(FALSE,FALSE,'TrueType font support','an optional part of the GD library and the "gd" PHP extension'),
133 'memory_get_usage' => array(FALSE,TRUE,'memory-usage debugging','not supported on all PHP versions and platforms')
134 );
135 
136 $results=array();
137 
13813simandl if($environment == 'CLI')
139 {
140 // Console_Getopt is only needed by the CLI tool.
141 $included = @include_once 'Console/Getopt.php';
142 
143 if($included != 1)
144 {
145 $noncritical++;
146 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");
147 }
148 else
149 {
150 print wordwrap("The Console_Getopt PEAR module is available. That's good!\n\n");
151 }
152 
153 }
154 
1551simandl foreach ($functions as $function=>$details)
156 {
157 $exists = ""; $notes="";
158 if($environment=='web') print "<tr><td align=right>$function()</td>";
159 
160 if(function_exists($function))
161 {
162 $exists = "YES";
163 if($environment=='web') print "<td><img alt=\"YES\" src=\"images/tick.png\" /></td>";
164 }
165 else
166 {
167 $exists = "NO";
168 if($details[0])
169 {
170 $notes .= "CRITICAL. ";
171 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/exclamation.png\" /><b>CRITICAL</b> ";
172 $critical++;
173 } else {
174 if(!$details[1])
175 {
176 $notes .= "Non-Critical. ";
177 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/cross.png\" /><i>non-critical</i> ";
178 $noncritical++;
179 }
180 else
181 {
182 $notes .= "Minor. ";
183 if($environment=='web') print "<td><img alt=\"NO\" src=\"images/cross.png\" /><i>minor</i> ";
184 }
185 }
186 $explanation = "This is required for ".$details[2].". It is ".$details[3].".";
187 $notes .= $explanation;
188 
189 if($environment=='web') print "$explanation</td>";
190 }
191 if($environment=='web') print "</tr>\n";
192 else
193 {
194 $wnotes = wordwrap($notes,50);
195 $lines = split("\n",$wnotes);
196 $i=0;
197 foreach ($lines as $noteline)
198 {
199 if($i==0)
200 {
201 print sprintf("%20s %5s %-52s\n",$function,$exists,$noteline);
202 $i++;
203 }
204 else
205 {
206 print sprintf("%20s %5s %-52s\n","","",$noteline);
207 $i++;
208 }
209 }
210 }
211 }
212 
213 if($environment=='web') print "</table>";
214 
215 if( ($critical + $noncritical) > 0)
216 {
217 if($environment=='web')
218 {
219 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>";
220 }
221 else
222 {
223 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";
224 }
225 
226 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");
227 if($environment=='web') print "</p>";
228 }
229 
230 if($environment=="CLI") print "\n---------------------------------------------------------------------\n";
231 
232 if($critical>0)
233 {
234 if($environment=='web') print "<div class=\"critical\">";
23585simandl print wordwrap("There are problems with your PHP or server environment that will stop Weathermap from working. You need to correct these issues if you wish to use Weathermap.\n");
2361simandl if($environment=='web') print "</div>";
237 }
238 else
239 {
240 if($noncritical>0)
241 {
24213simandl if($environment=='web') print "<div class=\"noncritical\">";
2431simandl 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");
24413simandl if($environment=='web') print "</div>";
2451simandl 
246 }
247 else
248 {
24913simandl if($environment=='web') print "<div class=\"ok\">";
250 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");
251 if($environment=='web') print "</div>";
2521simandl 
253 }
254 }
25513simandl if($environment=='web') print "</body></html>";
256 
257 function return_bytes($val) {
258 $val = trim($val);
259 if($val != '')
260 {
261 $last = strtolower($val{strlen($val)-1});
262 switch($last) {
263 // The 'G' modifier is available since PHP 5.1.0
264 case 'g':
265 $val *= 1024;
266 case 'm':
267 $val *= 1024;
268 case 'k':
269 $val *= 1024;
270 }
271 }
272 else
273 {
274 $val = 0;
275 }
276 
277 return $val;
278}
2791simandl?>
28085simandl</table>
281</body>
282</html>

Powered by WebSVN 2.2.1