903525728718b7e4d0995e752f7a1147236272f2
[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 $helptab['rack']['design'] = 'rackspace';
59 $helptab['rack']['problems'] = 'rackspace';
60
61 $page['objgroup']['title_handler'] = 'dynamic_title_objgroup';
62 $page['objgroup']['handler'] = 'handler_objgroup';
63 $page['objgroup']['bypass'] = 'group_id';
64 $page['objgroup']['parent'] = 'objects';
65
66 $page['object']['title_handler'] = 'dynamic_title_object';
67 $page['object']['bypass'] = 'object_id';
68 $page['object']['bypass_type'] = 'uint';
69 $page['object']['parent'] = 'objgroup';
70 $tab['object']['default'] = 'View';
71 $tab['object']['edit'] = 'Properties';
72 $tab['object']['rackspace'] = 'Rackspace';
73 $tab['object']['ports'] = 'Ports';
74 $tab['object']['network'] = 'IPv4';
75 $tab['object']['portfwrd'] = 'NATv4';
76 $tab['object']['switchvlans'] = 'Live VLANs';
77 $tab['object']['snmpportfinder'] = 'SNMP port finder';
78 $tab['object']['lvsconfig'] = 'LVS configuration';
79 $tabhandler['object']['default'] = 'renderRackObject';
80 $tabhandler['object']['edit'] = 'renderEditObjectForm';
81 $tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
82 $tabhandler['object']['ports'] = 'renderPortsForObject';
83 $tabhandler['object']['network'] = 'renderNetworkForObject';
84 $tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
85 $tabhandler['object']['switchvlans'] = 'renderVLANMembership';
86 $tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
87 $tabhandler['object']['lvsconfig'] = 'renderLVSConfig';
88 $helptab['object']['network'] = 'nets';
89 $helptab['object']['ports'] = 'ports';
90 $helptab['object']['portfwrd'] = 'nets';
91 $helptab['object']['rackspace'] = 'rackspace';
92 $trigger['object']['network'] = 'trigger_ipv4';
93 $trigger['object']['portfwrd'] = 'trigger_natv4';
94 $trigger['object']['switchvlans'] = 'trigger_switchvlans';
95 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
96 $trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
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'] = 'Subnets';
117 $helptab['ipv4space']['default'] = 'nets';
118 $helptab['ipv4space']['newrange'] = 'nets';
119 $tabhandler['ipv4space']['default'] = 'renderAddressspace';
120 $tabhandler['ipv4space']['newrange'] = 'renderAddNewRange';
121 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
122 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
123
124 $page['iprange']['title_handler'] = 'dynamic_title_iprange';
125 $page['iprange']['parent'] = 'ipv4space';
126 $page['iprange']['bypass'] = 'id';
127 $tab['iprange']['default'] = 'Browse';
128 $tab['iprange']['properties'] = 'Properties';
129 $helptab['iprange']['default'] = 'nets';
130 $helptab['iprange']['properties'] = 'nets';
131 $tabhandler['iprange']['default'] = 'renderIPRange';
132 $tabhandler['iprange']['properties'] = 'renderIPRangeProperties';
133 $ophandler['iprange']['properties']['editRange'] = 'editRange';
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 $helptab['ipaddress']['default'] = 'nets';
142 $helptab['ipaddress']['properties'] = 'nets';
143 $helptab['ipaddress']['assignment'] = 'nets';
144 $tabhandler['ipaddress']['default'] = 'renderIPAddress';
145 $tabhandler['ipaddress']['properties'] = 'renderIPAddressProperties';
146 $tabhandler['ipaddress']['assignment'] = 'renderIPAddressAssignment';
147 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
148 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
149 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
150 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
151
152 $page['vservices']['title'] = 'Virtual services';
153 $page['vservices']['parent'] = 'ipv4space';
154 $tab['vservices']['default'] = 'View';
155 $tab['vservices']['edit'] = 'Edit';
156 $tabhandler['vservices']['default'] = 'renderVSList';
157 $tabhandler['vservices']['edit'] = 'renderVSListEditForm';
158 $ophandler['vservices']['edit']['add'] = 'addVService';
159 $ophandler['vservices']['edit']['del'] = 'deleteVService';
160 $ophandler['vservices']['edit']['upd'] = 'updateVService';
161
162 $page['vservice']['title_handler'] = 'dynamic_title_vservice';
163 $page['vservice']['parent'] = 'vservices';
164 $page['vservice']['bypass'] = 'id';
165 $page['vservice']['bypass_type'] = 'uint';
166 $page['vservice']['handler'] = 'renderVirtualService';
167
168 $page['rspools']['title'] = 'RS pools';
169 $page['rspools']['parent'] = 'ipv4space';
170 $tab['rspools']['default'] = 'View';
171 $tab['rspools']['edit'] = 'Edit';
172 $tabhandler['rspools']['default'] = 'renderRSPoolList';
173 $tabhandler['rspools']['edit'] = 'editRSPools';
174 $ophandler['rspools']['edit']['add'] = 'addRSPool';
175 $ophandler['rspools']['edit']['del'] = 'deleteRSPool';
176 $ophandler['rspools']['edit']['upd'] = 'updateRSPool';
177
178 $page['rspool']['title_handler'] = 'dynamic_title_rspool';
179 $page['rspool']['parent'] = 'rspools';
180 $page['rspool']['bypass'] = 'id';
181 $page['rspool']['bypass_type'] = 'uint';
182 $tab['rspool']['default'] = 'View';
183 $tab['rspool']['editlblist'] = 'Load Balancers';
184 $tab['rspool']['editrslist'] = 'RS list';
185 $tab['rspool']['rsinservice'] = 'RS in service';
186 $tabhandler['rspool']['default'] = 'renderRSPool';
187 $tabhandler['rspool']['editrslist'] = 'renderRSPoolServerForm';
188 $tabhandler['rspool']['editlblist'] = 'renderRSPoolLBForm';
189 $tabhandler['rspool']['rsinservice'] = 'renderRSPoolRSInServiceForm';
190 $ophandler['rspool']['editrslist']['addRS'] = 'addRealServer';
191 $ophandler['rspool']['editrslist']['delRS'] = 'deleteRealServer';
192 $ophandler['rspool']['editrslist']['updRS'] = 'updateRealServer';
193 $ophandler['rspool']['editrslist']['addMany'] = 'addRealServers';
194 $ophandler['rspool']['editlblist']['addLB'] = 'addLoadBalancer';
195 $ophandler['rspool']['editlblist']['delLB'] = 'deleteLoadBalancer';
196 $ophandler['rspool']['editlblist']['updLB'] = 'updateLoadBalancer';
197 $ophandler['rspool']['rsinservice']['upd'] = 'updateRSInService';
198
199 $page['rservers']['title'] = 'Real servers';
200 $page['rservers']['parent'] = 'ipv4space';
201 $page['rservers']['handler'] = 'renderRealServerList';
202
203 $page['lbs']['title'] = 'Load balancers';
204 $page['lbs']['parent'] = 'ipv4space';
205 $page['lbs']['handler'] = 'renderLBList';
206
207 $page['search']['title_handler'] = 'dynamic_title_search';
208 $page['search']['handler'] = 'handler_search';
209 $page['search']['parent'] = 'index';
210 $page['search']['bypass'] = 'q';
211
212 $page['config']['title'] = 'Configuration';
213 $page['config']['handler'] = 'handler_config';
214 $page['config']['parent'] = 'index';
215
216 $page['accounts']['title'] = 'Accounts';
217 $page['accounts']['parent'] = 'config';
218 $tab['accounts']['default'] = 'View';
219 $tab['accounts']['edit'] = 'Change';
220 $tabhandler['accounts']['default'] = 'renderAccounts';
221 $tabhandler['accounts']['edit'] = 'renderAccountsEditForm';
222 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
223 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
224 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
225 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
226
227 $page['perms']['title'] = 'Permissions';
228 $page['perms']['parent'] = 'config';
229 $tab['perms']['default'] = 'View';
230 $tab['perms']['edit'] = 'Change';
231 $tabhandler['perms']['default'] = 'renderPermissions';
232 $tabhandler['perms']['edit'] = 'renderPermissionsEditForm';
233 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
234 $ophandler['perms']['edit']['grant'] = 'grantPermission';
235
236 $page['portmap']['title'] = 'Port compatibility map';
237 $page['portmap']['handler'] = 'handler_portmap';
238 $page['portmap']['parent'] = 'config';
239 $tab['portmap']['default'] = 'View';
240 $tab['portmap']['edit'] = 'Change';
241 $ophandler['portmap']['edit']['save'] = 'savePortMap';
242
243 $page['attrs']['title'] = 'Attributes';
244 $page['attrs']['parent'] = 'config';
245 $tab['attrs']['default'] = 'View';
246 $tab['attrs']['editattrs'] = 'Edit attributes';
247 $tab['attrs']['editmap'] = 'Edit map';
248 $tabhandler['attrs']['default'] = 'renderAttributes';
249 $tabhandler['attrs']['editattrs'] = 'renderEditAttributesForm';
250 $tabhandler['attrs']['editmap'] = 'renderEditAttrMapForm';
251 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
252 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
253 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
254 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
255 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
256
257 $page['dict']['title'] = 'Dictionary';
258 $page['dict']['parent'] = 'config';
259 $tab['dict']['default'] = 'View';
260 $tab['dict']['edit'] = 'Edit words';
261 $tab['dict']['chapters'] = 'Manage chapters';
262 $tabhandler['dict']['default'] = 'renderDictionary';
263 $tabhandler['dict']['edit'] = 'renderDictionaryEditor';
264 $tabhandler['dict']['chapters'] = 'renderChaptersEditor';
265 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
266 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
267 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
268 $ophandler['dict']['chapters']['del'] = 'delChapter';
269 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
270 $ophandler['dict']['chapters']['add'] = 'addChapter';
271
272 $page['ui']['title'] = 'User interface';
273 $page['ui']['parent'] = 'config';
274 $tab['ui']['default'] = 'View';
275 $tab['ui']['edit'] = 'Change';
276 $tab['ui']['reset'] = 'Reset';
277 $tabhandler['ui']['default'] = 'renderUIConfig';
278 $tabhandler['ui']['edit'] = 'renderUIConfigEditForm';
279 $tabhandler['ui']['reset'] = 'renderUIResetForm';
280 $ophandler['ui']['edit']['upd'] = 'updateUI';
281 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
282
283 $page['reports']['title'] = 'Reports';
284 $page['reports']['parent'] = 'index';
285 $tab['reports']['default'] = 'View';
286 $tabhandler['reports']['default'] = 'renderReportSummary';
287
288 $page['help']['title'] = 'Help';
289 $page['help']['handler'] = 'renderHelpTab';
290 $page['help']['parent'] = 'index';
291 $tab['help']['default'] = 'Welcome';
292 $tab['help']['quickstart'] = 'Quick start';
293 $tab['help']['workflow'] = 'Workflow';
294 $tab['help']['rackspace'] = 'Rackspace';
295 $tab['help']['objects'] = 'Objects';
296 $tab['help']['nets'] = 'Networking';
297 $tab['help']['auth'] = '[ User accounts & permissions ]';
298 $tab['help']['dict'] = '[ Dictionary ]';
299 $tab['help']['ports'] = 'Ports and links';
300 $tab['help']['hacking'] = '[ Hacker\'s guide ]';
301
302 // This function returns array if page numbers leading to the target page
303 // plus page number of target page itself. The first element is the target
304 // page number and the last element is the index page number.
305 function getPath ($targetno)
306 {
307 global $page;
308 $path = array();
309 // Recursion breaks at first parentless page.
310 if (!isset ($page[$targetno]['parent']))
311 $path = array ($targetno);
312 else
313 {
314 $path = getPath ($page[$targetno]['parent']);
315 $path[] = $targetno;
316 }
317 return $path;
318 }
319
320 function showPathAndSearch ($pageno)
321 {
322 global $root, $page;
323 // Path.
324 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
325 $path = getPath ($pageno);
326 foreach ($path as $no)
327 {
328 $title['params'] = array();
329 if (isset ($page[$no]['title']))
330 $title['name'] = $page[$no]['title'];
331 elseif (isset ($page[$no]['title_handler']))
332 $title = $page[$no]['title_handler']($no);
333 else
334 $title['name'] = '[N/A]';
335 echo ": <a href='${root}?page=${no}";
336 foreach ($title['params'] as $param_name => $param_value)
337 echo "&${param_name}=${param_value}";
338 echo "'>" . $title['name'] . "</a>";
339 }
340 echo "</td>";
341 // Search form.
342 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
343 echo "<form method=get action='${root}'><td>";
344 echo '<input type=hidden name=page value=search>';
345 // This input will be the first, if we don't add ports or addresses.
346 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
347 }
348
349 function getTitle ($pageno, $tabno)
350 {
351 global $page;
352 if (isset ($page[$pageno]['title']))
353 return $page[$pageno]['title'];
354 elseif (isset ($page[$pageno]['title_handler']))
355 {
356 $tmp = $page[$pageno]['title_handler']($pageno);
357 return $tmp['name'];
358 }
359 else
360 return getConfigVar ('enterprise');
361 }
362
363 function showTabs ($pageno, $tabno)
364 {
365 global $tab, $root, $page, $remote_username, $trigger;
366 if (!isset ($tab[$pageno]['default']))
367 return;
368 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
369 foreach ($tab[$pageno] as $tabidx => $tabtitle)
370 {
371 // Hide forbidden tabs.
372 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
373 continue;
374 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
375 if
376 (
377 isset ($trigger[$pageno][$tabidx]) &&
378 $trigger[$pageno][$tabidx] () != TRUE
379 )
380 continue;
381 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
382 echo " href='${root}?page=${pageno}&tab=${tabidx}";
383 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
384 {
385 $bpname = $page[$pageno]['bypass'];
386 $bpval = $_REQUEST[$bpname];
387 echo "&${bpname}=${bpval}";
388 }
389 echo "'>${tabtitle}</a></li>\n";
390 }
391 lookupHelpTopic ($pageno, $tabno);
392 echo "</ul></div></td>\n";
393 }
394
395 // This function returns pages, which are direct children of the requested
396 // page and are accessible by the current user.
397 function getDirectChildPages ($pageno)
398 {
399 global $page, $remote_username;
400 $children = array();
401 foreach ($page as $cpageno => $cpage)
402 if
403 (
404 isset ($cpage['parent']) and
405 $cpage['parent'] == $pageno and
406 authorized ($remote_username, $cpageno, 'default') == TRUE
407 )
408 $children[$cpageno] = $cpage;
409 return $children;
410 }
411
412 function getAllChildPages ($parent)
413 {
414 global $page;
415 // Array pointer is global, so if we don't create local copies of
416 // the global array, we can't advance any more after nested call
417 // of getAllChildPages returns.
418 $mypage = $page;
419 $mykids = array();
420 foreach ($mypage as $ctitle => $cpage)
421 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
422 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
423 return $mykids;
424 }
425
426 ?>