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