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