]>
Commit | Line | Data |
---|---|---|
8e8fb1da LS |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | sub showmenu() { | |
23 | print <<EOF | |
24 | <div id="menu"> | |
25 | <ul> | |
26 | EOF | |
27 | ; | |
28 | foreach my $k1 ( sort keys %$menu ) { | |
29 | if (! $menu->{$k1}{'enabled'}) { | |
30 | next; | |
31 | } | |
32 | my $link = getlink($menu->{$k1}); | |
33 | if ($link eq '') { | |
34 | next; | |
35 | } | |
36 | if (! is_menu_visible($link)) { | |
37 | next; | |
38 | } | |
39 | if ($menu->{$k1}->{'selected'}) { | |
40 | print "<li><a href=\"$link\" class=\"active\">$menu->{$k1}{'caption'}</a></li>"; | |
41 | } else { | |
42 | print "<li><a href=\"$link\">$menu->{$k1}{'caption'}</a></li>"; | |
43 | } | |
44 | } | |
45 | print <<EOF | |
46 | </ul> | |
47 | </div> | |
48 | EOF | |
49 | ; | |
50 | } | |
51 | ||
52 | sub getselected($) { | |
53 | my $root = shift; | |
54 | if (!$root) { | |
55 | return 0; | |
56 | } | |
57 | ||
58 | foreach my $item (%$root) { | |
59 | if ($root->{$item}{'selected'}) { | |
60 | return $root->{$item}; | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | sub showsubsection($$) { | |
66 | my $root = shift; | |
67 | ||
68 | if (! $root) { | |
69 | return; | |
70 | } | |
71 | my $selected = getselected($root); | |
72 | if (! $selected) { | |
73 | return; | |
74 | } | |
75 | my $submenus = $selected->{'subMenu'}; | |
76 | if (! $submenus) { | |
77 | return; | |
78 | } | |
79 | ||
80 | print <<EOF | |
81 | <h4><span>Side</span>menu</h4> | |
82 | <ul class="links"> | |
83 | EOF | |
84 | ; | |
85 | foreach my $item (sort keys %$submenus) { | |
86 | my $hash = $submenus->{$item}; | |
87 | if (! $hash->{'enabled'}) { | |
88 | next; | |
89 | } | |
90 | my $link = getlink($hash); | |
91 | if ($link eq '') { | |
92 | next; | |
93 | } | |
94 | if (! is_menu_visible($link)) { | |
95 | next; | |
96 | } | |
97 | if ($hash->{'selected'}) { | |
98 | print '<li class="selected">'; | |
99 | } else { | |
100 | print '<li>'; | |
101 | } | |
102 | ||
103 | print "<a href=\"$link\">$hash->{'caption'}</a></li>"; | |
104 | } | |
105 | ||
106 | print <<EOF | |
107 | </ul> | |
108 | EOF | |
109 | ; | |
110 | } | |
111 | ||
112 | ||
113 | sub showsubsubsection($) { | |
114 | my $root = shift; | |
115 | if (!$root) { | |
116 | return; | |
117 | } | |
118 | my $selected = getselected($root); | |
119 | if (! $selected) { | |
120 | return | |
121 | } | |
122 | if (! $selected->{'subMenu'}) { | |
123 | return | |
124 | } | |
125 | ||
126 | showsubsection($selected->{'subMenu'}, 'menu-subtop'); | |
127 | } | |
128 | ||
129 | sub openpage { | |
130 | my $title = shift; | |
131 | my $boh = shift; | |
132 | my $extrahead = shift; | |
133 | ||
134 | @URI=split ('\?', $ENV{'REQUEST_URI'} ); | |
135 | &General::readhash("${swroot}/main/settings", \%settings); | |
136 | &genmenu(); | |
137 | ||
138 | my $h2 = gettitle($menu); | |
139 | ||
140 | $title = "-= IPFire - $title =-"; | |
141 | if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') { | |
142 | $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title"; | |
143 | } | |
144 | ||
145 | print <<END | |
146 | <?xml version='1.0' encoding='UTF-8'?> | |
147 | <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> | |
148 | <html xmlns='http://www.w3.org/1999/xhtml'> | |
149 | <head> | |
150 | <title>$title</title> | |
151 | $extrahead | |
8e8fb1da LS |
152 | <link rel="shortcut icon" href="/favicon.ico" /> |
153 | <link rel="stylesheet" type="text/css" href="/themes/darkdos/include/style.css" /> | |
154 | <script language="javascript" type="text/javascript"> | |
155 | ||
156 | function swapVisibility(id) { | |
157 | el = document.getElementById(id); | |
158 | if(el.style.display != 'block') { | |
159 | el.style.display = 'block' | |
160 | } | |
161 | else { | |
162 | el.style.display = 'none' | |
163 | } | |
164 | } | |
165 | </script> | |
166 | END | |
167 | ; | |
168 | if ($settings{'SPEED'} ne 'off') { | |
169 | print <<END | |
660f9728 | 170 | <script type="text/javascript" src="/include/jquery.js"></script> |
8e8fb1da LS |
171 | <script type="text/javascript"> |
172 | var t_current; | |
173 | var t_last; | |
174 | var rxb_current; | |
175 | var rxb_last; | |
176 | var txb_current; | |
177 | var txb_last; | |
178 | function refreshInetInfo() { | |
179 | \$.ajax({ | |
180 | url: '/cgi-bin/speed.cgi', | |
181 | success: function(xml){ | |
182 | t_current = new Date(); | |
183 | var t_diff = t_current - t_last; | |
184 | t_last = t_current; | |
185 | ||
186 | rxb_current = \$("rxb",xml).text(); | |
187 | var rxb_diff = rxb_current - rxb_last; | |
188 | rxb_last = rxb_current; | |
189 | ||
190 | var rx_kbs = rxb_diff/t_diff; | |
191 | rx_kbs = Math.round(rx_kbs*10)/10; | |
192 | ||
193 | txb_current = \$("txb",xml).text(); | |
194 | var txb_diff = txb_current - txb_last; | |
195 | txb_last = txb_current; | |
196 | ||
197 | var tx_kbs = txb_diff/t_diff; | |
198 | tx_kbs = Math.round(tx_kbs*10)/10; | |
199 | ||
200 | \$("#rx_kbs").text(rx_kbs + ' kb/s'); | |
201 | \$("#tx_kbs").text(tx_kbs + ' kb/s'); | |
202 | } | |
203 | }); | |
204 | window.setTimeout("refreshInetInfo()", 3000); | |
205 | } | |
206 | \$(document).ready(function(){ | |
207 | refreshInetInfo(); | |
208 | }); | |
209 | </script> | |
210 | </head> | |
211 | <body> | |
212 | END | |
213 | ; | |
214 | } | |
215 | else { | |
216 | print "</head>\n<body>";} | |
217 | print <<END | |
218 | <!-- IPFIRE HEADER --> | |
219 | ||
220 | <div id="header"> | |
221 | ||
222 | <div id="header_inner" class="fixed"> | |
223 | ||
224 | <div id="logo"> | |
225 | END | |
226 | ; | |
227 | if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') { | |
228 | print "<h1><span>$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}</span></h1><br />"; | |
229 | } else { | |
725396af | 230 | print "<h1><span><a href='https://www.ipfire.org' style='text-decoration: none;'>-= IPFire =-</a></span></h1><br />"; |
8e8fb1da LS |
231 | } |
232 | print <<END | |
233 | <h2>+ $h2 +</h2> | |
234 | </div> | |
235 | ||
236 | END | |
237 | ; | |
238 | &showmenu(); | |
239 | ||
240 | print <<END | |
241 | </div> | |
242 | </div> | |
243 | ||
244 | <div id="main"> | |
245 | <div id="main_inner" class="fixed"> | |
246 | <div id="primaryContent_2columns"> | |
247 | <div id="columnA_2columns"> | |
248 | END | |
249 | ; | |
250 | } | |
251 | ||
252 | sub openpagewithoutmenu { | |
253 | my $title = shift; | |
254 | my $boh = shift; | |
255 | my $extrahead = shift; | |
256 | ||
257 | @URI=split ('\?', $ENV{'REQUEST_URI'} ); | |
258 | &General::readhash("${swroot}/main/settings", \%settings); | |
259 | &genmenu(); | |
260 | ||
261 | my $h2 = gettitle($menu); | |
262 | ||
263 | $title = "-= IPFire - $title =-"; | |
264 | if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') { | |
265 | $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title"; | |
266 | } | |
267 | ||
268 | print <<END | |
269 | <?xml version='1.0' encoding='UTF-8'?> | |
270 | <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> | |
271 | <html xmlns='http://www.w3.org/1999/xhtml'> | |
272 | <head> | |
273 | <title>$title</title> | |
274 | $extrahead | |
275 | END | |
276 | ; | |
277 | if ($settings{'FX'} ne 'off') { | |
278 | print <<END | |
279 | <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)" /> | |
280 | <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)" /> | |
281 | END | |
282 | ; | |
283 | } | |
284 | print <<END | |
285 | <link rel="shortcut icon" href="/favicon.ico" /> | |
286 | <link rel="stylesheet" type="text/css" href="/include/style.css" /> | |
287 | <script language="javascript" type="text/javascript"> | |
288 | ||
289 | function swapVisibility(id) { | |
290 | el = document.getElementById(id); | |
291 | if(el.style.display != 'block') { | |
292 | el.style.display = 'block' | |
293 | } | |
294 | else { | |
295 | el.style.display = 'none' | |
296 | } | |
297 | } | |
298 | </script> | |
299 | ||
300 | </head> | |
301 | <body> | |
302 | <!-- IPFIRE HEADER --> | |
303 | ||
304 | <div id="header"> | |
305 | ||
306 | <div id="header_inner" class="fixed"> | |
307 | ||
308 | <div id="logo"> | |
309 | <h1><span>-= IPFire =-</span></h1> | |
310 | <h2>+ $h2 +</h2> | |
311 | </div> | |
312 | </div> | |
313 | </div> | |
314 | ||
315 | <div id="main"> | |
316 | <div id="main_inner" class="fixed"> | |
317 | <div id="primaryContent_2columns"> | |
318 | <div id="columnA_2columns"> | |
319 | END | |
320 | ; | |
321 | } | |
322 | ||
323 | sub closepage () { | |
324 | my $status = &connectionstatus(); | |
325 | my $uptime = `/usr/bin/uptime|cut -d \" \" -f 4-`; | |
326 | $uptime =~ s/year(s|)/$Lang::tr{'year'}/; | |
327 | $uptime =~ s/month(s|)/$Lang::tr{'month'}/; | |
328 | $uptime =~ s/day(s|)/$Lang::tr{'day'}/; | |
329 | $uptime =~ s/user(s|)/$Lang::tr{'user'}/; | |
330 | $uptime =~ s/load average/$Lang::tr{'uptime load average'}/; | |
331 | ||
332 | print <<END | |
333 | </div> | |
334 | </div> | |
335 | ||
336 | <div id="secondaryContent_2columns"> | |
337 | ||
338 | <div id="columnC_2columns"> | |
339 | END | |
340 | ; | |
341 | &showsubsection($menu); | |
342 | &showsubsubsection($menu); | |
343 | ||
344 | print <<END | |
345 | </div> | |
346 | </div> | |
347 | <br class="clear" /> | |
348 | <div id="footer" class="fixed"> | |
349 | <b>Status:</b> $status <b>Uptime:</b> $uptime | |
350 | END | |
351 | ; | |
352 | if ($settings{'SPEED'} ne 'off') { | |
353 | print <<END | |
354 | <br /> | |
355 | <b>$Lang::tr{'bandwidth usage'}:</b> | |
356 | $Lang::tr{'incoming'}: <span id="rx_kbs"></span> $Lang::tr{'outgoing'}: <span id="tx_kbs"></span> | |
357 | ||
358 | END | |
359 | ; | |
360 | } | |
361 | print <<END | |
362 | </div> | |
363 | </div> | |
364 | </div> | |
365 | </body> | |
366 | </html> | |
367 | END | |
368 | ; | |
369 | } | |
370 | ||
371 | sub openbigbox | |
372 | { | |
373 | } | |
374 | ||
375 | sub closebigbox | |
376 | { | |
377 | } | |
378 | ||
379 | sub openbox | |
380 | { | |
381 | $width = $_[0]; | |
382 | $align = $_[1]; | |
383 | $caption = $_[2]; | |
384 | ||
385 | print <<END | |
386 | <!-- openbox --> | |
387 | <div class="post" align="$align"> | |
388 | END | |
389 | ; | |
390 | ||
391 | if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; } | |
392 | } | |
393 | ||
394 | sub closebox | |
395 | { | |
396 | print <<END | |
397 | </div> | |
398 | <br class="clear" /> | |
399 | <!-- closebox --> | |
400 | END | |
401 | ; | |
402 | } | |
403 | ||
404 | 1; |