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