1 | 13 | simandl | #!/usr/local/bin/php |
2 | 1 | simandl | <?php |
3 | | | |
4 | 13 | simandl | // PHP Weathermap 0.92 |
5 | 1 | simandl | // Copyright Howard Jones, 2005-2007 howie@thingy.com |
6 | | | // http://www.network-weathermap.com/ |
7 | | | // Released under the GNU Public License |
8 | | | require_once 'Console/Getopt.php'; |
9 | | | |
10 | | | require_once "Weathermap.class.php"; |
11 | | | |
12 | | | if (!module_checks()) { die ("Quitting: Module checks failed.\n"); } |
13 | | | |
14 | | | // $weathermap_debugging=TRUE; // XXX - This needs to come out again! |
15 | | | $map=new Weathermap; |
16 | | | $map->context="cli"; |
17 | | | |
18 | | | $output="html"; |
19 | | | $configfile="weathermap.conf"; |
20 | | | $htmlfile=''; |
21 | | | $imagefile=''; |
22 | | | $DEBUG=0; |
23 | | | $dumpafter=0; |
24 | | | $randomdata=0; |
25 | | | $dumpconfig=''; |
26 | | | $defines=array(); |
27 | | | |
28 | | | // ************************************************************************************** |
29 | | | // THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE! |
30 | 13 | simandl | $map->rrdtool="/usr/local/rrdtool-1.2.15/bin/rrdtool"; |
31 | 1 | simandl | // (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example) |
32 | | | // ************************************************************************************** |
33 | | | |
34 | | | // initialize object |
35 | | | $cg=new Console_Getopt(); |
36 | | | $short_opts=''; |
37 | | | $long_opts=array |
38 | | | ( |
39 | | | "version", |
40 | | | "help", |
41 | | | "image-uri=", |
42 | | | "config=", |
43 | | | "output=", |
44 | | | "debug", |
45 | | | "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 | | | |
59 | | | if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); } |
60 | | | |
61 | | | $gopts=$ret[0]; |
62 | | | |
63 | | | if (sizeof($gopts) > 0) |
64 | | | { |
65 | | | foreach ($gopts as $o) |
66 | | | { |
67 | | | switch ($o[0]) |
68 | | | { |
69 | | | case '--config': |
70 | | | $configfile=$o[1]; |
71 | | | break; |
72 | | | |
73 | | | case '--htmloutput': |
74 | | | $htmlfile=$o[1]; |
75 | | | break; |
76 | | | |
77 | | | case '--dumpafter': |
78 | | | $dumpafter=1; |
79 | | | break; |
80 | | | |
81 | | | case '--image-uri': |
82 | | | $map->imageuri=$o[1]; |
83 | | | break; |
84 | | | |
85 | | | case '--dumpconfig': |
86 | | | $map->dumpconfig=$o[1]; |
87 | | | break; |
88 | | | |
89 | | | case '--randomdata': |
90 | | | $randomdata=1; |
91 | | | break; |
92 | | | |
93 | | | case '--debug': |
94 | | | $DEBUG=1; |
95 | | | |
96 | | | $map->debugging=TRUE; |
97 | | | $weathermap_debugging=TRUE; |
98 | | | break; |
99 | | | |
100 | | | case '--sizedebug': |
101 | | | case '--no-data': |
102 | | | $map->sizedebug=TRUE; |
103 | | | break; |
104 | | | |
105 | | | case '--bulge': |
106 | | | $map->widthmod=TRUE; |
107 | | | break; |
108 | | | |
109 | | | case '--output': |
110 | | | $imagefile=$o[1]; |
111 | | | break; |
112 | | | |
113 | | | case '--define': |
114 | | | preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches); |
115 | | | $varname = $matches[1]; |
116 | | | $value = $matches[2]; |
117 | | | debug(">> $varname = '$value'\n"); |
118 | | | // save this for later, so that when the map object exists, it can be defined |
119 | | | $defines[$varname]=$value; |
120 | | | break; |
121 | | | |
122 | | | case '--version': |
123 | | | print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n"; |
124 | | | exit(); |
125 | | | break; |
126 | | | |
127 | | | case '--help': |
128 | | | print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n"; |
129 | | | print "Copyright Howard Jones, 2005-2007 howie@thingy.com\nReleased under the GNU Public License\nhttp://www.network-weathermap.com/\n\n"; |
130 | | | |
131 | | | print "Usage: php weathermap [options]\n\n"; |
132 | | | |
133 | | | print " --config {filename} - filename to read from. Default weathermap.conf\n"; |
134 | | | print " --output {filename} - filename to write image. Default weathermap.png\n"; |
135 | | | print " --htmloutput {filename} - filename to write HTML. Default weathermap.html\n\n"; |
136 | | | |
137 | | | print " --image-uri {uri} - URI to prefix <img> tags in HTML.\n"; |
138 | | | print " --bulge - Enable link-bulging mode. See manual.\n\n"; |
139 | | | |
140 | | | print " --no-data - skip the data-reading process (just a 'grey' map)\n"; |
141 | 13 | simandl | print " --randomdata - as above, but use random data\n"; |
142 | 1 | simandl | print " --debug - produce (LOTS) of debugging information during run\n"; |
143 | | | print " --dump-after - dump all internal PHP structures (HUGE)\n"; |
144 | | | print " --dumpconfig {filename} - filename to write a new config to (for testing)\n\n"; |
145 | | | |
146 | | | print " --help - show this help\n"; |
147 | | | print " --version - show version number\n\n"; |
148 | | | print "More info at http://www.network-weathermap.com/\n"; |
149 | | | exit(); |
150 | | | break; |
151 | | | } |
152 | | | } |
153 | | | } |
154 | | | |
155 | | | if ($DEBUG) |
156 | | | { |
157 | | | print "\n------------------------------------\n"; |
158 | | | print "Starting PHP-Weathermap run, with config: $configfile\n"; |
159 | | | } |
160 | | | |
161 | | | if ($map->ReadConfig($configfile)) |
162 | | | { |
163 | | | // allow command-lines to override the config file, but provide a default if neither are present |
164 | | | if ($imagefile == '') |
165 | | | { |
166 | | | if ($map->imageoutputfile == '') { $imagefile="weathermap.png"; } |
167 | | | else { $imagefile=$map->imageoutputfile; } |
168 | | | } |
169 | | | |
170 | | | if ($htmlfile == '') |
171 | | | { |
172 | | | if ($map->htmloutputfile != '') { $htmlfile=$map->htmloutputfile; } |
173 | | | } |
174 | | | |
175 | | | // feed in any command-line defaults, so that they appear as if SET lines in the config |
176 | | | |
177 | | | // FIXME |
178 | | | foreach ($defines as $hintname=>$hint) |
179 | | | { |
180 | | | $map->add_hint($hintname,$hint); |
181 | | | } |
182 | | | |
183 | | | if (!$map->sizedebug) |
184 | | | { |
185 | | | if ($randomdata == 1) { $map->RandomData(); } |
186 | | | else { $map->ReadData(); } |
187 | | | } |
188 | | | |
189 | | | if ($imagefile != '') |
190 | | | { |
191 | | | $map->DrawMap($imagefile); |
192 | | | $map->imagefile=$imagefile; |
193 | | | } |
194 | | | |
195 | | | if ($htmlfile != '') |
196 | | | { |
197 | | | $fd=fopen($htmlfile, 'w'); |
198 | | | fwrite($fd, |
199 | | | '<!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 |
200 | | | . '</title></head><body>'); |
201 | | | |
202 | | | if ($map->htmlstyle == "overlib") |
203 | | | { |
204 | | | fwrite($fd, |
205 | | | "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n"); |
206 | | | fwrite($fd, |
207 | | | "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n"); |
208 | | | } |
209 | | | |
210 | | | fwrite($fd, $map->MakeHTML()); |
211 | | | fwrite($fd, |
212 | | | '<hr />Network Map created with <a href="http://www.network-weathermap.com/?vs=' |
213 | | | . $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION |
214 | | | . '</a></body></html>'); |
215 | | | fclose ($fd); |
216 | | | } |
217 | | | |
218 | | | if ($map->dumpconfig != '') |
219 | | | $map->WriteConfig($map->dumpconfig); |
220 | | | |
221 | | | if ($dumpafter == 1) |
222 | | | print_r ($map); |
223 | | | } |
224 | | | else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); } |
225 | | | |
226 | | | // vim:ts=4:sw=4: |
227 | | | |
228 | | | ?> |