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