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