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