r2406 fixed bug in object page
[racktables] / inc / interface.php
CommitLineData
b325120a 1<?php
e673ee24
DO
2/*
3*
4* This file contains frontend functions for RackTables.
5*
6*/
7
9c0b0016
DO
8// Interface function's special.
9$nextorder['odd'] = 'even';
10$nextorder['even'] = 'odd';
11
52c836b1
DO
12// address allocation type
13$aat = array
14(
15 'regular' => 'Connected',
16 'virtual' => 'Loopback',
17 'shared' => 'Shared',
18 'router' => 'Router',
19);
beb9e88a 20// address allocation code, IPv4 addresses and objects view
52c836b1
DO
21$aac = array
22(
23 'regular' => '',
24 'virtual' => '<strong>L</strong>',
25 'shared' => '<strong>S</strong>',
26 'router' => '<strong>R</strong>',
27);
beb9e88a
DO
28// address allocation code, IPv4 networks view
29$aac2 = array
30(
31 'regular' => '',
32 'virtual' => '<strong>L:</strong>',
29025f8e 33 'shared' => '<strong>S:</strong>',
beb9e88a
DO
34 'router' => '<strong>R:</strong>',
35);
52c836b1 36
7056988c
DO
37// Let's have it here, so extensions can add their own images.
38$image = array();
39$image['error']['path'] = 'pix/error.png';
40$image['error']['width'] = 76;
41$image['error']['height'] = 17;
42$image['logo']['path'] = 'pix/defaultlogo.png';
43$image['logo']['width'] = 210;
44$image['logo']['height'] = 40;
45$image['rackspace']['path'] = 'pix/racks.png';
46$image['rackspace']['width'] = 218;
47$image['rackspace']['height'] = 200;
48$image['objects']['path'] = 'pix/server.png';
49$image['objects']['width'] = 218;
50$image['objects']['height'] = 200;
e1ae3fb4
AD
51$image['files']['path'] = 'pix/files.png';
52$image['files']['width'] = 218;
53$image['files']['height'] = 200;
7056988c
DO
54$image['ipv4space']['path'] = 'pix/addressspace.png';
55$image['ipv4space']['width'] = 218;
56$image['ipv4space']['height'] = 200;
57$image['ipv4slb']['path'] = 'pix/slb.png';
58$image['ipv4slb']['width'] = 218;
59$image['ipv4slb']['height'] = 200;
60$image['config']['path'] = 'pix/configuration.png';
61$image['config']['width'] = 218;
62$image['config']['height'] = 200;
63$image['reports']['path'] = 'pix/report.png';
64$image['reports']['width'] = 218;
65$image['reports']['height'] = 200;
e1ae3fb4
AD
66$image['download']['path'] = 'pix/download.png';
67$image['download']['width'] = 16;
68$image['download']['height'] = 16;
08cd1902
AD
69$image['DOWNLOAD']['path'] = 'pix/download-big.png';
70$image['DOWNLOAD']['width'] = 32;
71$image['DOWNLOAD']['height'] = 32;
7056988c
DO
72$image['link']['path'] = 'pix/tango-network-wired.png';
73$image['link']['width'] = 16;
74$image['link']['height'] = 16;
7056988c
DO
75$image['add']['path'] = 'pix/tango-list-add.png';
76$image['add']['width'] = 16;
77$image['add']['height'] = 16;
a685a26a
DO
78$image['ADD']['path'] = 'pix/tango-list-add-big.png';
79$image['ADD']['width'] = 32;
80$image['ADD']['height'] = 32;
7056988c
DO
81$image['delete']['path'] = 'pix/tango-list-remove.png';
82$image['delete']['width'] = 16;
83$image['delete']['height'] = 16;
1bdc2bfc
DO
84$image['destroy']['path'] = 'pix/tango-edit-delete.png';
85$image['destroy']['width'] = 16;
86$image['destroy']['height'] = 16;
87$image['nodestroy']['path'] = 'pix/tango-edit-delete-gray.png';
88$image['nodestroy']['width'] = 16;
89$image['nodestroy']['height'] = 16;
90$image['DESTROY']['path'] = 'pix/tango-edit-delete-big.png';
97b1f33b
DO
91$image['DESTROY']['width'] = 32;
92$image['DESTROY']['height'] = 32;
7056988c
DO
93$image['nodelete']['path'] = 'pix/tango-list-remove-shadow.png';
94$image['nodelete']['width'] = 16;
95$image['nodelete']['height'] = 16;
7056988c
DO
96$image['inservice']['path'] = 'pix/tango-emblem-system.png';
97$image['inservice']['width'] = 16;
98$image['inservice']['height'] = 16;
99$image['notinservice']['path'] = 'pix/tango-dialog-error.png';
100$image['notinservice']['width'] = 16;
101$image['notinservice']['height'] = 16;
7056988c
DO
102$image['find']['path'] = 'pix/tango-system-search.png';
103$image['find']['width'] = 16;
104$image['find']['height'] = 16;
7056988c
DO
105$image['next']['path'] = 'pix/tango-go-next.png';
106$image['next']['width'] = 32;
107$image['next']['height'] = 32;
108$image['prev']['path'] = 'pix/tango-go-previous.png';
109$image['prev']['width'] = 32;
110$image['prev']['height'] = 32;
111$image['clear']['path'] = 'pix/tango-edit-clear.png';
112$image['clear']['width'] = 16;
113$image['clear']['height'] = 16;
61a61189
DO
114$image['CLEAR']['path'] = 'pix/tango-edit-clear-big.png';
115$image['CLEAR']['width'] = 32;
116$image['CLEAR']['height'] = 32;
7056988c
DO
117$image['save']['path'] = 'pix/tango-document-save.png';
118$image['save']['width'] = 16;
119$image['save']['height'] = 16;
120$image['SAVE']['path'] = 'pix/tango-document-save-big.png';
121$image['SAVE']['width'] = 32;
122$image['SAVE']['height'] = 32;
123$image['create']['path'] = 'pix/tango-document-new.png';
124$image['create']['width'] = 16;
125$image['create']['height'] = 16;
126$image['CREATE']['path'] = 'pix/tango-document-new-big.png';
127$image['CREATE']['width'] = 32;
128$image['CREATE']['height'] = 32;
129$image['DENIED']['path'] = 'pix/tango-dialog-error-big.png';
130$image['DENIED']['width'] = 32;
131$image['DENIED']['height'] = 32;
d28d7f4d
DO
132$image['apply']['path'] = 'pix/tango-emblem-system.png';
133$image['apply']['width'] = 16;
134$image['apply']['height'] = 16;
737a3f72
DO
135$image['node-collapsed']['path'] = 'pix/node-collapsed.png';
136$image['node-collapsed']['width'] = 16;
137$image['node-collapsed']['height'] = 16;
138$image['node-expanded']['path'] = 'pix/node-expanded.png';
139$image['node-expanded']['width'] = 16;
140$image['node-expanded']['height'] = 16;
fec0c8da
DO
141$image['node-expanded-static']['path'] = 'pix/node-expanded-static.png';
142$image['node-expanded-static']['width'] = 16;
143$image['node-expanded-static']['height'] = 16;
09620506
DO
144$image['dragons']['path'] = 'pix/mitsudragon.png';
145$image['dragons']['width'] = 125;
146$image['dragons']['height'] = 21;
b1a970c7
DO
147$image['LB']['path'] = 'pix/loadbalancer.png';
148$image['LB']['width'] = 32;
149$image['LB']['height'] = 32;
150$image['RS pool']['path'] = 'pix/serverpool.png';
151$image['RS pool']['width'] = 48;
152$image['RS pool']['height'] = 16;
153$image['VS']['path'] = 'pix/servicesign.png';
154$image['VS']['width'] = 39;
155$image['VS']['height'] = 62;
8b3874a5
DO
156$image['router']['path'] = 'pix/router.png';
157$image['router']['width'] = 32;
158$image['router']['height'] = 32;
f9fb73e4
DO
159$image['LINK']['path'] = 'pix/tango-emblem-symbolic-link-big.png';
160$image['LINK']['width'] = 32;
161$image['LINK']['height'] = 32;
7a0f5847
DO
162$image['favorite']['path'] = 'pix/tango-emblem-favorite.png';
163$image['favorite']['width'] = 16;
164$image['favorite']['height'] = 16;
4f12d88f
DO
165$image['computer']['path'] = 'pix/tango-computer.png';
166$image['computer']['width'] = 16;
167$image['computer']['height'] = 16;
7056988c 168
e5c4506d
DO
169// This may be populated later onsite, report rendering function will use it.
170// See the $systemreport for structure.
171$localreports = array();
172
e673ee24
DO
173// Main menu.
174function renderIndex ()
175{
176 global $root;
177?>
178<table border=0 cellpadding=0 cellspacing=0 width='100%'>
179 <tr>
180 <td>
181 <div style='text-align: center; margin: 10px; '>
182 <table width='100%' cellspacing=0 cellpadding=30 class=mainmenu border=0>
183 <tr>
184 <td>
4fbb5a00 185 <h1><a href='<?php echo makeHref(array('page'=>'rackspace')) ?>'>Rackspace<br>
b325120a 186 <?php printImageHREF ('rackspace'); ?></a></h1>
e673ee24
DO
187 </td>
188 <td>
4fbb5a00 189 <h1><a href='<?php echo makeHref(array('page'=>'objects')) ?>'>Objects<br>
b325120a 190 <?php printImageHREF ('objects'); ?></a></h1>
e673ee24 191 </td>
e673ee24 192 <td>
4fbb5a00 193 <h1><a href='<?php echo makeHref(array('page'=>'ipv4space')) ?>'>IPv4 space<br>
e1ae3fb4 194 <?php printImageHREF ('ipv4space'); ?></a></h1>
e673ee24
DO
195 </td>
196 <td>
4fbb5a00 197 <h1><a href='<?php echo makeHref(array('page'=>'files')) ?>'>Files<br>
e1ae3fb4 198 <?php printImageHREF ('files'); ?></a></h1>
e673ee24 199 </td>
e1ae3fb4 200 </tr>
e1ae3fb4 201 <tr>
ae545907 202 <td>
4fbb5a00 203 <h1><a href='<?php echo makeHref(array('page'=>'config')) ?>'>Configuration<br>
f4d879a9 204 <?php printImageHREF ('config'); ?></a></h1>
ae545907 205 </td>
e1ae3fb4 206 <td>
4fbb5a00 207 <h1><a href='<?php echo makeHref(array('page'=>'reports')) ?>'>Reports<br>
f4d879a9 208 <?php printImageHREF ('reports'); ?></a></h1>
e1ae3fb4
AD
209 </td>
210 <td>
4fbb5a00 211 <h1><a href='<?php echo makeHref(array('page'=>'ipv4slb')) ?>'>IPv4 SLB<br>
f4d879a9 212 <?php printImageHREF ('ipv4slb'); ?></a></h1>
e1ae3fb4 213 </td>
f4d879a9 214 <td>&nbsp;</td>
e673ee24
DO
215 </tr>
216 </table>
217 </div>
218 </td>
219 </tr>
220</table>
b325120a 221<?php
e673ee24
DO
222}
223
224function renderRackspace ()
225{
932cf41f 226 $tagfilter = getTagFilter();
094a8e6e 227 $tagfilter_str = getTagFilterStr ($tagfilter);
489a7502
DO
228 echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
229 renderTagFilterPortlet ($tagfilter, 'rack');
230 echo '</td><td class=pcright>';
231 echo '<table border=0 cellpadding=10 cellpadding=1>';
e673ee24 232 // generate thumb gallery
489a7502 233 $rackrowList = getRackspace ($tagfilter);
4fbb5a00 234 global $nextorder;
d5157018 235 $rackwidth = getRackImageWidth();
e673ee24
DO
236 $order = 'odd';
237 foreach ($rackrowList as $rackrow)
238 {
84466afa 239 echo "<tr class=row_${order}><th class=tdleft>";
4fbb5a00 240 echo "<a href='".makeHref(array('page'=>'row', 'row_id'=>$rackrow['row_id']))."${tagfilter_str}'>";
a0d54e7e
DO
241 echo "${rackrow['row_name']}</a></th>";
242 $rackList = getRacksForRow ($rackrow['row_id'], $tagfilter);
e673ee24 243 echo "<td><table border=0 cellspacing=5><tr>";
64b95774 244 foreach ($rackList as $rack)
e673ee24 245 {
4fbb5a00 246 echo "<td align=center><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$rack['id']))."'>";
e673ee24 247 echo "<img border=0 width=${rackwidth} height=";
d5157018 248 echo getRackImageHeight ($rack['height']);
e673ee24 249 echo " title='${rack['height']} units'";
d2ec5490 250 echo "src='render_image.php?img=minirack&rack_id=${rack['id']}'>";
e673ee24
DO
251 echo "<br>${rack['name']}</a></td>";
252 }
253 echo "</tr></table></tr>\n";
254 $order = $nextorder[$order];
255 }
256 echo "</table>\n";
489a7502 257 echo "</td></tr></table>\n";
e673ee24
DO
258}
259
345fd640
AD
260function renderRackspaceRowEditor ()
261{
262 function printNewItemTR ()
263 {
264 printOpFormIntro ('addRow');
265 echo "<tr><td><input type=text name=name tabindex=100></td><td>";
266 printImageHREF ('create', 'Add new row', TRUE, 101);
267 echo "</td></tr></form>";
268 }
4fbb5a00 269 global $pageno, $tabno;
345fd640
AD
270 startPortlet ('Rows');
271 showMessageOrError();
272 echo "<table border=0 cellspacing=0 cellpadding=5 align=center class=widetable>\n";
273 echo "<tr><th>Name</th></tr>\n";
274 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
275 printNewItemTR();
276 $rackrowList = getRackspace ();
277 foreach ($rackrowList as $rackrow)
278 {
279 printOpFormIntro ('updateRow', array ('row_id' => $rackrow['row_id']));
280 echo "<tr><td><input type=text name=name value='${rackrow['row_name']}'></td><td>";
281 printImageHREF ('save', 'Save changes', TRUE);
282 echo "</td></form></tr>\n";
283 }
284 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
285 printNewItemTR();
286 echo "</table><br>\n";
287 finishPortlet();
288}
289
d5157018 290function renderRow ($row_id = 0)
e673ee24
DO
291{
292 if ($row_id == 0)
293 {
39a6338a 294 showError ('Invalid row_id', __FUNCTION__);
e673ee24
DO
295 return;
296 }
297 if (($rowInfo = getRackRowInfo ($row_id)) == NULL)
298 {
39a6338a 299 showError ('getRackRowInfo() failed', __FUNCTION__);
e673ee24
DO
300 return;
301 }
a0d54e7e
DO
302 $tagfilter = getTagFilter();
303 $rackList = getRacksForRow ($row_id, $tagfilter);
e673ee24
DO
304 // Main layout starts.
305 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
306
307 // Left portlet with row information.
308 echo "<tr><td class=pcleft>";
a8ce7234 309 startPortlet ($rowInfo['name']);
e673ee24 310 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
4fbb5a00
DY
311 echo "<tr><th width='50%' class=tdright>Racks:</th><td class=tdleft>${rowInfo['rackCount']}</td></tr>\n";
312 echo "<tr><th width='50%' class=tdright>Units:</th><td class=tdleft>${rowInfo['sumHeight']}</td></tr>\n";
04d619d0 313 echo "<tr><th width='50%' class=tdright>%% used:</th><td class=tdleft>";
114e50af
DO
314 renderProgressBar (getRSUforRackRow ($rackList));
315 echo "</td></tr>\n";
e673ee24
DO
316 echo "</table><br>\n";
317 finishPortlet();
318
a0d54e7e 319 echo "</td><td class=pcright rowspan=2>";
e673ee24 320
4fbb5a00 321 global $nextorder;
d5157018 322 $rackwidth = getRackImageWidth() * getConfigVar ('ROW_SCALE');
e673ee24
DO
323 $order = 'odd';
324 startPortlet ('Racks');
325 echo "<table border=0 cellspacing=5 align='center'><tr>";
64b95774 326 foreach ($rackList as $rack)
e673ee24 327 {
4fbb5a00 328 echo "<td align=center class=row_${order}><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$rack['id']))."'>";
d5157018 329 echo "<img border=0 width=${rackwidth} height=" . (getRackImageHeight ($rack['height']) * getConfigVar ('ROW_SCALE'));
e673ee24 330 echo " title='${rack['height']} units'";
d2ec5490 331 echo "src='render_image.php?img=minirack&rack_id=${rack['id']}'>";
e673ee24
DO
332 echo "<br>${rack['name']}</a></td>";
333 $order = $nextorder[$order];
334 }
335 echo "</tr></table>\n";
336 finishPortlet();
a0d54e7e 337 echo "</td></tr>";
e673ee24 338
a0d54e7e
DO
339 echo "<tr><td class=pcleft>";
340 renderTagFilterPortlet ($tagfilter, 'rack', 'row_id', $row_id);
e673ee24
DO
341 echo "</td></tr></table>";
342}
343
04f110a0 344function showError ($info = '', $location = 'N/A')
e673ee24 345{
04f110a0
DO
346 if (preg_match ('/\.php$/', $location))
347 $location = basename ($location);
348 elseif ($location != 'N/A')
349 $location = $location . '()';
350 echo "<div class=msg_error>An error has occured in [${location}]. ";
e673ee24
DO
351 if (empty ($info))
352 echo 'No additional information is available.';
353 else
354 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
4fbb5a00 355 echo "Go back or try starting from <a href='".makeHref()."'>index page</a>.<br></div>\n";
e673ee24
DO
356}
357
358// This function renders rack as HTML table.
359function renderRack ($rack_id = 0, $hl_obj_id = 0)
360{
361 if ($rack_id == 0)
362 {
39a6338a 363 showError ('Invalid rack_id', __FUNCTION__);
e673ee24
DO
364 return;
365 }
366 if (($rackData = getRackData ($rack_id)) == NULL)
367 {
39a6338a 368 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
369 return;
370 }
4fbb5a00 371 global $pageno, $tabno;
e673ee24
DO
372 markAllSpans ($rackData);
373 if ($hl_obj_id > 0)
374 highlightObject ($rackData, $hl_obj_id);
375 markupObjectProblems ($rackData);
376 $prev_id = getPrevIDforRack ($rackData['row_id'], $rack_id);
377 $next_id = getNextIDforRack ($rackData['row_id'], $rack_id);
d48d8820 378 echo "<center><table border=0><tr valign=middle>";
4fbb5a00 379 echo "<td><h2><a href='".makeHref(array('page'=>'row', 'row_id'=>$rackData['row_id']))."'>${rackData['row_name']}</a> :</h2></td>";
e673ee24
DO
380 // FIXME: use 'bypass'?
381 if ($prev_id != NULL)
9803c56c 382 {
4fbb5a00 383 echo "<td><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$prev_id))."'>";
9803c56c 384 printImageHREF ('prev', 'previous rack');
d48d8820 385 echo "</a></td>";
9803c56c 386 }
4fbb5a00 387 echo "<td><h2><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$rackData['id']))."'>${rackData['name']}</a></h2></td>";
e673ee24 388 if ($next_id != NULL)
9803c56c 389 {
4fbb5a00 390 echo "<td><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$next_id))."'>";
f444c095 391 printImageHREF ('next', 'next rack');
d48d8820 392 echo "</a></td>";
9803c56c 393 }
d48d8820 394 echo "</h2></td></tr></table>\n";
e673ee24 395 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
d08147d6
DO
396 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
397 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
e673ee24
DO
398 for ($i = $rackData['height']; $i > 0; $i--)
399 {
d08147d6 400 echo "<tr><th>${i}</th>";
e673ee24
DO
401 for ($locidx = 0; $locidx < 3; $locidx++)
402 {
403 if (isset ($rackData[$i][$locidx]['skipped']))
404 continue;
405 $state = $rackData[$i][$locidx]['state'];
406 echo "<td class=state_${state}";
407 if (isset ($rackData[$i][$locidx]['hl']))
408 echo $rackData[$i][$locidx]['hl'];
409 if (isset ($rackData[$i][$locidx]['colspan']))
410 echo ' colspan=' . $rackData[$i][$locidx]['colspan'];
411 if (isset ($rackData[$i][$locidx]['rowspan']))
412 echo ' rowspan=' . $rackData[$i][$locidx]['rowspan'];
413 echo ">";
414 switch ($state)
415 {
416 case 'T':
417 $objectData = getObjectInfo ($rackData[$i][$locidx]['object_id']);
418 if (!empty ($objectData['asset_no']))
419 $prefix = "<div title='${objectData['asset_no']}";
420 else
421 $prefix = "<div title='no asset tag";
422 // Don't tell about label, if it matches common name.
423 if ($objectData['name'] != $objectData['label'] and !empty ($objectData['label']))
424 $suffix = ", visible label is \"${objectData['label']}\"'>";
425 else
426 $suffix = "'>";
427 echo $prefix . $suffix;
4fbb5a00 428 echo "<a href='".makeHref(array('page'=>'object', 'object_id'=>$objectData['id']))."'>${objectData['dname']}</a></div>";
e673ee24
DO
429 break;
430 case 'A':
431 echo '<div title="This rackspace does not exist">&nbsp;</div>';
432 break;
433 case 'F':
434 echo '<div title="Free rackspace">&nbsp;</div>';
435 break;
436 case 'U':
437 echo '<div title="Problematic rackspace, you CAN\'T mount here">&nbsp;</div>';
438 break;
439 default:
440 echo '<div title="No data">&nbsp;</div>';
441 break;
442 }
443 echo '</td>';
444 }
445 echo "</tr>\n";
446 }
447 echo "</table></center>\n";
448}
449
e673ee24
DO
450function renderNewRackForm ($row_id)
451{
f19c75d6 452 showMessageOrError();
f19c75d6 453
50b4ba85 454 startPortlet ('Add one');
f19c75d6 455 printOpFormIntro ('addRack', array ('got_data' => 'TRUE'));
e673ee24 456 echo '<table border=0 align=center>';
b901bf1f
DO
457 $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
458 if ($defh == 0)
459 $defh = '';
72d52730
DO
460 echo "<tr><th class=tdright>Rack name (*):</th><td class=tdleft><input type=text name=rack_name tabindex=1></td>";
461 echo "<td rowspan=4>Assign tags:<br>";
462 renderTagSelect();
463 echo "</td></tr>\n";
b8094ae4 464 echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height1 tabindex=2 value='${defh}'></td></tr>\n";
4134b5c0 465 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment tabindex=3></td></tr>\n";
f19c75d6
DO
466 echo "<tr><td class=submit colspan=2>";
467 printImageHREF ('CREATE', 'Add', TRUE);
468 echo "</td></tr></table></form>";
406b54bd 469 finishPortlet();
406b54bd 470
50b4ba85 471 startPortlet ('Add many');
f19c75d6 472 printOpFormIntro ('addRack', array ('got_mdata' => 'TRUE'));
50b4ba85
DO
473 echo '<table border=0 align=center>';
474 $defh = getConfigVar ('DEFAULT_RACK_HEIGHT');
475 if ($defh == 0)
476 $defh = '';
72d52730
DO
477 echo "<tr><th class=tdright>Height in units (*):</th><td class=tdleft><input type=text name=rack_height2 value='${defh}'></td>";
478 echo "<td rowspan=3 valign=top>Assign tags:<br>";
479 renderTagSelect();
480 echo "</td></tr>\n";
50b4ba85 481 echo "<tr><th class=tdright>Rack names (*):</th><td class=tdleft><textarea name=rack_names cols=40 rows=25></textarea></td></tr>\n";
f19c75d6
DO
482 echo "<tr><td class=submit colspan=2>";
483 printImageHREF ('CREATE', 'Add', TRUE);
e673ee24
DO
484 echo '</form></table>';
485 finishPortlet();
486}
487
488function renderEditObjectForm ($object_id)
489{
490 showMessageOrError();
e673ee24 491
4fbb5a00 492 global $pageno, $tabno;
e673ee24
DO
493 $object = getObjectInfo ($object_id);
494 if ($object == NULL)
495 {
39a6338a 496 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
497 return;
498 }
cdd3efe9 499 startPortlet ();
43fb6eaf 500 printOpFormIntro ('update');
cdd3efe9
AD
501 echo '<table border=0 width=100%><tr><td class=pcleft>';
502
503 // static attributes
e673ee24 504 echo '<table border=0 align=center>';
cdd3efe9 505 echo "<tr><th colspan=2><h2>Static attributes</h2></th></tr>";
e673ee24
DO
506 echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
507 printSelect (getObjectTypeList(), 'object_type_id', $object['objtype_id']);
508 echo "</td></tr>\n";
22bb04da 509 // baseline info
e673ee24
DO
510 echo "<tr><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='${object['name']}'></td></tr>\n";
511 echo "<tr><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='${object['label']}'></td></tr>\n";
512 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";
4fbb5a00 513 /*echo "<tr><th class=tdright>Has problems:</th><td class=tdleft><input type=checkbox name=object_has_problems";
e673ee24
DO
514 if ($object['has_problems'] == 'yes')
515 echo ' checked';
4fbb5a00
DY
516 echo "></td></tr>\n";*/
517 echo "<tr><th class=tdright>Actions:</th><td class=tdleft><a href='".
518 makeHrefProcess(array('op'=>'deleteObject', 'page'=>'objects', 'tab'=>'default', 'object_id'=>$object_id, 'name'=>$object['name'])).
519 "' onclick=\"javascript:return confirm('Are you sure you want to delete the object?')\">Delete object</a></td></tr>\n";
e673ee24 520 echo "<tr><td colspan=2><b>Comment:</b><br><textarea name=object_comment rows=10 cols=80>${object['comment']}</textarea></td></tr>";
cdd3efe9
AD
521 echo '</table>';
522
523 echo '</td><td class=pcright>';
e673ee24 524
cdd3efe9 525 // optional attributes
e673ee24 526 $values = getAttrValues ($object_id);
2b98d5a2 527 if (count($values) > 0)
e673ee24 528 {
2b98d5a2
AD
529 echo "<table border=0 cellspacing=0 cellpadding=5 align=center class=widetable>\n";
530 echo "<tr><th colspan=3><h2>Optional attributes</h2></th></tr>";
531 echo "<tr><th>&nbsp;</th><th>Attribute</th><th>Value</th></tr>\n";
532 echo '<input type=hidden name=num_attrs value=' . count($values) . ">\n";
533 $i = 0;
534 foreach ($values as $record)
e673ee24 535 {
2b98d5a2
AD
536 echo "<input type=hidden name=${i}_attr_id value=${record['id']}>";
537 echo '<tr><td>';
538 if (!empty ($record['value']))
539 {
4fbb5a00 540 echo "<a href='".makeHrefProcess(array('op'=>'clearSticker', 'object_id'=>$object_id, 'attr_id'=>$record['id']))."'>";
2b98d5a2
AD
541 printImageHREF ('clear', 'Clear value');
542 echo '</a>';
543 }
544 else
545 echo '&nbsp;';
546 echo '</td>';
547 echo "<td class=tdright>${record['name']}:</td><td class=tdleft>";
548 switch ($record['type'])
549 {
550 case 'uint':
551 case 'float':
552 case 'string':
553 echo "<input type=text name=${i}_value value='${record['value']}'>";
554 break;
555 case 'dict':
556 $chapter = readChapter ($record['chapter_name']);
557 $chapter[0] = '-- NOT SET --';
558 printSelect ($chapter, "${i}_value", $record['key']);
559 break;
560 }
561 echo "</td></tr>\n";
562 $i++;
e673ee24 563 }
2b98d5a2 564 echo "</table>";
e673ee24 565 }
2b98d5a2 566 echo "</td></tr>\n";
cdd3efe9
AD
567
568 echo "<tr><th class=submit colspan=2>";
5bbbeaa2 569 printImageHREF ('SAVE', 'Save changes', TRUE);
cdd3efe9 570 echo "</form></th></tr></table>\n";
e673ee24 571 finishPortlet();
e673ee24 572
cdd3efe9 573 echo '<table border=0 width=100%><tr><td>';
e673ee24
DO
574 startPortlet ('history');
575 renderHistory ($pageno, $object_id);
576 finishPortlet();
cdd3efe9 577 echo '</td></tr></table>';
e673ee24
DO
578}
579
580// This is a clone of renderEditObjectForm().
581function renderEditRackForm ($rack_id)
582{
0c2b7c4a
DO
583 showMessageOrError();
584 global $pageno;
e673ee24
DO
585 $rack = getRackData ($rack_id);
586 if ($rack == NULL)
587 {
39a6338a 588 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
589 return;
590 }
591
e673ee24 592 startPortlet ('Rack attributes');
7056988c 593 printOpFormIntro ('updateRack');
e673ee24
DO
594 echo '<table border=0 align=center>';
595 echo "<tr><th class=tdright>Rack row:</th><td class=tdleft>";
4fbb5a00 596 printSelect (getRackRows(), 'rack_row_id', $rack['row_id']);
e673ee24
DO
597 echo "</td></tr>\n";
598 echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name value='${rack['name']}'></td></tr>\n";
599 echo "<tr><th class=tdright>Height (required):</th><td class=tdleft><input type=text name=rack_height value='${rack['height']}'></td></tr>\n";
600 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment value='${rack['comment']}'></td></tr>\n";
7056988c
DO
601 echo "<tr><td class=submit colspan=2>";
602 printImageHREF ('SAVE', 'Save changes', TRUE);
603 echo "</td></tr>\n";
e673ee24
DO
604 echo '</form></table><br>';
605 finishPortlet();
606
607 startPortlet ('History');
608 renderHistory ($pageno, $rack_id);
609 finishPortlet();
610}
611
612// This is a helper for creators and editors.
a65f9f54 613function printSelect ($rowList, $select_name, $selected_id = NULL, $tabindex = NULL)
e673ee24 614{
9e7f32a7
DO
615 // First collect all data for OPTGROUPs, then ouput it and dump
616 // the rest of records as is.
617 $optgroup = array();
618 $other = array();
4c330a14 619 foreach ($rowList as $dict_key => $dict_value)
e673ee24 620 {
f0b540a3 621 if (strpos ($dict_value, '%GSKIP%') !== FALSE)
9e7f32a7 622 {
f0b540a3 623 $tmp = explode ('%GSKIP%', $dict_value, 2);
9e7f32a7
DO
624 $optgroup[$tmp[0]][$dict_key] = $tmp[1];
625 }
f0b540a3 626 elseif (strpos ($dict_value, '%GPASS%') !== FALSE)
2613bc1c 627 {
f0b540a3 628 $tmp = explode ('%GPASS%', $dict_value, 2);
2613bc1c
DO
629 $optgroup[$tmp[0]][$dict_key] = $tmp[1];
630 }
9e7f32a7
DO
631 else
632 $other[$dict_key] = $dict_value;
633 }
a65f9f54 634 echo "<select name=${select_name}" . ($tabindex ? " tabindex=${tabindex}" : '') . '>';
9e7f32a7
DO
635 if (!count ($optgroup))
636 {
637 foreach ($other as $dict_key => $dict_value)
638 {
639 echo "<option value=${dict_key}";
0b9b1063 640 if ($dict_key == $selected_id)
9e7f32a7
DO
641 echo ' selected';
642 echo ">${dict_value}</option>";
643 }
644 }
645 else
646 {
647 foreach ($optgroup as $groupname => $groupdata)
648 {
649 echo "<optgroup label='${groupname}'>";
650 foreach ($groupdata as $dict_key => $dict_value)
651 {
652 echo "<option value=${dict_key}";
0b9b1063 653 if ($dict_key == $selected_id)
9e7f32a7
DO
654 echo ' selected';
655 echo ">${dict_value}</option>";
656 }
657 echo "</optgroup>\n";
658 }
659 if (count ($other))
660 {
661 echo "<optgroup label='other'>\n";
662 foreach ($other as $dict_key => $dict_value)
663 {
664 echo "<option value=${dict_key}";
0b9b1063 665 if ($dict_key == $selected_id)
9e7f32a7
DO
666 echo ' selected';
667 echo ">${dict_value}</option>";
668 }
669 echo "</optgroup>\n";
670 }
e673ee24
DO
671 }
672 echo "</select>";
673}
674
254673dd
DO
675// used by renderGridForm() and renderRackPage()
676function renderRackInfoPortlet ($rackData)
677{
678 startPortlet ('summary');
679 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
680 echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
681 echo "<tr><th width='50%' class=tdright>Name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
682 echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
04d619d0 683 echo "<tr><th width='50%' class=tdright>%% used:</th><td class=tdleft>";
254673dd
DO
684 renderProgressBar (getRSUforRack ($rackData));
685 echo "</td></tr>\n";
686 echo "<tr><th width='50%' class=tdright>Objects:</th><td class=tdleft>";
abef7149 687 echo count (stuffInRackspace ($rackData));
254673dd 688 echo "</td></tr>\n";
4fbb5a00 689 printTagTRs (makeHref(array('page'=>'rackspace', 'tab'=>'default'))."&");
254673dd
DO
690 if (!empty ($rackData['comment']))
691 echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
692 echo '</table>';
693 finishPortlet();
694}
695
e673ee24 696// This is a universal editor of rack design/waste.
7056988c 697// FIXME: switch to using printOpFormIntro()
bb09cca0 698function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $state2)
e673ee24
DO
699{
700 if ($rack_id == 0)
701 {
591ff2c4 702 showError ('Invalid rack_id', __FUNCTION__);
e673ee24
DO
703 return;
704 }
705 if (($rackData = getRackData ($rack_id)) == NULL)
706 {
591ff2c4 707 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
708 return;
709 }
710
4fbb5a00 711 global $pageno, $tabno;
254673dd 712 $filter ($rackData);
e673ee24
DO
713 markupObjectProblems ($rackData);
714
e673ee24
DO
715 // Render the result whatever it is.
716 // Main layout.
717 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
718 echo "<tr><td colspan=2 align=center><h1>${rackData['name']}</h1></td></tr>\n";
719
720 // Left column with information portlet.
721 echo "<tr><td class=pcleft height='1%' width='50%'>";
254673dd 722 renderRackInfoPortlet ($rackData);
e673ee24 723 echo "</td>\n";
bb09cca0 724 echo "<td class=pcright>";
e673ee24
DO
725
726 // Grid form.
727 startPortlet ($header);
728 echo "<center>\n";
729 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
730 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
731 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
4fbb5a00 732 printOpFormIntro ('updateRack');
e673ee24
DO
733 markupAtomGrid ($rackData, $state2);
734 renderAtomGrid ($rackData);
735 echo "</table></center>\n";
736 echo "<br><input type=submit name=do_update value='${submit}'></form><br><br>\n";
737 finishPortlet();
bb09cca0 738 echo "</td></tr></table>\n";
e673ee24
DO
739}
740
741function renderRackDesign ($rack_id)
742{
bb09cca0 743 renderGridForm ($rack_id, 'applyRackDesignMask', 'Rack design', 'Set rack design', 'A', 'F');
e673ee24
DO
744}
745
746function renderRackProblems ($rack_id = 0)
747{
bb09cca0 748 renderGridForm ($rack_id, 'applyRackProblemMask', 'Rack problems', 'Mark unusable atoms', 'F', 'U');
e673ee24
DO
749}
750
751function startPortlet ($title = '')
752{
753 echo "<div class=portlet><h2>${title}</h2>";
754}
755
756function finishPortlet ()
757{
758 echo "</div>\n";
759}
760
761function printRefsOfType ($refs, $type, $eq)
762{
e673ee24
DO
763 $gotone=0;
764 foreach ($refs as $ref)
765 {
766 if ($eq($ref['type'], $type))
767 {
768 if ($gotone) echo ', ';
4fbb5a00 769 echo "<a href='".makeHref(array('page'=>'object', 'object_id'=>$ref['object_id']))."'>";
4b2bf583
DO
770 if (!empty ($ref['name']))
771 echo $ref['name'] . '@';
772 echo "${ref['object_name']}</a>";
e673ee24
DO
773 $gotone=1;
774 }
775 }
776}
777
778function renderRackObject ($object_id = 0)
779{
4fbb5a00 780 global $nextorder, $aac;
e673ee24
DO
781 if ($object_id <= 0)
782 {
591ff2c4 783 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
784 return;
785 }
786 $info = getObjectInfo ($object_id);
787 if ($info == NULL)
788 {
591ff2c4 789 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
790 return;
791 }
792 // Main layout starts.
793 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
794 echo "<tr><td colspan=2 align=center><h1>${info['dname']}</h1></td></tr>\n";
795 // left column with uknown number of portlets
796 echo "<tr><td class=pcleft>";
0ab782bc 797 startPortlet ('summary');
e673ee24
DO
798 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
799 if (!empty ($info['name']))
800 echo "<tr><th width='50%' class=tdright>Common name:</th><td class=tdleft>${info['name']}</td></tr>\n";
9c0b0016 801 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
a0ec6295 802 echo "<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>\n";
e2ac59cf 803 echo "<tr><th width='50%' class=tdright>Object type:</th>";
4fbb5a00 804 echo "<td class=tdleft><a href='".makeHref(array('page'=>'objgroup', 'group_id'=>$info['objtype_id'], 'hl_object_id'=>$object_id))."'>${info['objtype_name']}</a></td></tr>\n";
e673ee24
DO
805 if (!empty ($info['asset_no']))
806 echo "<tr><th width='50%' class=tdright>Asset tag:</th><td class=tdleft>${info['asset_no']}</td></tr>\n";
a6305acc 807 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('REQUIRE_ASSET_TAG_FOR'))))
a0ec6295 808 echo "<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>\n";
e673ee24
DO
809 if (!empty ($info['label']))
810 echo "<tr><th width='50%' class=tdright>Visible label:</th><td class=tdleft>${info['label']}</td></tr>\n";
811 if (!empty ($info['barcode']))
812 echo "<tr><th width='50%' class=tdright>Barcode:</th><td class=tdleft>${info['barcode']}</td></tr>\n";
813 if ($info['has_problems'] == 'yes')
814 echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
24cbe8af 815 foreach (getAttrValues ($object_id, TRUE) as $record)
e673ee24 816 if (!empty ($record['value']))
4fb5bc8c 817 echo "<tr><th width='50%' class=tdright><span class=sticker>${record['name']}</span>:</th><td class=tdleft>${record['a_value']}</td></tr>\n";
4fbb5a00 818 printTagTRs (makeHref(array('page'=>'objgroup', 'tab'=>'default', 'group_id'=>$info['objtype_id']))."&");
e673ee24
DO
819 echo "</table><br>\n";
820 finishPortlet();
821
822 if (!empty ($info['comment']))
823 {
824 startPortlet ('Comment');
6cc5d6cd 825 echo '<div class=commentblock>' . string_insert_hrefs ($info['comment']) . '</div>';
e673ee24
DO
826 finishPortlet ();
827 }
828
e1ae3fb4
AD
829 renderFilesPortlet ('object', $object_id);
830
e673ee24
DO
831 $ports = getObjectPortsAndLinks ($object_id);
832 if (count ($ports))
833 {
0ab782bc 834 startPortlet ('ports and links');
e673ee24
DO
835 usort($ports, 'sortByName');
836 if ($ports)
837 {
838 $hl_port_id = 0;
839 if (isset ($_REQUEST['hl_port_id']))
840 {
2c6c7645 841 assertUIntArg ('hl_port_id', __FUNCTION__);
e673ee24
DO
842 $hl_port_id = $_REQUEST['hl_port_id'];
843 }
844 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
845 echo "<tr><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
846 echo "<th>Rem. Object</th><th>Rem. port</th></tr>\n";
847 foreach ($ports as $port)
848 {
849 echo '<tr';
850 if ($hl_port_id == $port['id'])
851 echo ' class=port_highlight';
852 echo "><td>${port['name']}</td><td>${port['label']}</td><td>${port['type']}</td>";
853 echo "<td>${port['l2address']}</td>";
854 if ($port['remote_object_id'])
855 {
4fbb5a00 856 echo "<td><a href='".makeHref(array('page'=>'object', 'object_id'=>$port['remote_object_id'], 'hl_port_id'=>$port['remote_id']))."'>${port['remote_object_name']}</a></td>";
e673ee24
DO
857 echo "<td>${port['remote_name']}</td>";
858 }
859 elseif (!empty ($port['reservation_comment']))
860 {
861 echo "<td><b>Reserved;</b></td>";
862 echo "<td>${port['reservation_comment']}</td>";
863 }
864 else
865 echo '<td>&nbsp;</td><td>&nbsp;</td>';
866 echo "</tr>\n";
867 }
868 echo "</table><br>\n";
869 }
870 finishPortlet();
871 }
85970da2 872
0ab782bc
DO
873 $alloclist = getObjectIPv4Allocations ($object_id);
874 if (count ($alloclist))
e673ee24 875 {
f28fbe8b 876 startPortlet ('IPv4 addresses');
e673ee24 877 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
f0ed1181 878 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
71287f1c 879 echo "<tr><th>OS interface</th><th>IP address</th><th colspan=2>network</th><th>routed by</th><th>peers</th></tr>\n";
83fdf85f
DO
880 else
881 echo "<tr><th>OS interface</th><th>IP address</th><th>peers</th></tr>\n";
fc0e3978
DO
882 $hl_ipv4_addr = '';
883 if (isset ($_REQUEST['hl_ipv4_addr']))
884 {
885 assertIPv4Arg ('hl_ipv4_addr', __FUNCTION__);
886 $hl_ipv4_addr = $_REQUEST['hl_ipv4_addr'];
887 }
85970da2 888 foreach ($alloclist as $dottedquad => $alloc)
e673ee24 889 {
0ab782bc
DO
890 $address_name = niftyString ($alloc['addrinfo']['name']);
891 $class = $alloc['addrinfo']['class'];
85970da2 892 $secondclass = ($hl_ipv4_addr == $dottedquad) ? 'tdleft port_highlight' : 'tdleft';
83fdf85f 893 $netid = getIPv4AddressNetworkId ($dottedquad);
d7a8186d 894 if (NULL !== $netid)
83fdf85f 895 {
d7a8186d
DO
896 $netinfo = getIPv4NetworkInfo ($netid);
897 loadIPv4AddrList ($netinfo);
83fdf85f 898 }
d7a8186d
DO
899 echo "<tr class='${class}' valign=top><td class=tdleft>${alloc['osif']}</td><td class='${secondclass}'>";
900 if (NULL !== $netid)
4fbb5a00 901 echo "<a href='".makeHref(array('page'=>'ipaddress', 'ip'=>$dottedquad, 'hl_object_id'=>$object_id))."'>${dottedquad}</a>";
d7a8186d
DO
902 else
903 echo $dottedquad;
904 if (getConfigVar ('EXT_IPV4_VIEW') != 'yes')
905 echo '<small>/' . (NULL === $netid ? '??' : $netinfo['mask']) . '</small>';
351b1f45 906 echo '&nbsp;' . $aac[$alloc['type']];
83fdf85f 907 if (!empty ($alloc['addrinfo']['name']))
28a664e7 908 echo ' (' . niftyString ($alloc['addrinfo']['name']) . ')';
83fdf85f 909 echo '</td>';
f0ed1181 910 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
b90c3907 911 {
83fdf85f 912 if (NULL === $netid)
d7a8186d 913 echo '<td colspan=2>N/A</td><td>&nbsp;</td>';
83fdf85f 914 else
83fdf85f 915 {
d7a8186d 916 printIPv4NetInfoTDs ($netinfo, $secondclass);
8b3874a5
DO
917 // filter out self-allocation
918 $other_routers = array();
d7a8186d 919 foreach (findRouters ($netinfo['addrlist']) as $router)
8b3874a5
DO
920 if ($router['id'] != $object_id)
921 $other_routers[] = $router;
922 printRoutersTD ($other_routers);
83fdf85f 923 }
b90c3907 924 }
83fdf85f 925 // peers
0ab782bc 926 echo "<td class='${secondclass}'>\n";
0ab782bc 927 $prefix = '';
2c817354 928 if ($alloc['addrinfo']['reserved'] == 'yes')
e673ee24 929 {
85970da2 930 echo $prefix . '<strong>RESERVED</strong>';
0ab782bc
DO
931 $prefix = '; ';
932 }
933 foreach ($alloc['addrinfo']['allocs'] as $allocpeer)
934 {
935 if ($allocpeer['object_id'] == $object_id)
936 continue;
4fbb5a00 937 echo $prefix . "<a href='".makeHref(array('page'=>'object', 'object_id'=>$allocpeer['object_id']))."'>";
0ab782bc
DO
938 if (!empty ($allocpeer['osif']))
939 echo $allocpeer['osif'] . '@';
940 echo $allocpeer['object_name'] . '</a>';
0ab782bc 941 $prefix = '; ';
e673ee24 942 }
e673ee24
DO
943 echo "</td></tr>\n";
944 }
945 echo "</table><br>\n";
946 finishPortlet();
947 }
948
eeb4a5d8 949 $forwards = getNATv4ForObject ($object_id);
e673ee24
DO
950 if (count($forwards['in']) or count($forwards['out']))
951 {
f28fbe8b 952 startPortlet('NATv4');
e673ee24
DO
953
954 if (count($forwards['out']))
955 {
956
f28fbe8b 957 echo "<h3>locally performed NAT</h3>";
e673ee24 958
105a3bc8 959 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n";
f28fbe8b 960 echo "<tr><th>Proto</th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Rule comment</th></tr>\n";
e673ee24
DO
961
962 foreach ($forwards['out'] as $pf)
963 {
2c817354
DO
964 $class = 'trerror';
965 $osif = '';
966 if (isset ($alloclist [$pf['localip']]))
967 {
968 $class = $alloclist [$pf['localip']]['addrinfo']['class'];
969 $osif = $alloclist [$pf['localip']]['osif'] . ': ';
970 }
e673ee24 971 echo "<tr class='$class'>";
4fbb5a00
DY
972 echo "<td>${pf['proto']}</td><td class=tdleft>${osif}<a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['localip']))."'>${pf['localip']}</a>:${pf['localport']}</td>";
973 echo "<td class=tdleft><a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['remoteip']))."'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
53ef3908 974 $address = getIPv4Address ($pf['remoteip']);
e673ee24 975 echo "<td class='description'>";
53ef3908
DO
976 if (count ($address['allocs']))
977 foreach($address['allocs'] as $bond)
4fbb5a00 978 echo "<a href='".makeHref(array('page'=>'object', 'tab'=>'default', 'object_id'=>$bond['object_id']))."'>${bond['object_name']}(${bond['name']})</a> ";
f28fbe8b
DO
979 elseif (!empty ($pf['remote_addr_name']))
980 echo '(' . $pf['remote_addr_name'] . ')';
53ef3908 981 echo "</td><td class='description'>${pf['description']}</td></tr>";
e673ee24
DO
982 }
983 echo "</table><br><br>";
984 }
985 if (count($forwards['in']))
986 {
f28fbe8b 987 echo "<h3>arriving NAT connections</h3>";
105a3bc8 988 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n";
f28fbe8b 989 echo "<tr><th>Matched endpoint</th><th>Source object</th><th>Translated to</th><th>Rule comment</th></tr>\n";
e673ee24
DO
990 foreach ($forwards['in'] as $pf)
991 {
992 echo "<tr>";
4fbb5a00
DY
993 echo "<td>${pf['proto']}/<a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['localip']))."'>${pf['localip']}</a>:${pf['localport']}</td>";
994 echo "<td class='description'><a href='".makeHref(array('page'=>'object', 'tab'=>'default', 'object_id'=>$pf['object_id']))."'>${pf['object_name']}</a>";
995 echo "</td><td><a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['remoteip']))."'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
e673ee24
DO
996 echo "<td class='description'>${pf['description']}</td></tr>";
997 }
e673ee24
DO
998 echo "</table><br><br>";
999 }
1000 finishPortlet();
1001 }
1002
78e7b769
DO
1003 $pools = getRSPoolsForObject ($object_id);
1004 if (count ($pools))
1005 {
300826cb 1006 $order = 'odd';
78e7b769
DO
1007 startPortlet ('Real server pools');
1008 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
732e4578 1009 echo "<tr><th>VS</th><th>RS pool</th><th>RS</th><th>VS config</th><th>RS config</th></tr>\n";
748805bf 1010 foreach ($pools as $vs_id => $info)
78e7b769 1011 {
b1a970c7
DO
1012 echo "<tr valign=top class=row_${order}><td class=tdleft>";
1013 renderVSCell ($vs_id);
1014 echo "</td><td class=tdleft>";
1015 renderRSPoolCell ($info['pool_id'], $info['pool_name']);
1016 echo '</td><td class=tdleft>' . $info['rscount'] . '</td>';
1017 echo "<td class=slbconf>${info['vsconfig']}</td>";
1018 echo "<td class=slbconf>${info['rsconfig']}</td>";
78e7b769 1019 echo "</tr>\n";
300826cb 1020 $order = $nextorder[$order];
78e7b769
DO
1021 }
1022 echo "</table>\n";
1023 finishPortlet();
1024 }
e673ee24
DO
1025 echo "</td>\n";
1026
7056988c 1027 // After left column we have (surprise!) right column with rackspace portlet only.
e673ee24
DO
1028 echo "<td class=pcright>";
1029 // rackspace portlet
0ab782bc 1030 startPortlet ('rackspace allocation');
e673ee24
DO
1031 // FIXME: now we call getRackData() twice
1032 $racks = getResidentRacksData ($object_id);
1033 foreach ($racks as $rackData)
1034 renderRack ($rackData['id'], $object_id);
1035 echo '<br>';
1036 finishPortlet();
1037 echo "</td></tr>";
1038 echo "</table>\n";
1039}
1040
1041function renderRackMultiSelect ($sname, $racks, $selected)
1042{
04571888
DO
1043 // Transform the given flat list into a list of groups, each representing a rack row.
1044 $rdata = array();
e673ee24 1045 foreach ($racks as $rack)
04571888
DO
1046 if (!isset ($rdata[$rack['row_name']]))
1047 $rdata[$rack['row_name']] = array ($rack['id'] => $rack['name']);
1048 else
1049 $rdata[$rack['row_name']][$rack['id']] = $rack['name'];
4fbb5a00 1050 echo "<select name=${sname} multiple size=" . getConfigVar ('MAXSELSIZE') . " onchange='getElementsByName(\"updateObjectAllocation\")[0].submit()'>\n";
04571888 1051 foreach ($rdata as $optgroup => $racklist)
e673ee24 1052 {
04571888
DO
1053 echo "<optgroup label='${optgroup}'>";
1054 foreach ($racklist as $rack_id => $rack_name)
1055 {
1056 echo "<option value=${rack_id}";
1057 if (!(array_search ($rack_id, $selected) === FALSE))
1058 echo ' selected';
1059 echo">${rack_name}</option>\n";
1060 }
e673ee24
DO
1061 }
1062 echo "</select>\n";
1063}
1064
1065function showMessageOrError ()
1066{
46f92ff7 1067 if (isset ($_REQUEST['message']))
e673ee24 1068 echo "<div class=msg_success>${_REQUEST['message']}</div>";
46f92ff7 1069 elseif (isset ($_REQUEST['error']))
e673ee24 1070 echo "<div class=msg_error>${_REQUEST['error']}</div>";
46f92ff7
DO
1071 elseif (isset ($_REQUEST['log']))
1072 printLog (unserialize (base64_decode ($_REQUEST['log'])));
e673ee24
DO
1073}
1074
1075// This function renders a form for port edition.
1076function renderPortsForObject ($object_id = 0)
1077{
39b4abd0
DO
1078 function printNewItemTR ()
1079 {
1080 printOpFormIntro ('addPort');
1081 echo "<tr><td>";
f5ff50f5 1082 printImageHREF ('add', 'add a port', TRUE);
39b4abd0 1083 echo "</td><td><input type=text size=8 name=port_name tabindex=100></td>\n";
3decd141
DO
1084 echo "<td><input type=text size=24 name=port_label tabindex=101></td><td>";
1085 printSelect (getPortTypes(), 'port_type_id', getConfigVar ('default_port_type'), 102);
39b4abd0 1086 echo "<td><input type=text name=port_l2address tabindex=103></td>\n";
9318d2ef
DO
1087 echo "<td colspan=3>&nbsp;</td><td>";
1088 printImageHREF ('add', 'add a port', TRUE, 104);
1089 echo "</td></tr></form>";
39b4abd0 1090 }
4fbb5a00 1091 global $pageno, $tabno;
e673ee24
DO
1092 if ($object_id <= 0)
1093 {
591ff2c4 1094 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1095 return;
1096 }
1097 showMessageOrError();
1098 startPortlet ('Ports and interfaces');
1099 $ports = getObjectPortsAndLinks ($object_id);
1100 usort($ports, 'sortByName');
1101 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
1102 echo "<tr><th>&nbsp;</th><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
1103 echo "<th>Rem. object</th><th>Rem. port</th><th>(Un)link or (un)reserve</th><th>&nbsp;</th></tr>\n";
39b4abd0
DO
1104 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
1105 printNewItemTR();
e673ee24
DO
1106 foreach ($ports as $port)
1107 {
7056988c 1108 printOpFormIntro ('editPort', array ('port_id' => $port['id']));
4fbb5a00 1109 echo "<tr><td><a href='".makeHrefProcess(array('op'=>'delport', 'port_id'=>$port['id'], 'object_id'=>$object_id, 'port_name'=>$port['name']))."'>";
e673ee24
DO
1110 printImageHREF ('delete', 'Unlink and Delete this port');
1111 echo "</a></td>\n";
1112 echo "<td><input type=text name=name value='${port['name']}' size=8></td>";
1113 echo "<td><input type=text name=label value='${port['label']}' size=24></td>";
611170af
AD
1114 if (!$port['remote_object_id'])
1115 {
1116 echo "<td>";
1117 printSelect (getPortTypes(), 'port_type_id', $port['type_id']);
1118 echo "</td>";
1119 }
1120 else
1121 {
1122 echo "<input type=hidden name=port_type_id value='${port['type_id']}'>";
1123 echo "<td>${port['type']}</td>\n";
1124 }
e673ee24
DO
1125 echo "<td><input type=text name=l2address value='${port['l2address']}'></td>\n";
1126 if ($port['remote_object_id'])
1127 {
4fbb5a00 1128 echo "<td><a href='".makeHref(array('page'=>'object', 'object_id'=>$port['remote_object_id']))."'>${port['remote_object_name']}</a></td>";
e673ee24 1129 echo "<td>${port['remote_name']}</td>";
4fbb5a00
DY
1130 echo "<td><a href='".
1131 makeHrefProcess(array(
1132 'op'=>'unlinkPort',
1133 'port_id'=>$port['id'],
1134 'object_id'=>$object_id,
1135 'port_name'=>$port['name'],
1136 'remote_port_name'=>$port['remote_name'],
1137 'remote_object_name'=>$port['remote_object_name'])).
1138 "'>";
39be655e 1139 printImageHREF ('clear', 'Unlink this port');
e673ee24
DO
1140 echo "</a></td>";
1141 }
1142 elseif (!empty ($port['reservation_comment']))
1143 {
1144 echo "<td><b>Reserved;</b></td>";
1145 echo "<td><input type=text name=reservation_comment value='${port['reservation_comment']}'></td>";
4fbb5a00
DY
1146 echo "<td><a href='".
1147 makeHrefProcess(array(
1148 'op'=>'useup',
1149 'port_id'=>$port['id'],
1150 'object_id'=>$object_id)).
1151 "'>";
39be655e 1152 printImageHREF ('clear', 'Use up this port');
e673ee24
DO
1153 echo "</a></td>";
1154 }
1155 else
1156 {
1157 echo "<td>&nbsp;</td><td>&nbsp;</td>";
1158 echo "<td>";
4fbb5a00 1159 echo "<a href='javascript:;' onclick='window.open(\"".makeHrefPortLinkHelper(array('port'=>$port['id'], 'type'=>$port['type_id'], 'object_id'=>$object_id, 'port_name'=>$port['name']))."\",\"findlink\",\"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
e673ee24
DO
1160 printImageHREF ('link', 'Link this port');
1161 echo "</a> <input type=text name=reservation_comment>";
1162 echo "</td>\n";
1163 }
5bbbeaa2
DO
1164 echo "<td>";
1165 printImageHREF ('save', 'Save changes', TRUE);
1166 echo "</td></form></tr>\n";
e673ee24 1167 }
39b4abd0
DO
1168 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
1169 printNewItemTR();
e673ee24
DO
1170 echo "</table><br>\n";
1171 finishPortlet();
1172
1173 startPortlet ('Add/update multiple ports');
7056988c 1174 printOpFormIntro ('addMultiPorts');
e673ee24 1175 echo 'Format: <select name=format>';
e673ee24
DO
1176 echo '<option value=c3600asy>Cisco 3600 async: sh line | inc TTY</option>';
1177 echo '<option value=fiwg selected>Foundry ServerIron/FastIron WorkGroup/Edge: sh int br</option>';
e673ee24 1178 echo '<option value=fisxii>Foundry FastIron SuperX/II4000: sh int br</option>';
351d4dbf 1179 echo '<option value=ssv1>SSV:&lt;interface name&gt; &lt;MAC address&gt;</option>';
e673ee24
DO
1180 echo "</select>";
1181 echo 'Default port type: ';
3decd141 1182 printSelect (getPortTypes(), 'port_type', getConfigVar ('default_port_type'), 102);
e673ee24
DO
1183 echo "<input type=submit value='Parse output'><br>\n";
1184 echo "<textarea name=input cols=100 rows=50></textarea><br>\n";
1185 echo '</form>';
1186 finishPortlet();
1187}
1188
72d8ced3 1189function renderIPv4ForObject ($object_id = 0)
e673ee24 1190{
39b4abd0
DO
1191 function printNewItemTR ()
1192 {
1193 global $aat;
1194 printOpFormIntro ('addIPv4Allocation');
1195 echo "<tr><td>";
f5ff50f5 1196 printImageHREF ('add', 'allocate', TRUE);
39b4abd0
DO
1197 echo "</td>";
1198 echo "<td class=tdleft><input type='text' size='10' name='bond_name' tabindex=100></td>\n";
1199 echo "<td class=tdleft><input type=text name='ip' tabindex=101></td>\n";
1200 echo "<td colspan=3>&nbsp;</td><td>";
f5ff50f5 1201 printSelect ($aat, 'bond_type', NULL, 102);
9318d2ef 1202 echo "</td><td>&nbsp;</td><td>";
f5ff50f5 1203 printImageHREF ('add', 'allocate', TRUE, 103);
9318d2ef 1204 echo "</td></tr></form>";
39b4abd0 1205 }
4fbb5a00 1206 global $pageno, $tabno, $aat;
e673ee24
DO
1207 if ($object_id <= 0)
1208 {
591ff2c4 1209 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1210 return;
1211 }
1212 showMessageOrError();
72d8ced3 1213 startPortlet ('Allocations');
85970da2 1214 $alloclist = getObjectIPv4Allocations ($object_id);
e673ee24 1215 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
79e45b4c
DO
1216 echo '<tr><th>&nbsp;</th><th>OS interface</th><th>IP address</th>';
1217 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
1218 echo '<th colspan=2>network</th><th>routed by</th>';
1219 echo '<th>type</th><th>misc</th><th>&nbsp</th></tr>';
09620506 1220
39b4abd0
DO
1221 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
1222 printNewItemTR();
85970da2 1223 foreach ($alloclist as $dottedquad => $alloc)
e673ee24 1224 {
85970da2 1225 $class = $alloc['addrinfo']['class'];
79e45b4c 1226 $netid = getIPv4AddressNetworkId ($dottedquad);
d7a8186d
DO
1227 if (NULL !== $netid)
1228 {
1229 $netinfo = getIPv4NetworkInfo ($netid);
1230 loadIPv4AddrList ($netinfo);
1231 }
85970da2 1232 printOpFormIntro ('updIPv4Allocation', array ('ip' => $dottedquad));
4fbb5a00 1233 echo "<tr class='$class' valign=top><td><a href='".makeHrefProcess(array('op'=>'delIPv4Allocation', 'ip'=>$dottedquad, 'object_id'=>$object_id))."'>";
e673ee24
DO
1234 printImageHREF ('delete', 'Delete this IPv4 address');
1235 echo "</a></td>";
d7a8186d
DO
1236 echo "<td class=tdleft><input type='text' name='bond_name' value='${alloc['osif']}' size=10></td><td class=tdleft>";
1237 if (NULL !== $netid)
4fbb5a00 1238 echo "<a href='".makeHref(array('page'=>'ipaddress', 'ip'=>$dottedquad))."'>${dottedquad}</a>";
d7a8186d
DO
1239 else
1240 echo $dottedquad;
79e45b4c 1241 if (getConfigVar ('EXT_IPV4_VIEW') != 'yes')
d7a8186d 1242 echo '<small>/' . (NULL === $netid ? '??' : $netinfo['mask']) . '</small>';
79e45b4c 1243 if (!empty ($alloc['addrinfo']['name']))
28a664e7 1244 echo ' (' . niftyString ($alloc['addrinfo']['name']) . ')';
79e45b4c
DO
1245 echo '</td>';
1246 // FIXME: this a copy-and-paste from renderRackObject()
1247 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
1248 {
1249 if (NULL === $netid)
d7a8186d 1250 echo '<td colspan=2>N/A</td><td>&nbsp;</td>';
79e45b4c 1251 else
79e45b4c 1252 {
d7a8186d
DO
1253 printIPv4NetInfoTDs ($netinfo);
1254 echo "<td class=tdleft>";
1255 // FIXME: These calls are really heavy, replace them with a more appropriate dedicated function.
1256 $newline = '';
1257 foreach (findRouters ($netinfo['addrlist']) as $router)
1258 {
1259 if ($router['id'] == $object_id)
1260 continue;
4fbb5a00 1261 echo $newline . $router['addr'] . ", <a href='".makeHref(array('page'=>'object', 'object_id'=>$router['id'], 'hl_ipv4_addr'=>$router['addr']))."'>";
d7a8186d
DO
1262 echo (empty ($router['iface']) ? '' : $router['iface'] . '@') . $router['dname'] . '</a>';
1263 $routertags = loadRackObjectTags ($router['id']);
1264 if (count ($routertags))
4fbb5a00 1265 echo '<br><small>' . serializeTags ($routertags, makeHref(array('page'=>'objects', 'tab'=>'default'))."&") . '</small>';
d7a8186d
DO
1266 $newline = '<br>';
1267 }
1268 echo '</td>';
79e45b4c 1269 }
79e45b4c
DO
1270 }
1271 echo '<td>';
85970da2 1272 printSelect ($aat, 'bond_type', $alloc['type']);
e673ee24 1273 echo "</td><td>";
85970da2 1274 $prefix = '';
4940e4d5 1275 if ($alloc['addrinfo']['reserved'] == 'yes')
e673ee24 1276 {
85970da2
DO
1277 echo $prefix . '<strong>RESERVED</strong>';
1278 $prefix = '; ';
e673ee24 1279 }
85970da2 1280 foreach ($alloc['addrinfo']['allocs'] as $allocpeer)
e673ee24 1281 {
85970da2
DO
1282 if ($allocpeer['object_id'] == $object_id)
1283 continue;
4fbb5a00 1284 echo $prefix . "<a href='".makeHref(array('page'=>'object', 'object_id'=>$allocpeer['object_id']))."'>";
85970da2
DO
1285 if (!empty ($allocpeer['osif']))
1286 echo $allocpeer['osif'] . '@';
1287 echo $allocpeer['object_name'] . '</a>';
1288 $prefix = '; ';
e673ee24 1289 }
d54b9495
DO
1290 echo "</td><td>";
1291 printImageHREF ('save', 'Save changes', TRUE);
1292 echo "</td></form></tr>\n";
e673ee24 1293 }
39b4abd0
DO
1294 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
1295 printNewItemTR();
e673ee24 1296
09620506 1297 echo "</table><br>\n";
e673ee24
DO
1298 finishPortlet();
1299
1300}
1301
baf37d01
DO
1302// Log structure versions:
1303// 1: the whole structure is a list of code-message pairs
1304// 2 and later: there's a "v" field set, which indicates the version
1305// 2: there's a "m" list set to hold message code and optional arguments
e673ee24
DO
1306function printLog ($log)
1307{
baf37d01
DO
1308 switch (TRUE)
1309 {
1310 case !isset ($log['v']):
ebb5441d 1311 case $log['v'] == 1:
baf37d01 1312 foreach ($log as $key => $record)
ebb5441d 1313 if ($key !== 'v')
baf37d01
DO
1314 echo "<div class=msg_${record['code']}>${record['message']}</div>";
1315 break;
1316 case $log['v'] == 2:
1317 $msginfo = array
1318 (
ebb5441d 1319 0 => array ('code' => 'success', 'format' => 'Success: %s'),
baf37d01
DO
1320 1 => array ('code' => 'success', 'format' => '%u new records done, %u already existed'),
1321 2 => array ('code' => 'success', 'format' => 'NATv4 rule was successfully added.'),
1322 3 => array ('code' => 'success', 'format' => 'NATv4 rule was successfully deleted.'),
1323 4 => array ('code' => 'success', 'format' => 'NATv4 rule was successfully updated'),
1324 5 => array ('code' => 'success', 'format' => 'Port %s was added successfully'),
1325 6 => array ('code' => 'success', 'format' => 'Port %s was updated successfully'),
1326 7 => array ('code' => 'success', 'format' => 'Port %s was deleted successfully'),
1327 8 => array ('code' => 'success', 'format' => 'Port %s successfully linked with port %s at object %s'),
1328 9 => array ('code' => 'success', 'format' => 'Port %s was successfully unlinked from %s@%s'),
1329 10 => array ('code' => 'success', 'format' => 'Added %u ports, updated %u ports, encountered %u errors.'),
1330 11 => array ('code' => 'success', 'format' => 'Reservation removed.'),
1331 12 => array ('code' => 'success', 'format' => 'allocation updated'),
1332 13 => array ('code' => 'success', 'format' => 'allocated'),
1333 14 => array ('code' => 'success', 'format' => 'deallocated'),
1334 15 => array ('code' => 'success', 'format' => 'Reset succeeded.'),
1335 16 => array ('code' => 'success', 'format' => 'Update done'),
1336 17 => array ('code' => 'success', 'format' => 'Update(s) succeeded.'),
1337 18 => array ('code' => 'success', 'format' => 'Load balancer was successfully added'),
1338 19 => array ('code' => 'success', 'format' => 'Load balancer was successfully deleted'),
1339 20 => array ('code' => 'success', 'format' => 'Load balancer info was successfully updated'),
1340 21 => array ('code' => 'success', 'format' => 'Generation complete'),
1341 22 => array ('code' => 'success', 'format' => 'Chained %u tags'),
1342 23 => array ('code' => 'success', 'format' => 'IPv4 prefix successfully added'),
1343 24 => array ('code' => 'success', 'format' => 'IPv4 prefix deleted'),
1344 25 => array ('code' => 'success', 'format' => 'IPv4 prefix updated'),
1345 26 => array ('code' => 'success', 'format' => '%u IP address(es) were successfully updated'),
1346 27 => array ('code' => 'success', 'format' => 'IPv4 address updated'),
1347 28 => array ('code' => 'success', 'format' => 'Virtual service was successfully created'),
1348 29 => array ('code' => 'success', 'format' => 'Virtual service was successfully deleted'),
1349 30 => array ('code' => 'success', 'format' => 'Virtual service was successfully updated'),
1350 31 => array ('code' => 'success', 'format' => 'RS pool was successfully created'),
1351 32 => array ('code' => 'success', 'format' => 'RS pool was successfully deleted'),
1352 33 => array ('code' => 'success', 'format' => 'RS pool was successfully updated'),
1353 34 => array ('code' => 'success', 'format' => 'Real server was successfully added'),
1354 35 => array ('code' => 'success', 'format' => 'Real server was successfully deleted'),
1355 36 => array ('code' => 'success', 'format' => 'Real server was successfully updated'),
1356 37 => array ('code' => 'success', 'format' => 'Successfully added %u real servers'),
1357 38 => array ('code' => 'success', 'format' => '%u real server(s) were successfully (de)activated'),
1358 39 => array ('code' => 'success', 'format' => 'User account %s updated.'),
1359 40 => array ('code' => 'success', 'format' => 'User account %s created.'),
79b8ad1e
DO
1360// ...
1361// ...
baf37d01
DO
1362 43 => array ('code' => 'success', 'format' => 'Saved successfully.'),
1363 44 => array ('code' => 'success', 'format' => '%s failures and %s successfull changes.'),
1364 45 => array ('code' => 'success', 'format' => "Attribute '%s' created."),
1365 46 => array ('code' => 'success', 'format' => 'Rename successful.'),
1366 47 => array ('code' => 'success', 'format' => 'Attribute was deleted.'),
1367 48 => array ('code' => 'success', 'format' => 'Supplement succeeded.'),
1368 49 => array ('code' => 'success', 'format' => 'Reduction succeeded.'),
1369 50 => array ('code' => 'success', 'format' => 'Reduction succeeded.'),
1370 51 => array ('code' => 'success', 'format' => 'Update succeeded.'),
1371 52 => array ('code' => 'success', 'format' => 'Supplement succeeded.'),
1372 53 => array ('code' => 'success', 'format' => 'Chapter was deleted.'),
1373 54 => array ('code' => 'success', 'format' => 'Chapter was updated.'),
1374 55 => array ('code' => 'success', 'format' => 'Chapter was added.'),
1375 56 => array ('code' => 'success', 'format' => 'Update succeeded.'),
1376 57 => array ('code' => 'success', 'format' => 'Reset complete'),
1377 58 => array ('code' => 'success', 'format' => "Successfully deleted tag ."),
1378 59 => array ('code' => 'success', 'format' => "Created tag '%s'."),
1379 60 => array ('code' => 'success', 'format' => "Updated tag '%s'."),
ebb5441d 1380 61 => array ('code' => 'success', 'format' => 'Password changed successfully.'),
24dcb9d8 1381 62 => array ('code' => 'success', 'format' => 'gw: %s'),
f0ff4930
DO
1382 63 => array ('code' => 'success', 'format' => '%u change request(s) have been processed'),
1383 64 => array ('code' => 'success', 'format' => 'Port %s@%s has been assigned to VLAN %u'),
f19c75d6 1384 65 => array ('code' => 'success', 'format' => "Added new rack '%s'"),
03e6ef01 1385 66 => array ('code' => 'success', 'format' => "File sent Ok via handler '%s'"),
abef7149 1386 67 => array ('code' => 'success', 'format' => "Tag rolling done, %u objects involved"),
0c2b7c4a 1387 68 => array ('code' => 'success', 'format' => "Updated rack '%s'"),
e1ae3fb4
AD
1388 69 => array ('code' => 'success', 'format' => 'File %s was added successfully'),
1389 70 => array ('code' => 'success', 'format' => 'File %s was updated successfully'),
1390 71 => array ('code' => 'success', 'format' => 'File %s was linked successfully'),
1391 72 => array ('code' => 'success', 'format' => 'File %s was unlinked successfully'),
1392 73 => array ('code' => 'success', 'format' => 'File %s was deleted successfully'),
52b34485
AD
1393 74 => array ('code' => 'success', 'format' => 'Row %s was added successfully'),
1394 75 => array ('code' => 'success', 'format' => 'Row %s was updated successfully'),
1395 76 => array ('code' => 'success', 'format' => 'Object %s was deleted successfully'),
f0ff4930 1396
ebb5441d
DO
1397 100 => array ('code' => 'error', 'format' => 'Generic error: %s'),
1398 101 => array ('code' => 'error', 'format' => 'Port name cannot be empty'),
1399 102 => array ('code' => 'error', 'format' => "Error creating user account '%s'"),
1400 103 => array ('code' => 'error', 'format' => 'getHashByID() failed'),
1401 104 => array ('code' => 'error', 'format' => "Error updating user account '%s'"),
79b8ad1e
DO
1402// ...
1403// ...
1404// ...
ebb5441d
DO
1405 108 => array ('code' => 'error', 'format' => '%u failures and %u successfull changes.'),
1406 109 => array ('code' => 'error', 'format' => 'Update failed!'),
1407 110 => array ('code' => 'error', 'format' => 'Supplement failed!'),
1408 111 => array ('code' => 'error', 'format' => 'Reduction failed!'),
1409 112 => array ('code' => 'error', 'format' => 'Error adding chapter.'),
1410 113 => array ('code' => 'error', 'format' => 'Error updating chapter.'),
1411 114 => array ('code' => 'error', 'format' => 'Error deleting chapter.'),
1412 115 => array ('code' => 'error', 'format' => 'Error renaming attribute.'),
1413 116 => array ('code' => 'error', 'format' => 'Error creating attribute.'),
1414 117 => array ('code' => 'error', 'format' => 'Error deleting attribute.'),
1415 118 => array ('code' => 'error', 'format' => 'Supplement failed!'),
1416 119 => array ('code' => 'error', 'format' => 'Reduction failed!'),
1417 120 => array ('code' => 'error', 'format' => 'Reset failed!'),
1418 121 => array ('code' => 'error', 'format' => 'commitUpdateObject() failed'),
1419 122 => array ('code' => 'error', 'format' => 'One or more update(s) failed!'),
1420 123 => array ('code' => 'error', 'format' => 'Cannot process submitted data: unknown format code.'),
1421 124 => array ('code' => 'error', 'format' => 'Error removing reservation!'),
1422 125 => array ('code' => 'error', 'format' => "Update failed with error: '%s'"),
1423 126 => array ('code' => 'error', 'format' => 'addRStoRSPool() failed'),
1424 127 => array ('code' => 'error', 'format' => 'Added %u real servers and encountered %u errors'),
1425 128 => array ('code' => 'error', 'format' => 'commitDeleteRS() failed'),
1426 129 => array ('code' => 'error', 'format' => 'commitDeleteLB() failed'),
1427 130 => array ('code' => 'error', 'format' => 'commitDeleteVS() failed'),
1428 131 => array ('code' => 'error', 'format' => 'invalid format requested'),
1429 132 => array ('code' => 'error', 'format' => 'invalid protocol'),
1430 133 => array ('code' => 'error', 'format' => 'commitUpdateRS() failed'),
1431 134 => array ('code' => 'error', 'format' => 'commitUpdateLB() failed'),
1432 135 => array ('code' => 'error', 'format' => 'commitUpdateVS() failed'),
1433 136 => array ('code' => 'error', 'format' => 'addLBtoRSPool() failed'),
1434 137 => array ('code' => 'error', 'format' => 'addLBtoRSPool() failed'),
1435 138 => array ('code' => 'error', 'format' => 'commitDeleteRSPool() failed'),
1436 139 => array ('code' => 'error', 'format' => 'commitUpdateRSPool() failed'),
1437 140 => array ('code' => 'error', 'format' => 'Encountered %u errors, (de)activated %u real servers'),
1438 141 => array ('code' => 'error', 'format' => 'Encountered %u errors, updated %u IP address(es)'),
1439 142 => array ('code' => 'error', 'format' => 'executeAutoPorts() failed'),
1440 143 => array ('code' => 'error', 'format' => 'Tried chaining %u tags, but experienced %u errors.'),
1441 144 => array ('code' => 'error', 'format' => "Error deleting tag: '%s'"),
1442 145 => array ('code' => 'error', 'format' => "Invalid tag name '%s'"),
1443 146 => array ('code' => 'error', 'format' => "Tag '%s' (or similar name) already exists"),
1444 147 => array ('code' => 'error', 'format' => "Could not create tag '%s' because of error '%s'"),
1445 148 => array ('code' => 'error', 'format' => "Could not update tag '%s' because of error '%s'"),
1446 149 => array ('code' => 'error', 'format' => 'Turing test failed'),
1447 150 => array ('code' => 'error', 'format' => 'Can only change password under DB authentication.'),
1448 151 => array ('code' => 'error', 'format' => 'Old password doesn\'t match.'),
1449 152 => array ('code' => 'error', 'format' => 'New passwords don\'t match.'),
1450 153 => array ('code' => 'error', 'format' => 'Password change failed.'),
1451 154 => array ('code' => 'error', 'format' => "Verification error: %s"),
1452 155 => array ('code' => 'error', 'format' => 'Save failed.'),
1453 156 => array ('code' => 'error', 'format' => 'getSwitchVLANs() failed'),
e81fb764 1454 157 => array ('code' => 'error', 'format' => 'operation not permitted'),
24dcb9d8
DO
1455 158 => array ('code' => 'error', 'format' => 'Ignoring malformed record #%u in form submit'),
1456 159 => array ('code' => 'error', 'format' => 'Permission denied moving port %s from VLAN%u to VLAN%u'),
1457 160 => array ('code' => 'error', 'format' => 'Invalid arguments'),
1458 161 => array ('code' => 'error', 'format' => 'Endpoint not found. Please either set FQDN attribute or assign an IP address to the object.'),
1459 162 => array ('code' => 'error', 'format' => 'More than one IP address is assigned to this object, please configure FQDN attribute.'),
1460 163 => array ('code' => 'error', 'format' => 'Failed to get any response from queryGateway() or the gateway died'),
c030232f 1461 164 => array ('code' => 'error', 'format' => 'Gateway failure: %s.'),
24dcb9d8
DO
1462 165 => array ('code' => 'error', 'format' => 'Gateway failure: malformed reply.'),
1463 166 => array ('code' => 'error', 'format' => 'gw: %s'),
f0ff4930
DO
1464 167 => array ('code' => 'error', 'format' => 'Could not find port %s'),
1465 168 => array ('code' => 'error', 'format' => 'Port %s is a trunk'),
1466 169 => array ('code' => 'error', 'format' => 'Failed to configure %s, connector returned code %u'),
5222f192 1467 170 => array ('code' => 'error', 'format' => 'There is no network for IP address "%s"'),
f19c75d6
DO
1468 171 => array ('code' => 'error', 'format' => "Failed creating rack '%s'. Already exists in this row?"),
1469 172 => array ('code' => 'error', 'format' => 'Malformed request'),
e5c4506d
DO
1470 173 => array ('code' => 'error', 'format' => "Invalid IPv4 prefix '%s'"),
1471 174 => array ('code' => 'error', 'format' => 'Bad IPv4 address'),
1472 175 => array ('code' => 'error', 'format' => 'Invalid netmask'),
1473 176 => array ('code' => 'error', 'format' => 'This network already exists'),
0c2b7c4a 1474 177 => array ('code' => 'error', 'format' => 'commitUpdateRack() failed'),
121496b6 1475 178 => array ('code' => 'error', 'format' => 'file not found'),
f0ff4930 1476
24dcb9d8
DO
1477 200 => array ('code' => 'warning', 'format' => 'generic warning: %s'),
1478 201 => array ('code' => 'warning', 'format' => 'nothing happened...'),
1479 202 => array ('code' => 'warning', 'format' => 'gw: %s'),
f0ff4930
DO
1480 203 => array ('code' => 'warning', 'format' => 'Port %s seems to be the first in VLAN %u at this switch.'),
1481 204 => array ('code' => 'warning', 'format' => 'Check uplink/downlink configuration for proper operation.'),
1482 205 => array ('code' => 'warning', 'format' => '%u change request(s) have been ignored'),
baf37d01
DO
1483 );
1484 // Handle the arguments. Is there any better way to do it?
1485 foreach ($log['m'] as $record)
1486 {
5222f192
DO
1487 if (!isset ($record['c']) or !isset ($msginfo[$record['c']]))
1488 {
1489 echo '<div class=msg_neutral>(this message was lost)</div>';
1490 continue;
1491 }
baf37d01
DO
1492 if (isset ($record['a']))
1493 switch (count ($record['a']))
1494 {
1495 case 1:
1496 $msgtext = sprintf
1497 (
1498 $msginfo[$record['c']]['format'],
1499 $record['a'][0]
1500 );
1501 break;
1502 case 2:
1503 $msgtext = sprintf
1504 (
1505 $msginfo[$record['c']]['format'],
1506 $record['a'][0],
1507 $record['a'][1]
1508 );
1509 break;
1510 case 3:
1511 $msgtext = sprintf
1512 (
1513 $msginfo[$record['c']]['format'],
1514 $record['a'][0],
1515 $record['a'][1],
1516 $record['a'][2]
1517 );
1518 break;
1519 case 4:
1520 default:
1521 $msgtext = sprintf
1522 (
1523 $msginfo[$record['c']]['format'],
1524 $record['a'][0],
1525 $record['a'][1],
1526 $record['a'][2],
1527 $record['a'][3]
1528 );
1529 break;
1530 }
1531 else
1532 $msgtext = $msginfo[$record['c']]['format'];
1533 echo '<div class=msg_' . $msginfo[$record['c']]['code'] . ">${msgtext}</div>";
1534 }
1535 break;
1536 default:
1537 echo '<div class=msg_error>' . __FUNCTION__ . ': internal error</div>';
1538 break;
1539 }
e673ee24
DO
1540}
1541
1542/*
1543The following conditions must be followed:
15441. We can mount onto free atoms only. This means: if any record for an atom
1545already exists in RackSpace, it can't be used for mounting.
15462. We can't unmount from 'W' atoms. Operator should review appropriate comments
1547and either delete them before unmounting or refuse to unmount the object.
1548*/
1549
1550// We extensively use $_REQUEST in the function.
7056988c 1551// FIXME: move related code into ophandler
e673ee24
DO
1552function renderRackSpaceForObject ($object_id = 0)
1553{
1554 if ($object_id <= 0)
1555 {
591ff2c4 1556 showError ('Invalid object_id', __FUNCTION__);
e673ee24
DO
1557 return;
1558 }
1559 $is_submit = isset ($_REQUEST['got_atoms']);
1560 $is_update = isset ($_REQUEST['rackmulti'][0]);
1561 $info = getObjectInfo ($object_id);
1562 if ($info == NULL)
1563 {
591ff2c4 1564 showError ('getObjectInfo() failed', __FUNCTION__);
e673ee24
DO
1565 return;
1566 }
1567 // Always process occupied racks plus racks chosen by user. First get racks with
1568 // already allocated rackspace...
1569 $workingRacksData = getResidentRacksData ($object_id);
1570 if ($workingRacksData === NULL)
1571 {
1572 print_r ($workingRacksData);
591ff2c4 1573 showError ('getResidentRacksData() failed', __FUNCTION__);
e673ee24
DO
1574 return;
1575 }
1576
1577 // ...and then add those chosen by user (if any).
1578 if ($is_update)
1579 foreach ($_REQUEST['rackmulti'] as $cand_id)
1580 {
1581 if (!isset ($workingRacksData[$cand_id]))
1582 {
1583 $rackData = getRackData ($cand_id);
1584 if ($rackData == NULL)
1585 {
591ff2c4 1586 showError ('getRackData() failed', __FUNCTION__);
e673ee24
DO
1587 return NULL;
1588 }
1589 $workingRacksData[$cand_id] = $rackData;
1590 }
1591 }
1592
1593 // Do it only once...
1594 foreach ($workingRacksData as &$rackData)
1595 applyObjectMountMask ($rackData, $object_id);
1596 // Now we workaround an old caveat: http://bugs.php.net/bug.php?id=37410
1597 unset ($rackData);
1598
e673ee24 1599 // This is the time for rendering.
4fbb5a00
DY
1600 global $pageno, $tabno;
1601
1602 printOpFormIntro ('updateObjectAllocation');
1603
e673ee24
DO
1604 // Main layout starts.
1605 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
1606
1607 // Left portlet with rack list.
1608 echo "<td class=pcleft height='1%'>";
1609 startPortlet ('Racks');
1610 $allRacksData = getRacksForRow();
4b8d413e
DO
1611 if (count ($allRacksData) <= getConfigVar ('RACK_PRESELECT_THRESHOLD'))
1612 {
1613 foreach (array_keys ($allRacksData) as $rack_id)
1614 {
1615 $rackData = getRackData ($rack_id);
1616 if ($rackData == NULL)
1617 {
1618 showError ('getRackData() failed', __FUNCTION__);
1619 return NULL;
1620 }
1621 $workingRacksData[$rack_id] = $rackData;
1622 }
1623 foreach ($workingRacksData as &$rackData)
1624 applyObjectMountMask ($rackData, $object_id);
1625 unset ($rackData);
1626 }
1627 renderRackMultiSelect ('rackmulti[]', $allRacksData, array_keys ($workingRacksData));
e673ee24
DO
1628 echo "<br>";
1629 echo "<br>";
1630 finishPortlet();
1631 echo "</td>";
1632
1633 // Middle portlet with comment and submit.
1634 echo "<td class=pcleft>";
1635 startPortlet ('Comment');
1636 echo "<textarea name=comment rows=10 cols=40></textarea><br>\n";
1637 echo "<input type=submit value='Save' name=got_atoms>\n";
1638 echo "<br>";
1639 echo "<br>";
1640 finishPortlet();
1641 echo "</td>";
1642
1643 // Right portlet with rendered racks. If this form submit is not final, we have to
1644 // reflect the former state of the grid in current form.
1645 echo "<td class=pcright rowspan=2 height='1%'>";
1646 startPortlet ('Working copy');
1647 echo '<table border=0 cellspacing=10 align=center><tr>';
1648 foreach ($workingRacksData as $rack_id => $rackData)
1649 {
1650 // Order is important here: only original allocation is highlighted.
1651 highlightObject ($rackData, $object_id);
1652 markupAtomGrid ($rackData, 'T');
1653 // If we have a form processed, discard user input and show new database
1654 // contents.
1655 if (!$is_submit and $is_update)
1656 mergeGridFormToRack ($rackData);
1657 echo "<td valign=top>";
1658 echo "<center>\n<h2>${rackData['name']}</h2>\n";
1659 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
1660 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
1661 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1662 renderAtomGrid ($rackData);
9b7468b7
DO
1663 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
1664 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
e673ee24
DO
1665 echo "</table></center>\n";
1666 echo '</td>';
1667 }
1668 echo "</tr></table>";
1669 finishPortlet();
1670 echo "</td>\n";
1671
1672 echo "</form>\n";
1673 echo "</tr></table>\n";
1674}
1675
1676function renderMolecule ($mdata, $object_id)
1677{
1678 // sort data out
1679 $rackpack = array();
1680 global $loclist;
64b95774 1681 foreach ($mdata as $rua)
e673ee24
DO
1682 {
1683 $rack_id = $rua['rack_id'];
1684 $unit_no = $rua['unit_no'];
1685 $atom = $rua['atom'];
1686 if (!isset ($rackpack[$rack_id]))
1687 {
1688 $rackData = getRackData ($rack_id);
1689 for ($i = $rackData['height']; $i > 0; $i--)
1690 for ($locidx = 0; $locidx < 3; $locidx++)
1691 $rackData[$i][$locidx]['state'] = 'F';
1692 $rackpack[$rack_id] = $rackData;
1693 }
1694 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['state'] = 'T';
1695 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['object_id'] = $object_id;
1696 }
1697 // now we have some racks to render
64b95774 1698 foreach ($rackpack as $rackData)
e673ee24
DO
1699 {
1700 markAllSpans ($rackData);
1701 echo "<table class=molecule cellspacing=0>\n";
1702 echo "<caption>${rackData['name']}</caption>\n";
1703 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th><th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1704 for ($i = $rackData['height']; $i > 0; $i--)
1705 {
1706 echo "<tr><th>$i</th>";
1707 for ($locidx = 0; $locidx < 3; $locidx++)
1708 {
1709 $state = $rackData[$i][$locidx]['state'];
1710 echo "<td class=state_${state}>&nbsp;</td>\n";
1711 }
1712 echo "</tr>\n";
1713 }
1714 echo "</table>\n";
1715 }
1716}
1717
1718function renderUnmountedObjectsPortlet ()
1719{
1720 startPortlet ('Unmounted objects');
1721 $objs = getUnmountedObjects();
1722 if ($objs === NULL)
1723 {
591ff2c4 1724 showError ('getUnmountedObjects() failed', __FUNCTION__);
e673ee24
DO
1725 return;
1726 }
4fbb5a00 1727 global $nextorder;
e673ee24
DO
1728 $order = 'odd';
1729 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
4fbb5a00 1730 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset number</th></tr>';
e673ee24
DO
1731 foreach ($objs as $obj)
1732 {
4fbb5a00 1733 echo "<tr class=row_${order}><td><a href='".makeHref(array('page'=>'object', 'object_id'=>$obj['id']))."'>${obj['dname']}</a></td>";
e673ee24 1734 echo "<td>${obj['label']}</td>";
18d94c29 1735 echo "<td>${obj['asset_no']}</td>";
4fbb5a00 1736 echo "</tr>";
e673ee24
DO
1737 $order = $nextorder[$order];
1738 }
1739 echo "</table><br>\n";
1740 finishPortlet();
1741}
1742
1743function renderProblematicObjectsPortlet ()
1744{
1745 startPortlet ('Problematic objects');
1746 $objs = getProblematicObjects();
1747 if ($objs === NULL)
1748 {
591ff2c4 1749 showError ('getProblematicObjects() failed', __FUNCTION__);
e673ee24
DO
1750 return;
1751 }
4fbb5a00 1752 global $nextorder;
e673ee24
DO
1753 $order = 'odd';
1754 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1755 echo '<tr><th>Type</th><th>Common name</th></tr>';
1756 foreach ($objs as $obj)
1757 {
1758 echo "<tr class=row_${order}><td>${obj['objtype_name']}</td>";
4fbb5a00 1759 echo "<td><a href='".makeHref(array('page'=>'object', 'object_id'=>$obj['id']))."'>${obj['dname']}</a></tr>";
e673ee24
DO
1760 $order = $nextorder[$order];
1761 }
1762 echo "</table><br>\n";
1763 finishPortlet();
1764}
1765
7cc02fc1
DO
1766function renderObjectSpace ()
1767{
4fbb5a00 1768 global $taglist, $tagtree;
52b34485 1769 showMessageOrError();
7cc02fc1
DO
1770 echo "<table border=0 class=objectview>\n";
1771 echo "<tr><td class=pcleft width='50%'>";
1772 startPortlet ('View all by type');
1773 $groupInfo = getObjectGroupInfo();
1774 if ($groupInfo === NULL)
1775 {
1776 showError ('getObjectGroupInfo() failed', __FUNCTION__);
1777 return;
1778 }
1779 if (count ($groupInfo) == 0)
1780 echo "No objects exist in DB";
1781 else
1782 {
1783 echo '<div align=left><ul>';
1784 foreach ($groupInfo as $gi)
4fbb5a00 1785 echo "<li><a href='".makeHref(array('page'=>'objgroup', 'group_id'=>$gi['id']))."'>${gi['name']}</a> (${gi['count']})</li>";
7cc02fc1
DO
1786 echo '</ul></div>';
1787 }
1788 finishPortlet();
1789
1790 echo '</td><td class=pcright>';
1791
1792 startPortlet ('View all by tag');
1793 if (count ($taglist) == 0)
1794 echo "No tags exist in DB";
1795 else
1796 renderTagCloud ('object');
1797 finishPortlet();
e673ee24
DO
1798 echo "</td></tr></table>\n";
1799}
1800
466dcbe6 1801function renderObjectGroup ()
7cc02fc1 1802{
4fbb5a00 1803 global $pageno, $tabno, $nextorder, $taglist, $tagtree;
52b34485 1804 showMessageOrError();
2c6c7645 1805 assertUIntArg ('group_id', __FUNCTION__, TRUE);
7cc02fc1 1806 $group_id = $_REQUEST['group_id'];
a0d54e7e
DO
1807 $tagfilter = getTagFilter();
1808 $tagfilter_str = getTagFilterStr ($tagfilter);
7cc02fc1
DO
1809 echo "<table border=0 class=objectview>\n";
1810 echo "<tr><td class=pcleft width='25%'>";
1811 startPortlet ('change type');
1812 $groupInfo = getObjectGroupInfo();
1813 if ($groupInfo === NULL)
1814 {
1815 showError ('getObjectGroupInfo() failed', __FUNCTION__);
1816 return;
1817 }
1818 if (count ($groupInfo) == 0)
1819 echo "No objects exist in DB";
1820 else
1821 {
1822 echo '<div align=left><ul>';
1823 foreach ($groupInfo as $gi)
1824 {
4fbb5a00 1825 echo "<li><a href='".makeHref(array('page'=>$pageno, 'group_id'=>$gi['id']))."${tagfilter_str}'>";
105cea6e
DO
1826 if ($gi['id'] == $group_id)
1827 echo '<strong>';
1828 echo "${gi['name']}</a>";
1829 if ($gi['id'] == $group_id)
1830 echo '</strong>';
1831 echo " (${gi['count']})";
1832 if ($gi['id'] == $group_id)
1833 echo ' &larr;';
1834 echo "</li>";
7cc02fc1
DO
1835 }
1836 echo '</ul></div>';
1837 }
1838 finishPortlet();
1839
1840 echo '</td><td class=pcleft>';
1841
11c8e4be 1842 $objects = getObjectList ($group_id, $tagfilter, getTFMode());
922b8da6 1843 startPortlet ('Objects (' . count ($objects) . ')');
7cc02fc1
DO
1844 if ($objects === NULL)
1845 {
1846 showError ('getObjectList() failed', __FUNCTION__);
1847 return;
1848 }
1849 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
4fbb5a00 1850 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Row/Rack</th><th></th></tr>';
7cc02fc1
DO
1851 $order = 'odd';
1852 foreach ($objects as $obj)
1853 {
8e700dd1
DO
1854 if (isset ($_REQUEST['hl_object_id']) and $_REQUEST['hl_object_id'] == $obj['id'])
1855 $secondclass = 'tdleft port_highlight';
1856 else
1857 $secondclass = 'tdleft';
2b3d64c5 1858 $tags = loadRackObjectTags ($obj['id']);
4fbb5a00 1859 echo "<tr class=row_${order} valign=top><td class='${secondclass}'><a href='".makeHref(array('page'=>'object', 'object_id'=>$obj['id']))."'><strong>${obj['dname']}</strong></a>";
2b3d64c5 1860 if (count ($tags))
4fbb5a00 1861 echo '<br><small>' . serializeTags ($tags, makeHref(array('page'=>$pageno, 'tab'=>'default', 'group_id'=>$group_id))."&") . '</small>';
2b3d64c5 1862 echo "</td><td class='${secondclass}'>${obj['label']}</td>";
8e700dd1 1863 echo "<td class='${secondclass}'>${obj['asset_no']}</td>";
7cc02fc1 1864 if ($obj['rack_id'])
4fbb5a00 1865 echo "<td class='${secondclass}'><a href='".makeHref(array('page'=>'row', 'row_id'=>$obj['row_id']))."'>${obj['Row_name']}</a>/<a href='".makeHref(array('page'=>'rack', 'rack_id'=>$obj['rack_id']))."'>${obj['Rack_name']}</a></td>";
7cc02fc1 1866 else
8e700dd1 1867 echo "<td class='${secondclass}'>Unmounted</td>";
7cc02fc1
DO
1868 echo '</tr>';
1869 $order = $nextorder[$order];
1870 }
1871 echo '</table>';
1872 finishPortlet();
1873
1874 echo "</td><td class=pcright width='25%'>";
1875
a0d54e7e 1876 renderTagFilterPortlet ($tagfilter, 'object', 'group_id', $group_id);
7cc02fc1 1877 echo "</td></tr></table>\n";
e673ee24
DO
1878}
1879
1880function renderEmptyPortsSelect ($port_id, $type_id)
1881{
1882 $ports = getEmptyPortsOfType($type_id);
1883 usort($ports, 'sortEmptyPorts');
1884 foreach ($ports as $port)
1885 {
1886 if ($port_id == $port['Port_id'])
1887 continue;
1888 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";
1889 }
1890}
1891
6ef9683b 1892function renderAllIPv4Allocations ()
e673ee24 1893{
6ef9683b 1894 $addresses = getAllIPv4Allocations();
e673ee24
DO
1895 usort($addresses, 'sortObjectAddressesAndNames');
1896 foreach ($addresses as $address)
1897 {
1898 echo "<option value='${address['ip']}' onclick='getElementById(\"ip\").value=\"${address['ip']}\";'>${address['object_name']} ${address['name']} ${address['ip']}</option>\n";
1899 }
1900}
1901
1902// History viewer for history-enabled simple dictionaries.
1903function renderHistory ($object_type, $object_id)
1904{
1905 switch ($object_type)
1906 {
1907 case 'row':
1908 $query = "select ctime, user_name, name, deleted, comment from RackRowHistory where id = ${object_id} order by ctime";
1909 $header = '<tr><th>change time</th><th>author</th><th>rack row name</th><th>is deleted?</th><th>rack row comment</th></tr>';
1910 $extra = 4;
1911 break;
1912 case 'rack':
1913 $query =
1914 "select ctime, user_name, rh.name, rh.deleted, d.dict_value as name, rh.height, rh.comment " .
1915 "from RackHistory as rh left join Dictionary as d on rh.row_id = d.dict_key " .
1916 "natural join Chapter " .
1917 "where chapter_name = 'RackRow' and rh.id = ${object_id} order by ctime";
1918 $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>';
1919 $extra = 6;
1920 break;
1921 case 'object':
1922 $query =
4fbb5a00 1923 "select ctime, user_name, name, label, asset_no, deleted, has_problems, dict_value, comment " .
e673ee24
DO
1924 "from RackObjectHistory inner join Dictionary on objtype_id = dict_key natural join Chapter " .
1925 "where chapter_name = 'RackObjectType' and id=${object_id} order by ctime";
4fbb5a00 1926 $header = '<tr><th>change time</th><th>author</th><th>common name</th><th>visible label</th><th>asset no</th><th>is deleted?</th><th>has problems?</th><th>object type</th><th>comment</th></tr>';
e673ee24
DO
1927 $extra = 9;
1928 break;
1929 default:
591ff2c4 1930 showError ("Uknown object type '${object_type}'", __FUNCTION__);
e673ee24
DO
1931 return;
1932 }
1933 global $dbxlink;
1934 $result = $dbxlink->query ($query);
1935 if ($result == NULL)
1936 {
591ff2c4 1937 showError ('SQL query failed', __FUNCTION__);
e673ee24
DO
1938 return;
1939 }
1940 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1941 $order = 'odd';
1942 global $nextorder;
1943 echo $header;
1944 while ($row = $result->fetch (PDO::FETCH_NUM))
1945 {
1946 echo "<tr class=row_${order}><td>${row[0]}</td>";
1947 for ($i = 1; $i <= $extra; $i++)
1948 echo "<td>" . $row[$i] . "</td>";
1949 echo "</tr>\n";
1950 $order = $nextorder[$order];
1951 }
1952 echo "</table><br>\n";
1953}
1954
1955function renderRackspaceHistory ()
1956{
4fbb5a00 1957 global $nextorder, $pageno, $tabno;
e673ee24
DO
1958 $order = 'odd';
1959 $history = getRackspaceHistory();
1960 // Show the last operation by default.
1961 if (isset ($_REQUEST['op_id']))
1962 $op_id = $_REQUEST['op_id'];
1963 elseif (isset ($history[0]['mo_id']))
1964 $op_id = $history[0]['mo_id'];
1965 else $op_id = NULL;
1966
1967 $omid = NULL;
1968 $nmid = NULL;
1969 $object_id = 1;
1970 if ($op_id)
1971 list ($omid, $nmid) = getOperationMolecules ($op_id);
1972
1973 // Main layout starts.
1974 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
1975
1976 // Left top portlet with old allocation.
1977 echo "<tr><td class=pcleft>";
1978 startPortlet ('Old allocation');
1979 if ($omid)
1980 {
1981 $oldMolecule = getMolecule ($omid);
1982 renderMolecule ($oldMolecule, $object_id);
1983 }
1984 else
1985 echo "nothing";
1986 finishPortlet();
1987
1988 echo '</td><td class=pcright>';
1989
1990 // Right top portlet with new allocation
1991 startPortlet ('New allocation');
1992 if ($nmid)
1993 {
1994 $newMolecule = getMolecule ($nmid);
1995 renderMolecule ($newMolecule, $object_id);
1996 }
1997 else
1998 echo "nothing";
1999 finishPortlet();
737a3f72 2000
e673ee24 2001 echo '</td></tr><tr><td colspan=2>';
737a3f72 2002
e673ee24
DO
2003 // Bottom portlet with list
2004
2005 startPortlet ('Rackspace allocation history');
2006 echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
2007 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";
2008 foreach ($history as $row)
2009 {
2010 if ($row['mo_id'] == $op_id)
2011 $class = 'hl';
2012 else
2013 $class = "row_${order}";
4fbb5a00 2014 echo "<tr class=${class}><td><a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno, 'op_id'=>$row['mo_id']))."'>${row['ctime']}</a></td>";
e673ee24
DO
2015 echo "<td>${row['user_name']}</td>";
2016 echo "<td>${row['ro_id']}</td><td>${row['objtype_name']}</td><td>${row['name']}</td><td>${row['comment']}</td>\n";
2017 echo "</tr>\n";
2018 $order = $nextorder[$order];
2019 }
2020 echo "</table>\n";
2021 finishPortlet();
737a3f72 2022
e673ee24 2023 echo '</td></tr></table>';
e673ee24
DO
2024}
2025
d9f8a37a 2026function renderIPv4SpaceRecords ($tree, &$tagcache, $baseurl, $target = 0, $level = 1)
d65353ad
DO
2027{
2028 $self = __FUNCTION__;
2029 foreach ($tree as $item)
2030 {
737a3f72 2031 $total = $item['addrt'];
64347dcf
DO
2032 if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
2033 {
2034 loadIPv4AddrList ($item); // necessary to compute router list and address counter
2035 $used = $item['addrc'];
2036 }
2037 else
2038 {
2039 $item['addrlist'] = array();
2040 $item['addrc'] = 0;
2041 }
0137d53c
DO
2042 if (isset ($item['id']))
2043 {
fec0c8da 2044 if ($item['symbol'] == 'node-collapsed')
d9f8a37a 2045 $expandurl = "${baseurl}&eid=" . $item['id'] . "#netid" . $item['id'];
fec0c8da 2046 elseif ($item['symbol'] == 'node-expanded')
d9f8a37a 2047 $expandurl = $baseurl . ($item['parent_id'] ? "&eid=${item['parent_id']}#netid${item['parent_id']}" : '');
fec0c8da
DO
2048 else
2049 $expandurl = '';
0137d53c 2050 echo "<tr valign=top>";
fec0c8da 2051 printIPv4NetInfoTDs ($item, 'tdleft', $level, $item['symbol'], $expandurl);
0137d53c 2052 echo "<td class=tdcenter>";
d9f8a37a
DO
2053 if ($target == $item['id'])
2054 echo "<a name=netid${target}></a>";
64347dcf
DO
2055 if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
2056 {
2057 renderProgressBar ($total ? $used/$total : 0);
2058 echo "<br><small>${used}/${total}</small>";
2059 }
2060 else
2061 echo "<small>${total}</small>";
2062 echo "</td>";
0137d53c 2063 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
b6b87070 2064 printRoutersTD (findRouters ($item['addrlist']), $tagcache);
0137d53c 2065 echo "</tr>";
fec0c8da 2066 if ($item['symbol'] == 'node-expanded' or $item['symbol'] == 'node-expanded-static')
d9f8a37a 2067 $self ($item['kids'], $tagcache, $baseurl, $target, $level + 1);
0137d53c
DO
2068 }
2069 else
2070 {
0137d53c 2071 echo "<tr valign=top>";
fec0c8da 2072 printIPv4NetInfoTDs ($item, 'tdleft sparenetwork', $level, $item['symbol']);
0137d53c 2073 echo "<td class=tdcenter>";
64347dcf
DO
2074 if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
2075 {
2076 renderProgressBar ($used/$total, 'sparenetwork');
2077 echo "<br><small>${used}/${total}</small>";
2078 }
2079 else
2080 echo "<small>${total}</small>";
2081 echo "</td><td>&nbsp;</td></tr>";
0137d53c 2082 }
d65353ad
DO
2083 }
2084}
2085
04d619d0 2086function renderIPv4Space ()
e673ee24 2087{
4fbb5a00 2088 global $pageno, $tabno;
932cf41f 2089 $tagfilter = getTagFilter();
94a40058 2090 $netlist = getIPv4NetworkList ($tagfilter, getTFMode());
4fbb5a00
DY
2091
2092
94a40058 2093 $netcount = count ($netlist);
5388794d
DO
2094 // expand request can take either natural values or "ALL". Zero means no expanding.
2095 $eid = isset ($_REQUEST['eid']) ? $_REQUEST['eid'] : 0;
2096 $tree = prepareIPv4Tree ($netlist, $eid);
3630d1fb
DO
2097
2098 echo "<table border=0 class=objectview>\n";
2099 echo "<tr><td class=pcleft>";
94a40058 2100 startPortlet ("networks (${netcount})");
5388794d
DO
2101 echo '<h4>';
2102 if ($eid === 0)
4fbb5a00 2103 echo 'auto-collapsing at threshold ' . getConfigVar ('TREE_THRESHOLD') . " (<a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno, 'eid'=>'ALL'))."'>expand all</a>)";
5388794d 2104 elseif ($eid === 'ALL')
4fbb5a00 2105 echo "expanding all (<a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno))."'>auto-collapse</a>)";
5388794d
DO
2106 else
2107 {
2108 $netinfo = getIPv4NetworkInfo ($eid);
4fbb5a00 2109 echo "expanding ${netinfo['ip']}/${netinfo['mask']} (<a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno))."'>auto-collapse</a> / <a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno, 'eid'=>'ALL'))."'>expand&nbsp;all</a>)";
5388794d
DO
2110 }
2111 echo "</h4><table class='widetable' border=0 cellpadding=5 cellspacing=0 align='center'>\n";
64347dcf 2112 echo "<tr><th>prefix</th><th>name/tags</th><th>capacity</th>";
f0ed1181 2113 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
57dece2f
DO
2114 echo "<th>routed by</th>";
2115 echo "</tr>\n";
fec0c8da 2116 $tagcache = array();
4fbb5a00 2117 $baseurl = makeHref(array('page'=>$pageno, 'tab'=>$tabno)) . getTagFilterStr ($tagfilter);
5388794d 2118 renderIPv4SpaceRecords ($tree, $tagcache, $baseurl, $eid);
e673ee24 2119 echo "</table>\n";
a7fe7729 2120 finishPortlet();
74ccacff 2121 echo '</td><td class=pcright>';
5b7bd02e 2122 renderTagFilterPortlet ($tagfilter, 'ipv4net');
74ccacff 2123 echo "</td></tr></table>\n";
f973f491 2124}
a7fe7729 2125
f973f491
DO
2126function renderIPv4SLB ()
2127{
4fbb5a00 2128 global $page, $nextorder;
a7fe7729 2129
6fec9f39 2130 startPortlet ('SLB configuration');
b3c50e6c 2131 echo "<table border=0 width='100%'><tr>";
ee437dab 2132 foreach (array ('ipv4vslist', 'ipv4rsplist', 'rservers', 'lbs') as $pno)
4fbb5a00 2133 echo "<td><h3><a href='".makeHref(array('page'=>$pno))."'>" . $page[$pno]['title'] . "</a></h3></td>";
b3c50e6c
DO
2134 echo '</tr></table>';
2135 finishPortlet();
2136
c3bdc503 2137 $summary = getSLBSummary();
6fec9f39 2138 startPortlet ('SLB tactical overview');
4cadac8f
DO
2139 // A single id-keyed array isn't used here to preserve existing
2140 // order of LBs returned by getSLBSummary()
c3bdc503
DO
2141 $lblist = array();
2142 $lbdname = array();
4cadac8f 2143 foreach ($summary as $vipdata)
da04825a 2144 foreach (array_keys ($vipdata['lblist']) as $lb_object_id)
c3bdc503
DO
2145 if (!in_array ($lb_object_id, $lblist))
2146 {
2147 $oi = getObjectInfo ($lb_object_id);
2148 $lbdname[$lb_object_id] = $oi['dname'];
2149 $lblist[] = $lb_object_id;
2150 }
2151 if (!count ($summary))
2152 echo 'none configured';
2153 else
2154 {
80e85ea1 2155 $order = 'odd';
c3bdc503 2156 echo "<table class='widetable' border=0 cellpadding=5 cellspacing=0 align='center'>\n";
b1a970c7 2157 echo "<tr valign=top><td>&nbsp;</td>";
c3bdc503 2158 foreach ($lblist as $lb_object_id)
b1a970c7 2159 {
4fbb5a00 2160 #echo "<th><a href='".makeHref(array('page'=>'object', 'tab'=>'default', 'object_id'=>$lb_object_id))."'>" . $lbdname[$lb_object_id] . "</a></th>";
b1a970c7
DO
2161 echo '<td>';
2162 renderLBCell ($lb_object_id);
2163 echo '</td>';
2164 }
c3bdc503 2165 echo "</tr>\n";
4cadac8f
DO
2166 foreach ($summary as $vsid => $vsdata)
2167 {
b1a970c7
DO
2168 echo "<tr class=row_${order}><td class=tdleft>";
2169 renderVSCell ($vsid);
6fec9f39 2170 echo "</td>";
4cadac8f 2171 foreach ($lblist as $lb_object_id)
da04825a 2172 {
60fbcece 2173 echo '<td class=tdleft>';
2b4eee17 2174 if (!isset ($vsdata['lblist'][$lb_object_id]))
da04825a
DO
2175 echo '&nbsp;';
2176 else
6fec9f39
DO
2177 {
2178 echo $vsdata['lblist'][$lb_object_id]['size'];
4fbb5a00 2179// echo " (<a href='".makeHref(array('page'=>'ipv4rspool', 'pool_id'=>$vsdata['lblist'][$lb_object_id]['id'])). "'>";
79a9edb4 2180// echo $vsdata['lblist'][$lb_object_id]['name'] . '</a>)';
6fec9f39 2181 }
da04825a
DO
2182 echo '</td>';
2183 }
2184 echo "</tr>\n";
80e85ea1 2185 $order = $nextorder[$order];
4cadac8f 2186 }
c3bdc503
DO
2187 echo "</table>\n";
2188 }
a7fe7729 2189 finishPortlet ();
e673ee24
DO
2190}
2191
04d619d0 2192function renderIPv4SpaceEditor ()
e673ee24 2193{
4fbb5a00 2194 global $pageno, $tabno;
e673ee24 2195 showMessageOrError();
2a201216 2196
a262e150
DO
2197 // IPv4 validator
2198?>
2199 <script type="text/javascript">
2200 function init() {
2201 document.add_new_range.range.setAttribute('match', "^\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?\\/\\d\\d?$");
2202
2203 Validate.init();
2204 }
2205 window.onload=init;
2206 </script>
2207<?php
2208
4c0653e2 2209 startPortlet ("Add new");
04d619d0 2210 echo '<table border=0 cellpadding=10 align=center>';
7056988c
DO
2211 // This form requires a name, so JavaScript validator can find it.
2212 // No printOpFormIntro() hence
4fbb5a00 2213 echo "<form method=post name='add_new_range' action='".makeHrefProcess()."'>\n";
42023f03 2214 echo "<input type=hidden name=op value=addIPv4Prefix>\n";
04d619d0
DO
2215 // tags column
2216 echo '<tr><td rowspan=4><h3>assign tags</h3>';
5c0bb421 2217 renderTagSelect();
04d619d0
DO
2218 echo '</td>';
2219 // inputs column
2220 echo "<th class=tdright>prefix</th><td class=tdleft><input type=text name='range' size=18 class='live-validate' tabindex=1></td>";
2221 echo "<tr><th class=tdright>name</th><td class=tdleft><input type=text name='name' size='20' tabindex=2></td></tr>";
0c16ef0c 2222 echo "<tr><th class=tdright>connected network</th><td class=tdleft><input type=checkbox name='is_bcast' tabindex=3></td></tr>";
04d619d0 2223 echo "<tr><td colspan=2>";
4c0653e2 2224 printImageHREF ('CREATE', 'Add a new network', TRUE, 4);
04d619d0 2225 echo '</td></tr>';
2a201216 2226 echo "</form></table><br><br>\n";
5c0bb421 2227 finishPortlet();
2a201216 2228
b18d26dc 2229 $addrspaceList = getIPv4NetworkList();
0c16ef0c
DO
2230 $netcount = count ($addrspaceList);
2231 if ($netcount)
e673ee24 2232 {
0c16ef0c 2233 startPortlet ("Manage existing (${netcount})");
04d619d0
DO
2234 echo "<table class='widetable' border=0 cellpadding=5 cellspacing=0 align='center'>\n";
2235 echo "<tr><th>&nbsp;</th><th>prefix</th><th>name</th><th>&nbsp;</th></tr>";
0c16ef0c 2236 foreach ($addrspaceList as $netinfo)
e673ee24 2237 {
4fbb5a00
DY
2238 echo "<form method=post action='".makeHrefProcess(array($op=>'updIPv4Prefix', 'id'=>$netinfo['id']))."'>";
2239 echo "<tr valign=top><td><a href='".makeHrefProcess(array('op'=>'delIPv4Prefix', 'id'=>$netinfo['id']))."'>";
0c16ef0c
DO
2240 printImageHREF ('delete', 'Delete this IP range');
2241 echo "</a></td>\n<td class=tdleft>${netinfo['ip']}/${netinfo['mask']}</td>";
2242 echo "<td><input type=text name=name size=40 value='${netinfo['name']}'>";
04d619d0
DO
2243 echo "</td><td>";
2244 printImageHREF ('save', 'Save changes', TRUE);
2245 echo "</td></tr></form>\n";
e673ee24 2246 }
04d619d0
DO
2247 echo "</table>";
2248 finishPortlet();
e673ee24 2249 }
e673ee24
DO
2250}
2251
beb9e88a 2252function renderIPv4Network ($id)
e673ee24 2253{
4fbb5a00 2254 global $pageno, $tabno, $aac2;
545478d0
DO
2255 $netmaskbylen = array
2256 (
2257 32 => '255.255.255.255',
2258 31 => '255.255.255.254',
2259 30 => '255.255.255.252',
2260 29 => '255.255.255.248',
2261 28 => '255.255.255.240',
2262 27 => '255.255.255.224',
2263 26 => '255.255.255.192',
2264 25 => '255.255.255.128',
2265 24 => '255.255.255.0',
2266 23 => '255.255.254.0',
2267 22 => '255.255.252.0',
2268 21 => '255.255.248.0',
2269 20 => '255.255.240.0',
2270 19 => '255.255.224.0',
2271 18 => '255.255.192.0',
2272 17 => '255.255.128.0',
2273 16 => '255.255.0.0',
2274 15 => '255.254.0.0',
2275 14 => '255.252.0.0',
2276 13 => '255.248.0.0',
2277 12 => '255.240.0.0',
2278 11 => '255.224.0.0',
2279 10 => '255.192.0.0',
2280 9 => '255.128.0.0',
2281 8 => '255.0.0.0',
2282 7 => '254.0.0.0',
2283 6 => '252.0.0.0',
2284 5 => '248.0.0.0',
2285 4 => '240.0.0.0',
2286 3 => '224.0.0.0',
2287 2 => '192.0.0.0',
2288 1 => '128.0.0.0'
2289 );
2290 $wildcardbylen = array
2291 (
2292 32 => '0.0.0.0',
2293 31 => '0.0.0.1',
2294 30 => '0.0.0.3',
2295 29 => '0.0.0.7',
2296 28 => '0.0.0.15',
2297 27 => '0.0.0.31',
2298 26 => '0.0.0.63',
2299 25 => '0.0.0.127',
2300 24 => '0.0.0.255',
2301 23 => '0.0.1.255',
2302 22 => '0.0.3.255',
2303 21 => '0.0.7.255',
2304 20 => '0.0.15.255',
2305 19 => '0.0.31.255',
2306 18 => '0.0.63.255',
2307 17 => '0.0.127.255',
2308 16 => '0.0.255.25',
2309 15 => '0.1.255.255',
2310 14 => '0.3.255.255',
2311 13 => '0.7.255.255',
2312 12 => '0.15.255.255',
2313 11 => '0.31.255.255',
2314 10 => '0.63.255.255',
2315 9 => '0.127.255.255',
2316 8 => '0.255.255.255',
2317 7 => '1.255.255.255',
2318 6 => '3.255.255.255',
2319 5 => '7.255.255.255',
2320 4 => '15.255.255.255',
2321 3 => '31.255.255.255',
2322 2 => '63.255.255.255',
2323 1 => '127.255.255.255'
2324 );
b901bf1f 2325 $maxperpage = getConfigVar ('IPV4_ADDRS_PER_PAGE');
e673ee24
DO
2326 if (isset($_REQUEST['pg']))
2327 $page = $_REQUEST['pg'];
2328 else
2329 $page=0;
2330
b6b87070
DO
2331 $range = getIPv4NetworkInfo ($id);
2332 loadIPv4AddrList ($range);
2034d968
DO
2333 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
2334 echo "<tr><td colspan=2 align=center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></td></tr>\n";
2335
2336 echo "<tr><td class=pcleft width='50%'>";
2337 startPortlet ('summary');
2338 $total = ($range['ip_bin'] | $range['mask_bin_inv']) - ($range['ip_bin'] & $range['mask_bin']) + 1;
2339 $used = count ($range['addrlist']);
2340 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
04d619d0
DO
2341
2342 echo "<tr><th width='50%' class=tdright>%% used:</th><td class=tdleft>";
2034d968
DO
2343 renderProgressBar ($used/$total);
2344 echo "&nbsp;${used}/${total}</td></tr>\n";
04d619d0 2345
001e61fa
DO
2346 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
2347 {
3444ecf2
DO
2348 // Build a backtrace from all parent networks.
2349 $clen = $range['mask'];
2350 $backtrace = array();
2351 while (NULL !== ($upperid = getIPv4AddressNetworkId ($range['ip'], $clen)))
2352 {
2353 $upperinfo = getIPv4NetworkInfo ($upperid);
2354 $clen = $upperinfo['mask'];
2355 $backtrace[] = $upperid;
2356 }
2357 $arrows = count ($backtrace);
2358 foreach (array_reverse ($backtrace) as $ancestorid)
001e61fa
DO
2359 {
2360 $ainfo = getIPv4NetworkInfo ($ancestorid);
3444ecf2
DO
2361 echo "<tr><th width='50%' class=tdright>";
2362 for ($i = 0; $i < $arrows; $i++)
2363 echo '&uarr;';
2364 $arrows--;
4fbb5a00 2365 echo "</th><td class=tdleft><a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno, 'id'=>$ainfo['id']))."'>${ainfo['ip']}/${ainfo['mask']}</a></td></tr>";
001e61fa 2366 }
3444ecf2
DO
2367 echo "<tr><th width='50%' class=tdright>&rarr;</th>";
2368 echo "<td class=tdleft>${range['ip']}/${range['mask']}</td></tr>";
001e61fa
DO
2369 // FIXME: get and display nested networks
2370 // $theitem = pickLeaf ($ipv4tree, $id);
2371 }
2372
545478d0
DO
2373 echo "<tr><th width='50%' class=tdright>Netmask:</th><td class=tdleft>";
2374 echo $netmaskbylen[$range['mask']];
2375 echo "</td></tr>\n";
04d619d0 2376
c607ab55
DO
2377 echo "<tr><th width='50%' class=tdright>Netmask:</th><td class=tdleft>";
2378 printf ('0x%08X', binMaskFromDec ($range['mask']));
2379 echo "</td></tr>\n";
2380
545478d0
DO
2381 echo "<tr><th width='50%' class=tdright>Wildcard bits:</th><td class=tdleft>";
2382 echo $wildcardbylen[$range['mask']];
2383 echo "</td></tr>\n";
04d619d0 2384
f3d0cb20 2385 $routers = findRouters ($range['addrlist']);
f0ed1181 2386 if (getConfigVar ('EXT_IPV4_VIEW') == 'yes' and count ($routers))
04d619d0 2387 {
57dece2f 2388 echo "<tr><th width='50%' class=tdright>Routed by:</th>";
f3d0cb20 2389 printRoutersTD ($routers);
57dece2f 2390 echo "</tr>\n";
04d619d0
DO
2391 }
2392
4fbb5a00 2393 printTagTRs (makeHref(array('page'=>'ipv4space', 'tab'=>'default'))."&");
2034d968
DO
2394 echo "</table><br>\n";
2395 finishPortlet();
e1ae3fb4
AD
2396
2397 renderFilesPortlet ('ipv4net', $id);
2034d968 2398 echo "</td>\n";
e673ee24 2399
2034d968
DO
2400 echo "<td class=pcright>";
2401 startPortlet ('details');
e673ee24
DO
2402 $startip = $range['ip_bin'] & $range['mask_bin'];
2403 $endip = $range['ip_bin'] | $range['mask_bin_inv'];
2404 $realstartip = $startip;
2405 $realendip = $endip;
2406 $numpages = 0;
2407 if($endip - $startip > $maxperpage)
2408 {
e673ee24
DO
2409 $numpages = ($endip - $startip)/$maxperpage;
2410 $startip = $startip + $page * $maxperpage;
2411 $endip = $startip + $maxperpage-1;
2412 }
2413 echo "<center>";
b901bf1f
DO
2414 if ($numpages)
2415 echo '<h3>' . long2ip ($startip) . ' ~ ' . long2ip ($endip) . '</h3>';
e673ee24
DO
2416 for ($i=0; $i<$numpages; $i++)
2417 {
2418 if ($i == $page)
2419 echo "<b>$i</b> ";
2420 else
4fbb5a00 2421 echo "<a href='".makeHref(array('page'=>$pageno, 'tab'=>$tabno, 'id'=>$id, 'pg'=>$i))."'>$i</a> ";
e673ee24
DO
2422 }
2423 echo "</center>";
2424
beb9e88a 2425 echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center' width='100%'>\n";
e673ee24
DO
2426 echo "<tr><th>Address</th><th>Name</th><th>Allocation</th></tr>\n";
2427
2428
b2035dca
DO
2429 for ($ip = $startip; $ip <= $endip; $ip++) :
2430 if (isset ($_REQUEST['hl_ipv4_addr']) and ip2long ($_REQUEST['hl_ipv4_addr']) == $ip)
2431 $secondstyle = 'tdleft port_highlight';
2727c7df 2432 else
b2035dca
DO
2433 $secondstyle = 'tdleft';
2434 if (!isset ($range['addrlist'][$ip]))
e673ee24 2435 {
4fbb5a00 2436 echo "<tr><td class=tdleft><a href='".makeHref(array('page'=>'ipaddress', 'ip'=>ip_long2quad($ip)))."'>" . ip_long2quad($ip);
b2035dca
DO
2437 echo "</a></td><td class='${secondstyle}'>&nbsp;</td><td class='${secondstyle}'>&nbsp;</td></tr>\n";
2438 continue;
2439 }
b2035dca 2440 $addr = $range['addrlist'][$ip];
2d318652 2441 echo "<tr class='${addr['class']}'>";
e673ee24 2442
4fbb5a00 2443 echo "<td class=tdleft><a href='".makeHref(array('page'=>'ipaddress', 'ip'=>$addr['ip']))."'>${addr['ip']}</a></td>";
b2035dca
DO
2444 echo "<td class='${secondstyle}'>${addr['name']}</td><td class='${secondstyle}'>";
2445 $delim = '';
2446 $prologue = '';
2447 if ( $addr['reserved'] == 'yes')
2448 {
2d318652 2449 echo "<strong>RESERVED</strong> ";
b2035dca
DO
2450 $delim = '; ';
2451 }
2d318652 2452 foreach ($range['addrlist'][$ip]['allocs'] as $ref)
b2035dca 2453 {
beb9e88a 2454 echo $delim . $aac2[$ref['type']];
4fbb5a00 2455 echo "<a href='".makeHref(array('page'=>'object', 'object_id'=>$ref['object_id'], 'hl_ipv4_addr'=>$addr['ip']))."'>";
b2035dca
DO
2456 echo $ref['name'] . (empty ($ref['name']) ? '' : '@');
2457 echo "${ref['object_name']}</a>";
2458 $delim = '; ';
2459 }
2460 if ($delim != '')
2461 {
6131056c 2462 $delim = '';
b2035dca
DO
2463 $prologue = '<br>';
2464 }
2d318652 2465 foreach ($range['addrlist'][$ip]['lblist'] as $ref)
b2035dca
DO
2466 {
2467 echo $prologue;
602663f4 2468 $prologue = '';
4fbb5a00
DY
2469 echo "${delim}<a href='".makeHref(array('page'=>'object', 'object_id'=>$ref['object_id']))."'>";
2470 echo "${ref['object_name']}</a>:<a href='".makeHref(array('page'=>'ipv4vs', 'vs_id'=>$ref['vs_id']))."'>";
b2035dca
DO
2471 echo "${ref['vport']}/${ref['proto']}</a>&rarr;";
2472 $delim = '; ';
2473 }
2474 if ($delim != '')
2475 {
2476 $delim = '';
2477 $prologue = '<br>';
e673ee24 2478 }
2d318652 2479 foreach ($range['addrlist'][$ip]['rslist'] as $ref)
b2035dca
DO
2480 {
2481 echo $prologue;
2482 $prologue = '';
4fbb5a00 2483 echo "${delim}&rarr;${ref['rsport']}@<a href='".makeHref(array('page'=>'ipv4rspool', 'pool_id'=>$ref['rspool_id']))."'>";
b2035dca
DO
2484 echo "${ref['rspool_name']}</a>";
2485 $delim = '; ';
2486 }
2487 echo "</td></tr>\n";
2488 endfor;
2727c7df 2489 // end of iteration
e673ee24
DO
2490
2491 echo "</table>";
2034d968
DO
2492 finishPortlet();
2493 echo "</td></tr></table>\n";
e673ee24
DO
2494}
2495
53ef3908 2496function renderIPv4NetworkProperties ($id)
e673ee24 2497{
e673ee24 2498 showMessageOrError();
53ef3908
DO
2499 $netdata = getIPv4NetworkInfo ($id);
2500 echo "<center><h1>${netdata['ip']}/${netdata['mask']}</h1></center>\n";
e673ee24 2501 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
7056988c 2502 printOpFormIntro ('editRange');
53ef3908
DO
2503 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='${netdata['name']}'></tr>";
2504 echo "<tr><td colspan=2 class=tdcenter>";
2505 printImageHREF ('SAVE', 'Save changes', TRUE);
2506 echo "</td></form></tr></table>\n";
e673ee24
DO
2507}
2508
2d318652 2509function renderIPv4Address ($dottedquad)
e673ee24 2510{
4fbb5a00 2511 global $aat;
2d318652 2512 $address = getIPv4Address ($dottedquad);
68225375 2513 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
2d318652
DO
2514 echo "<tr><td colspan=2 align=center><h1>${dottedquad}</h1></td></tr>\n";
2515 if (!empty ($address['name']))
68225375 2516 echo "<tr><td colspan=2 align=center><h2>${address['name']}</h2></td></tr>\n";
e673ee24 2517
68225375
DO
2518 echo "<tr><td class=pcleft>";
2519 startPortlet ('summary');
2520 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
04d619d0 2521 echo "<tr><th width='50%' class=tdright>Allocations:</th><td class=tdleft>" . count ($address['allocs']) . "</td></tr>\n";
68225375
DO
2522 echo "<tr><th width='50%' class=tdright>Originated NAT connections:</th><td class=tdleft>" . count ($address['outpf']) . "</td></tr>\n";
2523 echo "<tr><th width='50%' class=tdright>Arriving NAT connections:</th><td class=tdleft>" . count ($address['inpf']) . "</td></tr>\n";
04d619d0 2524 echo "<tr><th width='50%' class=tdright>SLB virtual services:</th><td class=tdleft>" . count ($address['lblist']) . "</td></tr>\n";
68225375
DO
2525 echo "<tr><th width='50%' class=tdright>SLB real servers:</th><td class=tdleft>" . count ($address['rslist']) . "</td></tr>\n";
2526 printTagTRs();
2527 echo "</table><br>\n";
2528 finishPortlet();
2529 echo "</td>\n";
e673ee24 2530
68225375 2531 echo "<td class=pcright>";
e673ee24 2532
f74d96c6 2533 if (isset ($address['class']))
59bebe2b 2534 {
8e700dd1 2535 startPortlet ('allocations');
2d318652
DO
2536 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center' width='100%'>\n";
2537 echo "<tr><th>object</th><th>OS interface</th><th>allocation type</th></tr>\n";
2538 $class = $address['class'];
2539 // render all allocation records for this address the same way
59bebe2b 2540 if ($address['reserved'] == 'yes')
2d318652
DO
2541 echo "<tr class='${class}'><td colspan=2>&nbsp;</td><td class=tdleft><strong>RESERVED</strong></td></tr>";
2542 foreach ($address['allocs'] as $bond)
59bebe2b 2543 {
8e700dd1
DO
2544 if (isset ($_REQUEST['hl_object_id']) and $_REQUEST['hl_object_id'] == $bond['object_id'])
2545 $secondclass = 'tdleft port_highlight';
2546 else
2547 $secondclass = 'tdleft';
4fbb5a00 2548 echo "<tr class='$class'><td class=tdleft><a href='".makeHref(array('page'=>'object', 'object_id'=>$bond['object_id'], 'hl_ipv4_addr'=>$dottedquad))."'>${bond['object_name']}</td><td class='${secondclass}'>${bond['name']}</td><td class='${secondclass}'><strong>";
52c836b1
DO
2549 echo $aat[$bond['type']];
2550 echo "</strong></td></tr>\n";
59bebe2b
DO
2551 }
2552 echo "</table><br><br>";
2553 finishPortlet();
2554 }
e673ee24 2555
f3d0cb20
DO
2556 // FIXME: The returned list is structured differently, than we expect it to be. One of the sides
2557 // must be fixed.
2d318652 2558 if (count ($address['lblist']))
e673ee24 2559 {
2d318652
DO
2560 startPortlet ('Virtual services (' . count ($address['lblist']) . ')');
2561 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center' width='100%'>\n";
59bebe2b 2562 echo "<tr><th>VS</th><th>name</th></tr>\n";
2d318652 2563 foreach ($address['lblist'] as $vsinfo)
e673ee24 2564 {
4fbb5a00 2565 echo "<tr><td class=tdleft><a href='".makeHref(array('page'=>'ipv4vs', 'vs_id'=>$vsinfo['vs_id']))."'>";
59bebe2b 2566 echo buildVServiceName ($vsinfo) . "</a></td><td class=tdleft>";
5fe1ed76 2567 echo $vsinfo['name'] . "</td></tr>\n";
e673ee24 2568 }
59bebe2b
DO
2569 echo "</table><br><br>";
2570 finishPortlet();
e673ee24 2571 }
5fe1ed76
DO
2572
2573 if (count ($address['rslist']))
2574 {
2575 startPortlet ('Real servers (' . count ($address['rslist']) . ')');
2d318652 2576 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center' width='100%'>\n";
53f4b619 2577 echo "<tr><th>&nbsp;</th><th>port</th><th>RS pool</th></tr>\n";
5fe1ed76
DO
2578 foreach ($address['rslist'] as $rsinfo)
2579 {
2580 echo "<tr><td>";
2581 if ($rsinfo['inservice'] == 'yes')
2582 printImageHREF ('inservice', 'in service');
2583 else
2584 printImageHREF ('notinservice', 'NOT in service');
4fbb5a00 2585 echo "</td><td class=tdleft>${rsinfo['rsport']}</td><td class=tdleft><a href='".makeHref(array('page'=>'ipv4rspool', 'pool_id'=>$rsinfo['rspool_id']))."'>";
2d318652 2586 echo $rsinfo['rspool_name'] . "</a></td></tr>\n";
5fe1ed76
DO
2587 }
2588 echo "</table><br><br>";
2589 finishPortlet();
2590 }
2591
68225375
DO
2592 if (count ($address['outpf']))
2593 {
105a3bc8 2594 startPortlet ('departing NAT rules');
2d318652 2595 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center' width='100%'>\n";
105a3bc8
DO
2596 echo "<tr><th>proto</th><th>from</th><th>to</th><th>comment</th></tr>\n";
2597 foreach ($address['outpf'] as $rule)
b62ff880 2598 echo "<tr><td>${rule['proto']}</td><td>${rule['localip']}:${rule['localport']}</td><td>${rule['remoteip']}:${rule['remoteport']}</td><td>${rule['description']}</td></tr>";
105a3bc8 2599 echo "</table>";
68225375
DO
2600 finishPortlet();
2601 }
105a3bc8
DO
2602
2603 if (count ($address['inpf']))
2604 {
2605 startPortlet ('arriving NAT rules');
2d318652 2606 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center' width='100%'>\n";
105a3bc8
DO
2607 echo "<tr><th>proto</th><th>from</th><th>to</th><th>comment</th></tr>\n";
2608 foreach ($address['inpf'] as $rule)
b62ff880 2609 echo "<tr><td>${rule['proto']}</td><td>${rule['localip']}:${rule['localport']}</td><td>${rule['remoteip']}:${rule['remoteport']}</td><td>${rule['description']}</td></tr>";
105a3bc8
DO
2610 echo "</table>";
2611 finishPortlet();
2612 }
2613
68225375
DO
2614 echo "</td></tr>";
2615 echo "</table>\n";
e673ee24
DO
2616}
2617
2d318652 2618function renderIPv4AddressProperties ($dottedquad)
e673ee24 2619{
e673ee24 2620 showMessageOrError();
2d318652
DO
2621 $address = getIPv4Address ($dottedquad);
2622 echo "<center><h1>$dottedquad</h1></center>\n";
7056988c 2623
1fbc9fd6 2624 startPortlet ('update');
e673ee24 2625 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
7056988c 2626 printOpFormIntro ('editAddress');
2d318652
DO
2627 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='${address['name']}'></tr>";
2628 echo "<td class='tdright'>Reserved:</td><td class='tdleft'><input type=checkbox name=reserved size=20 ";
2629 echo ($address['reserved']=='yes') ? 'checked' : '';
53ef3908
DO
2630 echo "></tr><tr><td colspan=2 class='tdcenter'>";
2631 printImageHREF ('SAVE', 'Save changes', TRUE);
2632 echo "</td></form></tr></table>\n";
1fbc9fd6
DO
2633 finishPortlet();
2634 if (empty ($address['name']) and $address['reserved'] == 'no')
2635 return;
7056988c 2636
1fbc9fd6 2637 startPortlet ('release');
7056988c 2638 printOpFormIntro ('editAddress', array ('name' => '', 'reserved' => ''));
1fbc9fd6
DO
2639 echo "<input type=submit value='release'></form>";
2640 finishPortlet();
e673ee24
DO
2641}
2642
2d318652 2643function renderIPv4AddressAllocations ($dottedquad)
e673ee24 2644{
e673ee24 2645 showMessageOrError();
39b4abd0
DO
2646 function printNewItemTR ()
2647 {
2648 global $aat;
2649 printOpFormIntro ('addIPv4Allocation');
2650 echo "<tr><td>";
9318d2ef 2651 printImageHREF ('add', 'allocate', TRUE);
f5ff50f5 2652 echo "</td><td><select name='object_id' tabindex=100>";
39b4abd0
DO
2653
2654 foreach (explode (',', getConfigVar ('IPV4_PERFORMERS')) as $type)
2655 foreach (getNarrowObjectList ($type) as $object)
2656 echo "<option value='${object['id']}'>${object['dname']}</option>";
2657
f5ff50f5
DO
2658 echo "</select></td><td><input type=text tabindex=101 name=bond_name size=10></td><td>";
2659 printSelect ($aat, 'bond_type', NULL, 102);
9318d2ef 2660 echo "</td><td>";
f5ff50f5 2661 printImageHREF ('add', 'allocate', TRUE, 103);
9318d2ef 2662 echo "</td></form></tr>";
39b4abd0 2663 }
4fbb5a00 2664 global $pageno, $tabno, $aat;
e673ee24 2665
2d318652 2666 $address = getIPv4Address ($dottedquad);
f74d96c6 2667
2d318652 2668 echo "<center><h1>${dottedquad}</h1></center>\n";
105a3bc8 2669 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n";
2d318652 2670 echo "<tr><th>&nbsp;</th><th>object</th><th>OS interface</th><th>allocation type</th><th>&nbsp;</th></tr>\n";
e673ee24 2671
39b4abd0
DO
2672 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
2673 printNewItemTR();
f74d96c6 2674 if (isset ($address['class']))
e673ee24 2675 {
f74d96c6
DO
2676 $class = $address['class'];
2677 if ($address['reserved'] == 'yes')
2678 echo "<tr class='${class}'><td colspan=3>&nbsp;</td><td class=tdleft><strong>RESERVED</strong></td><td>&nbsp;</td></tr>";
2679 foreach ($address['allocs'] as $bond)
2680 {
2681 echo "<tr class='$class'>";
2682 printOpFormIntro ('updIPv4Allocation', array ('object_id' => $bond['object_id']));
4fbb5a00 2683 echo "<td><a href='".makeHrefProcess(array('op'=>'delIPv4Allocation', 'ip'=>$dottedquad, 'object_id'=>$bond['object_id']))."'>";
f74d96c6
DO
2684 printImageHREF ('delete', 'Unallocate address');
2685 echo "</a></td>";
4fbb5a00 2686 echo "<td><a href='".makeHref(array('page'=>'object', 'object_id'=>$bond['object_id'], 'hl_ipv4_addr'=>$dottedquad))."'>${bond['object_name']}</td>";
f74d96c6
DO
2687 echo "<td><input type='text' name='bond_name' value='${bond['name']}' size=10></td><td>";
2688 printSelect ($aat, 'bond_type', $bond['type']);
2689 echo "</td><td>";
2690 printImageHREF ('save', 'Save changes', TRUE);
2691 echo "</td></form></tr>\n";
2692 }
e673ee24 2693 }
39b4abd0
DO
2694 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
2695 printNewItemTR();
e673ee24 2696 echo "</table><br><br>";
e673ee24
DO
2697}
2698
eeb4a5d8 2699function renderNATv4ForObject ($object_id = 0)
e673ee24 2700{
9318d2ef
DO
2701 function printNewItemTR ($alloclist)
2702 {
9318d2ef
DO
2703 printOpFormIntro ('addNATv4Rule');
2704 echo "<tr align='center'><td>";
2705 printImageHREF ('add', 'Add new NAT rule', TRUE);
2706 echo '</td><td>';
2707 printSelect (array ('TCP' => 'TCP', 'UDP' => 'UDP'), 'proto');
2708 echo "<select name='localip' tabindex=1>";
2709
2710 foreach ($alloclist as $dottedquad => $alloc)
2711 {
2712 $name = empty ($alloc['addrinfo']['name']) ? '' : (' (' . niftyString ($alloc['addrinfo']['name']) . ')');
2713 $osif = empty ($alloc['osif']) ? '' : ($alloc['osif'] . ': ');
2714 echo "<option value='${dottedquad}'>${osif}${dottedquad}${name}</option>";
2715 }
2716
2717 echo "</select>:<input type='text' name='localport' size='4' tabindex=2></td>";
2718 echo "<td><input type='text' name='remoteip' id='remoteip' size='10' tabindex=3>";
2719 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\");'>";
2720 printImageHREF ('find', 'Find object');
2721 echo "</a>";
2722 echo ":<input type='text' name='remoteport' size='4' tabindex=4></td><td></td>";
2723 echo "<td colspan=1><input type='text' name='description' size='20' tabindex=5></td><td>";
f5ff50f5 2724 printImageHREF ('add', 'Add new NAT rule', TRUE, 6);
9318d2ef
DO
2725 echo "</td></tr></form>";
2726 }
4fbb5a00 2727 global $pageno, $tabno;
e673ee24
DO
2728
2729 $info = getObjectInfo ($object_id);
eeb4a5d8 2730 $forwards = getNATv4ForObject ($object_id);
2c817354 2731 $alloclist = getObjectIPv4Allocations ($object_id);
e673ee24 2732 showMessageOrError();
f28fbe8b 2733 echo "<center><h2>locally performed NAT</h2></center>";
e673ee24 2734
105a3bc8 2735 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n";
d54b9495 2736 echo "<tr><th></th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Comment</th><th>&nbsp;</th></tr>\n";
e673ee24 2737
9318d2ef
DO
2738 if (getConfigVar ('ADDNEW_AT_TOP') == 'yes')
2739 printNewItemTR ($alloclist);
e673ee24
DO
2740 foreach ($forwards['out'] as $pf)
2741 {
2c817354
DO
2742 $class = 'trerror';
2743 $osif = '';
2744 if (isset ($alloclist [$pf['localip']]))
2745 {
2746 $class = $alloclist [$pf['localip']]['addrinfo']['class'];
2747 $osif = $alloclist [$pf['localip']]['osif'] . ': ';
2748 }
e673ee24
DO
2749
2750 echo "<tr class='$class'>";
4fbb5a00
DY
2751 echo "<td><a href='".
2752 makeHrefProcess(array(
2753 'op'=>'delNATv4Rule',
2754 'localip'=>$pf['localip'],
2755 'localport'=>$pf['localport'],
2756 'remoteip'=>$pf['remoteip'],
2757 'remoteport'=>$pf['remoteport'],
2758 'proto'=>$pf['proto'],
2759 'object_id'=>$object_id)).
2760 "'>";
4de22e7e
DO
2761 printImageHREF ('delete', 'Delete NAT rule');
2762 echo "</a></td>";
4fbb5a00 2763 echo "<td>${pf['proto']}/${osif}<a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['localip']))."'>${pf['localip']}</a>:${pf['localport']}";
f28fbe8b
DO
2764 if (!empty ($pf['local_addr_name']))
2765 echo ' (' . $pf['local_addr_name'] . ')';
2766 echo "</td>";
4fbb5a00 2767 echo "<td><a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['remoteip']))."'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
e673ee24 2768
53ef3908 2769 $address = getIPv4Address ($pf['remoteip']);
e673ee24
DO
2770
2771 echo "<td class='description'>";
53ef3908
DO
2772 if (count ($address['allocs']))
2773 foreach ($address['allocs'] as $bond)
4fbb5a00 2774 echo "<a href='".makeHref(array('page'=>'object', 'tab'=>'default', 'object_id'=>$bond['object_id']))."'>${bond['object_name']}(${bond['name']})</a> ";
f28fbe8b
DO
2775 elseif (!empty ($pf['remote_addr_name']))
2776 echo '(' . $pf['remote_addr_name'] . ')';
7056988c
DO
2777 printOpFormIntro
2778 (
2779 'updNATv4Rule',
2780 array
2781 (
2782 'localip' => $pf['localip'],
2783 'localport' => $pf['localport'],
2784 'remoteip' => $pf['remoteip'],
2785 'remoteport' => $pf['remoteport'],
2786 'proto' => $pf['proto']
2787 )
2788 );
2789 echo "</td><td class='description'>";
d54b9495
DO
2790 echo "<input type='text' name='description' value='${pf['description']}'></td><td>";
2791 printImageHREF ('save', 'Save changes', TRUE);
2792 echo "</td></form></tr>";
e673ee24 2793 }
9318d2ef
DO
2794 if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
2795 printNewItemTR ($alloclist);
e673ee24
DO
2796
2797 echo "</table><br><br>";
2798
f28fbe8b 2799 echo "<center><h2>arriving NAT connections</h2></center>";
105a3bc8 2800 echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n";
e673ee24
DO
2801 echo "<tr><th></th><th>Source</th><th>Source objects</th><th>Target</th><th>Description</th></tr>\n";
2802
2803 foreach ($forwards['in'] as $pf)
2804 {
4fbb5a00
DY
2805 echo "<tr><td><a href='".
2806 makeHrefProcess(array(
2807 'op'=>'delNATv4Rule',
2808 'localip'=>$pf['localip'],
2809 'localport'=>$pf['localport'],
2810 'remoteip'=>$pf['remoteip'],
2811 'remoteport'=>$pf['remoteport'],
2812 'proto'=>$pf['proto'],
2813 'object_id'=>$pf['object_id']
2814 )).
2815 "'>";
4de22e7e
DO
2816 printImageHREF ('delete', 'Delete NAT rule');
2817 echo "</a></td>";
4fbb5a00
DY
2818 echo "<td>${pf['proto']}/<a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['localip']))."'>${pf['localip']}</a>:${pf['localport']}</td>";
2819 echo "<td class='description'><a href='".makeHref(array('page'=>'object', 'tab'=>'default', 'object_id'=>$pf['object_id']))."'>${pf['object_name']}</a>";
2820 echo "</td><td><a href='".makeHref(array('page'=>'ipaddress', 'tab'=>'default', 'ip'=>$pf['remoteip']))."'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
e673ee24
DO
2821 echo "<td class='description'>${pf['description']}</td></tr>";
2822 }
2823
e673ee24 2824 echo "</table><br><br>";
e673ee24
DO
2825}
2826
7056988c 2827// FIXME: move related code away into ophandler(s)
e673ee24
DO
2828function renderAddMultipleObjectsForm ()
2829{
20c901a7 2830 global $root, $pageno, $tabno, $nextorder;
e673ee24
DO
2831
2832 $type_id = array();
7f791d1d 2833 $global_type_id = 0;
e673ee24
DO
2834 $name = array();
2835 $asset_no = array();
ce4d1a79 2836 $keepvalues1 = $keepvalues2 = FALSE;
7f791d1d 2837 $log = array();
e673ee24 2838 // Look for current submit.
7f791d1d 2839 if (isset ($_REQUEST['got_fast_data']))
e673ee24 2840 {
f60bb422 2841 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
ce4d1a79 2842 $keepvalues1 = TRUE;
9c0b0016
DO
2843 $max = getConfigVar ('MASSCOUNT');
2844 for ($i = 0; $i < $max; $i++)
e673ee24
DO
2845 {
2846 if (!isset ($_REQUEST["${i}_object_type_id"]))
2847 {
2848 $log[] = array ('code' => 'error', 'message' => "Submitted form is invalid at line " . $i + 1);
2849 break;
2850 }
2c6c7645
DO
2851 assertUIntArg ("${i}_object_type_id", __FUNCTION__, TRUE);
2852 assertStringArg ("${i}_object_name", __FUNCTION__, TRUE);
2853 assertStringArg ("${i}_object_label", __FUNCTION__, TRUE);
2854 assertStringArg ("${i}_object_asset_no", __FUNCTION__, TRUE);
2855 assertStringArg ("${i}_object_barcode", __FUNCTION__, TRUE);
e673ee24
DO
2856 $type_id[$i] = $_REQUEST["${i}_object_type_id"];
2857 // Save user input for possible rendering.
2858 $name[$i] = $_REQUEST["${i}_object_name"];
2859 $label[$i] = $_REQUEST["${i}_object_label"];
2860 $asset_no[$i] = $_REQUEST["${i}_object_asset_no"];
2861 $barcode[$i] = $_REQUEST["${i}_object_barcode"];
2862
f60bb422 2863 // It's better to skip silently, than to print a notice.
e673ee24
DO
2864 if ($type_id[$i] == 0)
2865 continue;
f60bb422 2866 if (commitAddObject ($name[$i], $label[$i], $barcode[$i], $type_id[$i], $asset_no[$i], $taglist) === TRUE)
e673ee24
DO
2867 $log[] = array ('code' => 'success', 'message' => "Added new object '${name[$i]}'");
2868 else
4d2e93f2 2869 $log[] = array ('code' => 'error', 'message' => __FUNCTION__ . ': commitAddObject() failed');
e673ee24 2870 }
e673ee24 2871 }
7f791d1d
DO
2872 elseif (isset ($_REQUEST['got_very_fast_data']))
2873 {
f60bb422 2874 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
ce4d1a79 2875 $keepvalues2 = TRUE;
2c6c7645
DO
2876 assertUIntArg ('global_type_id', __FUNCTION__, TRUE);
2877 assertStringArg ('namelist', __FUNCTION__, TRUE);
7f791d1d
DO
2878 $global_type_id = $_REQUEST['global_type_id'];
2879 if ($global_type_id == 0)
2880 {
2881 if (!empty ($_REQUEST['namelist']))
2882 $log[] = array ('code' => 'error', 'message' => 'Object type is not selected, check the form below');
2883 else
2884 $log[] = array ('code' => 'error', 'message' => 'Empty form has been ignored. Cheers.');
2885 }
2886 else
2887 {
2888 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
2889 $names1 = explode ('\n', $_REQUEST['namelist']);
2890 $names2 = array();
2891 foreach ($names1 as $line)
2892 {
2893 $parts = explode ('\r', $line);
2894 reset ($parts);
2895 if (empty ($parts[0]))
2896 continue;
2897 else
2898 $names2[] = rtrim ($parts[0]);
2899 }
2900 foreach ($names2 as $cname)
f60bb422 2901 if (commitAddObject ($cname, '', '', $global_type_id, '', $taglist) === TRUE)
7f791d1d
DO
2902 $log[] = array ('code' => 'success', 'message' => "Added new object '${cname}'");
2903 else
2904 $log[] = array ('code' => 'error', 'message' => "Could not add '${cname}'");
2905 }
2906 }
2907 printLog ($log);
e673ee24
DO
2908
2909 // Render a form for the next.
2910 $typelist = getObjectTypeList();
4c330a14 2911 $typelist[0] = 'select type...';
7f791d1d 2912
f60bb422
DO
2913 startPortlet ('Distinct types, same tags');
2914 $max = getConfigVar ('MASSCOUNT');
20c901a7 2915 echo "<form name=fastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
e673ee24 2916 echo '<table border=0 align=center>';
f60bb422
DO
2917 echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th>";
2918 echo "<th>Asset tag</th><th>Barcode</th><th>Tags</th></tr>\n";
7f791d1d 2919 // If a user forgot to select object type on input, we keep his
e673ee24 2920 // previous input in the form.
9c0b0016 2921 for ($i = 0; $i < $max; $i++)
e673ee24 2922 {
7f791d1d 2923 echo '<tr><td>';
e7ade6bf
DO
2924 // Don't employ DEFAULT_OBJECT_TYPE to avoid creating ghost records for pre-selected empty rows.
2925 printSelect ($typelist, "${i}_object_type_id", 0);
e673ee24
DO
2926 echo '</td>';
2927 echo "<td><input type=text size=30 name=${i}_object_name";
ce4d1a79 2928 if ($keepvalues1 and isset ($name[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2929 echo " value='${name[$i]}'";
2930 echo "></td>";
2931 echo "<td><input type=text size=30 name=${i}_object_label";
ce4d1a79 2932 if ($keepvalues1 and isset ($label[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2933 echo " value='${label[$i]}'";
2934 echo "></td>";
2935 echo "<td><input type=text size=20 name=${i}_object_asset_no";
ce4d1a79 2936 if ($keepvalues1 and isset ($asset_no[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2937 echo " value='${asset_no[$i]}'";
2938 echo "></td>";
2939 echo "<td><input type=text size=10 name=${i}_object_barcode";
ce4d1a79 2940 if ($keepvalues1 and isset ($barcode[$i]) and (!isset ($type_id[$i]) or $type_id[$i] == 0))
e673ee24
DO
2941 echo " value='${barcode[$i]}'";
2942 echo "></td>";
f60bb422
DO
2943 if ($i == 0)
2944 {
2945 echo "<td valign=top rowspan=${max}>";
2946 renderTagSelect();
2947 echo "</td>\n";
2948 }
e673ee24 2949 echo "</tr>\n";
e673ee24 2950 }
216c84bb 2951 echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Go!'></td></tr>\n";
e673ee24
DO
2952 echo "</form></table>\n";
2953 finishPortlet();
7f791d1d 2954
f60bb422 2955 startPortlet ('Same type, same tags');
20c901a7 2956 echo "<form name=veryfastform method=post action='${root}?page=${pageno}&tab=${tabno}'>";
f60bb422
DO
2957 echo "<table border=0 align=center><tr><th>names</th><th>type</th></tr>";
2958 echo "<tr><td rowspan=3><textarea name=namelist cols=40 rows=25>\n";
ce4d1a79 2959 if ($keepvalues2 and $global_type_id == 0)
7f791d1d 2960 echo $_REQUEST['namelist'];
f60bb422
DO
2961 echo "</textarea></td><td valign=top>";
2962 printSelect ($typelist, "global_type_id", getConfigVar ('DEFAULT_OBJECT_TYPE'));
2963 echo "</td></tr>";
2964 echo "<tr><th>Tags</th></tr>";
2965 echo "<tr><td valign=top>";
2966 renderTagSelect();
2967 echo "</td></tr>";
2968 echo "<tr><td colspan=2><input type=submit name=got_very_fast_data value='Go!'></td></tr></table>\n";
2969 echo "</form>\n";
7f791d1d 2970 finishPortlet();
e673ee24
DO
2971}
2972
2973function printGreeting ()
2974{
d6d79c36
DO
2975 global $root, $remote_username, $remote_displayname;
2976 echo "Hello, <a href='${root}?page=myaccount&tab=default'>${remote_displayname}</a>. This is RackTables " .
2977 CODE_VERSION .
2978 ". Click <a href='${root}?logout'>here</a> to logout.";
e673ee24
DO
2979}
2980
2981function renderSearchResults ()
2982{
2983 global $remote_username, $root;
2984 $terms = trim ($_REQUEST['q']);
2985 if (empty ($terms))
2986 {
591ff2c4 2987 showError ('Search string cannot be empty.', __FUNCTION__);
e673ee24
DO
2988 return;
2989 }
54522168 2990 if (!permitted ('objects', 'default'))
e673ee24 2991 {
591ff2c4 2992 showError ('You are not authorized for viewing information about objects.', __FUNCTION__);
e673ee24
DO
2993 return;
2994 }
ea5fc465 2995 $nhits = 0;
e673ee24
DO
2996 // If we search for L2 address, we can either find one or find none.
2997 if
2998 (
05771508
DO
2999 preg_match (RE_L2_IFCFG, $terms) or
3000 preg_match (RE_L2_SOLID, $terms) or
3001 preg_match (RE_L2_CISCO, $terms) or
1930dc7f 3002 preg_match (RE_L2_IPCFG, $terms) or
05771508
DO
3003 // Foundry STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
3004 preg_match (RE_L2_FDRYSTP, $terms)
e673ee24
DO
3005 )
3006 // Search for L2 address.
3007 {
3ec29bf4
DO
3008 $terms = str_replace ('.', '', $terms);
3009 $terms = str_replace (':', '', $terms);
1930dc7f 3010 $terms = str_replace ('-', '', $terms);
ea5fc465 3011 $terms = substr ($terms, -12);
e673ee24
DO
3012 $result = searchByl2address ($terms);
3013 if ($result !== NULL)
3014 {
ea5fc465
DO
3015 $nhits++;
3016 $lasthit = 'port';
3017 $summary['port'][] = $result;
e673ee24 3018 }
e673ee24 3019 }
05771508 3020 elseif (preg_match (RE_IP4_ADDR, $terms))
64347dcf 3021 // Search for IPv4 address.
e673ee24 3022 {
bb0a44e9 3023 if (NULL !== getIPv4AddressNetworkId ($terms))
e673ee24 3024 {
ea5fc465 3025 $nhits++;
f3d0cb20
DO
3026 $lasthit = 'ipv4addressbydq';
3027 $summary['ipv4addressbydq'][] = $terms;
e673ee24 3028 }
e673ee24 3029 }
05771508 3030 elseif (preg_match (RE_IP4_NET, $terms))
64347dcf
DO
3031 // Search for IPv4 network
3032 {
3033 list ($base, $len) = explode ('/', $terms);
3034 if (NULL !== ($tmp = getIPv4AddressNetworkId ($base, $len + 1)))
3035 {
3036 $nhits++;
3037 $lasthit = 'ipv4network';
3038 $summary['ipv4network'][] = getIPv4NetworkInfo ($tmp);
3039 }
3040 }
e673ee24 3041 else
ea5fc465 3042 // Search for objects, addresses, networks, virtual services and RS pools by their description.
e673ee24 3043 {
ea5fc465
DO
3044 $tmp = getObjectSearchResults ($terms);
3045 if (count ($tmp))
e673ee24 3046 {
ea5fc465
DO
3047 $nhits += count ($tmp);
3048 $lasthit = 'object';
3049 $summary['object'] = $tmp;
e673ee24 3050 }
ea5fc465
DO
3051 $tmp = getIPv4AddressSearchResult ($terms);
3052 if (count ($tmp))
e673ee24 3053 {
ea5fc465 3054 $nhits += count ($tmp);
f3d0cb20
DO
3055 $lasthit = 'ipv4addressbydescr';
3056 $summary['ipv4addressbydescr'] = $tmp;
ea5fc465
DO
3057 }
3058 $tmp = getIPv4PrefixSearchResult ($terms);
3059 if (count ($tmp))
3060 {
3061 $nhits += count ($tmp);
3062 $lasthit = 'ipv4network';
3063 $summary['ipv4network'] = $tmp;
3064 }
05411ccd
DO
3065 $tmp = getIPv4RSPoolSearchResult ($terms);
3066 if (count ($tmp))
3067 {
3068 $nhits += count ($tmp);
3069 $lasthit = 'ipv4rspool';
3070 $summary['ipv4rspool'] = $tmp;
3071 }
3072 $tmp = getIPv4VServiceSearchResult ($terms);
3073 if (count ($tmp))
3074 {
3075 $nhits += count ($tmp);
3076 $lasthit = 'ipv4vs';
3077 $summary['ipv4vs'] = $tmp;
3078 }
6a88e734
DO
3079 $tmp = getAccountSearchResult ($terms);
3080 if (count ($tmp))
3081 {
3082 $nhits += count ($tmp);
3083 $lasthit = 'user';
3084 $summary['user'] = $tmp;
3085 }
e1ae3fb4
AD
3086 $tmp = getFileSearchResult ($terms);
3087 if (count ($tmp))
3088 {
3089 $nhits += count ($tmp);
3090 $lasthit = 'file';
3091 $summary['file'] = $tmp;
3092 }
ea5fc465
DO
3093 }
3094 if ($nhits == 0)
3095 echo "<center><h2>Nothing found for '${terms}'</h2></center>";
3096 elseif ($nhits == 1)
3097 {
3098 $record = current ($summary[$lasthit]);
3099 switch ($lasthit)
3100 {
3101 case 'port':
3102 echo "<script language='Javascript'>document.location='${root}?page=object";
3103 echo "&hl_port_id=" . $record['port_id'];
3104 echo "&object_id=" . $record['object_id'] . "';//</script>";
3105 break;
f3d0cb20
DO
3106 case 'ipv4addressbydq':
3107 $parentnet = getIPv4AddressNetworkId ($record);
3108 if ($parentnet !== NULL)
e1ae3fb4 3109 echo "<script language='Javascript'>document.location='${root}?page=ipv4net&tab=default&id=${parentnet}&hl_ipv4_addr=${record}';//</script>";
f3d0cb20
DO
3110 else
3111 echo "<script language='Javascript'>document.location='${root}?page=ipaddress&ip=${record}';//</script>";
ea5fc465 3112 break;
f3d0cb20
DO
3113 case 'ipv4addressbydescr':
3114 $parentnet = getIPv4AddressNetworkId ($record['ip']);
3115 if ($parentnet !== NULL)
e1ae3fb4 3116 echo "<script language='Javascript'>document.location='${root}?page=ipv4net&tab=default&id=${parentnet}&hl_ipv4_addr=${record['ip']}';//</script>";
f3d0cb20
DO
3117 else
3118 echo "<script language='Javascript'>document.location='${root}?page=ipaddress&ip=${record['ip']}';//</script>";
ea5fc465
DO
3119 break;
3120 case 'ipv4network':
e1ae3fb4 3121 echo "<script language='Javascript'>document.location='${root}?page=ipv4net";
ea5fc465
DO
3122 echo "&id=${record['id']}";
3123 echo "';//</script>";
3124 break;
3125 case 'object':
3126 echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
3127 break;
05411ccd 3128 case 'ipv4rspool':
e1ae3fb4 3129 echo "<script language='Javascript'>document.location='${root}?page=ipv4rspool&pool_id=${record['pool_id']}';//</script>";
05411ccd
DO
3130 break;
3131 case 'ipv4vs':
49fb2686 3132 echo "<script language='Javascript'>document.location='${root}?page=ipv4vs&vs_id=${record['id']}';//</script>";
05411ccd 3133 break;
6a88e734
DO
3134 case 'user':
3135 echo "<script language='Javascript'>document.location='${root}?page=user&user_id=${record['user_id']}';//</script>";
3136 break;
e1ae3fb4
AD
3137 case 'file':
3138 echo "<script language='Javascript'>document.location='${root}?page=file&file_id=${record['id']}';//</script>";
3139 break;
ea5fc465
DO
3140 }
3141 return;
3142 }
3143 else
3144 {
3145 global $nextorder;
3146 $order = 'odd';
3147 echo "<center><h2>${nhits} result(s) found for '${terms}'</h2></center>";
3148 foreach ($summary as $where => $what)
3149 switch ($where)
e673ee24 3150 {
ea5fc465 3151 case 'object':
06adfe89 3152 startPortlet ("<a href='${root}?page=objects'>Objects</a>");
ea5fc465 3153 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
e1ae3fb4 3154 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Barcode</th></tr>';
ea5fc465
DO
3155 foreach ($what as $obj)
3156 {
2b3d64c5
DO
3157 $tags = loadRackObjectTags ($obj['id']);
3158 echo "<tr class=row_${order} valign=top><td class=tdleft><a href=\"${root}?page=object&object_id=${obj['id']}\">${obj['dname']}</a>";
3159 if (count ($tags))
3160 echo '<br><small>' . serializeTags ($tags) . '</small>';
3161 echo "</td><td>${obj['label']}</td>";
ea5fc465
DO
3162 echo "<td>${obj['asset_no']}</td>";
3163 echo "<td>${obj['barcode']}</td></tr>";
3164 $order = $nextorder[$order];
3165 }
3166 echo '</table>';
3167 finishPortlet();
3168 break;
3169 case 'ipv4network':
06adfe89 3170 startPortlet ("<a href='${root}?page=ipv4space'>IPv4 networks</a>");
ea5fc465 3171 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
e1ae3fb4 3172 echo '<tr><th>Network</th><th>Name/tags</th></tr>';
71287f1c 3173 foreach ($what as $netinfo)
ea5fc465 3174 {
71287f1c
DO
3175 echo "<tr class=row_${order} valign=top>";
3176 printIPv4NetInfoTDs ($netinfo);
3177 echo "</tr>\n";
ea5fc465
DO
3178 $order = $nextorder[$order];
3179 }
3180 echo '</table>';
3181 finishPortlet();
3182 break;
f3d0cb20 3183 case 'ipv4addressbydescr':
ea5fc465
DO
3184 startPortlet ('IPv4 addresses');
3185 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
f3d0cb20 3186 // FIXME: address, parent network, routers (if extended view is enabled)
e1ae3fb4 3187 echo '<tr><th>Address</th><th>Description</th></tr>';
ea5fc465
DO
3188 foreach ($what as $addr)
3189 {
f3d0cb20
DO
3190 echo "<tr class=row_${order}><td class=tdleft>";
3191 $parentnet = getIPv4AddressNetworkId ($addr['ip']);
3192 if ($parentnet !== NULL)
e1ae3fb4 3193 echo "<a href='${root}?page=ipv4net&tab=default&id=${parentnet}&hl_ipv4_addr=${addr['ip']}'>${addr['ip']}</a></td>";
f3d0cb20
DO
3194 else
3195 echo "<a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
ea5fc465
DO
3196 echo "<td class=tdleft>${addr['name']}</td></tr>";
3197 $order = $nextorder[$order];
3198 }
3199 echo '</table>';
3200 finishPortlet();
3201 break;
05411ccd 3202 case 'ipv4rspool':
ee437dab 3203 startPortlet ("<a href='${root}?page=ipv4rsplist'>RS pools</a>");
05411ccd
DO
3204 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
3205 foreach ($what as $rspool)
3206 {
e1ae3fb4 3207 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=ipv4rspool&pool_id=${rspool['pool_id']}'>";
05411ccd
DO
3208 echo buildRSPoolName ($rspool);
3209 echo "</a></td></tr>";
3210 $order = $nextorder[$order];
3211 }
3212 echo '</table>';
3213 finishPortlet();
3214 break;
3215 case 'ipv4vs':
a239e016 3216 startPortlet ("<a href='${root}?page=ipv4vslist'>Virtual services</a>");
05411ccd 3217 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
e1ae3fb4 3218 echo '<tr><th>VS</th><th>Description</th></tr>';
05411ccd
DO
3219 foreach ($what as $vs)
3220 {
49fb2686 3221 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=ipv4vs&vs_id=${vs['id']}'>";
05411ccd 3222 echo buildVServiceName ($vs);
6a88e734
DO
3223 echo "</a></td><td class=tdleft>${vs['name']}</td></tr>";
3224 $order = $nextorder[$order];
3225 }
3226 echo '</table>';
3227 finishPortlet();
3228 break;
3229 case 'user':
3230 startPortlet ("<a href='${root}?page=userlist'>Users</a>");
3231 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
e1ae3fb4 3232 echo '<tr><th>Username</th><th>Real Name</th></tr>';
6a88e734
DO
3233 foreach ($what as $item)
3234 {
3235 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=user&user_id=${item['user_id']}'>";
3236 echo $item['user_name'];
3237 echo "</a></td><td class=tdleft>${item['user_realname']}</td></tr>";
05411ccd
DO
3238 $order = $nextorder[$order];
3239 }
3240 echo '</table>';
3241 finishPortlet();
3242 break;
e1ae3fb4
AD
3243 case 'file':
3244 startPortlet ("<a href='${root}?page=files'>Files</a>");
3245 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
3246 echo '<tr><th>Name</th><th>Comment</th></tr>';
3247 foreach ($what as $item)
3248 {
3249 echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=file&file_id=${item['id']}'>";
3250 echo $item['name'];
3251 echo "</a></td><td class=tdleft>${item['comment']}</td></tr>";
3252 $order = $nextorder[$order];
3253 }
3254 echo '</table>';
3255 finishPortlet();
3256 break;
e673ee24 3257 }
e673ee24
DO
3258 }
3259}
3260
3261// This function prints a table of checkboxes to aid the user in toggling mount atoms
3262