jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [weathermap] - Blame information for rev 128

 

Line No. Rev Author Line
118simandl#!/usr/bin/php
21simandl<?php
3 
485simandl// PHP Weathermap 0.97a
5// Copyright Howard Jones, 2005-2009 howie@thingy.com
61simandl// http://www.network-weathermap.com/
7// Released under the GNU Public License
8require_once 'Console/Getopt.php';
9 
10require_once "Weathermap.class.php";
11 
12if (!module_checks()) { die ("Quitting: Module checks failed.\n"); }
13 
1485simandl// $weathermap_debugging=TRUE;
151simandl 
16$output="html";
17$configfile="weathermap.conf";
18$htmlfile='';
19$imagefile='';
20$dumpafter=0;
2185simandl$dumpstats=0;
221simandl$randomdata=0;
23$dumpconfig='';
24$defines=array();
25 
26// **************************************************************************************
27// THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE!
2885simandl$rrdtool="/usr/bin/rrdtool";
291simandl// (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example)
30// **************************************************************************************
31 
32// initialize object
33$cg=new Console_Getopt();
34$short_opts='';
35$long_opts=array
36 (
37 "version",
38 "help",
39 "image-uri=",
40 "config=",
41 "output=",
42 "debug",
4385simandl "uberdebug",
44 "stats",
451simandl "define=",
46 "no-data",
47 "randomdata",
48 "htmloutput=",
49 "dumpafter",
50 "bulge",
51 "sizedebug",
52 "dumpconfig="
53 );
54 
55$args=$cg->readPHPArgv();
56 
57$ret=$cg->getopt($args, $short_opts, $long_opts);
58 
59if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); }
60 
61$gopts=$ret[0];
62 
6385simandl$options_output = array();
64 
651simandlif (sizeof($gopts) > 0)
66{
67 foreach ($gopts as $o)
68 {
69 switch ($o[0])
70 {
71 case '--config':
7285simandl $configfile=$o[1];
731simandl break;
74 
75 case '--htmloutput':
76 $htmlfile=$o[1];
77 break;
78 
79 case '--dumpafter':
80 $dumpafter=1;
81 break;
82 
83 case '--image-uri':
8485simandl // $map->imageuri=$o[1];
85 $options_output['imageuri'] = $o[1];
861simandl break;
87 
88 case '--dumpconfig':
8985simandl //$map->dumpconfig=$o[1];
90 // $options_output['dumpconfig'] = $o[1];
91 $dumpconfig=$o[1];
921simandl break;
93 
94 case '--randomdata':
95 $randomdata=1;
96 break;
97 
9885simandl case '--stats':
99 $dumpstats=1;
100 break;
101 
102 case '--uberdebug':
103 // allow ALL trace messages (normally we block some of the chatty ones)
104 $weathermap_debug_suppress=array();
105 // FALL THROUGH
1061simandl case '--debug':
10785simandl $options_output['debugging'] = TRUE;
108 $weathermap_debugging=TRUE;
109 
110 // enable assertion handling
111 assert_options(ASSERT_ACTIVE, 1);
112 assert_options(ASSERT_WARNING, 0);
113 assert_options(ASSERT_QUIET_EVAL, 1);
1141simandl 
11585simandl // Set up the callback
116 assert_options(ASSERT_CALLBACK, 'my_assert_handler');
117 
1181simandl break;
119 
120 case '--sizedebug':
121 case '--no-data':
12285simandl //$map->sizedebug=TRUE;
123 $options_output['sizedebug'] = TRUE;
1241simandl break;
125 
126 case '--bulge':
12785simandl //$map->widthmod=TRUE;
128 $options_output['widthmod'] = TRUE;
1291simandl break;
130 
131 case '--output':
132 $imagefile=$o[1];
133 break;
134 
135 case '--define':
136 preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches);
13785simandl if(isset($matches[2]))
138 {
139 $varname = $matches[1];
140 $value = $matches[2];
141 debug(">> $varname = '$value'\n");
142 // save this for later, so that when the map object exists, it can be defined
143 $defines[$varname]=$value;
144 }
145 else
146 {
147 print "WARNING: --define format is: --define name=value\n";
148 }
1491simandl break;
150 
151 case '--version':
152 print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
153 exit();
154 break;
155 
156 case '--help':
157 print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
158 print "Copyright Howard Jones, 2005-2007 howie@thingy.com\nReleased under the GNU Public License\nhttp://www.network-weathermap.com/\n\n";
159 
160 print "Usage: php weathermap [options]\n\n";
161 
162 print " --config {filename} - filename to read from. Default weathermap.conf\n";
163 print " --output {filename} - filename to write image. Default weathermap.png\n";
164 print " --htmloutput {filename} - filename to write HTML. Default weathermap.html\n\n";
165 
166 print " --image-uri {uri} - URI to prefix <img> tags in HTML.\n";
167 print " --bulge - Enable link-bulging mode. See manual.\n\n";
16885simandl 
169 print " --define name=value - Define internal variables\n";
170 print " (equivalent to global SET in config file)\n\n";
1711simandl 
172 print " --no-data - skip the data-reading process (just a 'grey' map)\n";
17313simandl print " --randomdata - as above, but use random data\n";
1741simandl print " --debug - produce (LOTS) of debugging information during run\n";
175 print " --dump-after - dump all internal PHP structures (HUGE)\n";
176 print " --dumpconfig {filename} - filename to write a new config to (for testing)\n\n";
177 
178 print " --help - show this help\n";
179 print " --version - show version number\n\n";
180 print "More info at http://www.network-weathermap.com/\n";
181 exit();
182 break;
183 }
184 }
185}
186 
18785simandl// set this BEFORE we create the map object, so we get the debug output from Reset(), as well
188if(isset($options_output['debugging']) && $options_output['debugging'])
1891simandl{
19085simandl $weathermap_debugging=TRUE;
191 debug("------------------------------------\n");
192 debug("Starting PHP-Weathermap run, with config: $configfile\n");
193 debug("------------------------------------\n");
1941simandl}
195 
19685simandl$map=new Weathermap;
197$map->rrdtool = $rrdtool;
198$map->context="cli";
199 
200// now stuff in all the others, that we got from getopts
201foreach ($options_output as $key=>$value)
202{
203 $map->$key = $value;
204 // $map->add_hint($key,$value);
205}
206 
207$weathermap_map = $configfile;
208 
2091simandlif ($map->ReadConfig($configfile))
210{
211 // allow command-lines to override the config file, but provide a default if neither are present
212 if ($imagefile == '')
213 {
214 if ($map->imageoutputfile == '') { $imagefile="weathermap.png"; }
215 else { $imagefile=$map->imageoutputfile; }
216 }
217 
218 if ($htmlfile == '')
219 {
22085simandl if ($map->htmloutputfile != '') { $htmlfile = $map->htmloutputfile; }
2211simandl }
222 
223 // feed in any command-line defaults, so that they appear as if SET lines in the config
224 
22585simandl // XXX FIXME
2261simandl foreach ($defines as $hintname=>$hint)
227 {
228 $map->add_hint($hintname,$hint);
229 }
23085simandl 
231 // now stuff in all the others, that we got from getopts
232 foreach ($options_output as $key=>$value)
233 {
234 // $map->$key = $value;
235 $map->add_hint($key,$value);
236 }
2371simandl 
23885simandl if ( (isset($options_output['sizedebug']) && ! $options_output['sizedebug']) || (!isset($options_output['sizedebug'])) )
2391simandl {
240 if ($randomdata == 1) { $map->RandomData(); }
241 else { $map->ReadData(); }
242 }
243 
24485simandl # exit();
245 
2461simandl if ($imagefile != '')
247 {
248 $map->DrawMap($imagefile);
249 $map->imagefile=$imagefile;
250 }
251 
252 if ($htmlfile != '')
253 {
25485simandl debug("Writing HTML to $htmlfile\n");
255 
2561simandl $fd=fopen($htmlfile, 'w');
257 fwrite($fd,
25885simandl '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>');
259 if($map->htmlstylesheet != '') fwrite($fd,'<link rel="stylesheet" type="text/css" href="'.$map->htmlstylesheet.'" />');
260 fwrite($fd,'<meta http-equiv="refresh" content="300" /><title>' . $map->ProcessString($map->title, $map) . '</title></head><body>');
2611simandl 
262 if ($map->htmlstyle == "overlib")
263 {
264 fwrite($fd,
265 "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n");
266 fwrite($fd,
267 "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n");
268 }
269 
270 fwrite($fd, $map->MakeHTML());
271 fwrite($fd,
27285simandl '<hr /><span id="byline">Network Map created with <a href="http://www.network-weathermap.com/?vs='
2731simandl . $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION
27485simandl . '</a></span></body></html>');
2751simandl fclose ($fd);
276 }
277 
27885simandl if ($dumpconfig != '')
279 $map->WriteConfig($dumpconfig);
2801simandl 
28185simandl if ($dumpstats != '')
282 $map->DumpStats();
283 
2841simandl if ($dumpafter == 1)
285 print_r ($map);
28685simandl 
287# print_r ($map->node_template_tree);
288# print_r ($map->link_template_tree);
289 
290 # $map->cachefolder="editcache";
291 # $map->CacheUpdate(1);
292 
293 
2941simandl}
295else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); }
296 
29785simandl 
298 
299function my_assert_handler($file, $line, $code)
300{
301 echo "Assertion Failed:
302 File $file
303 Line $line
304 Code $code";
305 debug_print_backtrace();
306 exit();
307}
308 
3091simandl// vim:ts=4:sw=4:
310?>

Powered by WebSVN 2.2.1