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