r1422 + check bypass arg type before calling the tab handler
[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
14 $page['index']['title'] = 'static_title';
15 $page['index']['handler'] = 'renderIndex';
16
17 $page['rackspace']['title'] = 'static_title';
18 $page['rackspace']['handler'] = 'handler_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
25 $page['objects']['title'] = 'static_title';
26 $page['objects']['handler'] = 'handler_objects';
27 $page['objects']['parent'] = 'index';
28 $tab['objects']['default'] = 'View';
29 $tab['objects']['newobj'] = 'Add an object';
30 $tab['objects']['newmulti'] = 'Add multiple objects';
31
32 $page['row']['title'] = 'dynamic_title_row';
33 $page['row']['handler'] = 'handler_row';
34 $page['row']['bypass'] = 'row_id';
35 $page['row']['parent'] = 'rackspace';
36 $tab['row']['default'] = 'View';
37 $tab['row']['newrack'] = 'Add new rack';
38
39 $page['rack']['title'] = 'dynamic_title_rack';
40 $page['rack']['handler'] = 'handler_rack';
41 $page['rack']['bypass'] = 'rack_id';
42 $page['rack']['parent'] = 'row';
43 $tab['rack']['default'] = 'View';
44 $tab['rack']['edit'] = 'Properties';
45 $tab['rack']['design'] = 'Design';
46 $tab['rack']['problems'] = 'Problems';
47 $helptab['rack']['design'] = 'rackspace';
48 $helptab['rack']['problems'] = 'rackspace';
49
50 $page['objgroup']['title'] = 'dynamic_title_objgroup';
51 $page['objgroup']['handler'] = 'handler_objgroup';
52 $page['objgroup']['bypass'] = 'group_id';
53 $page['objgroup']['parent'] = 'objects';
54
55 $page['object']['title'] = 'dynamic_title_object';
56 $page['object']['bypass'] = 'object_id';
57 $page['object']['bypass_type'] = 'uint';
58 $page['object']['parent'] = 'objgroup';
59 $tab['object']['default'] = 'View';
60 $tab['object']['edit'] = 'Properties';
61 $tab['object']['rackspace'] = 'Rackspace';
62 $tab['object']['ports'] = 'Ports';
63 $tab['object']['network'] = 'IPv4';
64 $tab['object']['portfwrd'] = 'NATv4';
65 $tab['object']['switchvlans'] = 'Live VLANs';
66 $tab['object']['snmpportfinder'] = 'SNMP port finder';
67 $tabhandler['object']['default'] = 'renderRackObject';
68 $tabhandler['object']['edit'] = 'renderEditObjectForm';
69 $tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
70 $tabhandler['object']['ports'] = 'renderPortsForObject';
71 $tabhandler['object']['network'] = 'renderNetworkForObject';
72 $tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
73 $tabhandler['object']['switchvlans'] = 'renderVLANMembership';
74 $tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
75 $helptab['object']['network'] = 'nets';
76 $helptab['object']['ports'] = 'ports';
77 $helptab['object']['portfwrd'] = 'nets';
78 $helptab['object']['rackspace'] = 'rackspace';
79 $trigger['object']['switchvlans'] = 'trigger_switchvlans';
80 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
81 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
82 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
83 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
84 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
85 $ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
86 $ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
87 $ophandler['object']['ports']['useup'] = 'useupPort';
88 $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
89 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
90 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
91 $ophandler['object']['edit']['del'] = 'resetAttrValue';
92 $ophandler['object']['edit']['upd'] = 'updateAttrValues';
93 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
94 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
95 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
96 $ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
97
98 $page['ipv4space']['title'] = 'static_title';
99 $page['ipv4space']['handler'] = 'handler_ipv4space';
100 $page['ipv4space']['parent'] = 'index';
101 $tab['ipv4space']['default'] = 'Browse';
102 $tab['ipv4space']['newrange'] = 'Manage ranges';
103 $helptab['ipv4space']['default'] = 'nets';
104 $helptab['ipv4space']['newrange'] = 'nets';
105 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
106 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
107
108 $page['iprange']['title'] = 'dynamic_title_iprange';
109 $page['iprange']['handler'] = 'handler_iprange';
110 $page['iprange']['parent'] = 'ipv4space';
111 $page['iprange']['bypass'] = 'id';
112 $tab['iprange']['default'] = 'Browse';
113 $tab['iprange']['properties'] = 'Properties';
114 $helptab['iprange']['default'] = 'nets';
115 $helptab['iprange']['properties'] = 'nets';
116 $ophandler['iprange']['properties']['editRange'] = 'editRange';
117
118 $page['ipaddress']['title'] = 'dynamic_title_ipaddress';
119 $page['ipaddress']['handler'] = 'handler_ipaddress';
120 $page['ipaddress']['parent'] = 'iprange';
121 $page['ipaddress']['bypass'] = 'ip';
122 $tab['ipaddress']['default'] = 'Browse';
123 $tab['ipaddress']['properties'] = 'Properties';
124 $tab['ipaddress']['assignment'] = 'Allocation';
125 $helptab['ipaddress']['default'] = 'nets';
126 $helptab['ipaddress']['properties'] = 'nets';
127 $helptab['ipaddress']['assignment'] = 'nets';
128 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
129 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
130 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
131 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
132
133 $page['search']['title'] = 'dynamic_title_search';
134 $page['search']['handler'] = 'handler_search';
135 $page['search']['parent'] = 'index';
136 $page['search']['bypass'] = 'q';
137
138 $page['config']['title'] = 'static_title';
139 $page['config']['handler'] = 'handler_config';
140 $page['config']['parent'] = 'index';
141
142 $page['accounts']['title'] = 'static_title';
143 $page['accounts']['handler'] = 'handler_accounts';
144 $page['accounts']['parent'] = 'config';
145 $tab['accounts']['default'] = 'View';
146 $tab['accounts']['edit'] = 'Change';
147 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
148 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
149 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
150 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
151
152 $page['perms']['title'] = 'static_title';
153 $page['perms']['handler'] = 'handler_perms';
154 $page['perms']['parent'] = 'config';
155 $tab['perms']['default'] = 'View';
156 $tab['perms']['edit'] = 'Change';
157 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
158 $ophandler['perms']['edit']['grant'] = 'grantPermission';
159
160 $page['portmap']['title'] = 'static_title';
161 $page['portmap']['handler'] = 'handler_portmap';
162 $page['portmap']['parent'] = 'config';
163 $tab['portmap']['default'] = 'View';
164 $tab['portmap']['edit'] = 'Change';
165 $ophandler['portmap']['edit']['save'] = 'savePortMap';
166
167 $page['attrs']['title'] = 'static_title';
168 $page['attrs']['handler'] = 'handler_attrs';
169 $page['attrs']['parent'] = 'config';
170 $tab['attrs']['default'] = 'View';
171 $tab['attrs']['editattrs'] = 'Edit attributes';
172 $tab['attrs']['editmap'] = 'Edit map';
173 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
174 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
175 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
176 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
177 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
178
179 $page['dict']['title'] = 'static_title';
180 $page['dict']['handler'] = 'handler_dict';
181 $page['dict']['parent'] = 'config';
182 $tab['dict']['default'] = 'View';
183 $tab['dict']['edit'] = 'Edit words';
184 $tab['dict']['chapters'] = 'Manage chapters';
185 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
186 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
187 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
188 $ophandler['dict']['chapters']['del'] = 'delChapter';
189 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
190 $ophandler['dict']['chapters']['add'] = 'addChapter';
191
192 $page['ui']['title'] = 'static_title';
193 $page['ui']['handler'] = 'handler_ui';
194 $page['ui']['parent'] = 'config';
195 $tab['ui']['default'] = 'View';
196 $tab['ui']['edit'] = 'Change';
197 $tab['ui']['reset'] = 'Reset';
198 $ophandler['ui']['edit']['upd'] = 'updateUI';
199 $ophandler['ui']['reset']['go'] = 'resetUIConfig';
200
201 $page['reports']['title'] = 'static_title';
202 $page['reports']['handler'] = 'handler_reports';
203 $page['reports']['parent'] = 'index';
204 $tab['reports']['default'] = 'View';
205
206 $page['help']['title'] = 'static_title';
207 $page['help']['handler'] = 'handler_help';
208 $page['help']['parent'] = 'index';
209 $tab['help']['default'] = 'Welcome';
210 $tab['help']['quickstart'] = 'Quick start';
211 $tab['help']['workflow'] = 'Workflow';
212 $tab['help']['rackspace'] = 'Rackspace';
213 $tab['help']['objects'] = 'Objects';
214 $tab['help']['nets'] = 'Networking';
215 $tab['help']['auth'] = '[ User accounts & permissions ]';
216 $tab['help']['dict'] = '[ Dictionary ]';
217 $tab['help']['ports'] = 'Ports and links';
218 $tab['help']['hacking'] = '[ Hacker\'s guide ]';
219
220 // This function returns array if page numbers leading to the target page
221 // plus page number of target page itself. The first element is the target
222 // page number and the last element is the index page number.
223 function getPath ($targetno)
224 {
225 global $page;
226 $path = array();
227 // Recursion breaks at first parentless page.
228 if (!isset ($page[$targetno]['parent']))
229 $path = array ($targetno);
230 else
231 {
232 $path = getPath ($page[$targetno]['parent']);
233 $path[] = $targetno;
234 }
235 return $path;
236 }
237
238 function showPathAndSearch ($pageno)
239 {
240 global $root, $page;
241 // Path.
242 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
243 if (isset ($page[$pageno]['title']))
244 {
245 $path = getPath ($pageno);
246 foreach ($path as $dummy => $no)
247 {
248 $title = $page[$no]['title']($no);
249 echo ": <a href='${root}?page=${no}";
250 foreach ($title['params'] as $param_name => $param_value)
251 echo "&${param_name}=${param_value}";
252 echo "'>" .$title['name'] . "</a>";
253 }
254 }
255 echo "</td>";
256 // Search form.
257 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
258 echo "<form method=get action='${root}'><td>";
259 echo '<input type=hidden name=page value=search>';
260 // This input will be the first, if we don't add ports or addresses.
261 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
262 }
263
264 function getTitle ($pageno, $tabno)
265 {
266 global $page;
267 if (!isset ($page[$pageno]['title']))
268 return getConfigVar ('enterprise');
269 $tmp = $page[$pageno]['title']($pageno);
270 return $tmp['name'];
271 }
272
273 function showTabs ($pageno, $tabno)
274 {
275 global $tab, $root, $page, $remote_username, $trigger;
276 if (!isset ($tab[$pageno]['default']))
277 return;
278 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
279 foreach ($tab[$pageno] as $tabidx => $tabtitle)
280 {
281 // Hide forbidden tabs.
282 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
283 continue;
284 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
285 if
286 (
287 isset ($trigger[$pageno][$tabidx]) &&
288 $trigger[$pageno][$tabidx] () != TRUE
289 )
290 continue;
291 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
292 echo " href='${root}?page=${pageno}&tab=${tabidx}";
293 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
294 {
295 $bpname = $page[$pageno]['bypass'];
296 $bpval = $_REQUEST[$bpname];
297 echo "&${bpname}=${bpval}";
298 }
299 echo "'>${tabtitle}</a></li>\n";
300 }
301 lookupHelpTopic ($pageno, $tabno);
302 echo "</ul></div></td>\n";
303 }
304
305 // This function returns pages, which are direct children of the requested
306 // page and are accessible by the current user.
307 function getDirectChildPages ($pageno)
308 {
309 global $page, $remote_username;
310 $children = array();
311 foreach ($page as $cpageno => $cpage)
312 if
313 (
314 isset ($cpage['parent']) and
315 $cpage['parent'] == $pageno and
316 authorized ($remote_username, $cpageno, 'default') == TRUE
317 )
318 $children[$cpageno] = $cpage;
319 return $children;
320 }
321
322 function getAllChildPages ($parent)
323 {
324 global $page;
325 // Array pointer is global, so if we don't create local copies of
326 // the global array, we can't advance any more after nested call
327 // of getAllChildPages returns.
328 $mypage = $page;
329 $mykids = array();
330 foreach ($mypage as $ctitle => $cpage)
331 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
332 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
333 return $mykids;
334 }
335
336 ?>