r4356 process8021QRecalcRequest(): employ assertPermission()
[racktables-incomplete-works] / wwwroot / inc / interface-lib.php
CommitLineData
ca8aa8e9
DO
1<?php
2
3// Let's have it here, so extensions can add their own images.
4$image = array();
5$image['logo']['path'] = 'pix/defaultlogo.png';
6$image['logo']['width'] = 210;
7$image['logo']['height'] = 40;
8$image['rackspace']['path'] = 'pix/racks.png';
9$image['rackspace']['width'] = 218;
10$image['rackspace']['height'] = 200;
11$image['objects']['path'] = 'pix/server.png';
12$image['objects']['width'] = 218;
13$image['objects']['height'] = 200;
14$image['depot']['path'] = 'pix/server.png';
15$image['depot']['width'] = 218;
16$image['depot']['height'] = 200;
17$image['files']['path'] = 'pix/files.png';
18$image['files']['width'] = 218;
19$image['files']['height'] = 200;
20$image['ipv4space']['path'] = 'pix/addressspace.png';
21$image['ipv4space']['width'] = 218;
22$image['ipv4space']['height'] = 200;
23$image['ipv6space']['path'] = 'pix/addressspacev6.png';
24$image['ipv6space']['width'] = 218;
25$image['ipv6space']['height'] = 200;
26$image['ipv4slb']['path'] = 'pix/slb.png';
27$image['ipv4slb']['width'] = 218;
28$image['ipv4slb']['height'] = 200;
29$image['config']['path'] = 'pix/configuration.png';
30$image['config']['width'] = 218;
31$image['config']['height'] = 200;
32$image['reports']['path'] = 'pix/report.png';
33$image['reports']['width'] = 218;
34$image['reports']['height'] = 200;
35$image['8021q']['path'] = 'pix/8021q.png';
36$image['8021q']['width'] = 218;
37$image['8021q']['height'] = 200;
38$image['objectlog']['path'] = 'pix/crystal-mimetypes-shellscript-218x200.png';
39$image['objectlog']['width'] = 218;
40$image['objectlog']['height'] = 200;
41$image['virtual']['path'] = 'pix/virtualresources.png';
42$image['virtual']['width'] = 218;
43$image['virtual']['height'] = 200;
44$image['download']['path'] = 'pix/download.png';
45$image['download']['width'] = 16;
46$image['download']['height'] = 16;
47$image['DOWNLOAD']['path'] = 'pix/download-big.png';
48$image['DOWNLOAD']['width'] = 32;
49$image['DOWNLOAD']['height'] = 32;
50$image['plug']['path'] = 'pix/tango-network-wired.png';
51$image['plug']['width'] = 16;
52$image['plug']['height'] = 16;
53$image['cut']['path'] = 'pix/tango-edit-cut-16x16.png';
54$image['cut']['width'] = 16;
55$image['cut']['height'] = 16;
56$image['Cut']['path'] = 'pix/tango-edit-cut-22x22.png';
57$image['Cut']['width'] = 22;
58$image['Cut']['height'] = 22;
59$image['CUT']['path'] = 'pix/tango-edit-cut-32x32.png';
60$image['CUT']['width'] = 32;
61$image['CUT']['height'] = 32;
62$image['add']['path'] = 'pix/tango-list-add.png';
63$image['add']['width'] = 16;
64$image['add']['height'] = 16;
65$image['ADD']['path'] = 'pix/tango-list-add-big.png';
66$image['ADD']['width'] = 32;
67$image['ADD']['height'] = 32;
68$image['delete']['path'] = 'pix/tango-list-remove.png';
69$image['delete']['width'] = 16;
70$image['delete']['height'] = 16;
71$image['DELETE']['path'] = 'pix/tango-list-remove-32x32.png';
72$image['DELETE']['width'] = 32;
73$image['DELETE']['height'] = 32;
74$image['destroy']['path'] = 'pix/tango-user-trash-16x16.png';
75$image['destroy']['width'] = 16;
76$image['destroy']['height'] = 16;
77$image['nodestroy']['path'] = 'pix/tango-user-trash-16x16-gray.png';
78$image['nodestroy']['width'] = 16;
79$image['nodestroy']['height'] = 16;
80$image['NODESTROY']['path'] = 'pix/tango-user-trash-32x32-gray.png';
81$image['NODESTROY']['width'] = 32;
82$image['NODESTROY']['height'] = 32;
83$image['DESTROY']['path'] = 'pix/tango-user-trash-32x32.png';
84$image['DESTROY']['width'] = 32;
85$image['DESTROY']['height'] = 32;
86$image['nodelete']['path'] = 'pix/tango-list-remove-shadow.png';
87$image['nodelete']['width'] = 16;
88$image['nodelete']['height'] = 16;
89$image['inservice']['path'] = 'pix/tango-emblem-system.png';
90$image['inservice']['width'] = 16;
91$image['inservice']['height'] = 16;
92$image['notinservice']['path'] = 'pix/tango-dialog-error.png';
93$image['notinservice']['width'] = 16;
94$image['notinservice']['height'] = 16;
95$image['find']['path'] = 'pix/tango-system-search.png';
96$image['find']['width'] = 16;
97$image['find']['height'] = 16;
98$image['next']['path'] = 'pix/tango-go-next.png';
99$image['next']['width'] = 32;
100$image['next']['height'] = 32;
101$image['prev']['path'] = 'pix/tango-go-previous.png';
102$image['prev']['width'] = 32;
103$image['prev']['height'] = 32;
104$image['COMMIT']['path'] = 'pix/tango-go-prev-next-32x32.png';
105$image['COMMIT']['width'] = 32;
106$image['COMMIT']['height'] = 32;
107$image['COMMIT gray']['path'] = 'pix/tango-go-prev-next-gray-32x32.png';
108$image['COMMIT gray']['width'] = 32;
109$image['COMMIT gray']['height'] = 32;
110$image['RECALC']['path'] = 'pix/tango-view-refresh-32x32.png';
111$image['RECALC']['width'] = 32;
112$image['RECALC']['height'] = 32;
113$image['clear']['path'] = 'pix/tango-edit-clear.png';
114$image['clear']['width'] = 16;
115$image['clear']['height'] = 16;
116$image['CLEAR']['path'] = 'pix/tango-edit-clear-big.png';
117$image['CLEAR']['width'] = 32;
118$image['CLEAR']['height'] = 32;
119$image['CLEAR gray']['path'] = 'pix/tango-edit-clear-gray-32x32.png';
120$image['CLEAR gray']['width'] = 32;
121$image['CLEAR gray']['height'] = 32;
122$image['save']['path'] = 'pix/tango-document-save-16x16.png';
123$image['save']['width'] = 16;
124$image['save']['height'] = 16;
125$image['SAVE']['path'] = 'pix/tango-document-save-32x32.png';
126$image['SAVE']['width'] = 32;
127$image['SAVE']['height'] = 32;
128$image['NOSAVE']['path'] = 'pix/tango-document-save-32x32-gray.png';
129$image['NOSAVE']['width'] = 32;
130$image['NOSAVE']['height'] = 32;
131$image['create']['path'] = 'pix/tango-document-new.png';
132$image['create']['width'] = 16;
133$image['create']['height'] = 16;
134$image['CREATE']['path'] = 'pix/tango-document-new-big.png';
135$image['CREATE']['width'] = 32;
136$image['CREATE']['height'] = 32;
137$image['DENIED']['path'] = 'pix/tango-dialog-error-big.png';
138$image['DENIED']['width'] = 32;
139$image['DENIED']['height'] = 32;
140$image['node-collapsed']['path'] = 'pix/node-collapsed.png';
141$image['node-collapsed']['width'] = 16;
142$image['node-collapsed']['height'] = 16;
143$image['node-expanded']['path'] = 'pix/node-expanded.png';
144$image['node-expanded']['width'] = 16;
145$image['node-expanded']['height'] = 16;
146$image['node-expanded-static']['path'] = 'pix/node-expanded-static.png';
147$image['node-expanded-static']['width'] = 16;
148$image['node-expanded-static']['height'] = 16;
149$image['dragons']['path'] = 'pix/mitsudragon.png';
150$image['dragons']['width'] = 195;
151$image['dragons']['height'] = 33;
152$image['LB']['path'] = 'pix/loadbalancer.png';
153$image['LB']['width'] = 32;
154$image['LB']['height'] = 32;
155$image['RS pool']['path'] = 'pix/serverpool.png';
156$image['RS pool']['width'] = 48;
157$image['RS pool']['height'] = 16;
158$image['VS']['path'] = 'pix/servicesign.png';
159$image['VS']['width'] = 39;
160$image['VS']['height'] = 62;
161$image['router']['path'] = 'pix/router.png';
162$image['router']['width'] = 32;
163$image['router']['height'] = 32;
164$image['object']['path'] = 'pix/bracket-16x16.png';
165$image['object']['width'] = 16;
166$image['object']['height'] = 16;
167$image['OBJECT']['path'] = 'pix/bracket-32x32.png';
168$image['OBJECT']['width'] = 32;
169$image['OBJECT']['height'] = 32;
170$image['attach']['path'] = 'pix/tango-mail-attachment-16x16.png';
171$image['attach']['width'] = 16;
172$image['attach']['height'] = 16;
173$image['Attach']['path'] = 'pix/tango-mail-attachment-22x22.png';
174$image['Attach']['width'] = 22;
175$image['Attach']['height'] = 22;
176$image['ATTACH']['path'] = 'pix/tango-mail-attachment-32x32.png';
177$image['ATTACH']['width'] = 32;
178$image['ATTACH']['height'] = 32;
179$image['favorite']['path'] = 'pix/tango-emblem-favorite.png';
180$image['favorite']['width'] = 16;
181$image['favorite']['height'] = 16;
182$image['computer']['path'] = 'pix/tango-computer.png';
183$image['computer']['width'] = 16;
184$image['computer']['height'] = 16;
185$image['empty file']['path'] = 'pix/crystal-file-empty-32x32.png';
186$image['empty file']['width'] = 32;
187$image['empty file']['height'] = 32;
188$image['text file']['path'] = 'pix/crystal-file-text-32x32.png';
189$image['text file']['width'] = 32;
190$image['text file']['height'] = 32;
191$image['image file']['path'] = 'pix/crystal-file-image-32x32.png';
192$image['image file']['width'] = 32;
193$image['image file']['height'] = 32;
194$image['text']['path'] = 'pix/tango-text-x-generic-16x16.png';
195$image['text']['width'] = 16;
196$image['text']['height'] = 16;
197$image['NET']['path'] = 'pix/crystal-network_local-32x32.png';
198$image['NET']['width'] = 32;
199$image['NET']['height'] = 32;
200$image['net']['path'] = 'pix/crystal-network_local-16x16.png';
201$image['net']['width'] = 16;
202$image['net']['height'] = 16;
203$image['USER']['path'] = 'pix/crystal-edit-user-32x32.png';
204$image['USER']['width'] = 32;
205$image['USER']['height'] = 32;
206$image['setfilter']['path'] = 'pix/pgadmin3-viewfiltereddata.png';
207$image['setfilter']['width'] = 32;
208$image['setfilter']['height'] = 32;
209$image['setfilter gray']['path'] = 'pix/pgadmin3-viewfiltereddata-grayscale.png';
210$image['setfilter gray']['width'] = 32;
211$image['setfilter gray']['height'] = 32;
212$image['resetfilter']['path'] = 'pix/pgadmin3-viewdata.png';
213$image['resetfilter']['width'] = 32;
214$image['resetfilter']['height'] = 32;
215$image['resetfilter gray']['path'] = 'pix/pgadmin3-viewdata-grayscale.png';
216$image['resetfilter gray']['width'] = 32;
217$image['resetfilter gray']['height'] = 32;
218$image['knight']['path'] = 'pix/smiley_knight.png';
219$image['knight']['width'] = 72;
220$image['knight']['height'] = 33;
221$image['Zoom']['path'] = 'pix/tango-system-search-22x22.png';
222$image['Zoom']['width'] = 22;
223$image['Zoom']['height'] = 22;
224$image['Zooming']['path'] = 'pix/tango-view-fullscreen-22x22.png';
225$image['Zooming']['width'] = 22;
226$image['Zooming']['height'] = 22;
227$image['UNLOCK']['path'] = 'pix/crystal-actions-unlock-32x32.png';
228$image['UNLOCK']['width'] = 32;
229$image['UNLOCK']['height'] = 32;
230$image['CLOCK']['path'] = 'pix/tango-appointment-32x32.png';
231$image['CLOCK']['width'] = 32;
232$image['CLOCK']['height'] = 32;
233$image['DQUEUE done']['path'] = 'pix/crystal-ok-32x32.png';
234$image['DQUEUE done']['width'] = 32;
235$image['DQUEUE done']['height'] = 32;
236$image['DQUEUE sync_aging']['path'] = 'pix/tango-appointment-32x32.png';
237$image['DQUEUE sync_aging']['width'] = 32;
238$image['DQUEUE sync_aging']['height'] = 32;
239$image['DQUEUE resync_aging']['path'] = 'pix/tango-appointment-32x32.png';
240$image['DQUEUE resync_aging']['width'] = 32;
241$image['DQUEUE resync_aging']['height'] = 32;
242$image['DQUEUE sync_ready']['path'] = 'pix/tango-emblem-system-32x32.png';
243$image['DQUEUE sync_ready']['width'] = 32;
244$image['DQUEUE sync_ready']['height'] = 32;
245$image['DQUEUE resync_ready']['path'] = 'pix/tango-emblem-important-32x32.png';
246$image['DQUEUE resync_ready']['width'] = 32;
247$image['DQUEUE resync_ready']['height'] = 32;
248$image['DQUEUE failed']['path'] = 'pix/tango-emblem-unreadable-32x32.png';
249$image['DQUEUE failed']['width'] = 32;
250$image['DQUEUE failed']['height'] = 32;
251$image['DQUEUE disabled']['path'] = 'pix/tango-emblem-readonly-32x32.png';
252$image['DQUEUE disabled']['width'] = 32;
253$image['DQUEUE disabled']['height'] = 32;
254$image['COPY']['path'] = 'pix/tango-edit-copy-32x32.png';
255$image['COPY']['width'] = 32;
256$image['COPY']['height'] = 32;
257$image['html']['path'] = 'pix/tango-text-html.png';
258$image['html']['width'] = 16;
259$image['html']['height'] = 16;
260
261function printSelect ($optionList, $select_attrs = array(), $selected_id = NULL)
262{
263 echo getSelect ($optionList, $select_attrs, $selected_id);
264}
265
266// Input array keys are OPTION VALUEs and input array values are OPTION text.
c4ad9ac0 267function getSelect ($optionList, $select_attrs = array(), $selected_id = NULL, $treat_single_special = TRUE)
ca8aa8e9
DO
268{
269 $ret = '';
270 if (!array_key_exists ('name', $select_attrs))
271 return '';
272 // handle two corner cases in a specific way
273 if (count ($optionList) == 0)
274 return '(none)';
c4ad9ac0 275 if (count ($optionList) == 1 && $treat_single_special)
ca8aa8e9
DO
276 {
277 foreach ($optionList as $key => $value) { break; }
278 return "<input type=hidden name=${select_attrs['name']} id=${select_attrs['name']} value=${key}>" . $value;
279 }
280 if (!array_key_exists ('id', $select_attrs))
281 $select_attrs['id'] = $select_attrs['name'];
282 $ret .= '<select';
283 foreach ($select_attrs as $attr_name => $attr_value)
284 $ret .= " ${attr_name}=${attr_value}";
285 $ret .= '>';
286 foreach ($optionList as $dict_key => $dict_value)
287 $ret .= "<option value='${dict_key}'" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>";
288 $ret .= '</select>';
289 return $ret;
290}
291
292function printNiftySelect ($groupList, $select_attrs = array(), $selected_id = NULL, $autocomplete = false)
293{
294 echo getNiftySelect ($groupList, $select_attrs, $selected_id);
295}
296
297// Input is a cooked list of OPTGROUPs, each with own sub-list of OPTIONs in the same
298// format as printSelect() expects.
299function getNiftySelect ($groupList, $select_attrs, $selected_id = NULL)
300{
301 // special treatment for ungrouped data
302 if (count ($groupList) == 1 and isset ($groupList['other']))
303 return getSelect ($groupList['other'], $select_attrs, $selected_id);
304 if (!array_key_exists ('name', $select_attrs))
305 return '';
306 if (!array_key_exists ('id', $select_attrs))
307 $select_attrs['id'] = $select_attrs['name'];
308 $ret = '<select';
309 foreach ($select_attrs as $attr_name => $attr_value)
310 $ret .= " ${attr_name}=${attr_value}";
311 $ret .= '>';
312 foreach ($groupList as $groupname => $groupdata)
313 {
314 $ret .= "<optgroup label='${groupname}'>";
315 foreach ($groupdata as $dict_key => $dict_value)
316 $ret .= "<option value='${dict_key}'" . ($dict_key == $selected_id ? ' selected' : '') . ">${dict_value}</option>";
317 $ret .= '</optgroup>';
318 }
319 $ret .= '</select>';
320 return $ret;
321}
322
323function printImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0)
324{
325 echo getImageHREF ($tag, $title, $do_input, $tabindex);
326}
327
328// this would be better called mkIMG(), make "IMG" HTML element
329function getImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0)
330{
331 global $image;
332 if (!isset ($image[$tag]))
333 $tag = 'error';
334 $img = $image[$tag];
19f22ad8 335 $img['path'] = '?module=chrome&uri=' . $img['path'];
ca8aa8e9
DO
336 if ($do_input == TRUE)
337 return
338 "<input type=image name=submit class=icon " .
339 "src='${img['path']}' " .
340 "border=0 " .
341 ($tabindex ? "tabindex=${tabindex}" : '') .
342 (!strlen ($title) ? '' : " title='${title}'") . // JT: Add title to input hrefs too
343 ">";
344 else
345 return
346 "<img " .
347 "src='${img['path']}' " .
348 "width=${img['width']} " .
349 "height=${img['height']} " .
350 "border=0 " .
351 (!strlen ($title) ? '' : "title='${title}'") .
352 ">";
353}
354
355function renderAccessDenied ($and_exit = TRUE)
356{
357 header ('Content-Type: text/html; charset=UTF-8');
358 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
359 echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
360 echo "<head><title>RackTables: access denied</title>\n";
361 printPageHeaders();
362 echo "</head><body>";
363 global $pageno, $tabno,
364 $user_given_tags,
365 $target_given_tags,
366 $auto_tags,
367 $expl_tags,
368 $impl_tags;
369 echo "<table border=1 cellspacing=0 cellpadding=3 width='50%' align=center>\n";
370 echo '<tr><th colspan=2><h3>';
371 printImageHREF ('DENIED');
372 echo ' access denied ';
373 printImageHREF ('DENIED');
374 echo '</h3></th></tr>';
375 echo "<tr><th width='50%' class=tagchain>User given tags:</th><td class=tagchain>";
376 echo serializeTags ($user_given_tags) . "&nbsp;</td></tr>\n";
377 echo "<tr><th width='50%' class=tagchain>Target given tags:</th><td class=tagchain>";
378 echo serializeTags ($target_given_tags) . "&nbsp;</td></tr>\n";
379 echo "<tr><th width='50%' class=tagchain>Effective explicit tags:</th><td class=tagchain>";
380 echo serializeTags ($expl_tags) . "&nbsp;</td></tr>\n";
381 echo "<tr><th width='50%' class=tagchain>Effective implicit tags:</th><td class=tagchain>";
382 echo serializeTags ($impl_tags) . "&nbsp;</td></tr>\n";
383 echo "<tr><th width='50%' class=tagchain>Automatic tags:</th><td class=tagchain>";
384 echo serializeTags ($auto_tags) . "&nbsp;</td></tr>\n";
385 echo "<tr><th width='50%' class=tdright>Requested page:</th><td class=tdleft>${pageno}</td></tr>\n";
386 echo "<tr><th width='50%' class=tdright>Requested tab:</th><td class=tdleft>${tabno}</td></tr>\n";
387 echo "<tr><td colspan=2 align=center>Click <a href='index.php?logout'>here</a> to logout.</td></tr>\n";
388 echo "</table>\n";
389 echo "</body></html>";
390 if ($and_exit)
391 exit;
392}
393
967e3845
DO
394function dos2unix ($text)
395{
396 return str_replace ("\r\n", "\n", $text);
397}
398
399function escapeString ($value, $do_db_escape = FALSE)
400{
401 $ret = htmlspecialchars ($value, ENT_QUOTES, 'UTF-8');
402 if ($do_db_escape)
403 {
404 global $dbxlink;
405 $ret = substr ($dbxlink->quote ($ret), 1, -1);
406 }
407 return $ret;
408}
409
410function transformRequestData()
411{
412 global $sic;
413 // Magic quotes feature is deprecated, but just in case the local system
414 // still has it activated, reverse its effect.
415 if (function_exists ('get_magic_quotes_gpc') and get_magic_quotes_gpc())
416 foreach ($_REQUEST as $key => $value)
417 if (gettype ($value) == 'string')
418 $_REQUEST[$key] = stripslashes ($value);
419 // Escape any globals before we ever try to use them, but keep a copy of originals.
420 $sic = array();
421 foreach ($_REQUEST as $key => $value)
422 {
423 $sic[$key] = dos2unix ($value);
424 if (gettype ($value) == 'string')
425 $_REQUEST[$key] = escapeString (dos2unix ($value));
426 }
427
428 if (isset ($_SERVER['PHP_AUTH_USER']))
429 $_SERVER['PHP_AUTH_USER'] = escapeString ($_SERVER['PHP_AUTH_USER']);
430 if (isset ($_SERVER['REMOTE_USER']))
431 $_SERVER['REMOTE_USER'] = escapeString ($_SERVER['REMOTE_USER']);
432}
433
ca8aa8e9 434?>