]>
Commit | Line | Data |
---|---|---|
4b4aec3a | 1 | #!/usr/bin/perl |
70df8302 MT |
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 | ############################################################################### | |
4b4aec3a CS |
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'} ); | |
6be4dd24 | 135 | &General::readhash("${swroot}/main/settings", \%settings); |
4b4aec3a CS |
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 | |
eea1d2d7 JIW |
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> | |
2ad1a8bc MT |
150 | <title>$title</title> |
151 | $extrahead | |
4b4aec3a CS |
152 | END |
153 | ; | |
154 | if ($settings{'FX'} ne 'off') { | |
155 | print <<END | |
156 | <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)" /> | |
157 | <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)" /> | |
158 | END | |
159 | ; | |
160 | } | |
161 | print <<END | |
162 | <link rel="shortcut icon" href="/favicon.ico" /> | |
163 | <link rel="stylesheet" type="text/css" href="/themes/maniac/include/style.css" /> | |
164 | <script language="javascript" type="text/javascript"> | |
2ad1a8bc MT |
165 | |
166 | function swapVisibility(id) { | |
167 | el = document.getElementById(id); | |
168 | if(el.style.display != 'block') { | |
169 | el.style.display = 'block' | |
170 | } | |
171 | else { | |
172 | el.style.display = 'none' | |
173 | } | |
4b4aec3a | 174 | } |
2ad1a8bc | 175 | </script> |
18322edf CS |
176 | END |
177 | ; | |
178 | if ($settings{'SPEED'} ne 'off') { | |
179 | print <<END | |
2ad1a8bc MT |
180 | <script type="text/javascript" src="/include/jquery-1.9.1.min.js"></script> |
181 | <script type="text/javascript"> | |
182 | var t_current; | |
183 | var t_last; | |
184 | var rxb_current; | |
185 | var rxb_last; | |
186 | var txb_current; | |
187 | var txb_last; | |
188 | function refreshInetInfo() { | |
189 | \$.ajax({ | |
190 | url: '/cgi-bin/speed.cgi', | |
191 | success: function(xml){ | |
192 | t_current = new Date(); | |
193 | var t_diff = t_current - t_last; | |
194 | t_last = t_current; | |
195 | ||
196 | rxb_current = \$("rxb",xml).text(); | |
197 | var rxb_diff = rxb_current - rxb_last; | |
198 | rxb_last = rxb_current; | |
199 | ||
200 | var rx_kbs = rxb_diff/t_diff; | |
201 | rx_kbs = Math.round(rx_kbs*10)/10; | |
202 | ||
203 | txb_current = \$("txb",xml).text(); | |
204 | var txb_diff = txb_current - txb_last; | |
205 | txb_last = txb_current; | |
206 | ||
207 | var tx_kbs = txb_diff/t_diff; | |
208 | tx_kbs = Math.round(tx_kbs*10)/10; | |
209 | ||
210 | \$("#rx_kbs").text(rx_kbs + ' kb/s'); | |
211 | \$("#tx_kbs").text(tx_kbs + ' kb/s'); | |
212 | } | |
213 | }); | |
214 | window.setTimeout("refreshInetInfo()", 3000); | |
215 | } | |
216 | \$(document).ready(function(){ | |
217 | refreshInetInfo(); | |
d0d063fe | 218 | }); |
2ad1a8bc MT |
219 | </script> |
220 | </head> | |
221 | <body> | |
18322edf CS |
222 | END |
223 | ; | |
224 | } | |
225 | else { | |
2ad1a8bc | 226 | print "</head>\n<body>";} |
18322edf | 227 | print <<END |
4b4aec3a | 228 | <!-- IPFIRE HEADER --> |
2ad1a8bc MT |
229 | |
230 | <div id="header"> | |
231 | ||
232 | <div id="header_inner" class="fixed"> | |
233 | ||
234 | <div id="logo"> | |
4b4aec3a CS |
235 | END |
236 | ; | |
2ad1a8bc MT |
237 | if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') { |
238 | print "<h1><span>$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}</span></h1><br />"; | |
239 | } else { | |
240 | print "<h1><span>-= IPFire =-</span></h1><br />"; | |
241 | } | |
242 | print <<END | |
243 | <h2>+ $h2 +</h2> | |
244 | </div> | |
4b4aec3a CS |
245 | |
246 | END | |
247 | ; | |
248 | &showmenu(); | |
249 | ||
250 | print <<END | |
251 | </div> | |
252 | </div> | |
253 | ||
254 | <div id="main"> | |
255 | <div id="main_inner" class="fixed"> | |
256 | <div id="primaryContent_2columns"> | |
257 | <div id="columnA_2columns"> | |
258 | END | |
259 | ; | |
260 | } | |
261 | ||
262 | sub openpagewithoutmenu { | |
263 | my $title = shift; | |
264 | my $boh = shift; | |
265 | my $extrahead = shift; | |
266 | ||
267 | @URI=split ('\?', $ENV{'REQUEST_URI'} ); | |
6be4dd24 | 268 | &General::readhash("${swroot}/main/settings", \%settings); |
4b4aec3a CS |
269 | &genmenu(); |
270 | ||
271 | my $h2 = gettitle($menu); | |
272 | ||
273 | $title = "-= IPFire - $title =-"; | |
274 | if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') { | |
275 | $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title"; | |
276 | } | |
277 | ||
278 | print <<END | |
eea1d2d7 JIW |
279 | <?xml version='1.0' encoding='UTF-8'?> |
280 | <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> | |
281 | <html xmlns='http://www.w3.org/1999/xhtml'> | |
282 | <head> | |
283 | <title>$title</title> | |
2ad1a8bc | 284 | $extrahead |
4b4aec3a CS |
285 | END |
286 | ; | |
287 | if ($settings{'FX'} ne 'off') { | |
288 | print <<END | |
289 | <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)" /> | |
290 | <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)" /> | |
291 | END | |
292 | ; | |
293 | } | |
294 | print <<END | |
295 | <link rel="shortcut icon" href="/favicon.ico" /> | |
296 | <link rel="stylesheet" type="text/css" href="/include/style.css" /> | |
297 | <script language="javascript" type="text/javascript"> | |
2ad1a8bc MT |
298 | |
299 | function swapVisibility(id) { | |
300 | el = document.getElementById(id); | |
301 | if(el.style.display != 'block') { | |
302 | el.style.display = 'block' | |
303 | } | |
304 | else { | |
305 | el.style.display = 'none' | |
306 | } | |
307 | } | |
4b4aec3a CS |
308 | </script> |
309 | ||
2ad1a8bc MT |
310 | </head> |
311 | <body> | |
4b4aec3a | 312 | <!-- IPFIRE HEADER --> |
2ad1a8bc MT |
313 | |
314 | <div id="header"> | |
315 | ||
316 | <div id="header_inner" class="fixed"> | |
317 | ||
318 | <div id="logo"> | |
319 | <h1><span>-= IPFire =-</span></h1> | |
320 | <h2>+ $h2 +</h2> | |
321 | </div> | |
4b4aec3a | 322 | </div> |
2ad1a8bc MT |
323 | </div> |
324 | ||
325 | <div id="main"> | |
326 | <div id="main_inner" class="fixed"> | |
327 | <div id="primaryContent_2columns"> | |
328 | <div id="columnA_2columns"> | |
4b4aec3a CS |
329 | END |
330 | ; | |
331 | } | |
332 | ||
333 | sub closepage () { | |
70b1b5d2 JIW |
334 | my $status = &connectionstatus(); |
335 | my $uptime = `/usr/bin/uptime|cut -d \" \" -f 4-`; | |
336 | $uptime =~ s/year(s|)/$Lang::tr{'year'}/; | |
337 | $uptime =~ s/month(s|)/$Lang::tr{'month'}/; | |
338 | $uptime =~ s/day(s|)/$Lang::tr{'day'}/; | |
339 | $uptime =~ s/user(s|)/$Lang::tr{'user'}/; | |
340 | $uptime =~ s/load average/$Lang::tr{'uptime load average'}/; | |
341 | ||
4b4aec3a CS |
342 | print <<END |
343 | </div> | |
2ad1a8bc MT |
344 | </div> |
345 | ||
346 | <div id="secondaryContent_2columns"> | |
347 | ||
348 | <div id="columnC_2columns"> | |
4b4aec3a CS |
349 | END |
350 | ; | |
351 | &showsubsection($menu); | |
352 | &showsubsubsection($menu); | |
353 | ||
354 | print <<END | |
355 | </div> | |
5cf2c339 MT |
356 | <br class="clear" /> |
357 | <div id="footer" class="fixed"> | |
67fd2a70 | 358 | <b>Status:</b> $status <b>Uptime:</b> $uptime |
18322edf CS |
359 | END |
360 | ; | |
361 | if ($settings{'SPEED'} ne 'off') { | |
362 | print <<END | |
2ad1a8bc MT |
363 | <br /> |
364 | <b>$Lang::tr{'bandwidth usage'}:</b> | |
d0d063fe | 365 | $Lang::tr{'incoming'}: <span id="rx_kbs"></span> $Lang::tr{'outgoing'}: <span id="tx_kbs"></span> |
2ad1a8bc | 366 | |
18322edf CS |
367 | END |
368 | ; | |
369 | } | |
370 | print <<END | |
2ad1a8bc MT |
371 | </div> |
372 | </div> | |
373 | </div> | |
4b4aec3a CS |
374 | </body> |
375 | </html> | |
376 | END | |
377 | ; | |
378 | } | |
379 | ||
380 | sub openbigbox | |
381 | { | |
382 | } | |
383 | ||
384 | sub closebigbox | |
385 | { | |
386 | } | |
387 | ||
388 | sub openbox | |
389 | { | |
390 | $width = $_[0]; | |
391 | $align = $_[1]; | |
392 | $caption = $_[2]; | |
393 | ||
394 | print <<END | |
395 | <!-- openbox --> | |
2ad1a8bc | 396 | <div class="post" align="$align"> |
4b4aec3a CS |
397 | END |
398 | ; | |
2ad1a8bc | 399 | |
4b4aec3a CS |
400 | if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; } |
401 | } | |
402 | ||
403 | sub closebox | |
404 | { | |
405 | print <<END | |
406 | </div> | |
407 | <br class="clear" /> | |
408 | <!-- closebox --> | |
409 | END | |
410 | ; | |
411 | } | |
412 | ||
413 | 1; |