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