jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [editor.inc.php] - Blame information for rev 52

 

Line No. Rev Author Line
11simandl<?php
2function show_editor_startpage()
3{
413simandl global $mapdir, $WEATHERMAP_VERSION, $config_loaded, $cacti_found, $ignore_cacti;
51simandl 
6 $matches=0;
7 
8 print '<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" media="screen" href="editor.css" /> <script src="editor.js" type="text/javascript"></script><title>PHP Weathermap Editor ' . $WEATHERMAP_VERSION
9 . '</title></head><body>';
10 
11 print '<div id="nojs" class="alert"><b>WARNING</b> - ';
12 print 'Sorry, it\'s partly laziness on my part, but you really need JavaScript enabled and DOM support in your browser to use this editor. It\'s a visual tool, so accessibility is already an issue, if it is, and from a security viewpoint, you\'re already running my ';
13 print 'code on your <i>server</i> so either you trust it all having read it, or you\'re already screwed.<P>';
14 print 'If it\'s a major issue for you, please feel free to complain. It\'s mainly laziness as I said, and there could be a fallback (not so smooth) mode for non-javascript browsers if it was seen to be worthwhile (I would take a bit of convincing, because I don\'t see a benefit, personally).</div>';
1513simandl 
16 $errormessage = "";
17 
18 if(! $cacti_found && !$ignore_cacti)
19 {
20 $errormessage .= '$cacti_base is not set correctly. Cacti integration will be disabled in the editor.';
21 if($config_loaded != 1) { $errormessage .= " You might need to copy editor-config.php-dist to editor-config.php and edit it."; }
22 }
23 
24 if($errormessage != '')
25 {
26 print '<div class="alert" id="nocacti">'.$errormessage.'</div>';
27 }
281simandl 
29 print '<div id="withjs">';
30 print '<div id="dlgStart" class="dlgProperties" ><div class="dlgTitlebar">Welcome</div><div class="dlgBody">';
31 print 'Welcome to the PHP Weathermap '.$WEATHERMAP_VERSION.' editor.<p>';
32 print '<div style="border: 3px dashed red; background: #055; padding: 5px; font-size: 97%;"><b>NOTE:</b> This editor is not finished! There are many features of ';
33 print 'Weathermap that you will be missing out on if you choose to use the editor only.';
34 print 'These include: curves, node offsets, font definitions, colour changing, per-node/per-link settings and image uploading. You CAN use the editor without damaging these features if you added them by hand, however.</div><p>';
3513simandl 
36 
371simandl print 'Do you want to:<p>';
38 print 'Create A New Map:<br>';
39 print '<form method="GET">';
40 print 'Named: <input type="text" name="mapname" size="20">';
41 
42 print '<input name="action" type="hidden" value="newmap">';
43 print '<input type="submit" value="Create">';
44 print '</form>';
45 print 'OR<br />';
46 print 'Open An Existing Map (looking in ' . $mapdir . '):<ul class="filelist">';
47 
48 $titles = array();
49 
50 if (is_dir($mapdir))
51 {
52 $n=0;
53 $dh=opendir($mapdir);
54 
55 if ($dh)
56 {
57 while ($file=readdir($dh))
58 {
59 $realfile=$mapdir . DIRECTORY_SEPARATOR . $file;
60 
61// if(is_file($realfile) && ( preg_match('/\.conf$/',$file) ))
6213simandl if ( (is_file($realfile)) && (is_readable($realfile)) )
631simandl {
64 $title='(no title)';
65 $fd=fopen($realfile, "r");
6613simandl if($fd)
671simandl {
6813simandl while (!feof($fd))
69 {
70 $buffer=fgets($fd, 4096);
71 
72 if (preg_match("/^\s*TITLE\s+(.*)/i", $buffer, $matches)) { $title=$matches[1]; }
73 }
74 
75 fclose ($fd);
76 $titles[$file] = $title;
77 # print "<li><a href=\"?mapname=$file\">$file</a> - <span class=\"comment\">$title</span></li>\n";
78 $n++;
791simandl }
80 }
81 }
82 
83 closedir ($dh);
84 }
85 else { print "<LI>Can't Open mapdir to read</LI>"; }
86 
87 ksort($titles);
88 
89 foreach ($titles as $file=>$title)
90 {
91 $title = $titles[$file];
92 print "<li><a href=\"?mapname=$file\">$file</a> - <span class=\"comment\">$title</span></li>\n";
93 }
94 
95 if ($n == 0) { print "<LI>No files</LI>"; }
96 }
97 else { print "<LI>NO DIRECTORY named $mapdir</LI>"; }
98 
99 print "</UL>";
100 
101 print "</div>"; // dlgbody
102 print '<div class="dlgHelp" id="start_help">PHP Weathermap ' . $WEATHERMAP_VERSION
103 . ' Copyright &copy; 2005-2007 Howard Jones - howie@thingy.com<br />The current version should always be <a href="http://www.network-weathermap.com/">available here</a>, along with other related software. PHP Weathermap is licensed under the GNU Public License, version 2. See COPYING for details. This distribution also includes the Overlib library by Erik Bosrup.</div>';
104 
105 print "</div>"; // dlgStart
106 print "</div>"; // withjs
107 print "</body></html>";
108}
109 
110function snap($coord, $gridsnap = 0)
111{
112 if ($gridsnap == 0) { return ($coord); }
113 else { return ($coord - ($coord % $gridsnap)); }
114}
115 
116// Following function is based on code taken from here:
117// http://uk2.php.net/manual/en/security.globals.php
118//
119// It extracts a set of named variables into the global namespace,
120// validating them as they go. Returns True or False depending on if
121// validation fails. If it does fail, then nothing is added to the
122// global namespace.
123//
124function extract_with_validation($array, $paramarray, $prefix = "", $debug = FALSE)
125{
126 $all_present=TRUE;
127 $candidates=array(
128 );
129 
130 if ($debug)
131 print '<pre>';
132 
133 if ($debug)
134 print_r ($paramarray);
135 
136 if ($debug)
137 print_r ($array);
138 
139 foreach ($paramarray as $var)
140 {
141 $varname=$var[0];
142 $vartype=$var[1];
143 $varreqd=$var[2];
144 
145 if ($varreqd == 'req' && !array_key_exists($varname, $array)) { $all_present=FALSE; }
146 
147 if (array_key_exists($varname, $array))
148 {
149 $varvalue=$array[$varname];
150 
151 if ($debug)
152 print "Checking $varname...";
153 
154 $waspresent=$all_present;
155 
156 switch ($vartype)
157 {
158 case 'int':
159 if (!preg_match('/^\-*\d+$/', $varvalue)) { $all_present=FALSE; }
160 
161 break;
162 
163 case 'float':
164 if (!preg_match('/^\d+\.\d+$/', $varvalue)) { $all_present=FALSE; }
165 
166 break;
167 
168 case 'yesno':
169 if (!preg_match('/^(y|n|yes|no)$/i', $varvalue)) { $all_present=FALSE; }
170 
171 break;
172 
173 case 'sqldate':
174 if (!preg_match('/^\d\d\d\d\-\d\d\-\d\d$/i', $varvalue)) { $all_present=FALSE; }
175 
176 break;
177 
178 case 'any':
179 // we don't care at all
180 break;
181 
182 case 'ip':
183 if (!preg_match(
184 '/^((\d|[1-9]\d|2[0-4]\d|25[0-5]|1\d\d)(?:\.(\d|[1-9]\d|2[0-4]\d|25[0-5]|1\d\d)){3})$/',
185 $varvalue)) { $all_present=FALSE; }
186 
187 break;
188 
189 case 'alpha':
190 if (!preg_match('/^[A-Za-z]+$/', $varvalue)) { $all_present=FALSE; }
191 
192 break;
193 
194 case 'alphanum':
195 if (!preg_match('/^[A-Za-z0-9]+$/', $varvalue)) { $all_present=FALSE; }
196 
197 break;
198 
199 case 'bandwidth':
200 if (!preg_match('/^\d+\.?\d*[KMGT]*$/i', $varvalue)) { $all_present=FALSE; }
201 
202 break;
203 
204 default:
205 // an unknown type counts as an error, really
206 $all_present=FALSE;
207 
208 break;
209 }
210 
211 if ($debug && $waspresent != $all_present) { print "Failed on $varname."; }
212 
213 if ($all_present)
214 {
215 $candidates["{$prefix}{$varname}"]=$varvalue;
216 $candidates["{$prefix}{$varname}_slashes"]=addslashes($varvalue);
217 $candidates["{$prefix}{$varname}_url"]=urlencode($varvalue);
218 $candidates["{$prefix}{$varname}_html"]=htmlspecialchars($varvalue);
219 $candidates["{$prefix}{$varname}_url_html"]=htmlspecialchars(urlencode($varvalue));
220 }
221 }
222 else
223 {
224 if ($debug)
225 print "Skipping $varname\n";
226 }
227 }
228 
229 if ($debug)
230 print_r ($candidates);
231 
232 if ($all_present)
233 {
234 foreach ($candidates as $key => $value) { $GLOBALS[$key]=$value; }
235 }
236 
237 if ($debug)
238 print '</pre>';
239 
240 return ($all_present);
241}
242 
243function get_imagelist($imagedir)
244{
245 $imagelist = array();
246 
247 if (is_dir($imagedir))
248 {
249 $n=0;
250 $dh=opendir($imagedir);
251 
252 if ($dh)
253 {
254 while ($file=readdir($dh))
255 {
256 $realfile=$imagedir . DIRECTORY_SEPARATOR . $file;
257 $uri = $imagedir . "/" . $file;
258 
259 if(is_file($realfile) && ( preg_match('/\.(gif|jpg|png)$/i',$file) ))
260 {
261 $imagelist[] = $uri;
262 $n++;
263 }
264 }
265 
266 closedir ($dh);
267 }
268 }
269 return ($imagelist);
270}
27113simandl 
272function handle_inheritance(&$map, &$inheritables)
273{
274 foreach ($inheritables as $inheritable)
275 {
276 $fieldname = $inheritable[1];
277 $formname = $inheritable[2];
278 
279 $new = $_REQUEST[$formname];
280 
281 $old = ($inheritable[0]=='node' ? $map->defaultnode->$fieldname : $map->defaultlink->$fieldname);
282 
283 if($old != $new)
284 {
285 if($inheritable[0]=='node')
286 {
287 $map->defaultnode->$fieldname = $new;
288 foreach ($map->nodes as $node)
289 {
290 if($node->$fieldname == $old)
291 {
292 $map->nodes[$node->name]->$fieldname = $new;
293 }
294 }
295 }
296 
297 if($inheritable[0]=='link')
298 {
299 $map->defaultlink->$fieldname = $new;
300 foreach ($map->links as $link)
301 {
302 if($link->$fieldname == $old)
303 {
304 $map->links[$link->name]->$fieldname = $new;
305 }
306 }
307 }
308 }
309 }
310}
311 
312function get_fontlist(&$map,$name,$current)
313{
314 $output = '<select class="fontcombo" name="'.$name.'">';
315 
316 # $sortedfonts = $map->fonts;
317 # ksort ($sortedfonts);
318 ksort($map->fonts);
319 
320 foreach ($map->fonts as $fontnumber => $font)
321 {
322 $output .= '<option ';
323 if($current == $fontnumber) $output .= 'SELECTED';
324 $output .= ' value="'.$fontnumber.'">'.$fontnumber.' ('.$font->type.')</option>';
325 }
326 
327 $output .= "</select>";
328 
329 return($output);
330}
331 
3321simandl// vim:ts=4:sw=4:
333?>

Powered by WebSVN 2.2.1