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