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