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