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