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