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