]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - html/html/themes/ipfire/include/functions.pl
Fix spacing in new uptime bar.
[people/teissler/ipfire-2.x.git] / html / html / themes / ipfire / include / functions.pl
index c83897e0e075a7c60f30756e386778a74d1fa7e5..086ff183e4ca2b6a76650aff23995e0ac8d2e9e8 100644 (file)
@@ -1,31 +1,50 @@
 #!/usr/bin/perl
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 sub showmenu() {
     print <<EOF
-               <div id="menu">
-                       <ul>
+                <div id="menu">
+                        <ul>
 EOF
 ;
     foreach my $k1 ( sort keys %$menu ) {
-       if (! $menu->{$k1}{'enabled'}) {
-           next;
-       }
-       my $link = getlink($menu->{$k1});
-       if ($link eq '') {
-           next;
-       }
-       if (! is_menu_visible($link)) {
-           next;
-       }
-       if ($menu->{$k1}->{'selected'}) {
-           print "<li><a href=\"$link\" class=\"active\">$menu->{$k1}{'caption'}</a></li>";
-       } else {
-           print "<li><a href=\"$link\">$menu->{$k1}{'caption'}</a></li>";
-       }
+        if (! $menu->{$k1}{'enabled'}) {
+            next;
+        }
+        my $link = getlink($menu->{$k1});
+        if ($link eq '') {
+            next;
+        }
+        if (! is_menu_visible($link)) {
+            next;
+        }
+        if ($menu->{$k1}->{'selected'}) {
+            print "<li><a href=\"$link\" class=\"active\">$menu->{$k1}{'caption'}</a></li>";
+        } else {
+            print "<li><a href=\"$link\">$menu->{$k1}{'caption'}</a></li>";
+        }
     }
     print <<EOF
-                       </ul>
-               </div>
+                        </ul>
+                </div>
 EOF
 ;    
 }
@@ -33,13 +52,13 @@ EOF
 sub getselected($) {
     my $root = shift;
     if (!$root) {
-       return 0;
+        return 0;
     }
 
     foreach my $item (%$root) {
-       if ($root->{$item}{'selected'}) {
-           return $root->{$item};
-       }
+        if ($root->{$item}{'selected'}) {
+            return $root->{$item};
+        }
     }
 }
 
@@ -47,45 +66,45 @@ sub showsubsection($$) {
     my $root = shift;
 
     if (! $root) {
-       return;
+        return;
     }
     my $selected = getselected($root);
     if (! $selected) {
-       return;
+        return;
     }
     my $submenus = $selected->{'subMenu'};
     if (! $submenus) {
-       return;
+        return;
     }
 
     print <<EOF
-       <h4><span>Side</span>menu</h4>
-       <ul class="links">
+        <h4><span>Side</span>menu</h4>
+        <ul class="links">
 EOF
 ;
     foreach my $item (sort keys %$submenus) {
-       my $hash = $submenus->{$item};
-       if (! $hash->{'enabled'}) {
-           next;
-       }
-       my $link = getlink($hash);
-       if ($link eq '') {
-           next;
-       }
-       if (! is_menu_visible($link)) {
-           next;
-       }
-       if ($hash->{'selected'}) {
-           print '<li class="selected">';
-       } else {
-           print '<li>';
-       }
+        my $hash = $submenus->{$item};
+        if (! $hash->{'enabled'}) {
+            next;
+        }
+        my $link = getlink($hash);
+        if ($link eq '') {
+            next;
+        }
+        if (! is_menu_visible($link)) {
+            next;
+        }
+        if ($hash->{'selected'}) {
+            print '<li class="selected">';
+        } else {
+            print '<li>';
+        }
 
-       print "<a href=\"$link\">$hash->{'caption'}</a></li>";
+        print "<a href=\"$link\">$hash->{'caption'}</a></li>";
     }
 
     print <<EOF
-       </ul>
+        </ul>
 EOF
 ;
 }
@@ -94,14 +113,14 @@ EOF
 sub showsubsubsection($) {
     my $root = shift;
     if (!$root) {
-       return;
+        return;
     }
     my $selected = getselected($root);
     if (! $selected) {
-       return
+        return
     }
     if (! $selected->{'subMenu'}) {
-       return
+        return
     }
 
     showsubsection($selected->{'subMenu'}, 'menu-subtop');
@@ -124,14 +143,12 @@ sub openpage {
     }
 
     print <<END
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html>
-  <head>
-  <title>$title</title>
-
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+               <title>$title</title>
     $extrahead
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 END
 ;
     if ($settings{'FX'} ne 'off') {
@@ -144,96 +161,92 @@ END
     print <<END
     <link rel="shortcut icon" href="/favicon.ico" />
     <link rel="stylesheet" type="text/css" href="/themes/ipfire/include/style.css" />
+    $extrahead
     <script language="javascript" type="text/javascript">
       
         function swapVisibility(id) {
             el = document.getElementById(id);
-           if(el.style.display != 'block') {
-               el.style.display = 'block'
-           }
-           else {
-               el.style.display = 'none'
-           }
+            if(el.style.display != 'block') {
+                el.style.display = 'block'
+            }
+            else {
+                el.style.display = 'none'
+            }
         }
     </script>
-               <script type="text/javascript" language="javascript">
-                
-                   var http_request = false;
-                
-                   function LoadInetInfo(url) {
-                
-                       http_request = false;
-                
-                       if (window.XMLHttpRequest) { // Mozilla, Safari,...
-                           http_request = new XMLHttpRequest();
-                           if (http_request.overrideMimeType) {
-                               http_request.overrideMimeType('text/xml');
-                               // zu dieser Zeile siehe weiter unten
-                           }
-                       } else if (window.ActiveXObject) { // IE
-                           try {
-                               http_request = new ActiveXObject("Msxml2.XMLHTTP");
-                           } catch (e) {
-                               try {
-                                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
-                               } catch (e) {}
-                           }
-                       }
-                
-                       if (!http_request) {
-                           alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
-                           return false;
-                       }
-                       http_request.onreadystatechange = DisplayInetInfo;
-                       http_request.open('GET', url, true);
-                       http_request.send(null);
-                
-                   }
-                
-                   function DisplayInetInfo() {
-                       if (http_request.readyState == 4) {
-                            var xmldoc = http_request.responseXML;
-                            var root1_node = xmldoc.getElementsByTagName('rx_kbs').item(0);
-                            var root2_node = xmldoc.getElementsByTagName('tx_kbs').item(0);
-                            var root3_node = xmldoc.getElementsByTagName('rxb').item(0);
-                            var root4_node = xmldoc.getElementsByTagName('txb').item(0);
-               
-                            document.forms['speed'].txkb.value  = root1_node.firstChild.data;
-                            document.forms['speed'].rxkb.value  = root2_node.firstChild.data;
-               
-                                       // document.getElementsByTagName("input")[0].style.color = "#00FF00";
-                                       url    = "/cgi/bin/speed.cgi?rxb_last=" + root3_node.firstChild.data + "&txb_last=" + root4_node.firstChild.data;
-               
-                             window.setTimeout("LoadInetInfo(url)", 3000);
-                       }
-                
-                   }
-               </script>
+END
+;
+if ($settings{'SPEED'} ne 'off') {
+print <<END
+    <script type="text/javascript" src="/include/jquery-1.9.1.min.js"></script>
+    <script type="text/javascript">
+        var t_current;
+        var t_last;
+        var rxb_current;
+        var rxb_last;
+        var txb_current;
+        var txb_last;
+       function refreshInetInfo() {
+               \$.ajax({
+                       url: '/cgi-bin/speed.cgi',
+                        success: function(xml){
+                        t_current = new Date();
+                        var t_diff = t_current - t_last;
+                        t_last = t_current;
+
+                        rxb_current = \$("rxb",xml).text();
+                        var rxb_diff = rxb_current - rxb_last;
+                        rxb_last = rxb_current;
+
+                        var rx_kbs = rxb_diff/t_diff;
+                        rx_kbs = Math.round(rx_kbs*10)/10;
+
+                        txb_current = \$("txb",xml).text();
+                        var txb_diff = txb_current - txb_last;
+                        txb_last = txb_current;
+
+                        var tx_kbs = txb_diff/t_diff;
+                        tx_kbs = Math.round(tx_kbs*10)/10;
+
+                        \$("#rx_kbs").text(rx_kbs + ' kb/s');
+                        \$("#tx_kbs").text(tx_kbs + ' kb/s');
+                        }
+               });
+                window.setTimeout("refreshInetInfo()", 3000);
+       }
+       \$(document).ready(function(){
+               refreshInetInfo();
+       });
+    </script>
   </head>
-  <body onLoad="LoadInetInfo('/cgi-bin/speed.cgi')">
+  <body>
+END
+;
+}
+else {
+       print "</head><body>";}
+print <<END
 <!-- IPFIRE HEADER -->
 
 <div id="header">
-
        <div id="header_inner" class="fixed">
-
                <div id="logo">
 END
 ;
-    if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
-        print "<h1><span>$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}</span></h1><br />"; 
-    } else {
-                               print "<h1><span>IPFire</span></h1><br />";
-               }
-               print <<END
+if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
+    print "<h1><span>$settings{'HOSTNAME'}.$settings{'DOMAINNAME'}</span></h1><br />"; 
+} 
+else {
+    print "<h1><span>IPFire</span></h1><br />";
+}
+print <<END
                        <h2>$h2</h2>
                </div>
-
 END
 ;
-       &showmenu();
+&showmenu();
 
-print <<END    
+print <<END     
        </div>
 </div>
 
@@ -262,14 +275,11 @@ sub openpagewithoutmenu {
     }
 
     print <<END
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html>
-  <head>
-  <title>$title</title>
-
-    $extrahead
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+<?xml version='1.0' encoding='UTF-8'?>
+<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+<head>
+       <title>$title</title>
 END
 ;
     if ($settings{'FX'} ne 'off') {
@@ -282,73 +292,77 @@ END
     print <<END
     <link rel="shortcut icon" href="/favicon.ico" />
     <link rel="stylesheet" type="text/css" href="/include/style.css" />
+    $extrahead
     <script language="javascript" type="text/javascript">
       
         function swapVisibility(id) {
             el = document.getElementById(id);
-           if(el.style.display != 'block') {
-               el.style.display = 'block'
-           }
-           else {
-               el.style.display = 'none'
-           }
+            if(el.style.display != 'block') {
+                el.style.display = 'block'
+            }
+            else {
+                el.style.display = 'none'
+            }
         }
     </script>
-
   </head>
   <body>
 <!-- IPFIRE HEADER -->
-
-<div id="header">
-
-       <div id="header_inner" class="fixed">
-
-               <div id="logo">
-                       <h1><span>IPFire</span></h1>
-                       <h2>$h2</h2>
-               </div>  
+       <div id="header">
+               <div id="header_inner" class="fixed">
+                       <div id="logo">
+                               <h1><span>IPFire</span></h1>
+                               <h2>$h2</h2>
+                       </div>  
+               </div>
        </div>
-</div>
-
-<div id="main">
-       <div id="main_inner" class="fixed">
-               <div id="primaryContent_2columns">
-                       <div id="columnA_2columns">
+       <div id="main">
+               <div id="main_inner" class="fixed">
+                       <div id="primaryContent_2columns">
+                               <div id="columnA_2columns">
 END
 ;
 }
 
 sub closepage () {
-    my $status = &connectionstatus();
-    $uptime = `/usr/bin/uptime`;
-       
+       my $status = &connectionstatus();
+       my $uptime = `/usr/bin/uptime|cut -d \" \" -f 4-`;
+       $uptime =~ s/year(s|)/$Lang::tr{'year'}/;
+       $uptime =~ s/month(s|)/$Lang::tr{'month'}/;
+       $uptime =~ s/day(s|)/$Lang::tr{'day'}/;
+       $uptime =~ s/user(s|)/$Lang::tr{'user'}/;
+       $uptime =~ s/load average/$Lang::tr{'uptime load average'}/;     
+                               
     print <<END
+                               </div>
                        </div>
-               </div>
-
-               <div id="secondaryContent_2columns">
-               
-                       <div id="columnC_2columns">
+                       <div id="secondaryContent_2columns">
+                               <div id="columnC_2columns">
 END
 ;
     &showsubsection($menu);
     &showsubsubsection($menu);
 
-       print <<END                     
+        print <<END                     
+                               </div>
+            </div>
+            <br class="clear" />    
+                       <div id="footer" class="fixed">
+                               <b>Status:</b> $status <b>Uptime:</b> $uptime
+END
+;
+if ($settings{'SPEED'} ne 'off') {
+print <<END                        
+                               <br />
+                               <b>$Lang::tr{'bandwidth usage'}:</b>
+                               $Lang::tr{'incoming'}: <span id="rx_kbs"></span>&nbsp;$Lang::tr{'outgoing'}: <span id="tx_kbs"></span>
+END
+;
+}
+print <<END
                        </div>
                </div>
-
-               <br class="clear" />    
-               <div id="footer" class="fixed">
-                       <b>Status:</b> $status <b>Uptime:</b>$uptime <b>Version:</b> $FIREBUILD
-                       <br />
-                       <form name='speed'>
-                               <b>$Lang::tr{'bandwidth usage'}:</b> $Lang::tr{'incoming'}:<input type="text" name="rxkb" size="16" value="0,00 kb/s" style="border: 1px solid #FFFFFF; padding: 0; background-color: #FFFFFF" />
-                               $Lang::tr{'outgoing'}: <input type="text" name="txkb" size="16" value="0,00 kb/s" style="border: 1px solid #FFFFFF; padding: 0; background-color: #FFFFFF" />
-                       </form>
-               </div>
        </div>
-</div>
 </body>
 </html>
 END
@@ -369,21 +383,21 @@ sub openbox
        $align = $_[1];
        $caption = $_[2];
 
-       print <<END
+    print <<END
 <!-- openbox -->
-       <div class="post" align="$align">
+    <div class="post" style="text-align:$align">
 END
 ;
 
-       if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }
+    if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }
 }
 
 sub closebox
 {
-       print <<END
-       </div>
-       <br class="clear" />
-       <!-- closebox -->
+    print <<END
+    </div>
+    <br class="clear" />
+    <!-- closebox -->
 END
 ;
 }