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