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