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