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