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