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