r1465 + trying to resolve ticket:97 here
[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']['switchvlans'] = 'trigger_switchvlans';
93 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
94 $trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
95 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
96 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
97 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
98 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
99 $ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
100 $ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
101 $ophandler['object']['ports']['useup'] = 'useupPort';
102 $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
103 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
104 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
105 $ophandler['object']['edit']['del'] = 'resetAttrValue';
106 $ophandler['object']['edit']['upd'] = 'updateAttrValues';
107 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
108 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
109 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
110 $ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
111
112 $page['ipv4space']['title'] = 'IPv4 space';
113 $page['ipv4space']['parent'] = 'index';
114 $tab['ipv4space']['default'] = 'Browse';
115 $tab['ipv4space']['newrange'] = 'Subnets';
116 $tab['ipv4space']['editrstab'] = '[SLB RSs]';
117 $tab['ipv4space']['editlbconf'] = '[SLB LBs]';
118 $tab['ipv4space']['editvstab'] = '[SLB VSs]';
119 $helptab['ipv4space']['default'] = 'nets';
120 $helptab['ipv4space']['newrange'] = 'nets';
121 $tabhandler['ipv4space']['default'] = 'renderAddressspace';
122 $tabhandler['ipv4space']['newrange'] = 'renderAddNewRange';
123 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
124 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
125
126 $page['iprange']['title_handler'] = 'dynamic_title_iprange';
127 $page['iprange']['parent'] = 'ipv4space';
128 $page['iprange']['bypass'] = 'id';
129 $tab['iprange']['default'] = 'Browse';
130 $tab['iprange']['properties'] = 'Properties';
131 $helptab['iprange']['default'] = 'nets';
132 $helptab['iprange']['properties'] = 'nets';
133 $tabhandler['iprange']['default'] = 'renderIPRange';
134 $tabhandler['iprange']['properties'] = 'renderIPRangeProperties';
135 $ophandler['iprange']['properties']['editRange'] = 'editRange';
136
137 $page['ipaddress']['title_handler'] = 'dynamic_title_ipaddress';
138 $page['ipaddress']['parent'] = 'iprange';
139 $page['ipaddress']['bypass'] = 'ip';
140 $tab['ipaddress']['default'] = 'Browse';
141 $tab['ipaddress']['properties'] = 'Properties';
142 $tab['ipaddress']['assignment'] = 'Allocation';
143 $helptab['ipaddress']['default'] = 'nets';
144 $helptab['ipaddress']['properties'] = 'nets';
145 $helptab['ipaddress']['assignment'] = 'nets';
146 $tabhandler['ipaddress']['default'] = 'renderIPAddress';
147 $tabhandler['ipaddress']['properties'] = 'renderIPAddressProperties';
148 $tabhandler['ipaddress']['assignment'] = 'renderIPAddressAssignment';
149 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
150 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
151 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
152 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
153
154 $page['vservice']['title_handler'] = 'dynamic_title_vservice';
155 $page['vservice']['parent'] = 'ipv4space';
156 $page['vservice']['bypass'] = 'id';
157 $page['vservice']['bypass_type'] = 'uint';
158 $tab['vservice']['default'] = 'View';
159 $tab['vservice']['configs'] = '[Configuration]';
160 $tab['vservice']['rspool'] = '[Real servers]';
161 $tabhandler['vservice']['default'] = 'renderVirtualService';
162
163 $page['search']['title_handler'] = 'dynamic_title_search';
164 $page['search']['handler'] = 'handler_search';
165 $page['search']['parent'] = 'index';
166 $page['search']['bypass'] = 'q';
167
168 $page['config']['title'] = 'Configuration';
169 $page['config']['handler'] = 'handler_config';
170 $page['config']['parent'] = 'index';
171
172 $page['accounts']['title'] = 'Accounts';
173 $page['accounts']['parent'] = 'config';
174 $tab['accounts']['default'] = 'View';
175 $tab['accounts']['edit'] = 'Change';
176 $tabhandler['accounts']['default'] = 'renderAccounts';
177 $tabhandler['accounts']['edit'] = 'renderAccountsEditForm';
178 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
179 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
180 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
181 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
182
183 $page['perms']['title'] = 'Permissions';
184 $page['perms']['parent'] = 'config';
185 $tab['perms']['default'] = 'View';
186 $tab['perms']['edit'] = 'Change';
187 $tabhandler['perms']['default'] = 'renderPermissions';
188 $tabhandler['perms']['edit'] = 'renderPermissionsEditForm';
189 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
190 $ophandler['perms']['edit']['grant'] = 'grantPermission';
191
192 $page['portmap']['title'] = 'Port compatibility map';
193 $page['portmap']['handler'] = 'handler_portmap';
194 $page['portmap']['parent'] = 'config';
195 $tab['portmap']['default'] = 'View';
196 $tab['portmap']['edit'] = 'Change';
197 $ophandler['portmap']['edit']['save'] = 'savePortMap';
198
199 $page['attrs']['title'] = 'Attributes';
200 $page['attrs']['parent'] = 'config';
201 $tab['attrs']['default'] = 'View';
202 $tab['attrs']['editattrs'] = 'Edit attributes';
203 $tab['attrs']['editmap'] = 'Edit map';
204 $tabhandler['attrs']['default'] = 'renderAttributes';
205 $tabhandler['attrs']['editattrs'] = 'renderEditAttributesForm';
206 $tabhandler['attrs']['editmap'] = 'renderEditAttrMapForm';
207 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
208 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
209 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
210 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
211 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
212
213 $page['dict']['title'] = 'Dictionary';
214 $page['dict']['parent'] = 'config';
215 $tab['dict']['default'] = 'View';
216 $tab['dict']['edit'] = 'Edit words';
217 $tab['dict']['chapters'] = 'Manage chapters';
218 $tabhandler['dict']['default'] = 'renderDictionary';
219 $tabhandler['dict']['edit'] = 'renderDictionaryEditor';
220 $tabhandler['dict']['chapters'] = 'renderChaptersEditor';
221 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
222 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
223 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
224 $ophandler['dict']['chapters']['del'] = 'delChapter';
225 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
226 $ophandler['dict']['chapters']['add'] = 'addChapter';
227
228 $page['ui']['title'] = 'User interface';
229 $page['ui']['parent'] = 'config';
230 $tab['ui']['default'] = 'View';
231 $tab['ui']['edit'] = 'Change';
232 $tab['ui']['reset'] = 'Reset';
233 $tabhandler['ui']['default'] = 'renderUIConfig';
234 $tabhandler['ui']['edit'] = 'renderUIConfigEditForm';
235 $tabhandler['ui']['reset'] = 'renderUIResetForm';
236 $ophandler['ui']['edit']['upd'] = 'updateUI';
237 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
238
239 $page['reports']['title'] = 'Reports';
240 $page['reports']['parent'] = 'index';
241 $tab['reports']['default'] = 'View';
242 $tabhandler['reports']['default'] = 'renderReportSummary';
243
244 $page['help']['title'] = 'Help';
245 $page['help']['handler'] = 'renderHelpTab';
246 $page['help']['parent'] = 'index';
247 $tab['help']['default'] = 'Welcome';
248 $tab['help']['quickstart'] = 'Quick start';
249 $tab['help']['workflow'] = 'Workflow';
250 $tab['help']['rackspace'] = 'Rackspace';
251 $tab['help']['objects'] = 'Objects';
252 $tab['help']['nets'] = 'Networking';
253 $tab['help']['auth'] = '[ User accounts & permissions ]';
254 $tab['help']['dict'] = '[ Dictionary ]';
255 $tab['help']['ports'] = 'Ports and links';
256 $tab['help']['hacking'] = '[ Hacker\'s guide ]';
257
258 // This function returns array if page numbers leading to the target page
259 // plus page number of target page itself. The first element is the target
260 // page number and the last element is the index page number.
261 function getPath ($targetno)
262 {
263 global $page;
264 $path = array();
265 // Recursion breaks at first parentless page.
266 if (!isset ($page[$targetno]['parent']))
267 $path = array ($targetno);
268 else
269 {
270 $path = getPath ($page[$targetno]['parent']);
271 $path[] = $targetno;
272 }
273 return $path;
274 }
275
276 function showPathAndSearch ($pageno)
277 {
278 global $root, $page;
279 // Path.
280 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
281 $path = getPath ($pageno);
282 foreach ($path as $no)
283 {
284 $title['params'] = array();
285 if (isset ($page[$no]['title']))
286 $title['name'] = $page[$no]['title'];
287 elseif (isset ($page[$no]['title_handler']))
288 $title = $page[$no]['title_handler']($no);
289 else
290 $title['name'] = '[N/A]';
291 echo ": <a href='${root}?page=${no}";
292 foreach ($title['params'] as $param_name => $param_value)
293 echo "&${param_name}=${param_value}";
294 echo "'>" . $title['name'] . "</a>";
295 }
296 echo "</td>";
297 // Search form.
298 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
299 echo "<form method=get action='${root}'><td>";
300 echo '<input type=hidden name=page value=search>';
301 // This input will be the first, if we don't add ports or addresses.
302 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
303 }
304
305 function getTitle ($pageno, $tabno)
306 {
307 global $page;
308 if (isset ($page[$pageno]['title']))
309 return $page[$pageno]['title'];
310 elseif (isset ($page[$pageno]['title_handler']))
311 {
312 $tmp = $page[$pageno]['title_handler']($pageno);
313 return $tmp['name'];
314 }
315 else
316 return getConfigVar ('enterprise');
317 }
318
319 function showTabs ($pageno, $tabno)
320 {
321 global $tab, $root, $page, $remote_username, $trigger;
322 if (!isset ($tab[$pageno]['default']))
323 return;
324 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
325 foreach ($tab[$pageno] as $tabidx => $tabtitle)
326 {
327 // Hide forbidden tabs.
328 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
329 continue;
330 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
331 if
332 (
333 isset ($trigger[$pageno][$tabidx]) &&
334 $trigger[$pageno][$tabidx] () != TRUE
335 )
336 continue;
337 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
338 echo " href='${root}?page=${pageno}&tab=${tabidx}";
339 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
340 {
341 $bpname = $page[$pageno]['bypass'];
342 $bpval = $_REQUEST[$bpname];
343 echo "&${bpname}=${bpval}";
344 }
345 echo "'>${tabtitle}</a></li>\n";
346 }
347 lookupHelpTopic ($pageno, $tabno);
348 echo "</ul></div></td>\n";
349 }
350
351 // This function returns pages, which are direct children of the requested
352 // page and are accessible by the current user.
353 function getDirectChildPages ($pageno)
354 {
355 global $page, $remote_username;
356 $children = array();
357 foreach ($page as $cpageno => $cpage)
358 if
359 (
360 isset ($cpage['parent']) and
361 $cpage['parent'] == $pageno and
362 authorized ($remote_username, $cpageno, 'default') == TRUE
363 )
364 $children[$cpageno] = $cpage;
365 return $children;
366 }
367
368 function getAllChildPages ($parent)
369 {
370 global $page;
371 // Array pointer is global, so if we don't create local copies of
372 // the global array, we can't advance any more after nested call
373 // of getAllChildPages returns.
374 $mypage = $page;
375 $mykids = array();
376 foreach ($mypage as $ctitle => $cpage)
377 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
378 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
379 return $mykids;
380 }
381
382 ?>