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