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