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