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