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