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