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