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