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