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