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