r1943 + further work on ticket:23
[racktables] / inc / interface.php
CommitLineData
b325120a 1<?php
e673ee24
DO
2/*
3*
4* This file contains frontend functions for RackTables.
5*
6*/
7
9c0b0016
DO
8// Interface function's special.
9$nextorder['odd'] = 'even';
10$nextorder['even'] = 'odd';
11
e673ee24
DO
12// Main menu.
13function renderIndex ()
14{
15 global $root;
16?>
17<table border=0 cellpadding=0 cellspacing=0 width='100%'>
18 <tr>
19 <td>
20 <div style='text-align: center; margin: 10px; '>
21 <table width='100%' cellspacing=0 cellpadding=30 class=mainmenu border=0>
22 <tr>
23 <td>
b325120a
DO
24 <h1><a href='<?php echo $root; ?>?page=rackspace'>Rackspace<br>
25 <?php printImageHREF ('rackspace'); ?></a></h1>
e673ee24
DO
26 </td>
27 <td>
b325120a
DO
28 <h1><a href='<?php echo $root; ?>?page=objects'>Objects<br>
29 <?php printImageHREF ('objects'); ?></a></h1>
e673ee24
DO
30 </td>
31 <td>
b325120a
DO
32 <h1><a href='<?php echo $root; ?>?page=ipv4space'>IPv4 space<br>
33 <?php printImageHREF ('ipv4space'); ?></a></h1>
e673ee24
DO
34 </td>
35 </tr>
36 </table>
37 <table width='100%' cellspacing=0 cellpadding=30 class=mainmenu border=0>
38 <tr>
39 <td>
b325120a
DO
40 <h1><a href='<?php echo $root; ?>?page=config'>Configuration<br>
41 <?php printImageHREF ('config'); ?></a></h1>
e673ee24
DO
42 </td>
43 <td>
da95280e 44 <h1><a href='<?php echo $root; ?>?page=reports'>Reports<br>
b325120a 45 <?php printImageHREF ('reports'); ?></a></h1>
e673ee24 46 </td>
ae545907 47 <td>
f973f491
DO
48 <h1><a href='<?php echo $root; ?>?page=ipv4slb'>IPv4 SLB<br>
49 <?php printImageHREF ('ipv4slb'); ?></a></h1>
ae545907 50 </td>
e673ee24
DO
51 </tr>
52 </table>
53 </div>
54 </td>
55 </tr>
56</table>
b325120a 57<?php
e673ee24
DO
58}
59
60function renderRackspace ()
61{
932cf41f 62 $tagfilter = getTagFilter();
094a8e6e 63 $tagfilter_str = getTagFilterStr ($tagfilter);
489a7502
DO
64 echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
65 renderTagFilterPortlet ($tagfilter, 'rack');
66 echo '</td><td class=pcright>';
67 echo '<table border=0 cellpadding=10 cellpadding=1>';
e673ee24 68 // generate thumb gallery
489a7502 69 $rackrowList = getRackspace ($tagfilter);
9c0b0016
DO
70 global $root, $nextorder;
71 $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
e673ee24
DO
72 $order = 'odd';
73 foreach ($rackrowList as $rackrow)
74 {
84466afa 75 echo "<tr class=row_${order}><th class=tdleft>";
a0d54e7e
DO
76 echo "<a href='${root}?page=row&row_id=${rackrow['row_id']}${tagfilter_str}'>";
77 echo "${rackrow['row_name']}</a></th>";
78 $rackList = getRacksForRow ($rackrow['row_id'], $tagfilter);
e673ee24 79 echo "<td><table border=0 cellspacing=5><tr>";
64b95774 80 foreach ($rackList as $rack)
e673ee24
DO
81 {
82 echo "<td align=center><a href='${root}?page=rack&rack_id=${rack['id']}'>";
83 echo "<img border=0 width=${rackwidth} height=";
84 echo 3 + 3 + $rack['height'] * 2;
85 echo " title='${rack['height']} units'";
d2ec5490 86 echo "src='render_image.php?img=minirack&rack_id=${rack['id']}'>";
e673ee24
DO
87 echo "<br>${rack['name']}</a></td>";
88 }
89 echo "</tr></table></tr>\n";
90 $order = $nextorder[$order];
91 }
92 echo "</table>\n";
489a7502 93 echo "</td></tr></table>\n";
e673ee24
DO
94}
95
96function renderRow ($row_id)
97{
98 if ($row_id == 0)
99 {
39a6338a 100 showError ('Invalid row_id', __FUNCTION__);
e673ee24
DO
101 return;
102 }
103 if (($rowInfo = getRackRowInfo ($row_id)) == NULL)
104 {
39a6338a 105 showError ('getRackRowInfo() failed', __FUNCTION__);
e673ee24
DO
106 return;
107 }
a0d54e7e
DO
108 $tagfilter = getTagFilter();
109 $rackList = getRacksForRow ($row_id, $tagfilter);
e673ee24
DO
110 // Main layout starts.
111 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
112
113 // Left portlet with row information.
114 echo "<tr><td class=pcleft>";
51a2330f 115 startPortlet ($rowInfo['dict_value']);
e673ee24 116 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
e673ee24
DO
117 echo "<tr><th width='50%' class=tdright>Racks:</th><td class=tdleft>${rowInfo['count']}</td></tr>\n";
118 echo "<tr><th width='50%' class=tdright>Units:</th><td class=tdleft>${rowInfo['sum']}</td></tr>\n";
114e50af
DO
119 echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
120 renderProgressBar (getRSUforRackRow ($rackList));
121 echo "</td></tr>\n";
e673ee24
DO
122 echo "</table><br>\n";
123 finishPortlet();
124
a0d54e7e 125 echo "</td><td class=pcright rowspan=2>";
e673ee24 126
9c0b0016
DO
127 global $root, $nextorder;
128 $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
e673ee24
DO
129 $order = 'odd';
130 startPortlet ('Racks');
131 echo "<table border=0 cellspacing=5 align='center'><tr>";
64b95774 132 foreach ($rackList as $rack)
e673ee24
DO
133 {
134 echo "<td align=center class=row_${order}><a href='${root}?page=rack&rack_id=${rack['id']}'>";
9c0b0016
DO
135 echo "<img border=0 width=" . $rackwidth * getConfigVar ('ROW_SCALE') . " height=";
136 echo (3 + 3 + $rack['height'] * 2) * getConfigVar ('ROW_SCALE');
e673ee24 137 echo " title='${rack['height']} units'";
d2ec5490 138 echo "src='render_image.php?img=minirack&rack_id=${rack['id']}'>";
e673ee24
DO
139 echo "<br>${rack['name']}</a></td>";
140 $order = $nextorder[$order];
141 }
142 echo "</tr></table>\n";
143 finishPortlet();
a0d54e7e 144 echo "</td></tr>";
e673ee24 145
a0d54e7e
DO
146 echo "<tr><td class=pcleft>";
147 renderTagFilterPortlet ($tagfilter, 'rack', 'row_id', $row_id);
e673ee24
DO
148 echo "</td></tr></table>";
149}
150
39a6338a 151function showError ($info = '', $funcname = 'N/A')
e673ee24
DO
152{
153 global $root;
b1cae282 154 echo "<div class=msg_error>An error has occured in function [${funcname}]. ";
e673ee24
DO
155 if (empty ($info))
156 echo 'No additional information is available.';
157 else
158 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
159 echo "Go back or try starting from <a href='${root}'>index page</a>.<br></div>\n";
160}
161
162// This function renders rack as HTML table.
163function renderRack ($rack_id = 0, $hl_obj_id = 0)
164{
165 if ($rack_id == 0)
166 {
39a6338a 167 showError ('Invalid rack_id', __FUNCTION__);
e673ee24
DO
168 return;
169 }
170 if (($rackData = getRackData ($rack_id)) == NULL)
171 {
39a6338a 172 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
173 return;
174 }
175 global $root, $pageno, $tabno;
176 markAllSpans ($rackData);
177 if ($hl_obj_id > 0)
178 highlightObject ($rackData, $hl_obj_id);
179 markupObjectProblems ($rackData);
180 $prev_id = getPrevIDforRack ($rackData['row_id'], $rack_id);
181 $next_id = getNextIDforRack ($rackData['row_id'], $rack_id);
d48d8820
DO
182 echo "<center><table border=0><tr valign=middle>";
183 echo "<td><h2><a href='${root}?page=row&row_id=${rackData['row_id']}'>${rackData['row_name']}</a> :</h2></td>";
e673ee24
DO
184 // FIXME: use 'bypass'?
185 if ($prev_id != NULL)
9803c56c 186 {
d48d8820 187 echo "<td><a href='${root}?page=rack&rack_id=${prev_id}'>";
9803c56c 188 printImageHREF ('prev', 'previous rack');
d48d8820 189 echo "</a></td>";
9803c56c 190 }
d48d8820 191 echo "<td><h2><a href='${root}?page=rack&rack_id=${rackData['id']}'>${rackData['name']}</a></h2></td>";
e673ee24 192 if ($next_id != NULL)
9803c56c 193 {
d48d8820 194 echo "<td><a href='${root}?page=rack&rack_id=${next_id}'>";
f444c095 195 printImageHREF ('next', 'next rack');
d48d8820 196 echo "</a></td>";
9803c56c 197 }
d48d8820 198 echo "</h2></td></tr></table>\n";
1c81a02c
DO
199 if ($rackData['left_is_front'] == 'yes')
200 $markup = array ('left' => 'Front', 'right' => 'Back');
201 else
202 $markup = array ('left' => 'Back', 'right' => 'Front');
e673ee24 203 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
9ddfe309
DO
204 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>${markup['left']}</th>";
205 echo "<th width='50%'>Interior</th><th width='20%'>${markup['right']}</th></tr>\n";
e673ee24
DO
206 for ($i = $rackData['height']; $i > 0; $i--)
207 {
9ddfe309 208 echo '<tr><th>' . ($rackData['bottom_is_unit1'] == 'yes' ? $i : $rackData['height'] - $i + 1) . '</th>';
e673ee24
DO
209 for ($locidx = 0; $locidx < 3; $locidx++)
210 {
211 if (isset ($rackData[$i][$locidx]['skipped']))
212 continue;
213 $state = $rackData[$i][$locidx]['state'];
214 echo "<td class=state_${state}";
215 if (isset ($rackData[$i][$locidx]['hl']))
216 echo $rackData[$i][$locidx]['hl'];
217 if (isset ($rackData[$i][$locidx]['colspan']))
218 echo ' colspan=' . $rackData[$i][$locidx]['colspan'];
219 if (isset ($rackData[$i][$locidx]['rowspan']))
220 echo ' rowspan=' . $rackData[$i][$locidx]['rowspan'];
221 echo ">";
222 switch ($state)
223 {
224 case 'T':
225 $objectData = getObjectInfo ($rackData[$i][$locidx]['object_id']);
226 if (!empty ($objectData['asset_no']))
227 $prefix = "<div title='${objectData['asset_no']}";
228 else
229 $prefix = "<div title='no asset tag";
230 // Don't tell about label, if it matches common name.
231 if ($objectData['name'] != $objectData['label'] and !empty ($objectData['label']))
232 $suffix = ", visible label is \"${objectData['label']}\"'>";
233 else
234 $suffix = "'>";
235 echo $prefix . $suffix;
236 echo "<a href='${root}?page=object&object_id=${objectData['id']}'>${objectData['dname']}</a></div>";
237 break;
238 case 'A':
239 echo '<div title="This rackspace does not exist">&nbsp;</div>';
240 break;
241 case 'F':
242 echo '<div title="Free rackspace">&nbsp;</div>';
243 break;
244 case 'U':
245 echo '<div title="Problematic rackspace, you CAN\'T mount here">&nbsp;</div>';
246 break;
247 default:
248 echo '<div title="No data">&nbsp;</div>';
249 break;
250 }
251 echo '</td>';
252 }
253 echo "</tr>\n";
254 }
255 echo "</table></center>\n";
256}
257
e673ee24
DO
258function renderNewRackForm ($row_id)
259{
260 global $pageno, $tabno;
50b4ba85 261 $log = array();
406b54bd 262 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
e673ee24
DO
263
264 // Look for current submit.
265 if (isset ($_REQUEST['got_data']))
266 {
2c6c7645 267 assertStringArg ('rack_name', __FUNCTION__);
b8094ae4 268 assertUIntArg ('rack_height1', __FUNCTION__);
2c6c7645 269 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
e673ee24 270 $name = $_REQUEST['rack_name'];
e673ee24 271
b8094ae4 272 if (commitAddRack ($name, $_REQUEST['rack_height1'], $row_id, $_REQUEST['rack_comment'], $taglist) === TRUE)
e673ee24
DO
273 $log[] = array ('code' => 'success', 'message' => "Added new rack '${name}'");
274 else
50b4ba85
DO
275 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddRack() failed');
276 }
277 elseif (isset ($_REQUEST['got_mdata']))
278 {
b8094ae4 279 assertUIntArg ('rack_height2', __FUNCTION__);
50b4ba85
DO
280 assertStringArg ('rack_names', __FUNCTION__, TRUE);
281 // copy-and-paste from renderAddMultipleObjectsForm()
282 $names1 = explode ('\n', $_REQUEST['rack_names']);
283 $names2 = array();
284 foreach ($names1 as $line)
285 {
286 $parts = explode ('\r', $line);
287 reset ($parts);
288 if (empty ($parts[0]))
289 continue;
290 else
291 $names2[] = rtrim ($parts[0]);
292 }
293 foreach ($names2 as $cname)
b8094ae4 294 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $row_id, '', $taglist) === TRUE)
50b4ba85
DO
295 $log[] = array ('code' => 'success', 'message' => "Added new rack '${cname}'");
296 else
297 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddRack() failed');
e673ee24 298 }
50b4ba85 299 printLog ($log);
e673ee24 300
406b54bd 301 echo "<table border=0 width='100%'><tr><td valign=top>";
e673ee24 302 // Render a form for the next.
50b4ba85 303 startPortlet ('Add one');
e673ee24
DO
304 echo '<form>';
305 echo "<input type=hidden name=page value=${pageno}>";
306 echo "<input type=hidden name=tab value=${tabno}>";
307 echo "<input type=hidden name=row_id value=${row_id}>";
308 echo '<table border=0 align=center>';
b901bf1f
DO
309 $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
310 if ($defh == 0)
311 $defh = '';
50b4ba85 312 echo "<tr><th class=tdright>Rack name (*):</th><td class=tdleft><input type=text name=rack_name tabindex=1></td></tr>\n";
b8094ae4 313 echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height1 tabindex=2 value='${defh}'></td></tr>\n";
4134b5c0 314 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment tabindex=3></td></tr>\n";
50b4ba85 315 echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Add'></td></tr>\n";
406b54bd
DO
316 echo '</table>';
317 finishPortlet();
318 echo '</td>';
319
320 echo '<td rowspan=2 valign=top>';
321 startPortlet ('Pre-assigned tags');
322 renderTagSelect();
50b4ba85 323 finishPortlet();
406b54bd 324 echo '</td></tr>';
50b4ba85 325
406b54bd 326 echo '<tr><td valign=top>';
50b4ba85 327 startPortlet ('Add many');
50b4ba85
DO
328 echo '<table border=0 align=center>';
329 $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
330 if ($defh == 0)
331 $defh = '';
b8094ae4 332 echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height2 value='${defh}'></td></tr>\n";
50b4ba85
DO
333 echo "<tr><th class=tdright>Rack names (*):</th><td class=tdleft><textarea name=rack_names cols=40 rows=25></textarea></td></tr>\n";
334 echo "<tr><td class=submit colspan=2><input type=submit name=got_mdata value='Add'></td></tr>\n";
e673ee24
DO
335 echo '</form></table>';
336 finishPortlet();
406b54bd
DO
337 echo '</td></tr>';
338 echo '</table>';
e673ee24
DO
339}
340
341function renderEditObjectForm ($object_id)
342{
343 showMessageOrError();
344 // Handle submit.
345 if (isset ($_REQUEST['got_data']))
346 {
347 $log = array();
348 // object_id is already verified by page handler
2c6c7645
DO
349 assertUIntArg ('object_type_id', __FUNCTION__);
350 assertStringArg ('object_name', __FUNCTION__, TRUE);
351 assertStringArg ('object_label', __FUNCTION__, TRUE);
352 assertStringArg ('object_barcode', __FUNCTION__, TRUE);
353 assertStringArg ('object_asset_no', __FUNCTION__, TRUE);
e673ee24
DO
354 $type_id = $_REQUEST['object_type_id'];
355 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
356 $has_problems = 'yes';
357 else
358 $has_problems = 'no';
359 $name = $_REQUEST['object_name'];
360 $label = $_REQUEST['object_label'];
361 $barcode = $_REQUEST['object_barcode'];
362 $asset_no = $_REQUEST['object_asset_no'];
363 $comment = $_REQUEST['object_comment'];
364
365 if (commitUpdateObject ($object_id, $name, $label, $barcode, $type_id, $has_problems, $asset_no, $comment) === TRUE)
366 $log[] = array ('code' => 'success', 'message' => "Updated object '${name}'");
367 else
4d2e93f2 368 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitUpdateObject() failed');
c7fe33be
DO
369 // Invalidate thumb cache of all racks objects could occupy.
370 foreach (getResidentRacksData ($object_id, FALSE) as $rack_id)
371 resetThumbCache ($rack_id);
e673ee24
DO
372 printLog ($log);
373 }
374
375 global $pageno, $tabno;
376 $object = getObjectInfo ($object_id);
377 if ($object == NULL)
378 {
39a6338a 379 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
380 return;
381 }
382
383 // Render a form for the next submit;
384 echo '<table border=0 width=100%><tr>';
385
386 echo '<td class=pcleft>';
387 startPortlet ('Static attributes');
250a40c5 388 echo '<form method=post>';
e673ee24
DO
389 echo "<input type=hidden name=page value=${pageno}>";
390 echo "<input type=hidden name=tab value=${tabno}>";
391 echo "<input type=hidden name=object_id value=${object_id}>";
5bbbeaa2 392 echo "<input type=hidden name=got_data value=1>";
e673ee24
DO
393 echo '<table border=0 align=center>';
394 echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
395 printSelect (getObjectTypeList(), 'object_type_id', $object['objtype_id']);
396 echo "</td></tr>\n";
397 // Common attributes.
398 echo "<tr><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='${object['name']}'></td></tr>\n";
399 echo "<tr><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='${object['label']}'></td></tr>\n";
400 echo "<tr><th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value='${object['asset_no']}'></td></tr>\n";
401 echo "<tr><th class=tdright>Barcode:</th><td class=tdleft><input type=text name=object_barcode value='${object['barcode']}'></td></tr>\n";
402 echo "<tr><th class=tdright>Has problems:</th><td class=tdleft><input type=checkbox name=object_has_problems";
403 if ($object['has_problems'] == 'yes')
404 echo ' checked';
405 echo "></td></tr>\n";
406 echo "<tr><td colspan=2><b>Comment:</b><br><textarea name=object_comment rows=10 cols=80>${object['comment']}</textarea></td></tr>";
5bbbeaa2
DO
407 echo "<tr><th class=submit colspan=2>";
408 printImageHREF ('SAVE', 'Save changes', TRUE);
409 echo "</td></tr>\n";
e673ee24
DO
410 echo '</form></table><br>';
411 finishPortlet();
412 echo '</td>';
413
414 // Optional attributes.
415 echo '<td class=pcright>';
416 startPortlet ('Optional attributes');
417 $values = getAttrValues ($object_id);
418 global $root;
419 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
420 echo "<tr><th>&nbsp;</th><th>Attribute</th><th>Value</th><th>&nbsp;</th></tr>\n";
0dfb8a2a
DO
421 echo "<form method=post action='${root}process.php'>\n";
422 echo "<input type=hidden name=page value=${pageno}>\n";
423 echo "<input type=hidden name=tab value=${tabno}>\n";
424 echo "<input type=hidden name=op value=upd>\n";
425 echo "<input type=hidden name=object_id value=${object_id}>\n";
426 echo '<input type=hidden name=num_attrs value=' . count($values) . ">\n";
427
428 $i = 0;
e673ee24
DO
429 foreach ($values as $record)
430 {
0dfb8a2a 431 echo "<input type=hidden name=${i}_attr_id value=${record['id']}>";
0c4605ab 432 echo '<tr><td>';
ca1fec24 433 if (!empty ($record['value']))
0c4605ab
DO
434 {
435 echo "<a href=${root}process.php?page=${pageno}&tab=${tabno}&op=del&object_id=${object_id}&attr_id=${record['id']}>";
d48d8820 436 printImageHREF ('clear', 'Clear value');
0c4605ab
DO
437 echo '</a>';
438 }
439 else
d48d8820 440 echo '&nbsp;';
0c4605ab 441 echo '</td>';
e673ee24
DO
442 echo "<td class=tdright>${record['name']}:</td><td class=tdleft>";
443 switch ($record['type'])
444 {
445 case 'uint':
446 case 'float':
447 case 'string':
0dfb8a2a 448 echo "<input type=text name=${i}_value value='${record['value']}'>";
e673ee24
DO
449 break;
450 case 'dict':
451 $chapter = readChapter ($record['chapter_name']);
4c330a14 452 $chapter[0] = '-- NOT SET --';
0dfb8a2a 453 printSelect ($chapter, "${i}_value", $record['key']);
e673ee24
DO
454 break;
455 }
0dfb8a2a
DO
456 echo "</td></tr>\n";
457 $i++;
e673ee24 458 }
5bbbeaa2
DO
459 echo "<tr><td colspan=3>";
460 printImageHREF ('SAVE', 'Save changes', TRUE);
461 echo "</td></tr>\n";
0dfb8a2a 462 echo "</form>";
e673ee24
DO
463 echo "</table>\n";
464 finishPortlet();
465 echo '</td>';
466
467 echo '</tr><tr>';
468
469 echo '<td colspan=2>';
470 startPortlet ('history');
471 renderHistory ($pageno, $object_id);
472 finishPortlet();
473 echo '</td>';
474
475 echo '</tr></table>';
476}
477
478// This is a clone of renderEditObjectForm().
479function renderEditRackForm ($rack_id)
480{
481 // Handle submit.
482 if (isset ($_REQUEST['got_data']))
483 {
484 $log = array();
2c6c7645
DO
485 assertUIntArg ('rack_row_id', __FUNCTION__);
486 assertUIntArg ('rack_height', __FUNCTION__);
487 assertStringArg ('rack_name', __FUNCTION__);
488 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
e673ee24
DO
489 $row_id = $_REQUEST['rack_row_id'];
490 $height = $_REQUEST['rack_height'];
491 $name = $_REQUEST['rack_name'];
492 $comment = $_REQUEST['rack_comment'];
493
494 if (commitUpdateRack ($rack_id, $name, $height, $row_id, $comment) === TRUE)
495 $log[] = array ('code' => 'success', 'message' => "Updated rack '${name}'");
496 else
4d2e93f2 497 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitUpdateRack() failed');
c7fe33be 498 resetThumbCache ($rack_id);
e673ee24
DO
499 printLog ($log);
500 }
501
502 global $pageno, $tabno;
503 $rack = getRackData ($rack_id);
504 if ($rack == NULL)
505 {
39a6338a 506 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
507 return;
508 }
509
510 // Render a form for the next.
511 startPortlet ('Rack attributes');
512 echo '<form>';
513 echo "<input type=hidden name=page value=${pageno}>";
514 echo "<input type=hidden name=tab value=${tabno}>";
515 echo "<input type=hidden name=rack_id value=${rack_id}>";
516 echo '<table border=0 align=center>';
517 echo "<tr><th class=tdright>Rack row:</th><td class=tdleft>";
4c330a14 518 printSelect (readChapter ('RackRow'), 'rack_row_id', $rack['row_id']);
e673ee24
DO
519 echo "</td></tr>\n";
520 echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name value='${rack['name']}'></td></tr>\n";
521 echo "<tr><th class=tdright>Height (required):</th><td class=tdleft><input type=text name=rack_height value='${rack['height']}'></td></tr>\n";
522 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment value='${rack['comment']}'></td></tr>\n";
523 echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Update'></td></tr>\n";
524 echo '</form></table><br>';
525 finishPortlet();
526
527 startPortlet ('History');
528 renderHistory ($pageno, $rack_id);
529 finishPortlet();
530}
531
532// This is a helper for creators and editors.
533function printSelect ($rowList, $select_name, $selected_id = 1)
534{
9e7f32a7
DO
535 // First collect all data for OPTGROUPs, then ouput it and dump
536 // the rest of records as is.
537 $optgroup = array();
538 $other = array();
4c330a14 539 foreach ($rowList as $dict_key => $dict_value)
e673ee24 540 {
f0b540a3 541 if (strpos ($dict_value, '%GSKIP%') !== FALSE)
9e7f32a7 542 {
f0b540a3 543 $tmp = explode ('%GSKIP%', $dict_value, 2);
9e7f32a7
DO
544 $optgroup[$tmp[0]][$dict_key] = $tmp[1];
545 }
f0b540a3 546 elseif (strpos ($dict_value, '%GPASS%') !== FALSE)
2613bc1c 547 {
f0b540a3 548 $tmp = explode ('%GPASS%', $dict_value, 2);
2613bc1c
DO
549 $optgroup[$tmp[0]][$dict_key] = $tmp[1];
550 }
9e7f32a7
DO
551 else
552 $other[$dict_key] = $dict_value;
553 }
554 echo "<select name=${select_name}>";
555 if (!count ($optgroup))
556 {
557 foreach ($other as $dict_key => $dict_value)
558 {
559 echo "<option value=${dict_key}";
560 if ($dict_key == $selected_id)
561 echo ' selected';
562 echo ">${dict_value}</option>";
563 }
564 }
565 else
566 {
567 foreach ($optgroup as $groupname => $groupdata)
568 {
569 echo "<optgroup label='${groupname}'>";
570 foreach ($groupdata as $dict_key => $dict_value)
571 {
572 echo "<option value=${dict_key}";
573 if ($dict_key == $selected_id)
574 echo ' selected';
575 echo ">${dict_value}</option>";
576 }
577 echo "</optgroup>\n";
578 }
579 if (count ($other))
580 {
581 echo "<optgroup label='other'>\n";
582 foreach ($other as $dict_key => $dict_value)
583 {
584 echo "<option value=${dict_key}";
585 if ($dict_key == $selected_id)
586 echo ' selected';
587 echo ">${dict_value}</option>";
588 }
589 echo "</optgroup>\n";
590 }
e673ee24
DO
591 }
592 echo "</select>";
593}
594
254673dd
DO
595// used by renderGridForm() and renderRackPage()
596function renderRackInfoPortlet ($rackData)
597{
d9c609c4 598 global $root;
254673dd
DO
599 startPortlet ('summary');
600 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
601 echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
602 echo "<tr><th width='50%' class=tdright>Name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
603 echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
604 echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
605 renderProgressBar (getRSUforRack ($rackData));
606 echo "</td></tr>\n";
607 echo "<tr><th width='50%' class=tdright>Objects:</th><td class=tdleft>";
608 echo getObjectCount ($rackData);
609 echo "</td></tr>\n";
e2ac59cf 610 printTagTRs ("${root}?page=rackspace&");
254673dd
DO
611 if (!empty ($rackData['comment']))
612 echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
613 echo '</table>';
614 finishPortlet();
615}
616
e673ee24 617// This is a universal editor of rack design/waste.
bb09cca0 618function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $state2)
e673ee24
DO
619{
620 if ($rack_id == 0)
621 {
591ff2c4 622 showError ('Invalid rack_id', __FUNCTION__);
e673ee24
DO
623 return;
624 }
625 if (($rackData = getRackData ($rack_id)) == NULL)
626 {
591ff2c4 627 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
628 return;
629 }
630
631 global $root, $pageno, $tabno;
254673dd 632 $filter ($rackData);
e673ee24
DO
633 markupObjectProblems ($rackData);
634
635 // Process form submit.
636 if (isset ($_REQUEST['do_update']))
637 {
638 $log[] = processGridForm ($rackData, $state1, $state2);
254673dd
DO
639 printLog ($log);
640 $rackData = getRackData ($rack_id);
641 $filter ($rackData);
642 markupObjectProblems ($rackData);
e673ee24
DO
643 }
644
645 // Render the result whatever it is.
646 // Main layout.
647 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
648 echo "<tr><td colspan=2 align=center><h1>${rackData['name']}</h1></td></tr>\n";
649
650 // Left column with information portlet.
651 echo "<tr><td class=pcleft height='1%' width='50%'>";
254673dd 652 renderRackInfoPortlet ($rackData);
e673ee24 653 echo "</td>\n";
bb09cca0 654 echo "<td class=pcright>";
e673ee24
DO
655
656 // Grid form.
657 startPortlet ($header);
658 echo "<center>\n";
659 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
660 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
661 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
9d479d56 662 echo "<form method=post action='${root}?'>\n";
e673ee24
DO
663 echo "<input type=hidden name=page value=${pageno}>\n";
664 echo "<input type=hidden name=tab value=${tabno}>\n";
665 echo "<input type=hidden name=rack_id value=${rack_id}>\n";
666 markupAtomGrid ($rackData, $state2);
667 renderAtomGrid ($rackData);
668 echo "</table></center>\n";
669 echo "<br><input type=submit name=do_update value='${submit}'></form><br><br>\n";
670 finishPortlet();
bb09cca0 671 echo "</td></tr></table>\n";
e673ee24
DO
672}
673
674function renderRackDesign ($rack_id)
675{
bb09cca0 676 renderGridForm ($rack_id, 'applyRackDesignMask', 'Rack design', 'Set rack design', 'A', 'F');
e673ee24
DO
677}
678
679function renderRackProblems ($rack_id = 0)
680{
bb09cca0 681 renderGridForm ($rack_id, 'applyRackProblemMask', 'Rack problems', 'Mark unusable atoms', 'F', 'U');
e673ee24
DO
682}
683
684function startPortlet ($title = '')
685{
686 echo "<div class=portlet><h2>${title}</h2>";
687}
688
689function finishPortlet ()
690{
691 echo "</div>\n";
692}
693
694function printRefsOfType ($refs, $type, $eq)
695{
696 global $root;
697 $gotone=0;
698 foreach ($refs as $ref)
699 {
700 if ($eq($ref['type'], $type))
701 {
702 if ($gotone) echo ', ';
4b2bf583
DO
703 echo "<a href='${root}?page=object&object_id=${ref['object_id']}'>";
704 if (!empty ($ref['name']))
705 echo $ref['name'] . '@';
706 echo "${ref['object_name']}</a>";
e673ee24
DO
707 $gotone=1;
708 }
709 }
710}
711
712function renderRackObject ($object_id = 0)
713{
41bd8c87 714 global $root;
e673ee24
DO
715 if ($object_id <= 0)
716 {
591ff2c4 717 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
718 return;
719 }
720 $info = getObjectInfo ($object_id);
721 if ($info == NULL)
722 {
591ff2c4 723 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
724 return;
725 }
726 // Main layout starts.
727 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
728 echo "<tr><td colspan=2 align=center><h1>${info['dname']}</h1></td></tr>\n";
729 // left column with uknown number of portlets
730 echo "<tr><td class=pcleft>";
731 startPortlet ('Object information');
732 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
733 if (!empty ($info['name']))
734 echo "<tr><th width='50%' class=tdright>Common name:</th><td class=tdleft>${info['name']}</td></tr>\n";
9c0b0016 735 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
a0ec6295 736 echo "<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>\n";
e2ac59cf
DO
737 echo "<tr><th width='50%' class=tdright>Object type:</th>";
738 echo "<td class=tdleft><a href='${root}?page=objgroup&group_id=${info['objtype_id']}'>${info['objtype_name']}</a></td></tr>\n";
e673ee24
DO
739 if (!empty ($info['asset_no']))
740 echo "<tr><th width='50%' class=tdright>Asset tag:</th><td class=tdleft>${info['asset_no']}</td></tr>\n";
a6305acc 741 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('REQUIRE_ASSET_TAG_FOR'))))
a0ec6295 742 echo "<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>\n";
e673ee24
DO
743 if (!empty ($info['label']))
744 echo "<tr><th width='50%' class=tdright>Visible label:</th><td class=tdleft>${info['label']}</td></tr>\n";
745 if (!empty ($info['barcode']))
746 echo "<tr><th width='50%' class=tdright>Barcode:</th><td class=tdleft>${info['barcode']}</td></tr>\n";
747 if ($info['has_problems'] == 'yes')
748 echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
24cbe8af 749 foreach (getAttrValues ($object_id, TRUE) as $record)
e673ee24 750 if (!empty ($record['value']))
50a954f6 751 echo "<tr><th width='50%' class=opt_attr_th>${record['name']}:</th><td class=tdleft>${record['a_value']}</td></tr>\n";
e2ac59cf 752 printTagTRs ("${root}?page=objgroup&group_id=${info['objtype_id']}&");
e673ee24
DO
753 echo "</table><br>\n";
754 finishPortlet();
755
756 if (!empty ($info['comment']))
757 {
758 startPortlet ('Comment');
6cc5d6cd 759 echo '<div class=commentblock>' . string_insert_hrefs ($info['comment']) . '</div>';
e673ee24
DO
760 finishPortlet ();
761 }
762
763 $ports = getObjectPortsAndLinks ($object_id);
764 if (count ($ports))
765 {
766 startPortlet ('Ports and links');
767 usort($ports, 'sortByName');
768 if ($ports)
769 {
770 $hl_port_id = 0;
771 if (isset ($_REQUEST['hl_port_id']))
772 {
2c6c7645 773 assertUIntArg ('hl_port_id', __FUNCTION__);
e673ee24
DO
774 $hl_port_id = $_REQUEST['hl_port_id'];
775 }
776 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
777 echo "<tr><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
778 echo "<th>Rem. Object</th><th>Rem. port</th></tr>\n";
779 foreach ($ports as $port)
780 {
781 echo '<tr';
782 if ($hl_port_id == $port['id'])
783 echo ' class=port_highlight';
784 echo "><td>${port['name']}</td><td>${port['label']}</td><td>${port['type']}</td>";
785 echo "<td>${port['l2address']}</td>";
786 if ($port['remote_object_id'])
787 {
788 echo "<td><a href='${root}?page=object&object_id=${port['remote_object_id']}'>${port['remote_object_name']}</a></td>";
789 echo "<td>${port['remote_name']}</td>";
790 }
791 elseif (!empty ($port['reservation_comment']))
792 {
793 echo "<td><b>Reserved;</b></td>";
794 echo "<td>${port['reservation_comment']}</td>";
795 }
796 else
797 echo '<td>&nbsp;</td><td>&nbsp;</td>';
798 echo "</tr>\n";
799 }
800 echo "</table><br>\n";
801 }
802 finishPortlet();
803 }
804 $addresses = getObjectAddresses ($object_id);
805 usort($addresses, 'sortAddresses');
806 if (count ($addresses))
807 {
f28fbe8b 808 startPortlet ('IPv4 addresses');
e673ee24
DO
809 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
810 echo "<tr><th>Interface name</th><th>IP Address</th><th>Description</th><th>Misc</th></tr>\n";
fc0e3978
DO
811 $hl_ipv4_addr = '';
812 if (isset ($_REQUEST['hl_ipv4_addr']))
813 {
814 assertIPv4Arg ('hl_ipv4_addr', __FUNCTION__);
815 $hl_ipv4_addr = $_REQUEST['hl_ipv4_addr'];
816 }
e673ee24
DO
817 foreach ($addresses as $addr)
818 {
819 if (strlen($addr['address_name'])>40)
820 $address_name = substr($addr['address_name'],0,38).'...';
821 else
822 $address_name = $addr['address_name'];
823
824 $virtnum = countRefsOfType($addr['references'], 'virtual', 'eq');
825 $sharednum = countRefsOfType($addr['references'], 'shared', 'eq');
826 $regnum = countRefsOfType($addr['references'], 'regular', 'eq');
827 $notvirtnum = countRefsOfType($addr['references'], 'virtual', 'neq');
828
fc0e3978 829 echo "<tr";
e673ee24 830 if ($addr['address_reserved']=='yes')
fc0e3978 831 echo ' class=trerror';
e673ee24 832 elseif ($addr['type']!='virtual' && $regnum>0)
fc0e3978 833 echo ' class=trerror';
e673ee24 834 elseif ($addr['type']=='regular' && $sharednum>0)
fc0e3978 835 echo ' class=trerror';
e673ee24 836
fc0e3978
DO
837 if ($hl_ipv4_addr == $addr['ip'])
838 echo ' class=port_highlight';
839 echo "><td class=tdleft>${addr['name']}</td><td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td class='description'>$address_name</td><td class=tdleft>\n";
e673ee24
DO
840
841 if ($addr['address_reserved']=='yes')
842 echo "<b>Reserved;</b> ";
843
844 if ($addr['type'] == 'virtual')
845 {
846 echo "<b>V</b>";
847 if ($notvirtnum > 0)
848 {
849 echo " Owners: ";
850 printRefsOfType($addr['references'], 'virtual', 'neq');
851 }
852 }
853 elseif ($addr['type'] == 'shared')
854 {
855 echo "<b>S</b>";
856 if ($sharednum > 0)
857 {
858 echo " Peers: ";
859 printRefsOfType($addr['references'], 'shared', 'eq');
860 echo ";";
861 }
862 if ($virtnum > 0)
863 {
864 echo " Virtuals: ";
865 printRefsOfType($addr['references'], 'virtual', 'eq');
866 echo ";";
867 }
868 if ($regnum > 0)
869 {
870 echo " Collisions: ";
871 printRefsOfType($addr['references'], 'regular', 'eq');
872 }
873
874 }
875 else
876 {
877 if ($virtnum > 0)
878 {
879 echo " Virtuals: ";
880 printRefsOfType($addr['references'], 'virtual', 'eq');
881 echo ";";
882 }
883 if ($notvirtnum > 0)
884 {
885 echo " Collisions: ";
886 printRefsOfType($addr['references'], 'virtual', 'neq');
887 }
888 }
889
890 echo "</td></tr>\n";
891 }
892 echo "</table><br>\n";
893 finishPortlet();
894 }
895
eeb4a5d8 896 $forwards = getNATv4ForObject ($object_id);
e673ee24
DO
897 if (count($forwards['in']) or count($forwards['out']))
898 {
f28fbe8b 899 startPortlet('NATv4');
e673ee24
DO
900
901 if (count($forwards['out']))
902 {
903
f28fbe8b 904 echo "<h3>locally performed NAT</h3>";
e673ee24
DO
905
906 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
f28fbe8b 907 echo "<tr><th>Proto</th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Rule comment</th></tr>\n";
e673ee24
DO
908
909 foreach ($forwards['out'] as $pf)
910 {
24e85a1a 911 $class='trerrorg';
e673ee24
DO
912 $name='';
913 foreach ($addresses as $addr)
914 if ($addr['ip'] == $pf['localip'])
915 {
916 $class='';
917 $name=$addr['name'];
918 break;
919 }
920
921 echo "<tr class='$class'>";
922
f28fbe8b 923 echo "<td>${pf['proto']}</td><td class=tdleft>${name}: <a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
e673ee24 924
f28fbe8b 925 echo "<td class=tdleft><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
e673ee24
DO
926
927 $address=getIPAddress($pf['remoteip']);
928
929 echo "<td class='description'>";
f28fbe8b
DO
930 if (count ($address['bonds']))
931 foreach($address['bonds'] as $bond)
932 echo "<a href='${root}?page=object&tab=default&object_id=${bond['object_id']}'>${bond['object_name']}(${bond['name']})</a> ";
933 elseif (!empty ($pf['remote_addr_name']))
934 echo '(' . $pf['remote_addr_name'] . ')';
e673ee24
DO
935
936 echo "</td><td class='description'>${pf['description']}</td>";
937
938 echo "</tr>";
939 }
940 echo "</table><br><br>";
941 }
942 if (count($forwards['in']))
943 {
f28fbe8b 944 echo "<h3>arriving NAT connections</h3>";
e673ee24
DO
945
946 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
f28fbe8b 947 echo "<tr><th>Matched endpoint</th><th>Source object</th><th>Translated to</th><th>Rule comment</th></tr>\n";
e673ee24
DO
948
949 foreach ($forwards['in'] as $pf)
950 {
951 echo "<tr>";
952 echo "<td>${pf['proto']}/<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
953
954 echo "<td class='description'><a href='${root}?page=object&tab=default&object_id=${pf['object_id']}'>${pf['object_name']}</a>";
955
956 echo "</td><td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
957 echo "<td class='description'>${pf['description']}</td></tr>";
958 }
959
960 echo "</table><br><br>";
961 }
962 finishPortlet();
963 }
964
78e7b769
DO
965 $pools = getRSPoolsForObject ($object_id);
966 if (count ($pools))
967 {
968 startPortlet ('Real server pools');
969 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
732e4578 970 echo "<tr><th>VS</th><th>RS pool</th><th>RS</th><th>VS config</th><th>RS config</th></tr>\n";
748805bf 971 foreach ($pools as $vs_id => $info)
78e7b769 972 {
732e4578 973 echo "<tr valign=top><td class=tdleft><a href='${root}?page=vservice&id=${vs_id}'>";
748805bf
DO
974 echo buildVServiceName ($info);
975 echo '</a>';
976 if (!empty ($info['name']))
977 echo " (${info['name']})";
c0ae6968 978 echo "</td><td class=tdleft><a href='${root}?page=rspool&pool_id=${info['pool_id']}'>";
748805bf 979 echo (empty ($info['pool_name']) ? 'ANONYMOUS' : $info['pool_name']);
732e4578
DO
980 echo '</a></td><td class=tdleft>' . $info['rscount'] . '</td>';
981 echo "<td class=tdleft><pre>${info['vsconfig']}</pre></td>";
982 echo "<td class=tdleft><pre>${info['rsconfig']}</pre></td>";
78e7b769
DO
983 echo "</tr>\n";
984 }
985 echo "</table>\n";
986 finishPortlet();
987 }
e673ee24
DO
988 echo "</td>\n";
989
990 // After left column we have (surprise!) right column with rackspace portled only.
991 echo "<td class=pcright>";
992 // rackspace portlet
993 startPortlet ('Rackspace allocation');
994 // FIXME: now we call getRackData() twice
995 $racks = getResidentRacksData ($object_id);
996 foreach ($racks as $rackData)
997 renderRack ($rackData['id'], $object_id);
998 echo '<br>';
999 finishPortlet();
1000 echo "</td></tr>";
1001 echo "</table>\n";
1002}
1003
1004function renderRackMultiSelect ($sname, $racks, $selected)
1005{
9c0b0016 1006 echo "<select name=${sname} multiple size=" . getConfigVar ('MAXSELSIZE') . " onchange='getElementById(\"racks\").submit()'>\n";
e673ee24
DO
1007 foreach ($racks as $rack)
1008 {
1009 echo "<option value=${rack['id']}";
1010 if (!(array_search ($rack['id'], $selected) === FALSE))
1011 echo ' selected';
6a3a37b2 1012 echo">${rack['row_name']}: ${rack['name']}</option>\n";
e673ee24
DO
1013 }
1014 echo "</select>\n";
1015}
1016
1017function showMessageOrError ()
1018{
1019 if (isset($_REQUEST['message']))
1020 echo "<div class=msg_success>${_REQUEST['message']}</div>";
1021 if (isset($_REQUEST['error']))
1022 echo "<div class=msg_error>${_REQUEST['error']}</div>";
1023}
1024
1025// This function renders a form for port edition.
1026function renderPortsForObject ($object_id = 0)
1027{
1028 global $root, $pageno, $tabno;
1029 if ($object_id <= 0)
1030 {
591ff2c4 1031 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1032 return;
1033 }
1034 showMessageOrError();
1035 startPortlet ('Ports and interfaces');
1036 $ports = getObjectPortsAndLinks ($object_id);
1037 usort($ports, 'sortByName');
1038 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
1039 echo "<tr><th>&nbsp;</th><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
1040 echo "<th>Rem. object</th><th>Rem. port</th><th>(Un)link or (un)reserve</th><th>&nbsp;</th></tr>\n";
1041 foreach ($ports as $port)
1042 {
1043 echo "<form action='${root}process.php'>";
1044 echo "<input type=hidden name=op value=editPort>";
1045 echo "<input type=hidden name=page value='${pageno}'>\n";
1046 echo "<input type=hidden name=tab value='${tabno}'>\n";
1047 echo "<input type=hidden name=port_id value='${port['id']}'>";
1048 echo "<input type=hidden name=object_id value='$object_id'>\n";
1049 echo "<tr><td><a href='${root}process.php?op=delPort&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=$object_id&port_name=${port['name']}'>";
1050 printImageHREF ('delete', 'Unlink and Delete this port');
1051 echo "</a></td>\n";
1052 echo "<td><input type=text name=name value='${port['name']}' size=8></td>";
1053 echo "<td><input type=text name=label value='${port['label']}' size=24></td>";
1054 echo "<td>${port['type']}</td>\n";
1055 echo "<td><input type=text name=l2address value='${port['l2address']}'></td>\n";
1056 if ($port['remote_object_id'])
1057 {
1058 echo "<td><a href='${root}?page=object&object_id=${port['remote_object_id']}'>${port['remote_object_name']}</a></td>";
1059 echo "<td>${port['remote_name']}</td>";
1060 echo "<td><a href='${root}process.php?op=unlinkPort&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=$object_id&port_name=";
1061 echo urlencode ($port['name']);
1062 echo "&remote_port_name=${port['remote_name']}&remote_object_name=${port['remote_object_name']}'>";
1063 printImageHREF ('unlink', 'Unlink this port');
1064 echo "</a></td>";
1065 }
1066 elseif (!empty ($port['reservation_comment']))
1067 {
1068 echo "<td><b>Reserved;</b></td>";
1069 echo "<td><input type=text name=reservation_comment value='${port['reservation_comment']}'></td>";
1070 echo "<td><a href='${root}process.php?op=useup&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=${object_id}'>";
1071 printImageHREF ('useup', 'Use up this port');
1072 echo "</a></td>";
1073 }
1074 else
1075 {
1076 echo "<td>&nbsp;</td><td>&nbsp;</td>";
1077 echo "<td>";
1078 echo "<a href='javascript:;' onclick='window.open(\"${root}link_helper.php?port=${port['id']}&type=${port['type_id']}&object_id=$object_id&port_name=";
1079 echo urlencode ($port['name']);
1080 echo "\",\"findlink\",\"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
1081 printImageHREF ('link', 'Link this port');
1082 echo "</a> <input type=text name=reservation_comment>";
1083 echo "</td>\n";
1084 }
5bbbeaa2
DO
1085 echo "<td>";
1086 printImageHREF ('save', 'Save changes', TRUE);
1087 echo "</td></form></tr>\n";
e673ee24 1088 }
d48d8820
DO
1089 echo "<form action='${root}process.php'><tr><td>";
1090 printImageHREF ('add', '', TRUE, 104);
1091 echo "</td><td><input type=text size=8 name=port_name tabindex=100></td>\n";
e673ee24
DO
1092 echo "<td><input type=text size=24 name=port_label tabindex=101></td>";
1093 echo "<input type=hidden name=op value=addPort>\n";
1094 echo "<input type=hidden name=object_id value='${object_id}'>\n";
1095 echo "<input type=hidden name=page value='${pageno}'>\n";
1096 echo "<input type=hidden name=tab value='${tabno}'>\n";
1097 echo "<td><select name='port_type_id' tabindex=102>\n";
1098 $types = getPortTypes();
9c0b0016 1099 $default_port_type = getConfigVar ('default_port_type');
e673ee24
DO
1100 foreach ($types as $typeid => $typename)
1101 {
1102 echo "<option value='${typeid}'";
1103 if ($typeid == $default_port_type)
1104 echo " selected";
1105 echo ">${typename}</option>\n";
1106 }
1107 echo "</select></td>";
1108 echo "<td><input type=text name=port_l2address tabindex=103></td>\n";
d48d8820 1109 echo "<td colspan=4>&nbsp;</td></tr></form>";
e673ee24
DO
1110 echo "</table><br>\n";
1111 finishPortlet();
1112
1113 startPortlet ('Add/update multiple ports');
1114 echo "<form action=${root}process.php method=post>";
1115 echo "<input type=hidden name=page value='${pageno}'>\n";
1116 echo "<input type=hidden name=tab value='${tabno}'>\n";
1117 echo "<input type=hidden name=object_id value='${object_id}'>\n";
1118 echo "<input type=hidden name=op value=addMultiPorts>";
1119 echo 'Format: <select name=format>';
e673ee24
DO
1120 echo '<option value=c3600asy>Cisco 3600 async: sh line | inc TTY</option>';
1121 echo '<option value=fiwg selected>Foundry ServerIron/FastIron WorkGroup/Edge: sh int br</option>';
e673ee24 1122 echo '<option value=fisxii>Foundry FastIron SuperX/II4000: sh int br</option>';
351d4dbf 1123 echo '<option value=ssv1>SSV:&lt;interface name&gt; &lt;MAC address&gt;</option>';
e673ee24
DO
1124 echo "</select>";
1125 echo 'Default port type: ';
1126 echo "<select name=port_type>\n";
1127 foreach ($types as $typeid => $typename)
1128 {
1129 echo "<option value='${typeid}'";
1130 if ($typeid == $default_port_type)
1131 echo " selected";
1132 echo ">${typename}</option>\n";
1133 }
1134 echo "</select>";
1135 echo "<input type=submit value='Parse output'><br>\n";
1136 echo "<textarea name=input cols=100 rows=50></textarea><br>\n";
1137 echo '</form>';
1138 finishPortlet();
1139}
1140
1141function renderNetworkForObject ($object_id=0)
1142{
1143 global $root, $pageno, $tabno;
1144 if ($object_id <= 0)
1145 {
591ff2c4 1146 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1147 return;
1148 }
1149 showMessageOrError();
1150 startPortlet ('Network Addresses');
1151 $addresses = getObjectAddresses ($object_id);
1152 usort($addresses, 'sortAddresses');
1153 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
1154 echo "<tr><th>&nbsp;</th><th>Interface name</th><th>IP Address</th><th>Description</th><th>Type</th><th>Misc</th><th>&nbsp</th></tr>\n";
1155 foreach ($addresses as $addr)
1156 {
1157 if (strlen($addr['address_name'])>40)
1158 $address_name = substr($addr['address_name'],0,38).'...';
1159 else
1160 $address_name = $addr['address_name'];
1161
1162 $virtnum = countRefsOfType($addr['references'], 'virtual', 'eq');
1163 $sharednum = countRefsOfType($addr['references'], 'shared', 'eq');
1164 $regnum = countRefsOfType($addr['references'], 'regular', 'eq');
1165 $notvirtnum = countRefsOfType($addr['references'], 'virtual', 'neq');
1166
1167 if ($addr['address_reserved']=='yes')
24e85a1a 1168 $class='trerror';
e673ee24 1169 elseif ($addr['type']!='virtual' && $regnum>0)
24e85a1a 1170 $class='trerror';
e673ee24 1171 elseif ($addr['type']=='regular' && $sharednum>0)
24e85a1a 1172 $class='trerror';
e673ee24
DO
1173 else
1174 $class='';
1175
1176 echo "<form action='process.php'>";
1177 echo "<input type=hidden name=page value='${pageno}'>\n";
1178 echo "<input type=hidden name=tab value='${tabno}'>\n";
b4c1ef87 1179 echo "<input type=hidden name=op value=updIPv4Allocation>";
e673ee24
DO
1180 echo "<input type=hidden name=object_id value='$object_id'>";
1181 echo "<input type=hidden name=ip value='${addr['ip']}'>";
b4c1ef87 1182 echo "<tr class='$class'><td><a href='process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=${addr['ip']}&object_id=$object_id'>";
e673ee24
DO
1183 printImageHREF ('delete', 'Delete this IPv4 address');
1184 echo "</a></td>";
d54b9495
DO
1185 echo "<td class=tdleft><input type='text' name='bond_name' value='${addr['name']}' size=10></td>";
1186 echo "<td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
e673ee24
DO
1187 echo "<td class='description'>$address_name</td>\n";
1188 echo "<td><select name='bond_type'>";
1189 foreach (array('regular'=>'Regular', 'virtual'=>'Virtual', 'shared'=>'Shared') as $n => $v)
1190 {
1191 echo "<option value='$n'";
1192 if ($addr['type'] == $n)
1193 echo " selected";
1194 echo ">$v</option>";
1195 }
1196 echo "</td><td>";
1197 if ($addr['address_reserved']=='yes')
1198 echo "<b>Reserved</b>; ";
1199
1200 if ($addr['type'] == 'virtual')
1201 {
1202 if ($notvirtnum > 0)
1203 {
1204 echo " Owners: ";
1205 printRefsOfType($addr['references'], 'virtual', 'neq');
1206 }
1207 }
1208 elseif ($addr['type'] == 'shared')
1209 {
1210 if ($sharednum > 0)
1211 {
1212 echo " Peers: ";
1213 printRefsOfType($addr['references'], 'shared', 'eq');
1214 echo ";";
1215 }
1216 if ($virtnum > 0)
1217 {
1218 echo " Virtuals: ";
1219 printRefsOfType($addr['references'], 'virtual', 'eq');
1220 echo ";";
1221 }
1222 if ($regnum > 0)
1223 {
1224 echo " Collisions: ";
1225 printRefsOfType($addr['references'], 'regular', 'eq');
1226 }
1227
1228 }
1229 else
1230 {
1231 if ($virtnum > 0)
1232 {
1233 echo " Virtuals: ";
1234 printRefsOfType($addr['references'], 'virtual', 'eq');
1235 echo ";";
1236 }
1237 if ($notvirtnum > 0)
1238 {
1239 echo " Collisions: ";
1240 printRefsOfType($addr['references'], 'virtual', 'neq');
1241 }
1242 }
1243
d54b9495
DO
1244 echo "</td><td>";
1245 printImageHREF ('save', 'Save changes', TRUE);
1246 echo "</td></form></tr>\n";
e673ee24
DO
1247 }
1248
1249
d54b9495
DO
1250 echo "<form action='${root}process.php'><tr><td>";
1251 printImageHREF ('add', 'Allocate new address', TRUE, 99);
1252 echo "</td><td class=tdleft>";
b4c1ef87 1253 echo "<input type='text' size='10' name='bond_name' tabindex=100></td>\n";
e673ee24
DO
1254 echo "<input type=hidden name=page value='${pageno}'>\n";
1255 echo "<input type=hidden name=tab value='${tabno}'>\n";
b4c1ef87 1256 echo "<input type=hidden name=op value=addIPv4Allocation>\n";
e673ee24 1257 echo "<input type=hidden name=object_id value='$object_id'>\n";
d54b9495 1258 echo "<td class=tdleft><input type=text name='ip' tabindex=101>\n";
b4c1ef87 1259 echo "</td><td>&nbsp;</td><td><select name='bond_type' tabindex=102>";
e673ee24
DO
1260 echo "<option value='regular'>Regular</option>";
1261 echo "<option value='virtual'>Virtual</option>";
1262 echo "<option value='shared'>Shared</option>";
1263 echo "</select>";
d54b9495 1264 echo "</td><td colspan=2>&nbsp;</td></tr></form>";
e673ee24
DO
1265 echo "</table><br>\n";
1266 finishPortlet();
1267
1268}
1269
1270function printLog ($log)
1271{
1272 foreach ($log as $record)
1273 echo "<div class=msg_${record['code']}>${record['message']}</div>";
1274}
1275
1276/*
1277The following conditions must be followed:
12781. We can mount onto free atoms only. This means: if any record for an atom
1279already exists in RackSpace, it can't be used for mounting.
12802. We can't unmount from 'W' atoms. Operator should review appropriate comments
1281and either delete them before unmounting or refuse to unmount the object.
1282*/
1283
1284// We extensively use $_REQUEST in the function.
1285function renderRackSpaceForObject ($object_id = 0)
1286{
1287 if ($object_id <= 0)
1288 {
591ff2c4 1289 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1290 return;
1291 }
1292 $is_submit = isset ($_REQUEST['got_atoms']);
1293 $is_update = isset ($_REQUEST['rackmulti'][0]);
1294 $info = getObjectInfo ($object_id);
1295 if ($info == NULL)
1296 {
591ff2c4 1297 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
1298 return;
1299 }
1300 // Always process occupied racks plus racks chosen by user. First get racks with
1301 // already allocated rackspace...
1302 $workingRacksData = getResidentRacksData ($object_id);
1303 if ($workingRacksData === NULL)
1304 {
1305 print_r ($workingRacksData);
591ff2c4 1306 showError ('getResidentRacksData() failed', __FUNCTION__);
e673ee24
DO
1307 return;
1308 }
1309
1310 // ...and then add those chosen by user (if any).
1311 if ($is_update)
1312 foreach ($_REQUEST['rackmulti'] as $cand_id)
1313 {
1314 if (!isset ($workingRacksData[$cand_id]))
1315 {
1316 $rackData = getRackData ($cand_id);
1317 if ($rackData == NULL)
1318 {
591ff2c4 1319 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
1320 return NULL;
1321 }
1322 $workingRacksData[$cand_id] = $rackData;
1323 }
1324 }
1325
1326 // Do it only once...
1327 foreach ($workingRacksData as &$rackData)
1328 applyObjectMountMask ($rackData, $object_id);
1329 // Now we workaround an old caveat: http://bugs.php.net/bug.php?id=37410
1330 unset ($rackData);
1331
1332 // Here we process form submit by trying to save all submitted info to database.
1333 if ($is_submit)
1334 {
1335 $oldMolecule = getMoleculeForObject ($object_id);
1336 $worldchanged = FALSE;
1337 $log = array();
1338 foreach ($workingRacksData as $rack_id => $rackData)
1339 {
1340 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
1341 $log[] = $logrecord;
1342 if ($logrecord['code'] != 300)
1343 {
1344 $worldchanged = TRUE;
1345 // Reload our working copy after form processing.
1346 $rackData = getRackData ($rack_id);
1347 if ($rackData == NULL)
4d2e93f2 1348 $log[] = array ('code' => 500, 'message' => 'Working copy update failed in ', __FUNCTION__);
e673ee24
DO
1349 applyObjectMountMask ($rackData, $object_id);
1350 $workingRacksData[$rack_id] = $rackData;
1351 }
1352 }
1353 if ($worldchanged)
1354 {
1355 // Log a record.
1356 $newMolecule = getMoleculeForObject ($object_id);
1357 $oc = count ($oldMolecule);
1358 $nc = count ($newMolecule);
1359 $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
1360 $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
1361 global $remote_username;
1362 $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
1363 $query =
1364 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
1365 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
1366 global $dbxlink;
1367 $result = $dbxlink->query ($query);
1368 if ($result == NULL)
1369 $log[] = array ('code' => 'error', 'message' => 'SQL query failed during history logging.');
1370 else
1371 $log[] = array ('code' => 'success', 'message' => 'History logged.');
1372 }
1373 printLog ($log);
1374 }
1375
1376 // This is the time for rendering.
1377 global $root, $pageno, $tabno;
1378 echo "<form id='racks' action='${root}'>";
1379 echo "<input type=hidden name=page value='${pageno}'>\n";
1380 echo "<input type=hidden name=tab value='${tabno}'>\n";
1381 echo "<input type=hidden name=object_id value='${object_id}'>\n";
1382 // Main layout starts.
1383 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
1384
1385 // Left portlet with rack list.
1386 echo "<td class=pcleft height='1%'>";
1387 startPortlet ('Racks');
1388 $allRacksData = getRacksForRow();
4b8d413e
DO
1389 if (count ($allRacksData) <= getConfigVar ('RACK_PRESELECT_THRESHOLD'))
1390 {
1391 foreach (array_keys ($allRacksData) as $rack_id)
1392 {
1393 $rackData = getRackData ($rack_id);
1394 if ($rackData == NULL)
1395 {
1396 showError ('getRackData() failed', __FUNCTION__);
1397 return NULL;
1398 }
1399 $workingRacksData[$rack_id] = $rackData;
1400 }
1401 foreach ($workingRacksData as &$rackData)
1402 applyObjectMountMask ($rackData, $object_id);
1403 unset ($rackData);
1404 }
1405 renderRackMultiSelect ('rackmulti[]', $allRacksData, array_keys ($workingRacksData));
e673ee24
DO
1406 echo "<br>";
1407 echo "<br>";
1408 finishPortlet();
1409 echo "</td>";
1410
1411 // Middle portlet with comment and submit.
1412 echo "<td class=pcleft>";
1413 startPortlet ('Comment');
1414 echo "<textarea name=comment rows=10 cols=40></textarea><br>\n";
1415 echo "<input type=submit value='Save' name=got_atoms>\n";
1416 echo "<br>";
1417 echo "<br>";
1418 finishPortlet();
1419 echo "</td>";
1420
1421 // Right portlet with rendered racks. If this form submit is not final, we have to
1422 // reflect the former state of the grid in current form.
1423 echo "<td class=pcright rowspan=2 height='1%'>";
1424 startPortlet ('Working copy');
1425 echo '<table border=0 cellspacing=10 align=center><tr>';
1426 foreach ($workingRacksData as $rack_id => $rackData)
1427 {
1428 // Order is important here: only original allocation is highlighted.
1429 highlightObject ($rackData, $object_id);
1430 markupAtomGrid ($rackData, 'T');
1431 // If we have a form processed, discard user input and show new database
1432 // contents.
1433 if (!$is_submit and $is_update)
1434 mergeGridFormToRack ($rackData);
1435 echo "<td valign=top>";
1436 echo "<center>\n<h2>${rackData['name']}</h2>\n";
1437 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
1438 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
1439 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1440 renderAtomGrid ($rackData);
9b7468b7
DO
1441 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
1442 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
e673ee24
DO
1443 echo "</table></center>\n";
1444 echo '</td>';
1445 }
1446 echo "</tr></table>";
1447 finishPortlet();
1448 echo "</td>\n";
1449
1450 echo "</form>\n";
1451 echo "</tr></table>\n";
1452}
1453
1454function renderMolecule ($mdata, $object_id)
1455{
1456 // sort data out
1457 $rackpack = array();
1458 global $loclist;
64b95774 1459 foreach ($mdata as $rua)
e673ee24
DO
1460 {
1461 $rack_id = $rua['rack_id'];
1462 $unit_no = $rua['unit_no'];
1463 $atom = $rua['atom'];
1464 if (!isset ($rackpack[$rack_id]))
1465 {
1466 $rackData = getRackData ($rack_id);
1467 for ($i = $rackData['height']; $i > 0; $i--)
1468 for ($locidx = 0; $locidx < 3; $locidx++)
1469 $rackData[$i][$locidx]['state'] = 'F';
1470 $rackpack[$rack_id] = $rackData;
1471 }
1472 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['state'] = 'T';
1473 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['object_id'] = $object_id;
1474 }
1475 // now we have some racks to render
64b95774 1476 foreach ($rackpack as $rackData)
e673ee24
DO
1477 {
1478 markAllSpans ($rackData);
1479 echo "<table class=molecule cellspacing=0>\n";
1480 echo "<caption>${rackData['name']}</caption>\n";
1481 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th><th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1482 for ($i = $rackData['height']; $i > 0; $i--)
1483 {
1484 echo "<tr><th>$i</th>";
1485 for ($locidx = 0; $locidx < 3; $locidx++)
1486 {
1487 $state = $rackData[$i][$locidx]['state'];
1488 echo "<td class=state_${state}>&nbsp;</td>\n";
1489 }
1490 echo "</tr>\n";
1491 }
1492 echo "</table>\n";
1493 }
1494}
1495
1496function renderUnmountedObjectsPortlet ()
1497{
1498 startPortlet ('Unmounted objects');
1499 $objs = getUnmountedObjects();
1500 if ($objs === NULL)
1501 {
591ff2c4 1502 showError ('getUnmountedObjects() failed', __FUNCTION__);
e673ee24
DO
1503 return;
1504 }
1505 global $root, $nextorder;
1506 $order = 'odd';
1507 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
18d94c29 1508 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset number</th><th>Barcode</th></tr>';
e673ee24
DO
1509 foreach ($objs as $obj)
1510 {
1511 echo "<tr class=row_${order}><td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></td>";
1512 echo "<td>${obj['label']}</td>";
18d94c29
DO
1513 echo "<td>${obj['asset_no']}</td>";
1514 echo "<td>${obj['barcode']}</td></tr>";
e673ee24
DO
1515 $order = $nextorder[$order];
1516 }
1517 echo "</table><br>\n";
1518 finishPortlet();
1519}
1520
1521function renderProblematicObjectsPortlet ()
1522{
1523 startPortlet ('Problematic objects');
1524 $objs = getProblematicObjects();
1525 if ($objs === NULL)
1526 {
591ff2c4 1527 showError ('getProblematicObjects() failed', __FUNCTION__);
e673ee24
DO
1528 return;
1529 }
1530 global $root, $nextorder;
1531 $order = 'odd';
1532 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1533 echo '<tr><th>Type</th><th>Common name</th></tr>';
1534 foreach ($objs as $obj)
1535 {
1536 echo "<tr class=row_${order}><td>${obj['objtype_name']}</td>";
1537 echo "<td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></tr>";
1538 $order = $nextorder[$order];
1539 }
1540 echo "</table><br>\n";
1541 finishPortlet();
1542}
1543
7cc02fc1
DO
1544function renderObjectSpace ()
1545{
105cea6e 1546 global $root, $taglist, $tagtree;
7cc02fc1
DO
1547 echo "<table border=0 class=objectview>\n";
1548 echo "<tr><td class=pcleft width='50%'>";
1549 startPortlet ('View all by type');
1550 $groupInfo = getObjectGroupInfo();
1551 if ($groupInfo === NULL)
1552 {
1553 showError ('getObjectGroupInfo() failed', __FUNCTION__);
1554 return;
1555 }
1556 if (count ($groupInfo) == 0)
1557 echo "No objects exist in DB";
1558 else
1559 {
1560 echo '<div align=left><ul>';
1561 foreach ($groupInfo as $gi)
1562 echo "<li><a href='${root}?page=objgroup&group_id=${gi['id']}'>${gi['name']}</a> (${gi['count']})</li>";
1563 echo '</ul></div>';
1564 }
1565 finishPortlet();
1566
1567 echo '</td><td class=pcright>';
1568
1569 startPortlet ('View all by tag');
1570 if (count ($taglist) == 0)
1571 echo "No tags exist in DB";
1572 else
1573 renderTagCloud ('object');
1574 finishPortlet();
e673ee24
DO
1575 echo "</td></tr></table>\n";
1576}
1577
466dcbe6 1578function renderObjectGroup ()
7cc02fc1
DO
1579{
1580 global $root, $pageno, $tabno, $nextorder, $taglist, $tagtree;
2c6c7645 1581 assertUIntArg ('group_id', __FUNCTION__, TRUE);
7cc02fc1 1582 $group_id = $_REQUEST['group_id'];
a0d54e7e
DO
1583 $tagfilter = getTagFilter();
1584 $tagfilter_str = getTagFilterStr ($tagfilter);
7cc02fc1
DO
1585 echo "<table border=0 class=objectview>\n";
1586 echo "<tr><td class=pcleft width='25%'>";
1587 startPortlet ('change type');
1588 $groupInfo = getObjectGroupInfo();
1589 if ($groupInfo === NULL)
1590 {
1591 showError ('getObjectGroupInfo() failed', __FUNCTION__);
1592 return;
1593 }
1594 if (count ($groupInfo) == 0)
1595 echo "No objects exist in DB";
1596 else
1597 {
1598 echo '<div align=left><ul>';
1599 foreach ($groupInfo as $gi)
1600 {
a0d54e7e 1601 echo "<li><a href='${root}?page=${pageno}&group_id=${gi['id']}${tagfilter_str}'>";
105cea6e
DO
1602 if ($gi['id'] == $group_id)
1603 echo '<strong>';
1604 echo "${gi['name']}</a>";
1605 if ($gi['id'] == $group_id)
1606 echo '</strong>';
1607 echo " (${gi['count']})";
1608 if ($gi['id'] == $group_id)
1609 echo ' &larr;';
1610 echo "</li>";
7cc02fc1
DO
1611 }
1612 echo '</ul></div>';
1613 }
1614 finishPortlet();
1615
1616 echo '</td><td class=pcleft>';
1617
1618 startPortlet ('Objects');
1619 $objects = getObjectList ($group_id, $tagfilter);
1620 if ($objects === NULL)
1621 {
1622 showError ('getObjectList() failed', __FUNCTION__);
1623 return;
1624 }
1625 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1626 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Barcode</th><th>Rack</th></tr>';
1627 $order = 'odd';
1628 foreach ($objects as $obj)
1629 {
1630 echo "<tr class=row_${order}><td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></td>";
1631 echo "<td>${obj['label']}</td>";
1632 echo "<td>${obj['asset_no']}</td>";
1633 echo "<td>${obj['barcode']}</td>";
1634 if ($obj['rack_id'])
1635 echo "<td><a href='${root}?page=rack&rack_id=${obj['rack_id']}'>${obj['Rack_name']}</a></td>";
1636 else
1637 echo '<td>Unmounted</td>';
1638 echo '</tr>';
1639 $order = $nextorder[$order];
1640 }
1641 echo '</table>';
1642 finishPortlet();
1643
1644 echo "</td><td class=pcright width='25%'>";
1645
a0d54e7e 1646 renderTagFilterPortlet ($tagfilter, 'object', 'group_id', $group_id);
7cc02fc1 1647 echo "</td></tr></table>\n";
e673ee24
DO
1648}
1649
1650function renderEmptyPortsSelect ($port_id, $type_id)
1651{
1652 $ports = getEmptyPortsOfType($type_id);
1653 usort($ports, 'sortEmptyPorts');
1654 foreach ($ports as $port)
1655 {
1656 if ($port_id == $port['Port_id'])
1657 continue;
1658 echo "<option value='${port['Port_id']}' onclick='getElementById(\"remote_port_name\").value=\"${port['Port_name']}\"; getElementById(\"remote_object_name\").value=\"${port['Object_name']}\";'>${port['Object_name']} ${port['Port_name']}</option>\n";
1659 }
1660}
1661
1662function renderObjectAddressesAndNames ()
1663{
1664 $addresses = getObjectAddressesAndNames();
1665 usort($addresses, 'sortObjectAddressesAndNames');
1666 foreach ($addresses as $address)
1667 {
1668 echo "<option value='${address['ip']}' onclick='getElementById(\"ip\").value=\"${address['ip']}\";'>${address['object_name']} ${address['name']} ${address['ip']}</option>\n";
1669 }
1670}
1671
1672// History viewer for history-enabled simple dictionaries.
1673function renderHistory ($object_type, $object_id)
1674{
1675 switch ($object_type)
1676 {
1677 case 'row':
1678 $query = "select ctime, user_name, name, deleted, comment from RackRowHistory where id = ${object_id} order by ctime";
1679 $header = '<tr><th>change time</th><th>author</th><th>rack row name</th><th>is deleted?</th><th>rack row comment</th></tr>';
1680 $extra = 4;
1681 break;
1682 case 'rack':
1683 $query =
1684 "select ctime, user_name, rh.name, rh.deleted, d.dict_value as name, rh.height, rh.comment " .
1685 "from RackHistory as rh left join Dictionary as d on rh.row_id = d.dict_key " .
1686 "natural join Chapter " .
1687 "where chapter_name = 'RackRow' and rh.id = ${object_id} order by ctime";
1688 $header = '<tr><th>change time</th><th>author</th><th>rack name</th><th>is deleted?</th><th>rack row name</th><th>rack height</th><th>rack comment</th></tr>';
1689 $extra = 6;
1690 break;
1691 case 'object':
1692 $query =
1693 "select ctime, user_name, name, label, barcode, asset_no, deleted, has_problems, dict_value, comment " .
1694 "from RackObjectHistory inner join Dictionary on objtype_id = dict_key natural join Chapter " .
1695 "where chapter_name = 'RackObjectType' and id=${object_id} order by ctime";
1696 $header = '<tr><th>change time</th><th>author</th><th>common name</th><th>visible label</th><th>barcode</th><th>asset no</th><th>is deleted?</th><th>has problems?</th><th>object type</th><th>comment</th></tr>';
1697 $extra = 9;
1698 break;
1699 default:
591ff2c4 1700 showError ("Uknown object type '${object_type}'", __FUNCTION__);
e673ee24
DO
1701 return;
1702 }
1703 global $dbxlink;
1704 $result = $dbxlink->query ($query);
1705 if ($result == NULL)
1706 {
591ff2c4 1707 showError ('SQL query failed', __FUNCTION__);
e673ee24
DO
1708 return;
1709 }
1710 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1711 $order = 'odd';
1712 global $nextorder;
1713 echo $header;
1714 while ($row = $result->fetch (PDO::FETCH_NUM))
1715 {
1716 echo "<tr class=row_${order}><td>${row[0]}</td>";
1717 for ($i = 1; $i <= $extra; $i++)
1718 echo "<td>" . $row[$i] . "</td>";
1719 echo "</tr>\n";
1720 $order = $nextorder[$order];
1721 }
1722 echo "</table><br>\n";
1723}
1724
1725function renderRackspaceHistory ()
1726{
1727 global $root, $nextorder, $pageno, $tabno;
1728 $order = 'odd';
1729 $history = getRackspaceHistory();
1730 // Show the last operation by default.
1731 if (isset ($_REQUEST['op_id']))
1732 $op_id = $_REQUEST['op_id'];
1733 elseif (isset ($history[0]['mo_id']))
1734 $op_id = $history[0]['mo_id'];
1735 else $op_id = NULL;
1736
1737 $omid = NULL;
1738 $nmid = NULL;
1739 $object_id = 1;
1740 if ($op_id)
1741 list ($omid, $nmid) = getOperationMolecules ($op_id);
1742
1743 // Main layout starts.
1744 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
1745
1746 // Left top portlet with old allocation.
1747 echo "<tr><td class=pcleft>";
1748 startPortlet ('Old allocation');
1749 if ($omid)
1750 {
1751 $oldMolecule = getMolecule ($omid);
1752 renderMolecule ($oldMolecule, $object_id);
1753 }
1754 else
1755 echo "nothing";
1756 finishPortlet();
1757
1758 echo '</td><td class=pcright>';
1759
1760 // Right top portlet with new allocation
1761 startPortlet ('New allocation');
1762 if ($nmid)
1763 {
1764 $newMolecule = getMolecule ($nmid);
1765 renderMolecule ($newMolecule, $object_id);
1766 }
1767 else
1768 echo "nothing";
1769 finishPortlet();
1770
1771 echo '</td></tr><tr><td colspan=2>';
1772
1773 // Bottom portlet with list
1774
1775 startPortlet ('Rackspace allocation history');
1776 echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
1777 echo "<tr><th>timestamp</th><th>author</th><th>rack object ID</th><th>rack object type</th><th>rack object name</th><th>comment</th></tr>\n";
1778 foreach ($history as $row)
1779 {
1780 if ($row['mo_id'] == $op_id)
1781 $class = 'hl';
1782 else
1783 $class = "row_${order}";
1784 echo "<tr class=${class}><td><a href='${root}?page=${pageno}&tab=${tabno}&op_id=${row['mo_id']}'>${row['ctime']}</a></td>";
1785 echo "<td>${row['user_name']}</td>";
1786 echo "<td>${row['ro_id']}</td><td>${row['objtype_name']}</td><td>${row['name']}</td><td>${row['comment']}</td>\n";
1787 echo "</tr>\n";
1788 $order = $nextorder[$order];
1789 }
1790 echo "</table>\n";
1791 finishPortlet();
1792
1793 echo '</td></tr></table>';
1794
1795}
1796
1797function renderAddressspace ()
1798{
b3c50e6c 1799 global $root, $page;
a7fe7729 1800
74ccacff
DO
1801 echo "<table border=0 class=objectview>\n";
1802 echo "<tr><td class=pcleft>";
1803
a7fe7729 1804 startPortlet ('Subnets');
e673ee24 1805 echo "<table class='widetable' border=0 cellpadding=10 cellspacing=0 align='center'>\n";
932cf41f 1806 $tagfilter = getTagFilter();
74ccacff 1807 $addrspaceList = getAddressspaceList ($tagfilter);
119f2ad2 1808 echo "<tr><th>Subnet</th><th>Name</th><th>Utilization</th></tr>";
e673ee24
DO
1809 foreach ($addrspaceList as $iprange)
1810 {
119f2ad2
DO
1811 $range = getIPRange ($iprange['id']);
1812 $total = ($iprange['ip_bin'] | $iprange['mask_bin_inv']) - ($iprange['ip_bin'] & $iprange['mask_bin']) + 1;
1813 $used = count ($range['addrlist']);
1814 echo "<tr><td class=tdleft><a href='${root}?page=iprange&id=${iprange['id']}'>${iprange['ip']}/${iprange['mask']}</a></td>";
1815 echo "<td class=tdleft>${iprange['name']}</td><td class=tdleft>";
1816 renderProgressBar ($used/$total);
1817 echo " ${used}/${total}</td></tr>";
e673ee24
DO
1818 }
1819 echo "</table>\n";
a7fe7729 1820 finishPortlet();
74ccacff 1821 echo '</td><td class=pcright>';
5b7bd02e 1822 renderTagFilterPortlet ($tagfilter, 'ipv4net');
74ccacff 1823 echo "</td></tr></table>\n";
f973f491 1824}
a7fe7729 1825
f973f491
DO
1826function renderIPv4SLB ()
1827{
80e85ea1 1828 global $root, $page, $nextorder;
a7fe7729 1829
6fec9f39 1830 startPortlet ('SLB configuration');
b3c50e6c
DO
1831 echo "<table border=0 width='100%'><tr>";
1832 foreach (array ('vservices', 'rspools', 'rservers', 'lbs') as $pno)
e57dca7f 1833 echo "<td><h3><a href='${root}?page=${pno}'>" . $page[$pno]['title'] . "</a></h3></td>";
b3c50e6c
DO
1834 echo '</tr></table>';
1835 finishPortlet();
1836
c3bdc503 1837 $summary = getSLBSummary();
6fec9f39 1838 startPortlet ('SLB tactical overview');
4cadac8f
DO
1839 // A single id-keyed array isn't used here to preserve existing
1840 // order of LBs returned by getSLBSummary()
c3bdc503
DO
1841 $lblist = array();
1842 $lbdname = array();
4cadac8f 1843 foreach ($summary as $vipdata)
da04825a 1844 foreach (array_keys ($vipdata['lblist']) as $lb_object_id)
c3bdc503
DO
1845 if (!in_array ($lb_object_id, $lblist))
1846 {
1847 $oi = getObjectInfo ($lb_object_id);
1848 $lbdname[$lb_object_id] = $oi['dname'];
1849 $lblist[] = $lb_object_id;
1850 }
1851 if (!count ($summary))
1852 echo 'none configured';
1853 else
1854 {
80e85ea1 1855 $order = 'odd';
c3bdc503 1856 echo "<table class='widetable' border=0 cellpadding=5 cellspacing=0 align='center'>\n";
a7bc13c8 1857 echo "<tr><th>VS&nbsp;&darr; LB&nbsp;&rarr;</th>";
c3bdc503 1858 foreach ($lblist as $lb_object_id)
71b8bda1 1859 echo "<th><a href='${root}?page=object&tab=default&object_id=${lb_object_id}'>" . $lbdname[$lb_object_id] . "</a></th>";
c3bdc503 1860 echo "</tr>\n";
4cadac8f
DO
1861 foreach ($summary as $vsid => $vsdata)
1862 {
80e85ea1 1863 echo "<tr class=row_${order}><td class=tdleft><a href='$root?page=vservice&tab=default&id=${vsid}'>";
8d790216 1864 echo buildVServiceName ($vsdata);
6fec9f39
DO
1865 echo '</a>';
1866 if (!empty ($vsdata['name']))
1867 echo " (${vsdata['name']})";
1868 echo "</td>";
4cadac8f 1869 foreach ($lblist as $lb_object_id)
da04825a 1870 {
60fbcece 1871 echo '<td class=tdleft>';
2b4eee17 1872 if (!isset ($vsdata['lblist'][$lb_object_id]))
da04825a
DO
1873 echo '&nbsp;';
1874 else
6fec9f39
DO
1875 {
1876 echo $vsdata['lblist'][$lb_object_id]['size'];
c0ae6968 1877 echo " (<a href='${root}?page=rspool&pool_id=";
6fec9f39
DO
1878 echo $vsdata['lblist'][$lb_object_id]['id'] . "'>";
1879 echo $vsdata['lblist'][$lb_object_id]['name'] . '</a>)';
1880 }
da04825a
DO
1881 echo '</td>';
1882 }
1883 echo "</tr>\n";
80e85ea1 1884 $order = $nextorder[$order];
4cadac8f 1885 }
c3bdc503
DO
1886 echo "</table>\n";
1887 }
a7fe7729 1888 finishPortlet ();
e673ee24
DO
1889}
1890
1891function renderAddNewRange ()
1892{
1893 global $root, $pageno, $tabno;
1894 showMessageOrError();
2a201216 1895
5c0bb421 1896 startPortlet ("Add New");
2a201216 1897 echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
5c0bb421 1898 echo "<tr><th>Address range</th><th>Name</th><th>connected network</th><th>assign tags</th><th>&nbsp;</th></tr>\n";
2a201216
DY
1899 echo "<form name='add_new_range' action='process.php'>\n";
1900 echo "<input type=hidden name=op value=addRange>\n";
1901 echo "<input type=hidden name=page value='${pageno}'>\n";
1902 echo "<input type=hidden name=tab value='${tabno}'>\n";
5c0bb421 1903 echo "<tr valign=top><td class='tdcenter'><input type=text name='range' size=18 class='live-validate' tabindex=1></td>\n";
7059c1d2
DO
1904 echo "<td class='tdcenter'><input type=text name='name' size='20' tabindex=2></td>\n";
1905 echo "<td class='tdcenter'><input type=checkbox name='is_bcast' tabindex=3 checked></td>\n";
5c0bb421
DO
1906 echo "<td>\n";
1907 renderTagSelect();
1908 echo "</td>\n";
1909 echo "<td class='tdcenter'><input type=submit value='Add a new range' tabindex=4></td>\n";
1910 echo "</td></tr>\n";
2a201216 1911 echo "</form></table><br><br>\n";
5c0bb421 1912 finishPortlet();
2a201216 1913
5c0bb421 1914 startPortlet ("Manage Existing");
2a201216 1915 echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
e673ee24 1916 $addrspaceList = getAddressspaceList();
283824c8 1917 echo "<tr><th>&nbsp;</th><th>Address range</th><th>Name</th><th>Utilization</th></tr>";
e673ee24
DO
1918 foreach ($addrspaceList as $iprange)
1919 {
1920 $range = getIPRange($iprange['id']);
dc462202 1921 $usedips = count ($range['addrlist']);
283824c8 1922 $totalips = ($iprange['ip_bin'] | $iprange['mask_bin_inv']) - ($iprange['ip_bin'] & $iprange['mask_bin']) + 1;
0c4605ab 1923 echo "<tr><td>";
e673ee24
DO
1924 if ($usedips == 0)
1925 {
0c4605ab 1926 echo "<a href='process.php?op=delRange&page=${pageno}&tab=${tabno}&id=${iprange['id']}'>";
e673ee24 1927 printImageHREF ('delete', 'Delete this IP range');
0c4605ab 1928 echo "</a>";
e673ee24
DO
1929 }
1930 else
0c4605ab 1931 printImageHREF ('nodelete', 'There are IP addresses allocated or reserved');
20c901a7
DO
1932 echo "</td>\n<td class=tdleft><a href='${root}?page=iprange&id=${iprange['id']}'>";
1933 echo "${iprange['ip']}/${iprange['mask']}</a></td><td class=tdleft>${iprange['name']}";
1934 echo "</td><td class=tdleft>";
283824c8
DO
1935 renderProgressBar ($usedips / $totalips);
1936 echo " ${usedips}/${totalips}";
e673ee24
DO
1937 echo "</td></tr>";
1938 }
cee27f1d 1939 echo "</table>";
5c0bb421 1940 finishPortlet();
e673ee24
DO
1941}
1942
2fe5476a 1943function renderIPRange ($id)
e673ee24 1944{
41bd8c87 1945 global $root, $pageno, $tabno;
545478d0
DO
1946 $netmaskbylen = array
1947 (
1948 32 => '255.255.255.255',
1949 31 => '255.255.255.254',
1950 30 => '255.255.255.252',
1951 29 => '255.255.255.248',
1952 28 => '255.255.255.240',
1953 27 => '255.255.255.224',
1954 26 => '255.255.255.192',
1955 25 => '255.255.255.128',
1956 24 => '255.255.255.0',
1957 23 => '255.255.254.0',
1958 22 => '255.255.252.0',
1959 21 => '255.255.248.0',
1960 20 => '255.255.240.0',
1961 19 => '255.255.224.0',
1962 18 => '255.255.192.0',
1963 17 => '255.255.128.0',
1964 16 => '255.255.0.0',
1965 15 => '255.254.0.0',
1966 14 => '255.252.0.0',
1967 13 => '255.248.0.0',
1968 12 => '255.240.0.0',
1969 11 => '255.224.0.0',
1970 10 => '255.192.0.0',
1971 9 => '255.128.0.0',
1972 8 => '255.0.0.0',
1973 7 => '254.0.0.0',
1974 6 => '252.0.0.0',
1975 5 => '248.0.0.0',
1976 4 => '240.0.0.0',
1977 3 => '224.0.0.0',
1978 2 => '192.0.0.0',
1979 1 => '128.0.0.0'
1980 );
1981 $wildcardbylen = array
1982 (
1983 32 => '0.0.0.0',
1984 31 => '0.0.0.1',
1985 30 => '0.0.0.3',
1986 29 => '0.0.0.7',
1987 28 => '0.0.0.15',
1988 27 => '0.0.0.31',
1989 26 => '0.0.0.63',
1990 25 => '0.0.0.127',
1991 24 => '0.0.0.255',
1992 23 => '0.0.1.255',
1993 22 => '0.0.3.255',
1994 21 => '0.0.7.255',
1995 20 => '0.0.15.255',
1996 19 => '0.0.31.255',
1997 18 => '0.0.63.255',
1998 17 => '0.0.127.255',
1999 16 => '0.0.255.25',
2000 15 => '0.1.255.255',
2001 14 => '0.3.255.255',
2002 13 => '0.7.255.255',
2003 12 => '0.15.255.255',
2004 11 => '0.31.255.255',
2005 10 => '0.63.255.255',
2006 9 => '0.127.255.255',
2007 8 => '0.255.255.255',
2008 7 => '1.255.255.255',
2009 6 => '3.255.255.255',
2010 5 => '7.255.255.255',
2011 4 => '15.255.255.255',
2012 3 => '31.255.255.255',
2013 2 => '63.255.255.255',
2014 1 => '127.255.255.255'
2015 );
b901bf1f 2016 $maxperpage = getConfigVar ('IPV4_ADDRS_PER_PAGE');
e673ee24
DO
2017 if (isset($_REQUEST['pg']))
2018 $page = $_REQUEST['pg'];
2019 else
2020 $page=0;
2021
e673ee24 2022 $range = getIPRange($id);
2034d968
DO
2023 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
2024 echo "<tr><td colspan=2 align=center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></td></tr>\n";
2025
2026 echo "<tr><td class=pcleft width='50%'>";
2027 startPortlet ('summary');
2028 $total = ($range['ip_bin'] | $range['mask_bin_inv']) - ($range['ip_bin'] & $range['mask_bin']) + 1;
2029 $used = count ($range['addrlist']);
2030 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
2031 echo "<tr><th width='50%' class=tdright>Utilization:</th><td class=tdleft>";
2032 renderProgressBar ($used/$total);
2033 echo "&nbsp;${used}/${total}</td></tr>\n";
545478d0
DO
2034 echo "<tr><th width='50%' class=tdright>Netmask:</th><td class=tdleft>";
2035 echo $netmaskbylen[$range['mask']];
2036 echo "</td></tr>\n";
2037 echo "<tr><th width='50%' class=tdright>Wildcard bits:</th><td class=tdleft>";
2038 echo $wildcardbylen[$range['mask']];
2039 echo "</td></tr>\n";
e2ac59cf 2040 printTagTRs ("${root}?page=ipv4space&");
2034d968
DO
2041 echo "</table><br>\n";
2042 finishPortlet();
2043 echo "</td>\n";
e673ee24 2044
2034d968
DO
2045 echo "<td class=pcright>";
2046 startPortlet ('details');
e673ee24
DO
2047 $startip = $range['ip_bin'] & $range['mask_bin'];
2048 $endip = $range['ip_bin'] | $range['mask_bin_inv'];
2049 $realstartip = $startip;
2050 $realendip = $endip;
2051 $numpages = 0;
2052 if($endip - $startip > $maxperpage)
2053 {
e673ee24
DO
2054 $numpages = ($endip - $startip)/$maxperpage;
2055 $startip = $startip + $page * $maxperpage;
2056 $endip = $startip + $maxperpage-1;
2057 }
2058 echo "<center>";
b901bf1f
DO
2059 if ($numpages)
2060 echo '<h3>' . long2ip ($startip) . ' ~ ' . long2ip ($endip) . '</h3>';
e673ee24
DO
2061 for ($i=0; $i<$numpages; $i++)
2062 {
2063 if ($i == $page)
2064 echo "<b>$i</b> ";
2065 else
a60e0851 2066 echo "<a href='${root}?page=${pageno}&tab=${tabno}&id=$id&pg=$i'>$i</a> ";
e673ee24
DO
2067 }
2068 echo "</center>";
2069
2070 echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n";
2071 echo "<tr><th>Address</th><th>Name</th><th>Allocation</th></tr>\n";
2072
2073
2074 for($ip = $startip; $ip<=$endip; $ip++)
2075 {
dcee8072 2076 if (isset ($range['addrlist'][$ip]))
e673ee24
DO
2077 {
2078 $numshared = countRefsOfType($range['addrlist'][$ip]['references'], 'shared', 'eq');
2079 $numreg = countRefsOfType($range['addrlist'][$ip]['references'], 'regular', 'eq');
2080 $numvirt = countRefsOfType($range['addrlist'][$ip]['references'], 'virtual', 'eq');
602663f4
DO
2081 $numlb = count ($range['addrlist'][$ip]['lbrefs']);
2082 $numrs = count ($range['addrlist'][$ip]['rsrefs']);
e673ee24
DO
2083
2084 $addr = $range['addrlist'][$ip];
2085 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
24e85a1a 2086 echo "<tr class='trerror'>";
e485e609 2087 elseif ( $addr['reserved'] == 'yes' and $numshared+$numreg+$numvirt+$numlb+$numrs > 0)
24e85a1a 2088 echo "<tr class='trerror'>";
e673ee24
DO
2089 elseif ( $addr['reserved'] == 'yes')
2090 echo "<tr class='trbusy'>";
602663f4 2091 elseif ( $numshared > 0 || $numreg > 0 || $numlb > 0 || $numrs > 0)
e673ee24
DO
2092 echo "<tr class='trbusy'>";
2093 else
2094 echo "<tr>";
2095
edcd5a3d
DO
2096 echo "<td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
2097 echo "<td class=tdleft>${addr['name']}</td><td class=tdleft>";
6131056c 2098 $delim = '';
602663f4 2099 $prologue = '';
e673ee24 2100 if ( $addr['reserved'] == 'yes')
6131056c 2101 {
55434dd5 2102 echo "<b>Reserved</b> ";
6131056c
DO
2103 $delim = '; ';
2104 }
e673ee24
DO
2105 foreach ($range['addrlist'][$ip]['references'] as $ref)
2106 {
fc0e3978
DO
2107 echo "${delim}<a href='${root}?page=object&object_id=${ref['object_id']}";
2108 echo "&hl_ipv4_addr=${addr['ip']}'>";
db88e2de 2109 echo $ref['name'] . (empty ($ref['name']) ? '' : '@');
e26b085f
DO
2110 echo "${ref['object_name']}</a>";
2111 $delim = '; ';
e673ee24 2112 }
602663f4
DO
2113 if ($delim != '')
2114 {
2115 $delim = '';
2116 $prologue = '<br>';
2117 }
2118 foreach ($range['addrlist'][$ip]['lbrefs'] as $ref)
2119 {
2120 echo $prologue;
2121 $prologue = '';
2122 echo "${delim}<a href='${root}?page=object&object_id=${ref['object_id']}'>";
2123 echo "${ref['object_name']}</a>:<a href='${root}?page=vservice&id=${ref['vs_id']}'>";
2124 echo "${ref['vport']}/${ref['proto']}</a>&rarr;";
2125 $delim = '; ';
2126 }
2127 if ($delim != '')
2128 {
2129 $delim = '';
2130 $prologue = '<br>';
2131 }
2132 foreach ($range['addrlist'][$ip]['rsrefs'] as $ref)
2133 {
2134 echo $prologue;
2135 $prologue = '';
c0ae6968 2136 echo "${delim}&rarr;${ref['rsport']}@<a href='${root}?page=rspool&pool_id=${ref['rspool_id']}'>";
602663f4
DO
2137 echo "${ref['rspool_name']}</a>";
2138 $delim = '; ';
2139 }
e673ee24
DO
2140 echo "</td></tr>\n";
2141 }
2142 else
2143 {
2144 echo "<tr><td><a href='${root}?page=ipaddress&ip=".long2ip($ip)."'>".long2ip($ip)."</a></td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
2145 }
2146 }
2147
2148 echo "</table>";
2034d968
DO
2149 finishPortlet();
2150 echo "</td></tr></table>\n";
e673ee24
DO
2151}
2152
2fe5476a 2153function renderIPRangeProperties ($id)
e673ee24
DO
2154{
2155 global $pageno, $tabno;
e673ee24
DO
2156 showMessageOrError();
2157 $range = getIPRange($id);
2158 echo "<center><h1>${range['ip']}/${range['mask']}</h1></center>\n";
2159 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
2160 echo "<form action='process.php'><input type=hidden name=op value=editRange>";
2161 echo "<input type=hidden name=page value='${pageno}'>\n";
2162 echo "<input type=hidden name=tab value='${tabno}'>\n";
2163 echo "<input type=hidden name=id value='${id}'>";
2164 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='${range['name']}'></tr><tr><td colspan=2 class='tdcenter'><input type=submit value='Update range'></td></form></tr>";
2165 echo "</table>\n";
2166
2167}
2168
2169function renderIPAddress ()
2170{
2171 global $root;
2172 $ip = $_REQUEST['ip'];
68225375
DO
2173 $address = getIPAddress ($ip);
2174dump($address);
2175 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
2176 echo "<tr><td colspan=2 align=center><h1>${ip}</h1></td></tr>\n";
e673ee24 2177 if ($address['exists'] == 1)
68225375 2178 echo "<tr><td colspan=2 align=center><h2>${address['name']}</h2></td></tr>\n";
e673ee24 2179
68225375
DO
2180 echo "<tr><td class=pcleft>";
2181 startPortlet ('summary');
2182 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
2183 echo "<tr><th width='50%' class=tdright>Allocations:</th><td class=tdleft>" . count ($address['bonds']) . "</td></tr>\n";
2184 echo "<tr><th width='50%' class=tdright>Originated NAT connections:</th><td class=tdleft>" . count ($address['outpf']) . "</td></tr>\n";
2185 echo "<tr><th width='50%' class=tdright>Arriving NAT connections:</th><td class=tdleft>" . count ($address['inpf']) . "</td></tr>\n";
2186 echo "<tr><th width='50%' class=tdright>SLB virtual services:</th><td class=tdleft>" . count ($address['vslist']) . "</td></tr>\n";
2187 echo "<tr><th width='50%' class=tdright>SLB real servers:</th><td class=tdleft>" . count ($address['rslist']) . "</td></tr>\n";
2188 printTagTRs();
2189 echo "</table><br>\n";
2190 finishPortlet();
2191 echo "</td>\n";
e673ee24 2192
68225375 2193 echo "<td class=pcright>";
e673ee24
DO
2194 $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
2195 $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
2196 $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
2197
59bebe2b
DO
2198 if ($address['reserved'] == 'yes' or ($numshared + $numreg + $numvirt) > 0)
2199 {
68225375 2200 startPortlet ('Allocations');
59bebe2b
DO
2201 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
2202 echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
2203 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
2204 $class='trerror';
2205 elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
2206 $class='trerror';
2207 else
2208 $class='';
e673ee24 2209
59bebe2b
DO
2210 if ($address['reserved'] == 'yes')
2211 echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
2212 foreach ($address['bonds'] as $bond)
2213 {
fc0e3978
DO
2214 echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}";
2215 echo "&hl_ipv4_addr=${ip}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
59bebe2b
DO
2216 switch ($bond['type'])
2217 {
2218 case 'virtual':
2219 echo "Virtual";
2220 break;
2221 case 'shared':
2222 echo "Shared";
2223 break;
2224 case 'regular':
2225 echo "Regular";
2226 break;
2227 }
2228 echo "</b></td></tr>\n";
2229 }
2230 echo "</table><br><br>";
2231 finishPortlet();
2232 }
e673ee24 2233
59bebe2b 2234 if (count ($address['vslist']))
e673ee24 2235 {
59bebe2b
DO
2236 startPortlet ('Virtual services (' . count ($address['vslist']) . ')');
2237 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
2238 echo "<tr><th>VS</th><th>name</th></tr>\n";
2239 foreach ($address['vslist'] as $vsinfo)
e673ee24 2240 {
59bebe2b
DO
2241 echo "<tr><td class=tdleft><a href='${root}?page=vservice&id=${vsinfo['id']}'>";
2242 echo buildVServiceName ($vsinfo) . "</a></td><td class=tdleft>";
5fe1ed76 2243 echo $vsinfo['name'] . "</td></tr>\n";
e673ee24 2244 }
59bebe2b
DO
2245 echo "</table><br><br>";
2246 finishPortlet();
e673ee24 2247 }
5fe1ed76
DO
2248
2249 if (count ($address['rslist']))
2250 {
2251 startPortlet ('Real servers (' . count ($address['rslist']) . ')');
2252 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
53f4b619 2253 echo "<tr><th>&nbsp;</th><th>port</th><th>RS pool</th></tr>\n";
5fe1ed76
DO
2254 foreach ($address['rslist'] as $rsinfo)
2255 {
2256 echo "<tr><td>";
2257 if ($rsinfo['inservice'] == 'yes')
2258 printImageHREF ('inservice', 'in service');
2259 else
2260 printImageHREF ('notinservice', 'NOT in service');
c0ae6968 2261 echo "</td><td class=tdleft>${rsinfo['rsport']}</td><td class=tdleft><a href='${root}?page=rspool&pool_id=${rsinfo['pool_id']}'>";
5fe1ed76
DO
2262 echo $rsinfo['poolname'] . "</a></td></tr>\n";
2263 }
2264 echo "</table><br><br>";
2265 finishPortlet();
2266 }
2267
68225375
DO
2268 if (count ($address['outpf']))
2269 {
2270 startPortlet ('originating NAT rules');
2271 finishPortlet();
2272 }
2273 echo "</td></tr>";
2274 echo "</table>\n";
e673ee24
DO
2275}
2276
2277function renderIPAddressProperties ()
2278{
2279 global $pageno, $tabno;
2280 $ip = $_REQUEST['ip'];
2281 showMessageOrError();
2282 $address = getIPAddress($ip);
2283 echo "<center><h1>$ip</h1></center>\n";
2284 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
2285 echo "<form action='process.php'><input type=hidden name=op value=editAddress>";
2286 echo "<input type=hidden name=page value='${pageno}'>\n";
2287 echo "<input type=hidden name=tab value='${tabno}'>\n";
2288 echo "<input type=hidden name=ip value='${ip}'>";
2289 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='".($address['exists']==1?$address['name']:'')."'></tr>";
2290 echo "<td class='tdright'>Reserved:</td><td class='tdleft'><input type=checkbox name=reserved size=20 ".($address['exists']==1?(($address['reserved']=='yes')?'checked':''):'')."></tr>";
2291 echo "<tr><td colspan=2 class='tdcenter'><input type=submit value='Update address'></td></form></tr>";
2292 echo "</table>\n";
2293
2294}
2295
2296function renderIPAddressAssignment ()
2297{
2298 global $pageno, $tabno, $root;
2299 $ip = $_REQUEST['ip'];
2300 $address = getIPAddress($ip);
2301
2302 showMessageOrError();
2303 echo "<center><h1>$ip</h1></center>\n";
2304
2305
2306 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
b4c1ef87 2307 echo "<tr><th>&nbsp;</th><th>object name</th><th>object interface</th><th>allocation type</th><th>&nbsp;</th></tr>\n";
e673ee24
DO
2308
2309 $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
2310 $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
2311 $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
2312
2313
2314 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
24e85a1a 2315 $class='trerror';
e673ee24 2316 elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
24e85a1a 2317 $class='trerror';
e673ee24
DO
2318 else
2319 $class='';
2320
2321
2322
2323 if ($address['reserved'] == 'yes')
2324 echo "<tr class='$class'><td colspan='5'><b>RESERVED</b></td></tr>";
2325 foreach ($address['bonds'] as $bond)
2326 {
2327 echo "<tr class='$class'><form action='process.php'>";
b4c1ef87 2328 echo "<input type=hidden name=op value='updIPv4Allocation'>";
e673ee24
DO
2329 echo "<input type=hidden name=page value='${pageno}'>";
2330 echo "<input type=hidden name=tab value='${tabno}'>";
2331 echo "<input type=hidden name=ip value='$ip'>";
2332 echo "<input type=hidden name=object_id value='${bond['object_id']}'>";
b4c1ef87 2333 echo "<td><a href='process.php?op=delIPv4Allocation&page=${pageno}&tab=${tabno}&ip=$ip&object_id=${bond['object_id']}'>";
e673ee24
DO
2334 printImageHREF ('delete', 'Unallocate address');
2335 echo "</a></td>";
fc0e3978 2336 echo "<td><a href='${root}?page=object&object_id=${bond['object_id']}&hl_ipv4_addr=${ip}'>${bond['object_name']}</td>";
e673ee24
DO
2337 echo "<td><input type='text' name='bond_name' value='${bond['name']}' size=10></td>";
2338 echo "<td><select name='bond_type'>";
2339 switch ($bond['type'])
2340 {
2341 case 'virtual':
2342 echo "<option value='regular'>Regular</option>";
2343 echo "<option value='virtual' selected>Virtual</option>";
2344 echo "<option value='shared'>Shared</option>";
2345 break;
2346 case 'shared':
2347 echo "<option value='regular'>Regular</option>";
2348 echo "<option value='virtual'>Virtual</option>";
2349 echo "<option value='shared' selected>Shared</option>";
2350 break;
2351 case 'regular':
2352 echo "<option value='regular' selected>Regular</option>";
2353 echo "<option value='virtual'>Virtual</option>";
2354 echo "<option value='shared'>Shared</option>";
2355 break;
2356 }
b4c1ef87
DO
2357 echo "</select></td><td>";
2358 printImageHREF ('save', 'Save changes', TRUE);
2359 echo "</td></form></tr>\n";
e673ee24 2360 }
b4c1ef87 2361 echo "<form action='process.php'><input type='hidden' name='op' value='addIPv4Allocation'>";
e673ee24
DO
2362 echo "<input type=hidden name=page value='${pageno}'>\n";
2363 echo "<input type=hidden name=tab value='${tabno}'>\n";
2364 echo "<input type='hidden' name='ip' value='$ip'>";
b4c1ef87
DO
2365 echo "<td>";
2366 printImageHREF ('add', 'new allocation', TRUE);
2367 echo "</td><td><select name='object_id'>";
e673ee24 2368
6dbdc7c7
DO
2369 foreach (explode (',', getConfigVar ('IPV4_PERFORMERS')) as $type)
2370 foreach (getObjectList ($type) as $object)
e673ee24 2371 echo "<option value='${object['id']}'>${object['dname']}</option>";
e673ee24
DO
2372
2373 echo "</select></td><td><input type='text' name='bond_name' value='' size=10></td>";
2374 echo "<td><select name='bond_type'><option value='regular'>Regular</option><option value='virtual'>Virtual</option><option value='shared'>Shared</option></select></td>";
b4c1ef87 2375 echo "<td>&nbsp;</td></form></tr>";
e673ee24
DO
2376 echo "</table><br><br>";
2377
2378}
2379
eeb4a5d8 2380function renderNATv4ForObject ($object_id = 0)
e673ee24
DO
2381{
2382 global $pageno, $tabno, $root;
2383
2384 $info = getObjectInfo ($object_id);
eeb4a5d8 2385 $forwards = getNATv4ForObject ($object_id);
e673ee24
DO
2386 $addresses = getObjectAddresses ($object_id);
2387 showMessageOrError();
f28fbe8b 2388 echo "<center><h2>locally performed NAT</h2></center>";
e673ee24
DO
2389
2390 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
d54b9495 2391 echo "<tr><th></th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Comment</th><th>&nbsp;</th></tr>\n";
e673ee24
DO
2392
2393 foreach ($forwards['out'] as $pf)
2394 {
24e85a1a 2395 $class='trerror';
e673ee24
DO
2396 $name='';
2397 foreach ($addresses as $addr)
2398 if ($addr['ip'] == $pf['localip'])
2399 {
2400 $class='';
2401 $name = $addr['name'];
2402 break;
2403 }
2404
2405 echo "<tr class='$class'>";
eeb4a5d8 2406 echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto']}&object_id=$object_id&page=${pageno}&tab=${tabno}'>";
4de22e7e
DO
2407 printImageHREF ('delete', 'Delete NAT rule');
2408 echo "</a></td>";
f28fbe8b
DO
2409 echo "<td>${pf['proto']}/${name}: <a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}";
2410 if (!empty ($pf['local_addr_name']))
2411 echo ' (' . $pf['local_addr_name'] . ')';
2412 echo "</td>";
e673ee24
DO
2413 echo "<td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
2414
2415 $address=getIPAddress($pf['remoteip']);
2416
2417 echo "<td class='description'>";
f28fbe8b
DO
2418 if (count ($address['bonds']))
2419 foreach($address['bonds'] as $bond)
2420 echo "<a href='${root}?page=object&tab=default&object_id=${bond['object_id']}'>${bond['object_name']}(${bond['name']})</a> ";
2421 elseif (!empty ($pf['remote_addr_name']))
2422 echo '(' . $pf['remote_addr_name'] . ')';
eeb4a5d8
DO
2423 echo "</td><form action='process.php'><input type='hidden' name='op' value='updPortForwarding'><input type=hidden name=page value='${pageno}'>";
2424 echo "<input type=hidden name=tab value='${tabno}'><input type='hidden' name='object_id' value='$object_id'>";
2425 echo "<input type='hidden' name='localip' value='${pf['localip']}'><input type='hidden' name='localport' value='${pf['localport']}'>";
2426 echo "<input type='hidden' name='remoteip' value='${pf['remoteip']}'><input type='hidden' name='remoteport' value='${pf['remoteport']}'>";
2427 echo "<input type='hidden' name='proto' value='${pf['proto']}'><td class='description'>";
d54b9495
DO
2428 echo "<input type='text' name='description' value='${pf['description']}'></td><td>";
2429 printImageHREF ('save', 'Save changes', TRUE);
2430 echo "</td></form></tr>";
e673ee24
DO
2431 }
2432 echo "<form action='process.php'><input type='hidden' name='op' value='forwardPorts'>";
2433 echo "<input type='hidden' name='object_id' value='$object_id'>";
2434 echo "<input type=hidden name=page value='${pageno}'>\n";
2435 echo "<input type=hidden name=tab value='${tabno}'>\n";
d54b9495
DO
2436 echo "<tr align='center'><td>";
2437 printImageHREF ('add', 'Add new NAT rule', TRUE);
2438 echo '</td><td>';
eeb4a5d8 2439 printSelect (array ('TCP' => 'TCP', 'UDP' => 'UDP'), 'proto');
52c3543f 2440 echo "<select name='localip' tabindex=1>";
e673ee24
DO
2441
2442 foreach ($addresses as $addr)
09992c16
DO
2443 echo "<option value='${addr['ip']}'>" . (empty ($addr['name']) ? '' : "${addr['name']}: ") .
2444 "${addr['ip']}" . (empty ($addr['address_name']) ? '' : " (${addr['address_name']})") . "</option>";
e673ee24 2445
52c3543f
DO
2446 echo "</select>:<input type='text' name='localport' size='4' tabindex=2></td>";
2447 echo "<td><input type='text' name='remoteip' id='remoteip' size='10' tabindex=3>";
4de22e7e
DO
2448 echo "<a href='javascript:;' onclick='window.open(\"${root}/find_object_ip_helper.php\", \"findobjectip\", \"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
2449 printImageHREF ('find', 'Find object');
2450 echo "</a>";
52c3543f 2451 echo ":<input type='text' name='remoteport' size='4' tabindex=4></td><td></td>";
d54b9495 2452 echo "<td colspan=1><input type='text' name='description' size='20' tabindex=5></td><td>&nbsp;</td></tr>";
e673ee24
DO
2453 echo "</form>";
2454
2455 echo "</table><br><br>";
2456
f28fbe8b 2457 echo "<center><h2>arriving NAT connections</h2></center>";
e673ee24
DO
2458 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
2459 echo "<tr><th></th><th>Source</th><th>Source objects</th><th>Target</th><th>Description</th></tr>\n";
2460
2461 foreach ($forwards['in'] as $pf)
2462 {
eeb4a5d8 2463 echo "<tr><td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto']}&object_id=${pf['object_id']}&page=${pageno}&tab=${tabno}'>";
4de22e7e
DO
2464 printImageHREF ('delete', 'Delete NAT rule');
2465 echo "</a></td>";
e673ee24
DO
2466 echo "<td>${pf['proto']}/<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
2467 echo "<td class='description'><a href='${root}?page=object&tab=default&object_id=${pf['object_id']}'>${pf['object_name']}</a>";
2468 echo "</td><td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
2469 echo "<td class='description'>${pf['description']}</td></tr>";
2470 }
2471
e673ee24 2472 echo "</table><br><br>";
e673ee24
DO
2473}
2474
e673ee24
DO
2475function renderAddMultipleObjectsForm ()
2476{
20c901a7 2477 global $root, $pageno, $tabno, $nextorder;
e673ee24
DO
2478
2479 $type_id = array();
7f791d1d 2480 $global_type_id = 0;
e673ee24
DO
2481 $name = array();
2482 $asset_no = array();
2483 $keepvalues = FALSE;
7f791d1d 2484 $log = array();
e673ee24 2485 // Look for current submit.
7f791d1d 2486 if (isset ($_REQUEST['got_fast_data']))
e673ee24 2487 {
f60bb422 2488 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
e673ee24 2489 $keepvalues = TRUE;
9c0b0016
DO
2490 $max = getConfigVar ('MASSCOUNT');
2491 for ($i = 0; $i < $max; $i++)
e673ee24
DO
2492 {
2493 if (!isset ($_REQUEST["${i}_object_type_id"]))
2494 {
2495 $log[] = array ('code' => 'error', 'message' => "Submitted form is invalid at line " . $i + 1);
2496 break;
2497 }
2c6c7645
DO
2498 assertUIntArg ("${i}_object_type_id", __FUNCTION__, TRUE);
2499 assertStringArg ("${i}_object_name", __FUNCTION__, TRUE);
2500 assertStringArg ("${i}_object_label", __FUNCTION__, TRUE);
2501 assertStringArg ("${i}_object_asset_no", __FUNCTION__, TRUE);
2502 assertStringArg ("${i}_object_barcode", __FUNCTION__, TRUE);
e673ee24
DO
2503 $type_id[$i] = $_REQUEST["${i}_object_type_id"];
2504 // Save user input for possible rendering.
2505 $name[$i] = $_REQUEST["${i}_object_name"];
2506 $label[$i] = $_REQUEST["${i}_object_label"];
2507 $asset_no[$i] = $_REQUEST["${i}_object_asset_no"];
2508 $barcode[$i] = $_REQUEST["${i}_object_barcode"];
2509
f60bb422 2510 // It's better to skip silently, than to print a notice.
e673ee24
DO
2511 if ($type_id[$i] == 0)
2512 continue;
f60bb422 2513 if (commitAddObject ($name[$i], $label[$i], $barcode[$i], $type_id[$i], $asset_no[$i], $taglist) === TRUE)
e673ee24
DO
2514 $log[] = array ('code' => 'success', 'message' => "Added new object '${name[$i]}'");
2515 else
4d2e93f2 2516 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddObject() failed');
e673ee24 2517 }
e673ee24 2518 }
7f791d1d
DO
2519 elseif (isset ($_REQUEST['got_very_fast_data']))
2520 {
f60bb422 2521 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
7f791d1d 2522 $keepvalues = TRUE;
2c6c7645
DO
2523 assertUIntArg ('global_type_id', __FUNCTION__, TRUE);
2524 assertStringArg ('namelist', __FUNCTION__, TRUE);
7f791d1d
DO
2525 $global_type_id = $_REQUEST['global_type_id'];
2526 if ($global_type_id == 0)
2527 {
2528 if (!empty ($_REQUEST['namelist']))
2529 $log[] = array ('code' => 'error', 'message' => 'Object type is not selected, check the form below');
2530 else
2531 $log[] = array ('code' => 'error', 'message' => 'Empty form has been ignored. Cheers.');
2532 }
2533 else
2534 {
2535 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
2536 $names1 = explode ('\n', $_REQUEST['namelist']);
2537 $names2 = array();
2538 foreach ($names1 as $line)
2539 {
2540 $parts = explode ('\r', $line);
2541 reset ($parts);
2542 if (empty ($parts[0]))
2543 continue;
2544 else
2545 $names2[] = rtrim ($parts[0]);
2546 }
2547 foreach ($names2 as $cname)
f60bb422 2548 if (commitAddObject ($cname, '', '', $global_type_id, '', $taglist) === TRUE)
7f791d1d
DO
2549 $log[] = array ('code' => 'success', 'message' => "Added new object '${cname}'");
2550 else
2551 $log[] = array ('code' => 'error', 'message' => "Could not add '${cname}'");
2552 }
2553 }
2554 printLog ($log);
e673ee24
DO
2555
2556 // Render a form for the next.
2557 $typelist = getObjectTypeList();
4c330a14 2558 $typelist[0] = 'select type...';
7f791d1d 2559
f60bb422
DO
2560 startPortlet ('Distinct types, same tags');
2561 $max = getConfigVar ('MASSCOUNT');
20c901a7 2562 echo "<form name=fastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
e673ee24 2563 echo '<table border=0 align=center>';
f60bb422
DO
2564 echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th>";
2565 echo "<th>Asset tag</th><th>Barcode</th><th>Tags</th></tr>\n";
7f791d1d 2566 // If a user forgot to select object type on input, we keep his
e673ee24 2567 // previous input in the form.
9c0b0016 2568 for ($i = 0; $i < $max; $i++)
e673ee24 2569 {
7f791d1d 2570 echo '<tr><td>';
e7ade6bf
DO
2571 // Don't employ DEFAULT_OBJECT_TYPE to avoid creating ghost records for pre-selected empty rows.
2572 printSelect ($typelist, "${i}_object_type_id", 0);
e673ee24
DO
2573 echo '</td>';
2574 echo "<td><input type=text size=30 name=${i}_object_name";
f60bb422 2575 if ($keepvalues and isset ($name[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2576 echo " value='${name[$i]}'";
2577 echo "></td>";
2578 echo "<td><input type=text size=30 name=${i}_object_label";
f60bb422 2579 if ($keepvalues and isset ($label[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2580 echo " value='${label[$i]}'";
2581 echo "></td>";
2582 echo "<td><input type=text size=20 name=${i}_object_asset_no";
f60bb422 2583 if ($keepvalues and isset ($asset_no[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2584 echo " value='${asset_no[$i]}'";
2585 echo "></td>";
2586 echo "<td><input type=text size=10 name=${i}_object_barcode";
f60bb422 2587 if ($keepvalues and isset ($barcode[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2588 echo " value='${barcode[$i]}'";
2589 echo "></td>";
f60bb422
DO
2590 if ($i == 0)
2591 {
2592 echo "<td valign=top rowspan=${max}>";
2593 renderTagSelect();
2594 echo "</td>\n";
2595 }
e673ee24 2596 echo "</tr>\n";
e673ee24 2597 }
216c84bb 2598 echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Go!'></td></tr>\n";
e673ee24
DO
2599 echo "</form></table>\n";
2600 finishPortlet();
7f791d1d 2601
f60bb422 2602 startPortlet ('Same type, same tags');
20c901a7 2603 echo "<form name=veryfastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
f60bb422
DO
2604 echo "<table border=0 align=center><tr><th>names</th><th>type</th></tr>";
2605 echo "<tr><td rowspan=3><textarea name=namelist cols=40 rows=25>\n";
7f791d1d
DO
2606 if ($keepvalues and $global_type_id == 0)
2607 echo $_REQUEST['namelist'];
f60bb422
DO
2608 echo "</textarea></td><td valign=top>";
2609 printSelect ($typelist, "global_type_id", getConfigVar ('DEFAULT_OBJECT_TYPE'));
2610 echo "</td></tr>";
2611 echo "<tr><th>Tags</th></tr>";
2612 echo "<tr><td valign=top>";
2613 renderTagSelect();
2614 echo "</td></tr>";
2615 echo "<tr><td colspan=2><input type=submit name=got_very_fast_data value='Go!'></td></tr></table>\n";
2616 echo "</form>\n";
7f791d1d 2617 finishPortlet();
e673ee24
DO
2618}
2619
2620function printGreeting ()
2621{
59cd003e 2622 global $remote_username, $accounts, $root;
e673ee24 2623 $account = $accounts[$remote_username];
4eb5efb7 2624 echo "Hello, ${account['user_realname']}. This is RackTables " . CODE_VERSION . ". Click <a href='${root}?logout'>here</a> to logout.";
e673ee24
DO
2625}
2626
2627function renderSearchResults ()
2628{
2629 global $remote_username, $root;
2630 $terms = trim ($_REQUEST['q']);
2631 if (empty ($terms))
2632 {
591ff2c4 2633 showError ('Search string cannot be empty.', __FUNCTION__);
e673ee24
DO
2634 return;
2635 }
2636 if (!authorized ($remote_username, 'object', 'default'))
2637 {
591ff2c4 2638 showError ('You are not authorized for viewing information about objects.', __FUNCTION__);
e673ee24
DO
2639 return;
2640 }
ea5fc465 2641 $nhits = 0;
e673ee24
DO
2642 // If we search for L2 address, we can either find one or find none.
2643 if
2644 (
2645 preg_match ('/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i', $terms) or
2646 preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
ea5fc465
DO
2647 preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
2648 // STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
2649 preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms)
e673ee24
DO
2650 )
2651 // Search for L2 address.
2652 {
3ec29bf4
DO
2653 $terms = str_replace ('.', '', $terms);
2654 $terms = str_replace (':', '', $terms);
ea5fc465 2655 $terms = substr ($terms, -12);
e673ee24
DO
2656 $result = searchByl2address ($terms);
2657 if ($result !== NULL)
2658 {
ea5fc465
DO
2659 $nhits++;
2660 $lasthit = 'port';
2661 $summary['port'][] = $result;
e673ee24 2662 }
e673ee24
DO
2663 }
2664 elseif (preg_match ('/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?$/i', $terms))
2665 // Search for IP address.
2666 {
2667 $result = getRangeByIp ($terms);
2668 if ($result !== NULL)
2669 {
ea5fc465 2670 $nhits++;
bc3ab23e 2671 $lasthit = 'ipv4address1';
ea5fc465 2672 $summary['ipv4address1'][] = $terms;
e673ee24 2673 }
e673ee24
DO
2674 }
2675 else
ea5fc465 2676 // Search for objects, addresses, networks, virtual services and RS pools by their description.
e673ee24 2677 {
ea5fc465
DO
2678 $tmp = getObjectSearchResults ($terms);
2679 if (count ($tmp))
e673ee24 2680 {
ea5fc465
DO
2681 $nhits += count ($tmp);
2682 $lasthit = 'object';
2683 $summary['object'] = $tmp;
e673ee24 2684 }
ea5fc465
DO
2685 $tmp = getIPv4AddressSearchResult ($terms);
2686 if (count ($tmp))
e673ee24 2687 {
ea5fc465
DO
2688 $nhits += count ($tmp);
2689 $lasthit = 'ipv4address2';
2690 $summary['ipv4address2'] = $tmp;
2691 }
2692 $tmp = getIPv4PrefixSearchResult ($terms);
2693 if (count ($tmp))
2694 {
2695 $nhits += count ($tmp);
2696 $lasthit = 'ipv4network';
2697 $summary['ipv4network'] = $tmp;
2698 }
05411ccd
DO
2699 $tmp = getIPv4RSPoolSearchResult ($terms);
2700 if (count ($tmp))
2701 {
2702 $nhits += count ($tmp);
2703 $lasthit = 'ipv4rspool';
2704 $summary['ipv4rspool'] = $tmp;
2705 }
2706 $tmp = getIPv4VServiceSearchResult ($terms);
2707 if (count ($tmp))
2708 {
2709 $nhits += count ($tmp);
2710 $lasthit = 'ipv4vs';
2711 $summary['ipv4vs'] = $tmp;
2712 }
ea5fc465
DO
2713 }
2714 if ($nhits == 0)
2715 echo "<center><h2>Nothing found for '${terms}'</h2></center>";
2716 elseif ($nhits == 1)
2717 {
2718 $record = current ($summary[$lasthit]);
2719 switch ($lasthit)
2720 {
2721 case 'port':
2722 echo "<script language='Javascript'>document.location='${root}?page=object";
2723 echo "&hl_port_id=" . $record['port_id'];
2724 echo "&object_id=" . $record['object_id'] . "';//</script>";
2725 break;
2726 case 'ipv4address1':
2727 echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
2728 echo "&ip=${record}";
2729 echo "';//</script>";
2730 break;
2731 case 'ipv4address2':
2732 echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
fb9c8991 2733 echo "&ip=${record['ip']}";
ea5fc465
DO
2734 echo "';//</script>";
2735 break;
2736 case 'ipv4network':
2737 echo "<script language='Javascript'>document.location='${root}?page=iprange";
2738 echo "&id=${record['id']}";
2739 echo "';//</script>";
2740 break;
2741 case 'object':
2742 echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
2743 break;
05411ccd
DO
2744 case 'ipv4rspool':
2745 echo "<script language='Javascript'>document.location='${root}?page=rspool&pool_id=${record['pool_id']}';//</script>";
2746 break;
2747 case 'ipv4vs':
2748 echo "<script language='Javascript'>document.location='${root}?page=vservice&id=${record['id']}';//</script>";
2749 break;
ea5fc465
DO
2750 }
2751 return;
2752 }
2753 else
2754 {
2755 global $nextorder;
2756 $order = 'odd';
2757 echo "<center><h2>${nhits} result(s) found for '${terms}'</h2></center>";
2758 foreach ($summary as $where => $what)
2759 switch ($where)
e673ee24 2760 {
ea5fc465 2761 case 'object':
06adfe89 2762 startPortlet ("<a href='${root}?page=objects'>Objects</a>");
ea5fc465
DO
2763 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2764 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>barcode</th></tr>';
2765 foreach ($what as $obj)
2766 {
2767 echo "<tr class=row_${order}><td><a href=\"${root}?page=object&object_id=${obj['id']}\">${obj['dname']}</a></td>";
2768 echo "<td>${obj['label']}</td>";
2769 echo "<td>${obj['asset_no']}</td>";
2770 echo "<td>${obj['barcode']}</td></tr>";
2771 $order = $nextorder[$order];
2772 }
2773 echo '</table>';
2774 finishPortlet();
2775 break;
2776 case 'ipv4network':
06adfe89 2777 startPortlet ("<a href='${root}?page=ipv4space'>IPv4 networks</a>");
ea5fc465
DO
2778 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2779 echo '<tr><th>Network</th><th>Descritpion</th></tr>';
2780 foreach ($what as $net)
2781 {
2782 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=iprange&id=${net['id']}'>${net['ip']}";
2783 echo '/' . $net['mask'] . '</a></td>';
2784 echo "<td class=tdleft>${net['name']}</td></tr>";
2785 $order = $nextorder[$order];
2786 }
2787 echo '</table>';
2788 finishPortlet();
2789 break;
2790 case 'ipv4address2':
2791 startPortlet ('IPv4 addresses');
2792 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2793 echo '<tr><th>Address</th><th>Descritpion</th></tr>';
2794 foreach ($what as $addr)
2795 {
fd190b0a 2796 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=ipaddress&ip=${addr['ip']}'>";
ea5fc465
DO
2797 echo "${addr['ip']}</a></td>";
2798 echo "<td class=tdleft>${addr['name']}</td></tr>";
2799 $order = $nextorder[$order];
2800 }
2801 echo '</table>';
2802 finishPortlet();
2803 break;
05411ccd 2804 case 'ipv4rspool':
06adfe89 2805 startPortlet ("<a href='${root}?page=rspools'>RS pools</a>");
05411ccd
DO
2806 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2807 foreach ($what as $rspool)
2808 {
2809 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=rspool&pool_id=${rspool['pool_id']}'>";
2810 echo buildRSPoolName ($rspool);
2811 echo "</a></td></tr>";
2812 $order = $nextorder[$order];
2813 }
2814 echo '</table>';
2815 finishPortlet();
2816 break;
2817 case 'ipv4vs':
06adfe89 2818 startPortlet ("<a href='${root}?page=vservices'>Virtual services</a>");
05411ccd
DO
2819 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2820 echo '<tr><th>VS</th><th>Descritpion</th></tr>';
2821 foreach ($what as $vs)
2822 {
2823 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=vservice&id=${vs['id']}'>";
2824 echo buildVServiceName ($vs);
2825 echo "</a></td><td>${vs['name']}</td></tr>";
2826 $order = $nextorder[$order];
2827 }
2828 echo '</table>';
2829 finishPortlet();
2830 break;
e673ee24 2831 }
e673ee24
DO
2832 }
2833}
2834
2835// This function prints a table of checkboxes to aid the user in toggling mount atoms
2836// from one state to another. The first argument is rack data as
2837// produced by getRackData(), the second is the value used for the 'unckecked' state
2838// and the third is the value used for 'checked' state.
2839// Usage contexts:
2840// for mounting an object: printAtomGrid ($data, 'F', 'T')
2841// for changing rack design: printAtomGrid ($data, 'A', 'F')
2842// for adding rack problem: printAtomGrid ($data, 'F', 'U')
2843// for adding object problem: printAtomGrid ($data, 'T', 'W')
2844
2845function renderAtomGrid ($data)
2846{
2847 $rack_id = $data['id'];
2848 for ($unit_no = $data['height']; $unit_no > 0; $unit_no--)
2849 {
2850 echo "<tr><th>${unit_no}</th>";
2851 for ($locidx = 0; $locidx < 3; $locidx++)
2852 {
2853 $state = $data[$unit_no][$locidx]['state'];
2854 echo "<td class=state_${state}";
2855 if (isset ($data[$unit_no][$locidx]['hl']))
2856 echo $data[$unit_no][$locidx]['hl'];
2857 echo ">";
2858 if (!($data[$unit_no][$locidx]['enabled'] === TRUE))
2859 echo '<input type=checkbox disabled>';
2860 else
2861 echo "<input type=checkbox" . $data[$unit_no][$locidx]['checked'] . " name=atom_${rack_id}_${unit_no}_${locidx}>";
2862 echo '</td>';
2863 }
2864 echo "</tr>\n";
2865 }
2866}
2867
2868function renderPermissions ()
2869{
2870 startPortlet ('User permissions');
2871 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2872 echo "<tr><th>Username</th><th>Page</th><th>Tab</th><th>Access</th></tr>";
2873 global $perms, $nextorder;
2874 $order = 'odd';
2875 foreach ($perms as $username => $pages)
2876 foreach ($pages as $page => $tabs)
2877 foreach ($tabs as $tab => $access)
2878 {
2879 echo "<tr class=row_${order}><td class=tdleft>$username</td><td>$page</td><td>$tab</td><td>$access</td></tr>\n";
2880 $order = $nextorder[$order];
2881 }
2882 echo "</table>\n";
2883 finishPortlet();
2884}
2885
2886function renderAccounts ()
2887{
2888 global $nextorder, $accounts;
2889 startPortlet ('User accounts');
2890 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2891 echo "<tr><th class=tdleft>Username</th><th class=tdleft>Real name</th></tr>";
2892 $order = 'odd';
2893 foreach ($accounts as $user)
2894 {
20c901a7
DO
2895 echo "<tr class=row_${order}><td class=tdleft><div title='\$userid_${user['user_id']}'>";
2896 echo "${user['user_name']}</div></td>";
2897 echo "<td class=tdleft>${user['user_realname']}</td></li>";
e673ee24
DO
2898 $order = $nextorder[$order];
2899 }
2900 echo '</table>';
2901 finishPortlet();
2902}
2903
2904function renderAccountsEditForm ()
2905{
2906 global $root, $pageno, $tabno, $accounts;
2907 startPortlet ('User accounts');
2908 showMessageOrError();
2909 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
623457f8 2910 echo "<tr><th>status (click to change)</th><th>Username</th><th>Real name</th><th>Password</th><th>&nbsp;</th></tr>\n";
e673ee24
DO
2911 foreach ($accounts as $account)
2912 {
2913 echo "<form action='${root}process.php'>";
2914 echo "<input type=hidden name=op value=updateAccount>";
2915 echo "<input type=hidden name=page value='${pageno}'>\n";
2916 echo "<input type=hidden name=tab value='${tabno}'>\n";
2917 echo "<input type=hidden name=id value='${account['user_id']}'><tr>";
2918 echo "<td>";
2919 if ($account['user_enabled'] == 'yes' && $account['user_id'] != 1)
2920 {
2921 echo "<a href='${root}process.php?op=disableAccount&page=${pageno}&tab=${tabno}&id=${account['user_id']}'>";
2922 printImageHREF ('blockuser', 'disable account');
2923 echo "</a>\n";
2924 }
2925 if ($account['user_enabled'] == 'no' && $account['user_id'] != 1)
2926 {
2927 echo "<a href='${root}process.php?op=enableAccount&page=${pageno}&tab=${tabno}&id=${account['user_id']}'>";
2928 printImageHREF ('unblockuser', 'enable account');
2929 echo "</a>\n";
2930 }
2931 // Otherwise skip icon.
2932 echo "</td>";
2933 echo "<td><input type=text name=username value='${account['user_name']}' size=16></td>";
2934 echo "<td><input type=text name=realname value='${account['user_realname']}' size=24></td>";
8e5763a7
DO
2935 echo "<td><input type=password name=password value='${account['user_password_hash']}' size=64></td><td>";
2936 printImageHREF ('save', 'Save changes', TRUE);
2937 echo "</td></form></tr>\n";
e673ee24
DO
2938 }
2939 echo "<form action='${root}process.php' method=post><tr>";
2940 echo "<input type=hidden name=op value=createAccount>\n";
2941 echo "<input type=hidden name=page value='${pageno}'>\n";
2942 echo "<input type=hidden name=tab value='${tabno}'>\n";
8e5763a7 2943 echo "<td>&nbsp;</td><td><input type=text size=16 name=username tabindex=100></td>\n";
e673ee24 2944 echo "<td><input type=text size=24 name=realname tabindex=101></td>";
8e5763a7
DO
2945 echo "<td><input type=password size=64 name=password tabindex=102></td><td>";
2946 printImageHREF ('create', 'Add new account', TRUE, 103);
2947 echo "</td></tr></form>";
e673ee24
DO
2948 echo "</table><br>\n";
2949 finishPortlet();
2950}
2951
2952function printChildrenAsOptions ($root, $depth = 0)
2953{
2954 echo "<option value=${root['title']}>";
2955 if ($depth == 0)
2956 echo '* ';
2957 for ($i = 0; $i < $depth; $i++)
2958 echo '-- ';
2959 echo $root['title'];
2960 echo "</option>\n";
2961 foreach ($root['kids'] as $kid)
2962 printChildrenAsOptions ($kid, $depth + 1);
2963}
2964
2965// 1. Find all parentless pages.
2966// 2. For each of them recursively find all children.
2967// 3. Output the tree with recursion tree display.
2968function printPagesTree ()
2969{
2970 global $page;
2971 echo '<pre>';
2972 foreach ($page as $ctitle => $cpage)
2973 if (!isset ($cpage['parent']))
2974 {
2975 $croot['title'] = $ctitle;
2976 $croot['kids'] = getAllChildPages ($ctitle);
2977 printChildrenAsOptions ($croot);
2978 }
2979 echo '</pre>';
2980}
2981
2982function renderPermissionsEditForm ()
2983{
2984 global $root, $pageno, $tabno, $perms, $accounts;
2985 startPortlet ('User permissions');
2986 showMessageOrError();
2987 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
2988 echo "<tr><th>&nbsp;</th><th>Username</th><th>Page</th><th>Tab</th><th>Access</th></tr>\n";
2989 foreach ($perms as $username => $pages)
2990 foreach ($pages as $access_page => $tabs)
2991 foreach ($tabs as $access_tab => $access)
2992 {
2993 echo "<td>";
2994 if ($username != '%')
2995 $userid = $accounts[$username]['user_id'];
2996 else
2997 $userid = 0;
2998 echo "<a href='${root}process.php?op=revoke&page=${pageno}&tab=${tabno}&access_userid=${userid}&access_page=${access_page}&access_tab=${access_tab}'>";
2999 printImageHREF ('revoke', 'Revoke permission');
3000 echo "</a></td>";
3001 echo "<td>${username}</td>";
3002 echo "<td>${access_page}</td>";
3003 echo "<td>${access_tab}</td>";
3004 echo "<td>${access}</td>";
3005 echo "</tr>\n";
3006 }
3007 echo "<form action='${root}process.php' method=post><tr>";
3008 echo "<input type=hidden name=op value=grant>\n";
3009 echo "<input type=hidden name=page value='${pageno}'>\n";
3010 echo "<input type=hidden name=tab value='${tabno}'>\n";
3011 // FIXME: border=0 doesn't work here for unknown reason
3012 echo "<td>";
a5ae8c2a 3013 printImageHREF ('grant', '', TRUE, 103);
e673ee24
DO
3014 echo "</td>";
3015 echo "<td><select name=access_userid>";
3016 echo "<option value=0>ANY</option>";
3017 foreach ($accounts as $account)
3018 echo "<option value=${account['user_id']}>${account['user_name']}</option>";
3019 echo "</select></td>\n";
3020 echo "<td><select name=access_page>";
3021 echo "<option value='%'>ANY</option>";
3022 printPagesTree();
3023 echo "</select></td>";
3024 echo "<td><input type=text size=16 name=access_tab tabindex=102 value=default></td>";
3025 echo "<td><input type=radio name=access_value value=no checked>no <input type=radio name=access_value value=yes>yes</td>";
3026 echo "</tr></form>";
3027 echo "</table><br>\n";
3028 finishPortlet();
3029}
3030
17c32f4c
DO
3031function renderPortMapViewer ()
3032{
3033 renderPortMap (FALSE);
3034}
3035
3036function renderPortMapEditor ()
3037{
3038 renderPortMap (TRUE);
3039}
3040
e673ee24
DO
3041function renderPortMap ($editable = FALSE)
3042{
3043 global $nextorder, $root, $pageno, $tabno;
3044 showMessageOrError();
3045 startPortlet ("Port compatibility map");
3046 $ptlist = getPortTypes();
3047 $pclist = getPortCompat();
3048 $pctable = buildPortCompatMatrixFromList ($ptlist, $pclist);
3049 if ($editable)
3050 {
3051 echo "<form method=post action='${root}process.php'>";
3052 echo "<input type=hidden name=page value='${pageno}'>";
3053 echo "<input type=hidden name=tab value='${tabno}'>";
3054 echo "<input type=hidden name=op value=save>";
3055 }
3056 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
3057 echo "<tr><th class=vert_th>&nbsp;</th>";
3058 foreach ($ptlist as $name2)
3059 echo "<th>to ${name2}</th>";
3060 echo "</tr>";
3061 // Make a copy to have an independent array pointer.
3062 $ptlistY = $ptlist;
3063 $order = 'odd';
3064 foreach ($ptlistY as $type1 => $name1)
3065 {
3066 echo "<tr class=row_${order}><th class=vert_th style='border-bottom: 0px;'>from $name1</th>";
3067 foreach ($ptlist as $type2 => $name2)
3068 {
3069 echo '<td><input type=checkbox' . ($editable ? " name=atom_${type1}_${type2}" : ' disabled');
3070 echo ($pctable[$type1][$type2] ? ' checked' : '') . '></td>';
3071 }
3072 echo "</tr>\n";
3073 $order = $nextorder[$order];
3074 }
3075 echo '</table><br>';
3076 if ($editable)
3077 {
3078 echo "<input type=submit value='Save changes'>";
3079 echo "</form>";
3080 }
3081 finishPortlet();
3082}
3083
3084function renderConfigMainpage ()
3085{
3086 global $pageno, $root;
3087 $children = getDirectChildPages ($pageno);
3088 echo '<ul>';
27ef67da
DO
3089 // FIXME: assume all config kids to have static titles at the moment,
3090 // but use some proper abstract function later.
e673ee24 3091 foreach ($children as $cpageno => $child)
27ef67da 3092 echo "<li><a href='${root}?page=${cpageno}'>" . $child['title'] . "</li>\n";
e673ee24
DO
3093 echo '';
3094 echo '</ul>';
3095}
3096
3097function renderRackPage ($rack_id)
3098{
3099 if ($rack_id == 0)
3100 {
591ff2c4 3101 showError ('Invalid rack_id', __FUNCTION__);
e673ee24
DO
3102 return;
3103 }
3104 if (($rackData = getRackData ($rack_id)) == NULL)
3105 {
591ff2c4 3106 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
3107 return;
3108 }
3109 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
3110
3111 // Left column with information.
3112 echo "<td class=pcleft>";
254673dd 3113 renderRackInfoPortlet ($rackData);
e673ee24
DO
3114 echo '</td>';
3115
3116 // Right column with rendered rack.
3117 echo '<td>';
3118 startPortlet ('Rack diagram');
3119 renderRack ($rack_id);
3120 finishPortlet();
3121 echo '</td>';
3122
3123 echo '</tr></table>';
3124}
3125
3126function renderDictionary ()
3127{
3128 global $nextorder;
2dd59b15 3129 $dict = getDict (TRUE);
aa28ebdf 3130 echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
aa28ebdf
DO
3131 foreach ($dict as $chapter_no => $chapter)
3132 {
a22ec5b4 3133 $order = 'odd';
83d2fcca 3134 echo "<tr><th>Chapter</th><th>refs</th><th>Word</th></tr>\n";
aa28ebdf
DO
3135 $wc = count ($chapter['word']);
3136 echo "<tr class=row_${order}><td class=tdleft" . ($wc ? " rowspan = ${wc}" : '');
3137 echo "><div title='number=${chapter_no}'>${chapter['name']} (${wc} records)</div></td>";
3138 if (!$wc)
3139 echo "<td colspan=2>none</td>";
3140 else
e673ee24 3141 {
aa28ebdf
DO
3142 $chap_start = TRUE;
3143 foreach ($chapter['word'] as $key => $value)
3144 {
3145 if (!$chap_start)
3146 echo "<tr class=row_${order}>";
3147 else
3148 $chap_start = FALSE;
6bb8e41d
DO
3149 echo '<td>' . ($chapter['refcnt'][$key] ? $chapter['refcnt'][$key] : '&nbsp;') . '</td>';
3150 echo "<td><div title='key=${key}'>${value}</div></td></tr>\n";
aa28ebdf
DO
3151 $order = $nextorder[$order];
3152 }
e673ee24 3153 }
e673ee24 3154 }
2dd59b15 3155 echo "</table>\n<br>";
e673ee24
DO
3156}
3157
3158function renderDictionaryEditor ()
3159{
f632bd28 3160 global $root, $pageno, $tabno, $nextorder;
e673ee24 3161 $dict = getDict();
95d80773 3162 showMessageOrError();
f632bd28
DO
3163 echo "<br><table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
3164 foreach ($dict as $chapter_no => $chapter)
e673ee24 3165 {
f632bd28 3166 $order = 'odd';
b2f9fa84 3167 echo "<tr><th>Chapter</th><th>&nbsp;</th><th>Word</th><th>&nbsp;</th></tr>\n";
f632bd28
DO
3168 $wc = count ($chapter['word']);
3169 // One extra span for the new record per each chapter block.
3170 echo "<tr class=row_${order}><td class=tdleft" . ($wc ? ' rowspan = ' . ($wc + 1) : '');
3171 echo "><div title='number=${chapter_no}'>${chapter['name']} (${wc} records)</div></td>";
3172 echo "<form action='${root}process.php' method=post>";
3173 echo "<input type=hidden name=page value='${pageno}'>";
3174 echo "<input type=hidden name=tab value='${tabno}'>";
3175 echo "<input type=hidden name=op value=add>";
3176 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
3177 echo "<td>&nbsp;</td>";
3178 echo "<td class=tdright><input type=text name=dict_value size=32></td>";
95d80773 3179 echo "<td><input type=submit value='Add new'></td>";
f632bd28 3180 echo '</tr></form>';
b2f9fa84 3181 $order = $nextorder[$order];
e673ee24
DO
3182 foreach ($chapter['word'] as $key => $value)
3183 {
3184 echo "<form action='${root}process.php' method=post>";
3185 echo "<input type=hidden name=page value='${pageno}'>";
3186 echo "<input type=hidden name=tab value='${tabno}'>";
3187 echo "<input type=hidden name=op value='upd'>";
3188 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
3189 echo "<input type=hidden name=dict_key value='${key}'>";
95d80773 3190 echo "<tr class=row_${order}><td>";
f632bd28
DO
3191 // Prevent deleting words currently used somewhere.
3192 if ($chapter['refcnt'][$key])
b2f9fa84 3193 printImageHREF ('nodelete', 'referenced ' . $chapter['refcnt'][$key] . ' time(s)');
f632bd28
DO
3194 else
3195 {
3196 echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}&dict_key=${key}'>";
3197 printImageHREF ('delete', 'Delete word');
3198 echo "</a>";
3199 }
3200 echo '</td>';
e673ee24
DO
3201 echo "<td class=tdright><input type=text name=dict_value size=32 value='${value}'></td>";
3202 echo "<td><input type=submit value=OK></td>";
f632bd28
DO
3203 echo "</tr></form>\n";
3204 $order = $nextorder[$order];
3205 } // foreach ($chapter['word']
3206 } // foreach ($dict
3207 echo "</table>\n";
e673ee24
DO
3208}
3209
3210// We don't allow to rename/delete a sticky chapter and we don't allow
3211// to delete a non-empty chapter.
3212function renderChaptersEditor ()
3213{
3214 global $root, $pageno, $tabno;
3215 showMessageOrError();
3216 $dict = getDict();
3217 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
3218 echo '<tr><th>&nbsp;</th><th>Chapter name</th><th>Words</th><th>&nbsp;</th></tr>';
3219 foreach ($dict as $chapter)
3220 {
3221 $wordcount = count ($chapter['word']);
3222 $sticky = $chapter['sticky'];
3223 echo "<form action='${root}process.php' method=post>";
3224 echo "<input type=hidden name=page value='${pageno}'>";
3225 echo "<input type=hidden name=tab value='${tabno}'>";
3226 echo "<input type=hidden name=op value=upd>";
3227 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
3228 echo '<tr>';
3229 echo '<td>';
0c4605ab
DO
3230 if ($sticky)
3231 printImageHREF ('nodelete', 'system chapter');
3232 elseif ($wordcount > 0)
3233 printImageHREF ('nodelete', 'contains ' . $wordcount . ' word(s)');
e673ee24
DO
3234 else
3235 {
3236 echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}'>";
3237 printImageHREF ('delete', 'Remove chapter');
3238 echo "</a>";
3239 }
3240 echo '</td>';
3241 echo "<td><input type=text name=chapter_name value='${chapter['name']}'" . ($sticky ? ' disabled' : '') . "></td>";
3242 echo "<td class=tdleft>${wordcount}</td><td>";
3243 if ($sticky)
3244 echo '&nbsp;';
3245 else
3246 echo "<input type=submit value='OK'>";
3247 echo '</td></tr>';
3248 echo '</form>';
3249 }
3250 echo "<form action='${root}process.php' method=post>";
3251 echo "<input type=hidden name=page value='${pageno}'>";
3252 echo "<input type=hidden name=tab value='${tabno}'>";
3253 echo "<input type=hidden name=op value=add>";
3254 echo '<tr><td>';
a5ae8c2a 3255 printImageHREF ('add', '', TRUE);
e673ee24
DO
3256 echo "</td><td colspan=3><input type=text name=chapter_name></td>";
3257 echo '</tr>';
3258 echo '</form>';
3259 echo "</table>\n";
3260}
3261
3262function renderAttributes ()
3263{
3264 global $nextorder;
3265 $attrMap = getAttrMap();
3266 startPortlet ('Optional attributes');
3267 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
3268 echo "<tr><th class=tdleft>Attribute name</th><th class=tdleft>Attribute type</th><th class=tdleft>Applies to</th></tr>";
3269 $order = 'odd';
3270 foreach ($attrMap as $attr)
3271 {
3272 echo "<tr class=row_${order}>";
3273 echo "<td class=tdleft>${attr['name']}</td>";
3274 echo "<td class=tdleft>${attr['type']}</td>";
3275 echo '<td class=tdleft>';
3276 if (count ($attr['application']) == 0)
3277 echo '&nbsp;';
3278 else
3279 foreach ($attr['application'] as $app)
3280 if ($attr['type'] == 'dict')
3281 echo "${app['objtype_name']} (values from '${app['chapter_name']}')<br>";
3282 else
3283 echo "${app['objtype_name']}<br>";
3284 echo '</td>';
3285 echo "</tr>\n";
3286 $order = $nextorder[$order];
3287 }
3288 echo "</table><br>\n";
3289 finishPortlet();
3290}
3291
3292function renderEditAttributesForm ()
3293{
3294 global $root, $pageno, $tabno;
3295 $attrMap = getAttrMap();
3296 showMessageOrError();
3297 startPortlet ('Optional attributes');
3298 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
3299 echo '<tr><th>&nbsp;</th><th>Name</th><th>Type</th><th>&nbsp;</th></tr>';
3300 foreach ($attrMap as $attr)
3301 {
3302 echo "<form action='${root}process.php' method=post>";
3303 echo "<input type=hidden name=page value='${pageno}'>";
3304 echo "<input type=hidden name=tab value='${tabno}'>";
3305 echo "<input type=hidden name=op value=upd>";
3306 echo "<input type=hidden name=attr_id value='${attr['id']}'>";
3307 echo '<tr>';
3308 echo "<td><a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&attr_id=${attr['id']}'>";
3309 printImageHREF ('delete', 'Remove attribute');
3310 echo '</a></td>';
3311 echo "<td><input type=text name=attr_name value='${attr['name']}'></td>";
3312 echo "<td>${attr['type']}</td>";
3313 echo "<td><input type=submit value='OK'></td>";
3314 echo '</tr>';
3315 echo '</form>';
3316 }
3317 echo "<form action='${root}process.php' method=post>";
3318 echo "<input type=hidden name=page value='${pageno}'>";
3319 echo "<input type=hidden name=tab value='${tabno}'>";
3320 echo "<input type=hidden name=op value=add>";
3321 echo '<tr><td>';
a5ae8c2a 3322 printImageHREF ('add', '', TRUE);
e673ee24
DO
3323 echo "</td><td><input type=text name=attr_name></td>";
3324 echo '<td><select name=attr_type>';
3325 echo '<option value=uint>uint</option>';
3326 echo '<option value=float>float</option>';
3327 echo '<option value=string>string</option>';
3328 echo '<option value=dict>dict</option>';
3329 echo '</select></td>';
3330 echo '</tr>';
3331 echo '</form>';
3332 echo "</table>\n";
3333 finishPortlet();
3334}
3335
3336function renderEditAttrMapForm ()
3337{
3338 global $root, $pageno, $tabno;
3339 $attrMap = getAttrMap();
3340 showMessageOrError();
3341 startPortlet ('Attribute map');
3342 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
3343 echo '<tr><th>&nbsp;</th><th>Attribute name</th><th>Object type</th><th>Dictionary chapter</th></tr>';
3344 foreach ($attrMap as $attr)
3345 {
3346 if (count ($attr['application']) == 0)
3347 continue;
3348 foreach ($attr['application'] as $app)
3349 {
3350 echo '<tr>';
3351 echo '<td>';
3352 echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&";
3353 echo "attr_id=${attr['id']}&objtype_id=${app['objtype_id']}'>";
3354 printImageHREF ('delete', 'Remove mapping');
3355 echo "</a>";
3356 echo '</td>';
3357 echo "<td>${attr['name']}</td>";
3358 echo "<td>${app['objtype_name']}</td>";
3359 echo "<td>";
3360 if ($attr['type'] == 'dict')
3361 echo "${app['chapter_name']}";
3362 else
3363 echo '&nbsp;';
3364 echo "</td></tr>\n";
3365 }
3366 }
3367 echo "<form action='${root}process.php' method=post>";
3368 echo "<input type=hidden name=page value='${pageno}'>";
3369 echo "<input type=hidden name=tab value='${tabno}'>";
3370 echo "<input type=hidden name=op value=add>";
3371 echo '<tr><td>';
a5ae8c2a 3372 printImageHREF ('add', '', TRUE);
e673ee24
DO
3373 echo "</td><td><select name=attr_id>";
3374 $shortType['uint'] = 'U';
3375 $shortType['float'] = 'F';
3376 $shortType['string'] = 'S';
3377 $shortType['dict'] = 'D';
3378 foreach ($attrMap as $attr)
3379 echo "<option value=${attr['id']}>[" . $shortType[$attr['type']] . "] ${attr['name']}</option>";
3380 echo "</select></td>";
3381 echo '<td>';
3382 printSelect (getObjectTypeList(), 'objtype_id');
3383 echo '</td>';
3384 $dict = getDict();
3385 echo '<td><select name=chapter_no>';
3386 foreach ($dict as $chapter)
3387 if (!$chapter['sticky'])
3388 echo "<option value='${chapter['no']}'>${chapter['name']}</option>";
3389 echo '</select></td>';
3390 echo '</tr>';
3391 echo '</form>';
3392 echo "</table>\n";
3393 finishPortlet();
3394}
3395
a5ae8c2a 3396function printImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0)
e673ee24 3397{
a5ae8c2a
DO
3398 global $root;
3399 $image['error']['path'] = 'pix/error.png';
3400 $image['error']['width'] = 76;
3401 $image['error']['height'] = 17;
a5ae8c2a
DO
3402 $image['logo']['path'] = 'pix/defaultlogo.png';
3403 $image['logo']['width'] = 210;
3404 $image['logo']['height'] = 40;
3405 $image['rackspace']['path'] = 'pix/racks.png';
3406 $image['rackspace']['width'] = 218;
3407 $image['rackspace']['height'] = 200;
3408 $image['objects']['path'] = 'pix/server.png';
3409 $image['objects']['width'] = 218;
3410 $image['objects']['height'] = 200;
3411 $image['ipv4space']['path'] = 'pix/addressspace.png';
3412 $image['ipv4space']['width'] = 218;
3413 $image['ipv4space']['height'] = 200;
f973f491
DO
3414 $image['ipv4slb']['path'] = 'pix/slb.png';
3415 $image['ipv4slb']['width'] = 218;
3416 $image['ipv4slb']['height'] = 200;
a5ae8c2a
DO
3417 $image['config']['path'] = 'pix/configuration.png';
3418 $image['config']['width'] = 218;
3419 $image['config']['height'] = 200;
3420 $image['reports']['path'] = 'pix/report.png';
3421 $image['reports']['width'] = 218;
3422 $image['reports']['height'] = 200;
054b0ae9 3423 $image['useup']['path'] = 'pix/tango-edit-clear.png';
a5ae8c2a
DO
3424 $image['useup']['width'] = 16;
3425 $image['useup']['height'] = 16;
d48d8820
DO
3426 $image['link']['path'] = 'pix/tango-network-wired.png';
3427 $image['link']['width'] = 16;
3428 $image['link']['height'] = 16;
3429 $image['unlink']['path'] = 'pix/tango-edit-clear.png';
3430 $image['unlink']['width'] = 16;
3431 $image['unlink']['height'] = 16;
77811274 3432 $image['add']['path'] = 'pix/tango-list-add.png';
a5ae8c2a
DO
3433 $image['add']['width'] = 16;
3434 $image['add']['height'] = 16;
d48d8820 3435 $image['delete']['path'] = 'pix/tango-list-remove.png';
a5ae8c2a
DO
3436 $image['delete']['width'] = 16;
3437 $image['delete']['height'] = 16;
49fb1027 3438 $image['nodelete']['path'] = 'pix/tango-list-remove-shadow.png';
0c4605ab
DO
3439 $image['nodelete']['width'] = 16;
3440 $image['nodelete']['height'] = 16;
a5ae8c2a
DO
3441 $image['grant'] = $image['add'];
3442 $image['revoke'] = $image['delete'];
d48d8820 3443 $image['inservice']['path'] = 'pix/tango-emblem-system.png';
1f7d18fa
DO
3444 $image['inservice']['width'] = 16;
3445 $image['inservice']['height'] = 16;
d48d8820 3446 $image['notinservice']['path'] = 'pix/tango-dialog-error.png';
1f7d18fa
DO
3447 $image['notinservice']['width'] = 16;
3448 $image['notinservice']['height'] = 16;
81d26ca1
DO
3449 $image['blockuser'] = $image['inservice'];
3450 $image['unblockuser'] = $image['notinservice'];
77811274 3451 $image['find']['path'] = 'pix/tango-system-search.png';
4de22e7e
DO
3452 $image['find']['width'] = 16;
3453 $image['find']['height'] = 16;
b39e7545
DO
3454 $image['spacer']['path'] = 'pix/pixel.png';
3455 $image['spacer']['width'] = 16;
3456 $image['spacer']['height'] = 16;
9803c56c
DO
3457 $image['next']['path'] = 'pix/tango-go-next.png';
3458 $image['next']['width'] = 32;
3459 $image['next']['height'] = 32;
3460 $image['prev']['path'] = 'pix/tango-go-previous.png';
3461 $image['prev']['width'] = 32;
3462 $image['prev']['height'] = 32;
d48d8820
DO
3463 $image['clear']['path'] = 'pix/tango-edit-clear.png';
3464 $image['clear']['width'] = 16;
3465 $image['clear']['height'] = 16;
49fb1027
DO
3466 $image['save']['path'] = 'pix/tango-document-save.png';
3467 $image['save']['width'] = 16;
3468 $image['save']['height'] = 16;
5bbbeaa2
DO
3469 $image['SAVE']['path'] = 'pix/tango-document-save-big.png';
3470 $image['SAVE']['width'] = 32;
3471 $image['SAVE']['height'] = 32;
8e5763a7
DO
3472 $image['create']['path'] = 'pix/tango-document-new.png';
3473 $image['create']['width'] = 16;
3474 $image['create']['height'] = 16;
e673ee24
DO
3475 if (!isset ($image[$tag]))
3476 $tag = 'error';
3477 $img = $image[$tag];
a5ae8c2a
DO
3478 if ($do_input == TRUE)
3479 echo
3480 "<input type=image name=submit " .
3481 "src='${root}${img['path']}' " .
3482 "border=0 " .
3483 ($tabindex ? '' : "tabindex=${tabindex}") .
3484 ">";
3485 else
3486 echo
3487 "<img " .
3488 "src='${root}${img['path']}' " .
3489 "width=${img['width']} " .
3490 "height=${img['height']} " .
3491 "border=0 " .
3492 (empty ($title) ? '' : "title='${title}'") .
3493 ">";
e673ee24
DO
3494}
3495
3496// This function returns URL for favourite icon.
3497function getFaviconURL ()
3498{
46100c70
DO
3499 global $root;
3500 return $root . 'pix/racktables.ico';
e673ee24
DO
3501}
3502
3503function renderReportSummary ()
3504{
da95280e
DO
3505 echo "<table width='100%'>\n";
3506 echo "<tr><td class=pcleft>\n";
08b4cb24 3507 startPortlet ("Dictionary/objects stats");
da95280e
DO
3508 echo "<table>\n";
3509 foreach (getDictStats() as $header => $data)
7e233246 3510 echo "<tr><th class=tdright>${header}:</th><td class=tdleft>${data}</td></tr>\n";
8948cd63
DO
3511 echo "</table>\n";
3512 finishPortlet();
3513 startPortlet ('IPv4 stats');
3514 echo "<table>\n";
3515 foreach (getIPv4Stats() as $header => $data)
3516 echo "<tr><th class=tdright>${header}:</th><td class=tdleft>${data}</td></tr>\n";
3517 echo "</table>\n";
3518 finishPortlet();
3519 startPortlet ('Rackspace stats');
3520 echo "<table>\n";
3521 foreach (getRackspaceStats() as $header => $data)
3522 echo "<tr><th class=tdright>${header}:</th><td class=tdleft>${data}</td></tr>\n";
da95280e
DO
3523 echo "</table>\n";
3524 finishPortlet();
3525
3526 echo "</td><td class=pcright>\n";
3527
5bbbeaa2
DO
3528 startPortlet ("Tag popularity");
3529 echo "<table>\n";
3530 foreach (getTagStats() as $header => $data)
3531 echo "<tr><th class=tdright>${header}:</th><td class=tdleft>${data}</td></tr>\n";
3532 echo "</table>\n";
c461c579 3533 finishPortlet();
da95280e
DO
3534 echo "</td></tr>\n";
3535 echo "</table>\n";
c461c579
DO
3536}
3537
3538function dragon ()
3539{
5bbbeaa2 3540 startPortlet ('Here be dragons');
c461c579
DO
3541?>
3542<div class=dragon><pre><font color="#00ff33">
3543 \||/
3544 | <font color="#ff0000">@</font>___oo
3545 /\ /\ / (__<font color=yellow>,,,,</font>|
3546 ) /^\) ^\/ _)
3547 ) /^\/ _)
3548 ) _ / / _)
3549 /\ )/\/ || | )_)
3550 &lt; &gt; |(<font color=white>,,</font>) )__)