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