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