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