r1723 + getAutoPorts(): new function to hold AutoPorts kitchen in one place
[racktables] / inc / navigation.php
1 <?php
2 /*
3 *
4 * This file implements generic navigation for RackTables.
5 *
6 */
7
8 $page = array();
9 $tab = array();
10 $helptab = array();
11 $trigger = array();
12 $ophandler = array();
13 $tabhandler = array();
14
15 $page['index']['title'] = 'Main page';
16 $page['index']['handler'] = 'renderIndex';
17
18 $page['rackspace']['title'] = 'Rackspace';
19 $page['rackspace']['parent'] = 'index';
20 $tab['rackspace']['default'] = 'Browse';
21 $tab['rackspace']['history'] = 'History';
22 $tab['rackspace']['firstrow'] = 'Click me!';
23 $trigger['rackspace']['firstrow'] = 'trigger_emptyRackspace';
24 $tabhandler['rackspace']['default'] = 'renderRackspace';
25 $tabhandler['rackspace']['history'] = 'renderRackspaceHistory';
26 $tabhandler['rackspace']['firstrow'] = 'renderFirstRowForm';
27
28 $page['objects']['title'] = 'Objects';
29 $page['objects']['parent'] = 'index';
30 $tab['objects']['default'] = 'View';
31 $tab['objects']['newobj'] = 'Add an object';
32 $tab['objects']['newmulti'] = 'Add multiple objects';
33 $tabhandler['objects']['default'] = 'renderObjectGroupSummary';
34 $tabhandler['objects']['newobj'] = 'renderNewObjectForm';
35 $tabhandler['objects']['newmulti'] = 'renderAddMultipleObjectsForm';
36
37 $page['row']['title_handler'] = 'dynamic_title_row';
38 $page['row']['bypass'] = 'row_id';
39 $page['row']['bypass_type'] = 'uint';
40 $page['row']['parent'] = 'rackspace';
41 $tab['row']['default'] = 'View';
42 $tab['row']['newrack'] = 'Add new rack';
43 $tabhandler['row']['default'] = 'renderRow';
44 $tabhandler['row']['newrack'] = 'renderNewRackForm';
45
46 $page['rack']['title_handler'] = 'dynamic_title_rack';
47 $page['rack']['bypass'] = 'rack_id';
48 $page['rack']['bypass_type'] = 'uint';
49 $page['rack']['parent'] = 'row';
50 $tab['rack']['default'] = 'View';
51 $tab['rack']['edit'] = 'Properties';
52 $tab['rack']['design'] = 'Design';
53 $tab['rack']['problems'] = 'Problems';
54 $tabhandler['rack']['default'] = 'renderRackPage';
55 $tabhandler['rack']['edit'] = 'renderEditRackForm';
56 $tabhandler['rack']['design'] = 'renderRackDesign';
57 $tabhandler['rack']['problems'] = 'renderRackProblems';
58
59 $page['objgroup']['title_handler'] = 'dynamic_title_objgroup';
60 $page['objgroup']['handler'] = 'renderObjectGroup';
61 $page['objgroup']['bypass'] = 'group_id';
62 $page['objgroup']['bypass_type'] = 'uint';
63 $page['objgroup']['parent'] = 'objects';
64
65 $page['object']['title_handler'] = 'dynamic_title_object';
66 $page['object']['bypass'] = 'object_id';
67 $page['object']['bypass_type'] = 'uint';
68 $page['object']['parent'] = 'objgroup';
69 $tab['object']['default'] = 'View';
70 $tab['object']['edit'] = 'Properties';
71 $tab['object']['rackspace'] = 'Rackspace';
72 $tab['object']['ports'] = 'Ports';
73 $tab['object']['network'] = 'IPv4';
74 $tab['object']['portfwrd'] = 'NATv4';
75 $tab['object']['switchvlans'] = 'Live VLANs';
76 $tab['object']['snmpportfinder'] = 'SNMP port finder';
77 $tab['object']['slb'] = '[SLB]';
78 $tab['object']['lvsconfig'] = 'LVS configuration';
79 $tab['object']['autoports'] = 'AutoPorts';
80 $tabhandler['object']['default'] = 'renderRackObject';
81 $tabhandler['object']['edit'] = 'renderEditObjectForm';
82 $tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
83 $tabhandler['object']['ports'] = 'renderPortsForObject';
84 $tabhandler['object']['network'] = 'renderNetworkForObject';
85 $tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
86 $tabhandler['object']['switchvlans'] = 'renderVLANMembership';
87 $tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
88 $tabhandler['object']['lvsconfig'] = 'renderLVSConfig';
89 $tabhandler['object']['autoports'] = 'renderAutoPortsForm';
90 $trigger['object']['network'] = 'trigger_ipv4';
91 $trigger['object']['portfwrd'] = 'trigger_natv4';
92 $trigger['object']['switchvlans'] = 'trigger_switchvlans';
93 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
94 $trigger['object']['slb'] = 'trigger_natv4';
95 $trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
96 $trigger['object']['autoports'] = 'trigger_autoports';
97 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
98 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
99 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
100 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
101 $ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
102 $ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
103 $ophandler['object']['ports']['useup'] = 'useupPort';
104 $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
105 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
106 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
107 $ophandler['object']['edit']['del'] = 'resetAttrValue';
108 $ophandler['object']['edit']['upd'] = 'updateAttrValues';
109 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
110 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
111 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
112
113 $page['ipv4space']['title'] = 'IPv4 space';
114 $page['ipv4space']['parent'] = 'index';
115 $tab['ipv4space']['default'] = 'Browse';
116 $tab['ipv4space']['newrange'] = 'Manage';
117 $tabhandler['ipv4space']['default'] = 'renderAddressspace';
118 $tabhandler['ipv4space']['newrange'] = 'renderAddNewRange';
119 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
120 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
121
122 $page['iprange']['title_handler'] = 'dynamic_title_iprange';
123 $page['iprange']['parent'] = 'ipv4space';
124 $page['iprange']['bypass'] = 'id';
125 $page['iprange']['bypass_type'] = 'uint';
126 $tab['iprange']['default'] = 'Browse';
127 $tab['iprange']['properties'] = 'Properties';
128 $tab['iprange']['liveptr'] = 'Live PTR';
129 $tabhandler['iprange']['default'] = 'renderIPRange';
130 $tabhandler['iprange']['properties'] = 'renderIPRangeProperties';
131 $tabhandler['iprange']['liveptr'] = 'renderLivePTR';
132 $ophandler['iprange']['properties']['editRange'] = 'editRange';
133 $ophandler['iprange']['liveptr']['import'] = 'importPTRData';
134
135 $page['ipaddress']['title_handler'] = 'dynamic_title_ipaddress';
136 $page['ipaddress']['parent'] = 'iprange';
137 $page['ipaddress']['bypass'] = 'ip';
138 $tab['ipaddress']['default'] = 'Browse';
139 $tab['ipaddress']['properties'] = 'Properties';
140 $tab['ipaddress']['assignment'] = 'Allocation';
141 $tab['ipaddress']['editrslist'] = '[SLB real servers]';
142 $tabhandler['ipaddress']['default'] = 'renderIPAddress';
143 $tabhandler['ipaddress']['properties'] = 'renderIPAddressProperties';
144 $tabhandler['ipaddress']['assignment'] = 'renderIPAddressAssignment';
145 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
146 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
147 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
148 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
149
150 $page['ipv4slb']['title'] = 'IPv4 SLB';
151 $page['ipv4slb']['parent'] = 'index';
152 $page['ipv4slb']['handler'] = 'renderIPv4SLB';
153
154 $page['vservices']['title'] = 'Virtual services';
155 $page['vservices']['parent'] = 'ipv4slb';
156 $tab['vservices']['default'] = 'View';
157 $tab['vservices']['edit'] = 'Edit';
158 $tabhandler['vservices']['default'] = 'renderVSList';
159 $tabhandler['vservices']['edit'] = 'renderVSListEditForm';
160 $ophandler['vservices']['edit']['add'] = 'addVService';
161 $ophandler['vservices']['edit']['del'] = 'deleteVService';
162 $ophandler['vservices']['edit']['upd'] = 'updateVService';
163
164 $page['vservice']['title_handler'] = 'dynamic_title_vservice';
165 $page['vservice']['parent'] = 'vservices';
166 $page['vservice']['bypass'] = 'id';
167 $page['vservice']['bypass_type'] = 'uint';
168 $tab['vservice']['default'] = 'View';
169 $tab['vservice']['edit'] = '[Edit]';
170 $tab['vservice']['editlblist'] = '[Load balancers]';
171 $tabhandler['vservice']['default'] = 'renderVirtualService';
172
173 $page['rspools']['title'] = 'RS pools';
174 $page['rspools']['parent'] = 'ipv4slb';
175 $tab['rspools']['default'] = 'View';
176 $tab['rspools']['edit'] = 'Edit';
177 $tabhandler['rspools']['default'] = 'renderRSPoolList';
178 $tabhandler['rspools']['edit'] = 'editRSPools';
179 $ophandler['rspools']['edit']['add'] = 'addRSPool';
180 $ophandler['rspools']['edit']['del'] = 'deleteRSPool';
181 $ophandler['rspools']['edit']['upd'] = 'updateRSPool';
182
183 $page['rspool']['title_handler'] = 'dynamic_title_rspool';
184 $page['rspool']['parent'] = 'rspools';
185 $page['rspool']['bypass'] = 'id';
186 $page['rspool']['bypass_type'] = 'uint';
187 $tab['rspool']['default'] = 'View';
188 $tab['rspool']['edit'] = '[Edit]';
189 $tab['rspool']['editlblist'] = 'Load Balancers';
190 $tab['rspool']['editrslist'] = 'RS list';
191 $tab['rspool']['rsinservice'] = 'RS in service';
192 $trigger['rspool']['rsinservice'] = 'trigger_poolrscount';
193 $tabhandler['rspool']['default'] = 'renderRSPool';
194 $tabhandler['rspool']['editrslist'] = 'renderRSPoolServerForm';
195 $tabhandler['rspool']['editlblist'] = 'renderRSPoolLBForm';
196 $tabhandler['rspool']['rsinservice'] = 'renderRSPoolRSInServiceForm';
197 $ophandler['rspool']['editrslist']['addRS'] = 'addRealServer';
198 $ophandler['rspool']['editrslist']['delRS'] = 'deleteRealServer';
199 $ophandler['rspool']['editrslist']['updRS'] = 'updateRealServer';
200 $ophandler['rspool']['editrslist']['addMany'] = 'addRealServers';
201 $ophandler['rspool']['editlblist']['addLB'] = 'addLoadBalancer';
202 $ophandler['rspool']['editlblist']['delLB'] = 'deleteLoadBalancer';
203 $ophandler['rspool']['editlblist']['updLB'] = 'updateLoadBalancer';
204 $ophandler['rspool']['rsinservice']['upd'] = 'updateRSInService';
205
206 $page['rservers']['title'] = 'Real servers';
207 $page['rservers']['parent'] = 'ipv4slb';
208 $page['rservers']['handler'] = 'renderRealServerList';
209
210 $page['lbs']['title'] = 'Load balancers';
211 $page['lbs']['parent'] = 'ipv4slb';
212 $page['lbs']['handler'] = 'renderLBList';
213
214 $page['search']['title_handler'] = 'dynamic_title_search';
215 $page['search']['handler'] = 'renderSearchResults';
216 $page['search']['parent'] = 'index';
217 $page['search']['bypass'] = 'q';
218
219 $page['config']['title'] = 'Configuration';
220 $page['config']['handler'] = 'renderConfigMainpage';
221 $page['config']['parent'] = 'index';
222
223 $page['accounts']['title'] = 'Accounts';
224 $page['accounts']['parent'] = 'config';
225 $tab['accounts']['default'] = 'View';
226 $tab['accounts']['edit'] = 'Change';
227 $tabhandler['accounts']['default'] = 'renderAccounts';
228 $tabhandler['accounts']['edit'] = 'renderAccountsEditForm';
229 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
230 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
231 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
232 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
233
234 $page['perms']['title'] = 'Permissions';
235 $page['perms']['parent'] = 'config';
236 $tab['perms']['default'] = 'View';
237 $tab['perms']['edit'] = 'Change';
238 $tabhandler['perms']['default'] = 'renderPermissions';
239 $tabhandler['perms']['edit'] = 'renderPermissionsEditForm';
240 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
241 $ophandler['perms']['edit']['grant'] = 'grantPermission';
242
243 $page['portmap']['title'] = 'Port compatibility map';
244 $page['portmap']['handler'] = 'handler_portmap';
245 $page['portmap']['parent'] = 'config';
246 $tab['portmap']['default'] = 'View';
247 $tab['portmap']['edit'] = 'Change';
248 $ophandler['portmap']['edit']['save'] = 'savePortMap';
249
250 $page['attrs']['title'] = 'Attributes';
251 $page['attrs']['parent'] = 'config';
252 $tab['attrs']['default'] = 'View';
253 $tab['attrs']['editattrs'] = 'Edit attributes';
254 $tab['attrs']['editmap'] = 'Edit map';
255 $tabhandler['attrs']['default'] = 'renderAttributes';
256 $tabhandler['attrs']['editattrs'] = 'renderEditAttributesForm';
257 $tabhandler['attrs']['editmap'] = 'renderEditAttrMapForm';
258 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
259 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
260 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
261 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
262 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
263
264 $page['dict']['title'] = 'Dictionary';
265 $page['dict']['parent'] = 'config';
266 $tab['dict']['default'] = 'View';
267 $tab['dict']['edit'] = 'Edit words';
268 $tab['dict']['chapters'] = 'Manage chapters';
269 $tabhandler['dict']['default'] = 'renderDictionary';
270 $tabhandler['dict']['edit'] = 'renderDictionaryEditor';
271 $tabhandler['dict']['chapters'] = 'renderChaptersEditor';
272 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
273 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
274 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
275 $ophandler['dict']['chapters']['del'] = 'delChapter';
276 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
277 $ophandler['dict']['chapters']['add'] = 'addChapter';
278
279 $page['ui']['title'] = 'User interface';
280 $page['ui']['parent'] = 'config';
281 $tab['ui']['default'] = 'View';
282 $tab['ui']['edit'] = 'Change';
283 $tab['ui']['reset'] = 'Reset';
284 $tabhandler['ui']['default'] = 'renderUIConfig';
285 $tabhandler['ui']['edit'] = 'renderUIConfigEditForm';
286 $tabhandler['ui']['reset'] = 'renderUIResetForm';
287 $ophandler['ui']['edit']['upd'] = 'updateUI';
288 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
289
290 $page['reports']['title'] = 'Reports';
291 $page['reports']['parent'] = 'index';
292 $tab['reports']['default'] = 'View';
293 $tabhandler['reports']['default'] = 'renderReportSummary';
294
295 $page['help']['title'] = 'Help';
296 $page['help']['handler'] = 'renderHelpTab';
297 $page['help']['parent'] = 'index';
298
299 // This function returns array if page numbers leading to the target page
300 // plus page number of target page itself. The first element is the target
301 // page number and the last element is the index page number.
302 function getPath ($targetno)
303 {
304 global $page;
305 $path = array();
306 // Recursion breaks at first parentless page.
307 if (!isset ($page[$targetno]['parent']))
308 $path = array ($targetno);
309 else
310 {
311 $path = getPath ($page[$targetno]['parent']);
312 $path[] = $targetno;
313 }
314 return $path;
315 }
316
317 function showPathAndSearch ($pageno)
318 {
319 global $root, $page;
320 // Path.
321 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
322 $path = getPath ($pageno);
323 foreach ($path as $no)
324 {
325 $title['params'] = array();
326 if (isset ($page[$no]['title']))
327 $title['name'] = $page[$no]['title'];
328 elseif (isset ($page[$no]['title_handler']))
329 $title = $page[$no]['title_handler']($no);
330 else
331 $title['name'] = '[N/A]';
332 echo ": <a href='${root}?page=${no}";
333 foreach ($title['params'] as $param_name => $param_value)
334 echo "&${param_name}=${param_value}";
335 echo "'>" . $title['name'] . "</a>";
336 }
337 echo "</td>";
338 // Search form.
339 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
340 echo "<form method=get action='${root}'><td>";
341 echo '<input type=hidden name=page value=search>';
342 // This input will be the first, if we don't add ports or addresses.
343 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
344 }
345
346 function getTitle ($pageno, $tabno)
347 {
348 global $page;
349 if (isset ($page[$pageno]['title']))
350 return $page[$pageno]['title'];
351 elseif (isset ($page[$pageno]['title_handler']))
352 {
353 $tmp = $page[$pageno]['title_handler']($pageno);
354 return $tmp['name'];
355 }
356 else
357 return getConfigVar ('enterprise');
358 }
359
360 function showTabs ($pageno, $tabno)
361 {
362 global $tab, $root, $page, $remote_username, $trigger;
363 if (!isset ($tab[$pageno]['default']))
364 return;
365 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
366 foreach ($tab[$pageno] as $tabidx => $tabtitle)
367 {
368 // Hide forbidden tabs.
369 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
370 continue;
371 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
372 if
373 (
374 isset ($trigger[$pageno][$tabidx]) &&
375 $trigger[$pageno][$tabidx] () != TRUE
376 )
377 continue;
378 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
379 echo " href='${root}?page=${pageno}&tab=${tabidx}";
380 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
381 {
382 $bpname = $page[$pageno]['bypass'];
383 $bpval = $_REQUEST[$bpname];
384 echo "&${bpname}=${bpval}";
385 }
386 echo "'>${tabtitle}</a></li>\n";
387 }
388 lookupHelpTopic ($pageno, $tabno);
389 echo "</ul></div></td>\n";
390 }
391
392 // This function returns pages, which are direct children of the requested
393 // page and are accessible by the current user.
394 function getDirectChildPages ($pageno)
395 {
396 global $page, $remote_username;
397 $children = array();
398 foreach ($page as $cpageno => $cpage)
399 if
400 (
401 isset ($cpage['parent']) and
402 $cpage['parent'] == $pageno and
403 authorized ($remote_username, $cpageno, 'default') == TRUE
404 )
405 $children[$cpageno] = $cpage;
406 return $children;
407 }
408
409 function getAllChildPages ($parent)
410 {
411 global $page;
412 // Array pointer is global, so if we don't create local copies of
413 // the global array, we can't advance any more after nested call
414 // of getAllChildPages returns.
415 $mypage = $page;
416 $mykids = array();
417 foreach ($mypage as $ctitle => $cpage)
418 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
419 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
420 return $mykids;
421 }
422
423 ?>