1 | 1 | simandl | <?php |
2 | | | function show_editor_startpage() |
3 | | | { |
4 | | | global $mapdir, $WEATHERMAP_VERSION; |
5 | | | |
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>'; |
15 | | | |
16 | | | print '<div id="withjs">'; |
17 | | | print '<div id="dlgStart" class="dlgProperties" ><div class="dlgTitlebar">Welcome</div><div class="dlgBody">'; |
18 | | | print 'Welcome to the PHP Weathermap '.$WEATHERMAP_VERSION.' editor.<p>'; |
19 | | | 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 '; |
20 | | | print 'Weathermap that you will be missing out on if you choose to use the editor only.'; |
21 | | | 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>'; |
22 | | | print 'Do you want to:<p>'; |
23 | | | print 'Create A New Map:<br>'; |
24 | | | print '<form method="GET">'; |
25 | | | print 'Named: <input type="text" name="mapname" size="20">'; |
26 | | | |
27 | | | print '<input name="action" type="hidden" value="newmap">'; |
28 | | | print '<input type="submit" value="Create">'; |
29 | | | print '</form>'; |
30 | | | print 'OR<br />'; |
31 | | | print 'Open An Existing Map (looking in ' . $mapdir . '):<ul class="filelist">'; |
32 | | | |
33 | | | $titles = array(); |
34 | | | |
35 | | | if (is_dir($mapdir)) |
36 | | | { |
37 | | | $n=0; |
38 | | | $dh=opendir($mapdir); |
39 | | | |
40 | | | if ($dh) |
41 | | | { |
42 | | | while ($file=readdir($dh)) |
43 | | | { |
44 | | | $realfile=$mapdir . DIRECTORY_SEPARATOR . $file; |
45 | | | |
46 | | | // if(is_file($realfile) && ( preg_match('/\.conf$/',$file) )) |
47 | | | if (is_file($realfile) ) |
48 | | | { |
49 | | | $title='(no title)'; |
50 | | | $fd=fopen($realfile, "r"); |
51 | | | |
52 | | | while (!feof($fd)) |
53 | | | { |
54 | | | $buffer=fgets($fd, 4096); |
55 | | | |
56 | | | if (preg_match("/^\s*TITLE\s+(.*)/i", $buffer, $matches)) { $title=$matches[1]; } |
57 | | | } |
58 | | | |
59 | | | fclose ($fd); |
60 | | | $titles[$file] = $title; |
61 | | | # print "<li><a href=\"?mapname=$file\">$file</a> - <span class=\"comment\">$title</span></li>\n"; |
62 | | | $n++; |
63 | | | } |
64 | | | } |
65 | | | |
66 | | | closedir ($dh); |
67 | | | } |
68 | | | else { print "<LI>Can't Open mapdir to read</LI>"; } |
69 | | | |
70 | | | ksort($titles); |
71 | | | |
72 | | | foreach ($titles as $file=>$title) |
73 | | | { |
74 | | | $title = $titles[$file]; |
75 | | | print "<li><a href=\"?mapname=$file\">$file</a> - <span class=\"comment\">$title</span></li>\n"; |
76 | | | } |
77 | | | |
78 | | | if ($n == 0) { print "<LI>No files</LI>"; } |
79 | | | } |
80 | | | else { print "<LI>NO DIRECTORY named $mapdir</LI>"; } |
81 | | | |
82 | | | print "</UL>"; |
83 | | | |
84 | | | print "</div>"; // dlgbody |
85 | | | print '<div class="dlgHelp" id="start_help">PHP Weathermap ' . $WEATHERMAP_VERSION |
86 | | | . ' Copyright © 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>'; |
87 | | | |
88 | | | print "</div>"; // dlgStart |
89 | | | print "</div>"; // withjs |
90 | | | print "</body></html>"; |
91 | | | } |
92 | | | |
93 | | | function snap($coord, $gridsnap = 0) |
94 | | | { |
95 | | | if ($gridsnap == 0) { return ($coord); } |
96 | | | else { return ($coord - ($coord % $gridsnap)); } |
97 | | | } |
98 | | | |
99 | | | // Following function is based on code taken from here: |
100 | | | // http://uk2.php.net/manual/en/security.globals.php |
101 | | | // |
102 | | | // It extracts a set of named variables into the global namespace, |
103 | | | // validating them as they go. Returns True or False depending on if |
104 | | | // validation fails. If it does fail, then nothing is added to the |
105 | | | // global namespace. |
106 | | | // |
107 | | | function extract_with_validation($array, $paramarray, $prefix = "", $debug = FALSE) |
108 | | | { |
109 | | | $all_present=TRUE; |
110 | | | $candidates=array( |
111 | | | ); |
112 | | | |
113 | | | if ($debug) |
114 | | | print '<pre>'; |
115 | | | |
116 | | | if ($debug) |
117 | | | print_r ($paramarray); |
118 | | | |
119 | | | if ($debug) |
120 | | | print_r ($array); |
121 | | | |
122 | | | foreach ($paramarray as $var) |
123 | | | { |
124 | | | $varname=$var[0]; |
125 | | | $vartype=$var[1]; |
126 | | | $varreqd=$var[2]; |
127 | | | |
128 | | | if ($varreqd == 'req' && !array_key_exists($varname, $array)) { $all_present=FALSE; } |
129 | | | |
130 | | | if (array_key_exists($varname, $array)) |
131 | | | { |
132 | | | $varvalue=$array[$varname]; |
133 | | | |
134 | | | if ($debug) |
135 | | | print "Checking $varname..."; |
136 | | | |
137 | | | $waspresent=$all_present; |
138 | | | |
139 | | | switch ($vartype) |
140 | | | { |
141 | | | case 'int': |
142 | | | if (!preg_match('/^\-*\d+$/', $varvalue)) { $all_present=FALSE; } |
143 | | | |
144 | | | break; |
145 | | | |
146 | | | case 'float': |
147 | | | if (!preg_match('/^\d+\.\d+$/', $varvalue)) { $all_present=FALSE; } |
148 | | | |
149 | | | break; |
150 | | | |
151 | | | case 'yesno': |
152 | | | if (!preg_match('/^(y|n|yes|no)$/i', $varvalue)) { $all_present=FALSE; } |
153 | | | |
154 | | | break; |
155 | | | |
156 | | | case 'sqldate': |
157 | | | if (!preg_match('/^\d\d\d\d\-\d\d\-\d\d$/i', $varvalue)) { $all_present=FALSE; } |
158 | | | |
159 | | | break; |
160 | | | |
161 | | | case 'any': |
162 | | | // we don't care at all |
163 | | | break; |
164 | | | |
165 | | | case 'ip': |
166 | | | if (!preg_match( |
167 | | | '/^((\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})$/', |
168 | | | $varvalue)) { $all_present=FALSE; } |
169 | | | |
170 | | | break; |
171 | | | |
172 | | | case 'alpha': |
173 | | | if (!preg_match('/^[A-Za-z]+$/', $varvalue)) { $all_present=FALSE; } |
174 | | | |
175 | | | break; |
176 | | | |
177 | | | case 'alphanum': |
178 | | | if (!preg_match('/^[A-Za-z0-9]+$/', $varvalue)) { $all_present=FALSE; } |
179 | | | |
180 | | | break; |
181 | | | |
182 | | | case 'bandwidth': |
183 | | | if (!preg_match('/^\d+\.?\d*[KMGT]*$/i', $varvalue)) { $all_present=FALSE; } |
184 | | | |
185 | | | break; |
186 | | | |
187 | | | default: |
188 | | | // an unknown type counts as an error, really |
189 | | | $all_present=FALSE; |
190 | | | |
191 | | | break; |
192 | | | } |
193 | | | |
194 | | | if ($debug && $waspresent != $all_present) { print "Failed on $varname."; } |
195 | | | |
196 | | | if ($all_present) |
197 | | | { |
198 | | | $candidates["{$prefix}{$varname}"]=$varvalue; |
199 | | | $candidates["{$prefix}{$varname}_slashes"]=addslashes($varvalue); |
200 | | | $candidates["{$prefix}{$varname}_url"]=urlencode($varvalue); |
201 | | | $candidates["{$prefix}{$varname}_html"]=htmlspecialchars($varvalue); |
202 | | | $candidates["{$prefix}{$varname}_url_html"]=htmlspecialchars(urlencode($varvalue)); |
203 | | | } |
204 | | | } |
205 | | | else |
206 | | | { |
207 | | | if ($debug) |
208 | | | print "Skipping $varname\n"; |
209 | | | } |
210 | | | } |
211 | | | |
212 | | | if ($debug) |
213 | | | print_r ($candidates); |
214 | | | |
215 | | | if ($all_present) |
216 | | | { |
217 | | | foreach ($candidates as $key => $value) { $GLOBALS[$key]=$value; } |
218 | | | } |
219 | | | |
220 | | | if ($debug) |
221 | | | print '</pre>'; |
222 | | | |
223 | | | return ($all_present); |
224 | | | } |
225 | | | |
226 | | | function get_imagelist($imagedir) |
227 | | | { |
228 | | | $imagelist = array(); |
229 | | | |
230 | | | if (is_dir($imagedir)) |
231 | | | { |
232 | | | $n=0; |
233 | | | $dh=opendir($imagedir); |
234 | | | |
235 | | | if ($dh) |
236 | | | { |
237 | | | while ($file=readdir($dh)) |
238 | | | { |
239 | | | $realfile=$imagedir . DIRECTORY_SEPARATOR . $file; |
240 | | | $uri = $imagedir . "/" . $file; |
241 | | | |
242 | | | if(is_file($realfile) && ( preg_match('/\.(gif|jpg|png)$/i',$file) )) |
243 | | | { |
244 | | | $imagelist[] = $uri; |
245 | | | $n++; |
246 | | | } |
247 | | | } |
248 | | | |
249 | | | closedir ($dh); |
250 | | | } |
251 | | | } |
252 | | | return ($imagelist); |
253 | | | } |
254 | | | // vim:ts=4:sw=4: |
255 | | | ?> |