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