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