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