weathermap |
Subversion Repositories: |
Rev 18 | Rev 85 | |
---|---|---|
Line 2... | Line 2... | |
<?php |
<?php | |
|
| |
// PHP Weathermap 0.92 |
// PHP Weathermap 0.97a | |
// Copyright Howard Jones, 2005-2007 howie@thingy.com |
// Copyright Howard Jones, 2005-2009 howie@thingy.com | |
// http://www.network-weathermap.com/ |
// http://www.network-weathermap.com/ | |
// Released under the GNU Public License |
// Released under the GNU Public License | |
require_once 'Console/Getopt.php'; |
require_once 'Console/Getopt.php'; | |
|
| |
require_once "Weathermap.class.php"; |
require_once "Weathermap.class.php"; | |
|
| |
if (!module_checks()) { die ("Quitting: Module checks failed.\n"); } |
if (!module_checks()) { die ("Quitting: Module checks failed.\n"); } | |
|
| |
// $weathermap_debugging=TRUE; // XXX - This needs to come out again! |
// $weathermap_debugging=TRUE; | |
$map=new Weathermap; |
||
$map->context="cli"; |
||
|
| |
$output="html"; |
$output="html"; | |
$configfile="weathermap.conf"; |
$configfile="weathermap.conf"; | |
$htmlfile=''; |
$htmlfile=''; | |
$imagefile=''; |
$imagefile=''; | |
$DEBUG=0; |
||
$dumpafter=0; |
$dumpafter=0; | |
$dumpstats=0; | ||
$randomdata=0; |
$randomdata=0; | |
$dumpconfig=''; |
$dumpconfig=''; | |
$defines=array(); |
$defines=array(); | |
|
| |
// ************************************************************************************** |
// ************************************************************************************** | |
// THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE! |
// THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE! | |
$map->rrdtool="/usr/bin/rrdtool"; |
$rrdtool="/usr/bin/rrdtool"; | |
// (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example) |
// (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example) | |
// ************************************************************************************** |
// ************************************************************************************** | |
|
| |
// initialize object |
// initialize object | |
$cg=new Console_Getopt(); |
$cg=new Console_Getopt(); | |
Line 40... | Line 38... | |
"help", |
"help", | |
"image-uri=", |
"image-uri=", | |
"config=", |
"config=", | |
"output=", |
"output=", | |
"debug", |
"debug", | |
"uberdebug", | ||
"stats", | ||
"define=", |
"define=", | |
"no-data", |
"no-data", | |
"randomdata", |
"randomdata", | |
"htmloutput=", |
"htmloutput=", | |
"dumpafter", |
"dumpafter", | |
Line 57... | Line 57... | |
$ret=$cg->getopt($args, $short_opts, $long_opts); |
$ret=$cg->getopt($args, $short_opts, $long_opts); | |
|
| |
if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); } |
if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); } | |
|
| |
$gopts=$ret[0]; |
$gopts=$ret[0]; | |
| ||
$options_output = array(); | ||
|
| |
if (sizeof($gopts) > 0) |
if (sizeof($gopts) > 0) | |
{ |
{ | |
foreach ($gopts as $o) |
foreach ($gopts as $o) | |
{ |
{ | |
switch ($o[0]) |
switch ($o[0]) | |
{ |
{ | |
case '--config': |
case '--config': | |
$configfile=$o[1]; |
$configfile=$o[1]; | |
break; |
break; | |
|
| |
case '--htmloutput': |
case '--htmloutput': | |
$htmlfile=$o[1]; |
$htmlfile=$o[1]; | |
break; |
break; | |
Line 77... | Line 79... | |
case '--dumpafter': |
case '--dumpafter': | |
$dumpafter=1; |
$dumpafter=1; | |
break; |
break; | |
|
| |
case '--image-uri': |
case '--image-uri': | |
$map->imageuri=$o[1]; |
// $map->imageuri=$o[1]; | |
$options_output['imageuri'] = $o[1]; | ||
break; |
break; | |
|
| |
case '--dumpconfig': |
case '--dumpconfig': | |
$map->dumpconfig=$o[1]; |
//$map->dumpconfig=$o[1]; | |
// $options_output['dumpconfig'] = $o[1]; | ||
$dumpconfig=$o[1]; | ||
break; |
break; | |
|
| |
case '--randomdata': |
case '--randomdata': | |
$randomdata=1; |
$randomdata=1; | |
break; |
break; | |
|
| |
case '--stats': | ||
$dumpstats=1; | ||
break; | ||
| ||
case '--uberdebug': | ||
// allow ALL trace messages (normally we block some of the chatty ones) | ||
$weathermap_debug_suppress=array(); | ||
// FALL THROUGH | ||
case '--debug': |
case '--debug': | |
$DEBUG=1; |
$options_output['debugging'] = TRUE; | |
|
||
$map->debugging=TRUE; |
||
$weathermap_debugging=TRUE; |
$weathermap_debugging=TRUE; | |
| ||
// enable assertion handling | ||
assert_options(ASSERT_ACTIVE, 1); | ||
assert_options(ASSERT_WARNING, 0); | ||
assert_options(ASSERT_QUIET_EVAL, 1); | ||
| ||
// Set up the callback | ||
assert_options(ASSERT_CALLBACK, 'my_assert_handler'); | ||
| ||
break; |
break; | |
|
| |
case '--sizedebug': |
case '--sizedebug': | |
case '--no-data': |
case '--no-data': | |
$map->sizedebug=TRUE; |
//$map->sizedebug=TRUE; | |
$options_output['sizedebug'] = TRUE; | ||
break; |
break; | |
|
| |
case '--bulge': |
case '--bulge': | |
$map->widthmod=TRUE; |
//$map->widthmod=TRUE; | |
$options_output['widthmod'] = TRUE; | ||
break; |
break; | |
|
| |
case '--output': |
case '--output': | |
$imagefile=$o[1]; |
$imagefile=$o[1]; | |
break; |
break; | |
|
| |
case '--define': |
case '--define': | |
preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches); |
preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches); | |
$varname = $matches[1]; |
if(isset($matches[2])) | |
$value = $matches[2]; |
{ | |
debug(">> $varname = '$value'\n"); |
$varname = $matches[1]; | |
// save this for later, so that when the map object exists, it can be defined |
$value = $matches[2]; | |
$defines[$varname]=$value; |
debug(">> $varname = '$value'\n"); | |
// save this for later, so that when the map object exists, it can be defined | ||
$defines[$varname]=$value; | ||
} | ||
else | ||
{ | ||
print "WARNING: --define format is: --define name=value\n"; | ||
} | ||
break; |
break; | |
|
| |
case '--version': |
case '--version': | |
print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n"; |
print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n"; | |
exit(); |
exit(); | |
Line 134... | Line 163... | |
print " --output {filename} - filename to write image. Default weathermap.png\n"; |
print " --output {filename} - filename to write image. Default weathermap.png\n"; | |
print " --htmloutput {filename} - filename to write HTML. Default weathermap.html\n\n"; |
print " --htmloutput {filename} - filename to write HTML. Default weathermap.html\n\n"; | |
|
| |
print " --image-uri {uri} - URI to prefix <img> tags in HTML.\n"; |
print " --image-uri {uri} - URI to prefix <img> tags in HTML.\n"; | |
print " --bulge - Enable link-bulging mode. See manual.\n\n"; |
print " --bulge - Enable link-bulging mode. See manual.\n\n"; | |
| ||
print " --define name=value - Define internal variables\n"; | ||
print " (equivalent to global SET in config file)\n\n"; | ||
|
| |
print " --no-data - skip the data-reading process (just a 'grey' map)\n"; |
print " --no-data - skip the data-reading process (just a 'grey' map)\n"; | |
print " --randomdata - as above, but use random data\n"; |
print " --randomdata - as above, but use random data\n"; | |
print " --debug - produce (LOTS) of debugging information during run\n"; |
print " --debug - produce (LOTS) of debugging information during run\n"; | |
print " --dump-after - dump all internal PHP structures (HUGE)\n"; |
print " --dump-after - dump all internal PHP structures (HUGE)\n"; | |
Line 150... | Line 182... | |
break; |
break; | |
} |
} | |
} |
} | |
} |
} | |
|
| |
if ($DEBUG) |
// set this BEFORE we create the map object, so we get the debug output from Reset(), as well | |
if(isset($options_output['debugging']) && $options_output['debugging']) | ||
{ |
{ | |
print "\n------------------------------------\n"; |
$weathermap_debugging=TRUE; | |
print "Starting PHP-Weathermap run, with config: $configfile\n"; |
debug("------------------------------------\n"); | |
debug("Starting PHP-Weathermap run, with config: $configfile\n"); | ||
debug("------------------------------------\n"); | ||
} |
} | |
| ||
$map=new Weathermap; | ||
$map->rrdtool = $rrdtool; | ||
$map->context="cli"; | ||
| ||
// now stuff in all the others, that we got from getopts | ||
foreach ($options_output as $key=>$value) | ||
{ | ||
$map->$key = $value; | ||
// $map->add_hint($key,$value); | ||
} | ||
| ||
$weathermap_map = $configfile; | ||
|
| |
if ($map->ReadConfig($configfile)) |
if ($map->ReadConfig($configfile)) | |
{ |
{ | |
// allow command-lines to override the config file, but provide a default if neither are present |
// allow command-lines to override the config file, but provide a default if neither are present | |
if ($imagefile == '') |
if ($imagefile == '') | |
Line 167... | Line 215... | |
else { $imagefile=$map->imageoutputfile; } |
else { $imagefile=$map->imageoutputfile; } | |
} |
} | |
|
| |
if ($htmlfile == '') |
if ($htmlfile == '') | |
{ |
{ | |
if ($map->htmloutputfile != '') { $htmlfile=$map->htmloutputfile; } |
if ($map->htmloutputfile != '') { $htmlfile = $map->htmloutputfile; } | |
} |
} | |
|
| |
// feed in any command-line defaults, so that they appear as if SET lines in the config |
// feed in any command-line defaults, so that they appear as if SET lines in the config | |
|
| |
// FIXME |
// XXX FIXME | |
foreach ($defines as $hintname=>$hint) |
foreach ($defines as $hintname=>$hint) | |
{ |
{ | |
$map->add_hint($hintname,$hint); |
$map->add_hint($hintname,$hint); | |
} |
} | |
| ||
// now stuff in all the others, that we got from getopts | ||
foreach ($options_output as $key=>$value) | ||
{ | ||
// $map->$key = $value; | ||
$map->add_hint($key,$value); | ||
} | ||
|
| |
if (!$map->sizedebug) |
if ( (isset($options_output['sizedebug']) && ! $options_output['sizedebug']) || (!isset($options_output['sizedebug'])) ) | |
{ |
{ | |
if ($randomdata == 1) { $map->RandomData(); } |
if ($randomdata == 1) { $map->RandomData(); } | |
else { $map->ReadData(); } |
else { $map->ReadData(); } | |
} |
} | |
|
| |
# exit(); | ||
| ||
if ($imagefile != '') |
if ($imagefile != '') | |
{ |
{ | |
$map->DrawMap($imagefile); |
$map->DrawMap($imagefile); | |
$map->imagefile=$imagefile; |
$map->imagefile=$imagefile; | |
} |
} | |
|
| |
if ($htmlfile != '') |
if ($htmlfile != '') | |
{ |
{ | |
debug("Writing HTML to $htmlfile\n"); | ||
| ||
$fd=fopen($htmlfile, 'w'); |
$fd=fopen($htmlfile, 'w'); | |
fwrite($fd, |
fwrite($fd, | |
'<!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><meta http-equiv="refresh" content="300" /><title>' . $map->title |
'<!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>'); | |
. '</title></head><body>'); |
if($map->htmlstylesheet != '') fwrite($fd,'<link rel="stylesheet" type="text/css" href="'.$map->htmlstylesheet.'" />'); | |
fwrite($fd,'<meta http-equiv="refresh" content="300" /><title>' . $map->ProcessString($map->title, $map) . '</title></head><body>'); | ||
|
| |
if ($map->htmlstyle == "overlib") |
if ($map->htmlstyle == "overlib") | |
{ |
{ | |
fwrite($fd, |
fwrite($fd, | |
"<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"); |
"<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"); | |
Line 207... | Line 267... | |
"<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"); |
"<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"); | |
} |
} | |
|
| |
fwrite($fd, $map->MakeHTML()); |
fwrite($fd, $map->MakeHTML()); | |
fwrite($fd, |
fwrite($fd, | |
'<hr />Network Map created with <a href="http://www.network-weathermap.com/?vs=' |
'<hr /><span id="byline">Network Map created with <a href="http://www.network-weathermap.com/?vs=' | |
. $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION |
. $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION | |
. '</a></body></html>'); |
. '</a></span></body></html>'); | |
fclose ($fd); |
fclose ($fd); | |
} |
} | |
|
| |
if ($map->dumpconfig != '') |
if ($dumpconfig != '') | |
$map->WriteConfig($map->dumpconfig); |
$map->WriteConfig($dumpconfig); | |
|
| |
if ($dumpstats != '') | ||
$map->DumpStats(); | ||
| ||
if ($dumpafter == 1) |
if ($dumpafter == 1) | |
print_r ($map); |
print_r ($map); | |
| ||
# print_r ($map->node_template_tree); | ||
# print_r ($map->link_template_tree); | ||
| ||
# $map->cachefolder="editcache"; | ||
# $map->CacheUpdate(1); | ||
| ||
| ||
} |
} | |
else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); } |
else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); } | |
|
| |
// vim:ts=4:sw=4: |
||
|
| |
| ||
function my_assert_handler($file, $line, $code) | ||
{ | ||
echo "Assertion Failed: | ||
File $file | ||
Line $line | ||
Code $code"; | ||
debug_print_backtrace(); | ||
exit(); | ||
} | ||
| ||
// vim:ts=4:sw=4: | ||
?> |
?> | |
|
|