]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - config/cfgroot/header.pl
Großes Update:
[ipfire-2.x.git] / config / cfgroot / header.pl
index 353e8c07b3acceae008d144051280d3d6525d66a..3fd3a523e444acee3b22e17a30dae06e021c54db 100644 (file)
-# SmoothWall CGIs\r
-#\r
-# This code is distributed under the terms of the GPL\r
-#\r
-# (c) The SmoothWall Team\r
-# Copyright (C) 2002 Alex Hudson - getcgihash() rewrite\r
-# Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()\r
-# Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions\r
-# Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()\r
-# Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()\r
-#\r
-# $Id: header.pl,v 1.34.2.39 2004/11/26 15:51:27 alanh Exp $\r
-#\r
-package Header;\r
-\r
-use CGI();\r
-use Socket;\r
-use Time::Local;\r
-\r
-$|=1; # line buffering\r
-\r
-sub get_version() {\r
-    my $read_ver = `cat /etc/ipfire-release`;\r
-    if ($read_ver =~ /^$/) {\r
-       return "IPFire (unknown version)";\r
-    }\r
-    return $read_ver;\r
-}\r
-\r
-$Header::version = get_version();\r
-$Header::revision = 'final';\r
-$Header::swroot = '/var/ipfire';\r
-$Header::pagecolour = '#ffffff';\r
-#$Header::tablecolour = '#a0a0a0';\r
-$Header::tablecolour = '#FFFFFF';\r
-$Header::bigboxcolour = '#F6F4F4';\r
-$Header::boxcolour = '#EAE9EE';\r
-$Header::bordercolour = '#000000';\r
-$Header::table1colour = '#E0E0E0';\r
-$Header::table2colour = '#F0F0F0';\r
-$Header::colourred = '#993333';\r
-$Header::colourorange = '#FF9933';\r
-$Header::colouryellow = '#FFFF00';\r
-$Header::colourgreen = '#339933';\r
-$Header::colourblue = '#333399';\r
-$Header::colourfw = '#000000';\r
-$Header::colourvpn = '#990099';\r
-$Header::colourerr = '#FF0000';\r
-$Header::viewsize = 150;\r
-$Header::errormessage = '';\r
-my %menuhash = ();\r
-my $menu = \%menuhash;\r
-%settings = ();\r
-%ethsettings = ();\r
-@URI = ();\r
-$Header::supported=0;\r
-\r
-### Make sure this is an SSL request\r
-if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {\r
-    print "Status: 302 Moved\r\n";\r
-    print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";\r
-    exit 0;\r
-}\r
-\r
-### Initialize environment\r
-&readhash("${swroot}/main/settings", \%settings);\r
-&readhash("${swroot}/ethernet/settings", \%ethsettings);\r
-$language = $settings{'LANGUAGE'};\r
-$hostname = $settings{'HOSTNAME'};\r
-$hostnameintitle = 0;\r
-\r
-### Initialize language\r
-if ($language =~ /^(\w+)$/) {$language = $1;}\r
-\r
-### Read English Files\r
-if ( -d "/var/ipfire/langs/en/" ) {\r
-    opendir(DIR, "/var/ipfire/langs/en/");\r
-    @names = readdir(DIR) or die "Cannot Read Directory: $!\n";\r
-    foreach $name(@names) {\r
-        next if ($name eq ".");\r
-        next if ($name eq "..");\r
-        next if (!($name =~ /\.pl$/));\r
-        require "${swroot}/langs/en/${name}";\r
-    };\r
-};\r
-\r
-\r
-### Enable Language Files\r
-if ( -d "/var/ipfire/langs/${language}/" ) {\r
-    opendir(DIR, "/var/ipfire/langs/${language}/");\r
-    @names = readdir(DIR) or die "Cannot Read Directory: $!\n";\r
-    foreach $name(@names) {\r
-        next if ($name eq ".");\r
-        next if ($name eq "..");\r
-        next if (!($name =~ /\.pl$/));\r
-        require "${swroot}/langs/${language}/${name}";\r
-    };\r
-};\r
-\r
-\r
-require "${swroot}/langs/en.pl";\r
-require "${swroot}/langs/${language}.pl";\r
-\r
-sub orange_used () {\r
-    if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {\r
-       return 1;\r
-    }\r
-    return 0;\r
-}\r
-\r
-sub blue_used () {\r
-    if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {\r
-       return 1;\r
-    }\r
-    return 0;\r
-}\r
-\r
-sub is_modem {\r
-    if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {\r
-       return 1;\r
-    }\r
-    return 0;\r
-}\r
-\r
-### Initialize menu\r
-sub genmenu {\r
-    my %subsystemhash = ();\r
-    my $subsystem = \%subsystemhash;\r
-\r
-    $subsystem->{'01.home'} = {\r
-                             'caption' => $tr{'alt home'},\r
-                             'uri' => '/cgi-bin/index.cgi',\r
-                             'title' => "$tr{'alt home'}",\r
-                             'enabled' => 1,\r
-                             };\r
-    $subsystem->{'02.netwizard'} = {\r
-                                  'caption' => $tr{'network configuration'},\r
-                                  'uri' => '/cgi-bin/netwizard.cgi',\r
-                                  'title' => "$tr{'network configuration'}",\r
-                                  'enabled' => 1,\r
-                                  };\r
-    $subsystem->{'03.updates'} = {\r
-                                'caption' => $tr{'updates'},\r
-                                'uri' => '/cgi-bin/updates.cgi',\r
-                                'title' => "$tr{'updates'}",\r
-                                'enabled' => 0,\r
-                                };\r
-    $subsystem->{'04.passwords'} = {\r
-                                  'caption' => $tr{'sspasswords'},\r
-                                  'uri' => '/cgi-bin/changepw.cgi',\r
-                                  'title' => "$tr{'sspasswords'}",\r
-                                  'enabled' => 1,\r
-                                  };\r
-    $subsystem->{'05.ssh'} = {\r
-                            'caption' => $tr{'ssh access'},\r
-                            'uri' => '/cgi-bin/remote.cgi',\r
-                            'title' => "$tr{'ssh access'}",\r
-                            'enabled' => 1,\r
-                            };\r
-    $subsystem->{'06.gui'} = {\r
-                             'caption' => $tr{'gui settings'},\r
-                             'uri' => '/cgi-bin/gui.cgi',\r
-                             'title' => "$tr{'gui settings'}",\r
-                             'enabled' => 1,\r
-                             };\r
-    $subsystem->{'07.backup'} = {\r
-                               'caption' => $tr{'backup'},\r
-                               'uri' => '/cgi-bin/backup.cgi',\r
-                               'title' => "$tr{'backup'} / $tr{'restore'}",\r
-                               'enabled' => 1,\r
-                               };\r
-    $subsystem->{'08.shutdown'} = {\r
-                                 'caption' => $tr{'shutdown'},\r
-                                 'uri' => '/cgi-bin/shutdown.cgi',\r
-                                 'title' => "$tr{'shutdown'} / $tr{'reboot'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-    $subsystem->{'09.credits'} = {\r
-                                 'caption' => $tr{'credits'},\r
-                                 'uri' => '/cgi-bin/credits.cgi',\r
-                                 'title' => "$tr{'credits'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-\r
-    my %substatushash = ();\r
-    my $substatus = \%substatushash;\r
-    $substatus->{'01.systemstatus'} = {\r
-                                'caption' => $tr{'sssystem status'},\r
-                                'uri' => '/cgi-bin/status.cgi',\r
-                                'title' => "$tr{'system status information'}",\r
-                                'enabled' => 1,\r
-                                };\r
-    $substatus->{'02.networkstatus'} = {\r
-                                 'caption' => $tr{'ssnetwork status'},\r
-                                 'uri' => '/cgi-bin/netstatus.cgi',\r
-                                 'title' => "$tr{'network status information'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-    $substatus->{'03.systemgraphs'} = {\r
-                                      'caption' => $tr{'system graphs'},\r
-                                      'uri' => '/cgi-bin/graphs.cgi',\r
-                                      'novars' => 1,\r
-                                      'title' => "$tr{'system graphs'}",\r
-                                      'enabled' => 1,\r
-                                      };\r
-    $substatus->{'04.trafficgraphs'} = {\r
-                                       'caption' => $tr{'sstraffic graphs'},\r
-                                       'uri' => '/cgi-bin/graphs.cgi',\r
-                                       'vars' => 'graph=network',\r
-                                       'title' => "$tr{'network traffic graphs'}",\r
-                                       'enabled' => 1,\r
-                                       };\r
-    $substatus->{'05.proxygraphs'} = {\r
-                                     'caption' => $tr{'ssproxy graphs'},\r
-                                     'uri' => '/cgi-bin/proxygraphs.cgi',\r
-                                     'title' => "$tr{'proxy access graphs'}",\r
-                                     'enabled' => 1,\r
-                                     };\r
-    $substatus->{'06.connections'} = {\r
-                                     'caption' => $tr{'connections'},\r
-                                     'uri' => '/cgi-bin/connections.cgi',\r
-                                     'title' => "$tr{'connections'}",\r
-                                     'enabled' => 1,\r
-                                     };\r
-    $substatus->{'99.iptfilters'} = {\r
-                                     'caption' => $tr{'iptfilters iptable rules'},\r
-                                     'uri' => '/cgi-bin/iptfilters.cgi',\r
-                                     'title' => "$tr{'iptfilters iptable rules'}",\r
-                                     'enabled' => 1,\r
-                                     };\r
-\r
-    my %subnetworkhash = ();\r
-    my $subnetwork = \%subnetworkhash;\r
-\r
-    $subnetwork->{'01.dialup'} = {\r
-                                 'caption' => $tr{'alt dialup'},\r
-                                 'uri' => '/cgi-bin/pppsetup.cgi',\r
-                                 'title' => "$tr{'dialup settings'}",\r
-                                 'enabled' => 0,\r
-                                 };\r
-    $subnetwork->{'02.hosts'} = {\r
-                                'caption' => $tr{'edit hosts'},\r
-                                'uri' => '/cgi-bin/hosts.cgi',\r
-                                'title' => "$tr{'host configuration'}",\r
-                                'enabled' => 1,\r
-                                };\r
-    $subnetwork->{'03.upload'} = {\r
-                                 'caption' => $tr{'upload'},\r
-                                 'uri' => '/cgi-bin/upload.cgi',\r
-                                 'title' => "$tr{'firmware upload'}",\r
-                                 'enabled' => 0,\r
-                                 };\r
-    $subnetwork->{'04.aliases'} = {\r
-                                 'caption' => $tr{'aliases'},\r
-                                 'uri' => '/cgi-bin/aliases.cgi',\r
-                                 'title' => "$tr{'external aliases configuration'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-\r
-\r
-    my %subserviceshash = ();\r
-    my $subservices = \%subserviceshash;\r
-\r
-    $subservices->{'01.dhcp'} = {\r
-                                'caption' => $tr{'dhcp server'},\r
-                                'uri' => '/cgi-bin/dhcp.cgi',\r
-                                'title' => "$tr{'dhcp configuration'}",\r
-                                'enabled' => 1,\r
-                                };\r
-    $subservices->{'02.dyndns'} = {\r
-                                  'caption' => $tr{'dynamic dns'},\r
-                                  'uri' => '/cgi-bin/ddns.cgi',\r
-                                  'title' => "$tr{'dynamic dns client'}",\r
-                                  'enabled' => 1,\r
-                                };\r
-    $subservices->{'03.time'} = {\r
-                                  'caption' => $tr{'time server'},\r
-                                  'uri' => '/cgi-bin/time.cgi',\r
-                                  'title' => "$tr{'time server'}",\r
-                                  'enabled' => 1,\r
-                                };\r
-    $subservices->{'04.shaping'} = {\r
-                                   'caption' => $tr{'traffic shaping'},\r
-                                   'uri' => '/cgi-bin/shaping.cgi',\r
-                                   'title' => "$tr{'traffic shaping settings'}",\r
-                                   'enabled' => 1,\r
-                                   };\r
-    $subservices->{'05.ids'} = {'caption' => $tr{'intrusion detection'},\r
-                               'enabled' => 1,\r
-                               'uri' => '/cgi-bin/ids.cgi',\r
-                               'title' => "$tr{'intrusion detection system'} (Snort)",\r
-                               };\r
-\r
-\r
-    my %subfirewallhash = ();\r
-    my $subfirewall = \%subfirewallhash;\r
-\r
-    \r
-    $subfirewall->{'01.dnat'} = {\r
-                                'caption' => $tr{'ssport forwarding'},\r
-                                'uri' => '/cgi-bin/portfw.cgi',\r
-                                'title' => "$tr{'port forwarding configuration'}",\r
-                                'enabled' => 1,\r
-                                };\r
-    $subfirewall->{'02.xtaccess'} = {\r
-                                'caption' => $tr{'external access'},\r
-                                'uri' => '/cgi-bin/xtaccess.cgi',\r
-                                'title' => "$tr{'external access configuration'}",\r
-                                'enabled' => 1,\r
-                                };\r
-    $subfirewall->{'03.dmz'} = {\r
-                               'caption' => $tr{'ssdmz pinholes'},\r
-                               'uri' => '/cgi-bin/dmzholes.cgi',\r
-                               'title' => "$tr{'dmz pinhole configuration'}",\r
-                               'enabled' => 1,\r
-                                };\r
-    $subfirewall->{'04.outgoing'} = {\r
-                                    'caption' => $tr{'outgoing firewall'},\r
-                                    'uri' => '/cgi-bin/outgoingfw.cgi',\r
-                                    'title' => "$tr{'outgoing firewall'}",\r
-                                    'enabled' => 1,\r
-                                    };\r
-    \r
-\r
-\r
-    my %subhttphash = ();\r
-    my $subhttp = \%subhttphash;\r
-    $subhttp->{'01.proxy'} = {\r
-                             'caption' => $tr{'proxy'},\r
-                             'uri' => '/cgi-bin/advproxy.cgi',\r
-                             'title' => "HTTP: $tr{'web proxy configuration'}",\r
-                             'enabled' => 1,\r
-                             };\r
-    $subhttp->{'02.contentfilter'} = {\r
-                                     'caption' => $tr{'content filter'},\r
-                                     'uri' => '/cgi-bin/dansguardian.cgi',\r
-                                     'title' => "HTTP: $tr{'content filter'}",\r
-                                     'enabled' => 1,\r
-                                     };\r
-    $subhttp->{'03.antivirus'} = {\r
-                                 'caption' => $tr{'antivirus'},\r
-                                 'uri' => '/cgi-bin/httpantivirus.cgi',\r
-                                 'title' => "HTTP: $tr{'antivirus'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-     $subhttp->{'04.proxymanagment'} = {\r
-                                   'caption' => $tr{'DS Managment'},\r
-                                   'uri' => '/cgi-bin/proxygm.cgi',\r
-                                   'title' => "HTTP: $tr{'DS Managment'}",\r
-                                   'enabled' => 1,\r
-                                   };\r
-     $subhttp->{'05.activatedgroups'} = {\r
-                                   'caption' => $tr{'activated Groups'},\r
-                                   'uri' => '/cgi-bin/proxyag.cgi',\r
-                                   'title' => "HTTP: $tr{'activated Groups'}",\r
-                                   'enabled' => 1,\r
-                                   };\r
-     $subhttp->{'06.advancedproxy'} = {\r
-                                   'caption' => $tr{'Proxy Advanced'},\r
-                                   'uri' => '/cgi-bin/proxyad.cgi',\r
-                                   'title' => "HTTP: $tr{'Proxy Advanced'}",\r
-                                   'enabled' => 1,\r
-                                   };\r
-\r
-\r
-    my %subproxyhash = ();\r
-    my $subproxy = \%subproxyhash;\r
-\r
-    $subproxy->{'01.http'} = {'caption' => $tr{'HTTP'},\r
-                             'enabled' => 1,\r
-                             'subMenu' => $subhttp\r
-                             };\r
-    $subproxy->{'02.ftp'} = {'caption' => 'FTP',\r
-                             'enabled' => 1,\r
-                             'subMenu' => $subftp\r
-                             };\r
-\r
-\r
-\r
-    my %subopenvpnhash = ();\r
-    my $subopenvpn = \%subopenvpnhash;\r
-    $subopenvpn->{'01.server'} = {'caption' => $tr{'openvpn'},\r
-                                 'uri' => '/cgi-bin/openvpn.cgi',\r
-                                 'title' => "$tr{'virtual private networking'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-    $subopenvpn->{'02.client'} = {'caption' => $tr{'openvpnclient'},\r
-                                 'uri' => '/cgi-bin/openvpnclient.cgi',\r
-                                 'title' => "$tr{'virtual private networking'}",\r
-                                 'enabled' => 1,\r
-                                 };\r
-\r
-    my %subvpnhash = ();\r
-    my $subvpn = \%subvpnhash;\r
-\r
-    $subvpn->{'01.openvpn'} = {'caption' => $tr{'openvpn'},\r
-                              'subMenu' => $subopenvpn,\r
-                              'enabled' => 1,\r
-                          };\r
-    $subvpn->{'02.ipsec'} = {'caption' => $tr{'ipsec'},\r
-                            'uri' => '/cgi-bin/vpnmain.cgi',\r
-                            'title' => "$tr{'virtual private networking'}",\r
-                            'enabled' => 1,\r
-                        };\r
-\r
-    my %sublogshash = ();\r
-    my $sublogs = \%sublogshash;\r
-\r
-    $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},\r
-                                'uri' => '/cgi-bin/logs.cgi/summary.dat',\r
-                                'title' => "$tr{'log summary'}",\r
-                                'enabled' => 1\r
-                                };\r
-    $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},\r
-                                'uri' => '/cgi-bin/logs.cgi/config.dat',\r
-                                'title' => "$tr{'log settings'}",\r
-                                'enabled' => 1\r
-                                };\r
-    $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},\r
-                                'uri' => '/cgi-bin/logs.cgi/proxylog.dat',\r
-                                'title' => "$tr{'proxy log viewer'}",\r
-                                'enabled' => 1\r
-                                };\r
-    $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},\r
-                                'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',\r
-                                'title' => "$tr{'firewall log viewer'}",\r
-                                'enabled' => 1\r
-                                };\r
-    $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},\r
-                           'uri' => '/cgi-bin/logs.cgi/ids.dat',\r
-                           'title' => "$tr{'intrusion detection system log viewer'}",\r
-                           'enabled' => 1\r
-                           };\r
-    $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},\r
-                                     'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',\r
-                                     'title' => "$tr{'content filter log viewer'}",\r
-                                     'enabled' => 1\r
-                                     };\r
-    $sublogs->{'07.urlfilter'} = {\r
-                                     'caption' => $tr{'urlfilter log'},\r
-                                     'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',\r
-                                     'title' => "$tr{'urlfilter log'}",\r
-                                     'enabled' => 1,\r
-                                      };\r
-    $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},\r
-                                     'uri' => '/cgi-bin/logs.cgi/openvpn.dat',\r
-                                     'title' => "$tr{'openvpn log'}",\r
-                                     'enabled' => 1\r
-                                     };\r
-    $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},\r
-                                     'uri' => '/cgi-bin/logs.cgi/log.dat',\r
-                                     'title' => "$tr{'system log viewer'}",\r
-                                     'enabled' => 1\r
-                                     };\r
-    $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},\r
-                                      'uri' => '/cgi-bin/logs.cgi/userlog.dat',\r
-                                      'title' => "$tr{'user log viewer'}",\r
-                                      'enabled' => 1\r
-                                       };\r
-\r
-\r
-    $menu->{'01.system'} = {'caption' => $tr{'alt system'},\r
-                           'enabled' => 1,\r
-                           'subMenu' => $subsystem\r
-                           };\r
-    $menu->{'02.status'} = {'caption' => $tr{'status'},\r
-                           'enabled' => 1,\r
-                           'subMenu' => $substatus\r
-                           };\r
-    $menu->{'03.network'} = {'caption' => $tr{'network'},\r
-                            'enabled' => 1,\r
-                            'subMenu' => $subnetwork\r
-                            };\r
-    $menu->{'04.services'} = {'caption' => $tr{'alt services'},\r
-                             'enabled' => 1,\r
-                             'subMenu' => $subservices\r
-                             };\r
-    $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},\r
-                             'enabled' => 1,\r
-                             'subMenu' => $subfirewall\r
-                             };\r
-    $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},\r
-                          'enabled' => 1,\r
-                          'subMenu' => $subproxy\r
-                          };\r
-    $menu->{'07.vpn'} = {'caption' => 'VPN',\r
-                        'enabled' => 1,\r
-                        'subMenu' => $subvpn\r
-                        };\r
-    $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},\r
-                         'enabled' => 1,\r
-                         'subMenu' => $sublogs\r
-                         };\r
-\r
-\r
-\r
-    if (! blue_used() && ! orange_used()) {\r
-       $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;\r
-    }\r
-    if (-e '/etc/FLASH') {\r
-       $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0;  #disable squid\r
-       $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0;  #disable ids\r
-       $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0;  #disable ids\r
-    }\r
-}\r
-\r
-sub showhttpheaders\r
-{\r
-       print "Pragma: no-cache\n";\r
-       print "Cache-control: no-cache\n";\r
-       print "Connection: close\n";\r
-       print "Content-type: text/html\n\n";\r
-}\r
-\r
-sub is_menu_visible($) {\r
-    my $link = shift;\r
-    $link =~ s#\?.*$##;\r
-    return (-e $ENV{'DOCUMENT_ROOT'}."/../$link");\r
-}\r
-\r
-\r
-sub getlink($) {\r
-    my $root = shift;\r
-    if (! $root->{'enabled'}) {\r
-       return '';\r
-    }\r
-    if ($root->{'uri'} !~ /^$/) {\r
-       my $vars = '';\r
-       if ($root->{'vars'} !~ /^$/) {\r
-           $vars = '?'. $root->{'vars'};\r
-       }\r
-       if (! is_menu_visible($root->{'uri'})) {\r
-           return '';\r
-       }\r
-       return $root->{'uri'}.$vars;\r
-    }\r
-    my $submenus = $root->{'subMenu'};\r
-    if (! $submenus) {\r
-       return '';\r
-    }\r
-    foreach my $item (sort keys %$submenus) {\r
-       my $link = getlink($submenus->{$item});\r
-       if ($link ne '') {\r
-           return $link;\r
-       }\r
-    }\r
-    return '';\r
-}\r
-\r
-\r
-sub compare_url($) {\r
-    my $conf = shift;\r
-\r
-    my $uri = $conf->{'uri'};\r
-    my $vars = $conf->{'vars'};\r
-    my $novars = $conf->{'novars'};\r
-\r
-    if ($uri eq '') {\r
-       return 0;\r
-    }\r
-    if ($uri ne $URI[0]) {\r
-       return 0;\r
-    }\r
-    if ($novars) {\r
-       if ($URI[1] !~ /^$/) {\r
-           return 0;\r
-       }\r
-    }\r
-    if (! $vars) {\r
-       return 1;\r
-    }\r
-    return ($URI[1] eq $vars);\r
-}\r
-\r
-\r
-sub gettitle($) {\r
-    my $root = shift;\r
-\r
-    if (! $root) {\r
-       return '';\r
-    }\r
-    foreach my $item (sort keys %$root) {\r
-       my $val = $root->{$item};\r
-       if (compare_url($val)) {\r
-           $val->{'selected'} = 1;\r
-           if ($val->{'title'} !~ /^$/) {\r
-               return $val->{'title'};\r
-           }\r
-           return 'EMPTY TITLE';\r
-       }\r
-\r
-       my $title = gettitle($val->{'subMenu'});\r
-       if ($title ne '') {\r
-           $val->{'selected'} = 1;\r
-           return $title;\r
-       }\r
-    }\r
-    return '';\r
-}\r
-\r
-\r
-sub showmenu() {\r
-    print <<EOF\r
-  <div id="menu-top">\r
-    <ul>\r
-EOF\r
-;\r
-    foreach my $k1 ( sort keys %$menu ) {\r
-       if (! $menu->{$k1}{'enabled'}) {\r
-           next;\r
-       }\r
-\r
-       my $link = getlink($menu->{$k1});\r
-       if ($link eq '') {\r
-           next;\r
-       }\r
-       if (! is_menu_visible($link)) {\r
-           next;\r
-       }\r
-       if ($menu->{$k1}->{'selected'}) {\r
-           print '<li class="selected">';\r
-       } else {\r
-           print '<li>';\r
-       }\r
-\r
-       print <<EOF\r
-    <div class="rcorner">\r
-      <a href="$link">$menu->{$k1}{'caption'}</a>\r
-    </div>\r
-  </li>\r
-EOF\r
-;\r
-    }\r
-\r
-    print <<EOF\r
-    </ul>\r
-  </div>\r
-EOF\r
-;    \r
-}\r
-\r
-sub getselected($) {\r
-    my $root = shift;\r
-    if (!$root) {\r
-       return 0;\r
-    }\r
-\r
-    foreach my $item (%$root) {\r
-       if ($root->{$item}{'selected'}) {\r
-           return $root->{$item};\r
-       }\r
-    }\r
-}\r
-\r
-sub showsubsection($$) {\r
-    my $root = shift;\r
-    my $id = shift;\r
-    if ($id eq '') {\r
-       $id = 'menu-left';\r
-    }\r
-\r
-    if (! $root) {\r
-       return;\r
-    }\r
-    my $selected = getselected($root);\r
-    if (! $selected) {\r
-       return;\r
-    }\r
-    my $submenus = $selected->{'subMenu'};\r
-    if (! $submenus) {\r
-       return;\r
-    }\r
-\r
-    print <<EOF\r
-  <div id="$id">\r
-    <ul>\r
-EOF\r
-;\r
-    foreach my $item (sort keys %$submenus) {\r
-       my $hash = $submenus->{$item};\r
-       if (! $hash->{'enabled'}) {\r
-           next;\r
-       }\r
-\r
-       my $link = getlink($hash);\r
-       if ($link eq '') {\r
-           next;\r
-       }\r
-       if (! is_menu_visible($link)) {\r
-           next;\r
-       }\r
-       if ($hash->{'selected'}) {\r
-           print '<li class="selected">';\r
-       } else {\r
-           print '<li>';\r
-       }\r
-\r
-       print <<EOF\r
-      <a href="$link">$hash->{'caption'}</a>\r
-  </li>\r
-EOF\r
-;\r
-    }\r
-\r
-    print <<EOF\r
-    </ul>\r
-  </div>\r
-EOF\r
-;    \r
-\r
-}\r
-\r
-\r
-sub showsubsubsection($) {\r
-    my $root = shift;\r
-    if (!$root) {\r
-       return;\r
-    }\r
-    my $selected = getselected($root);\r
-    if (! $selected) {\r
-       return\r
-    }\r
-    if (! $selected->{'subMenu'}) {\r
-       return\r
-    }\r
-\r
-    showsubsection($selected->{'subMenu'}, 'menu-subtop');\r
-}\r
-\r
-\r
-sub get_helpuri() {\r
-    my $helpfile = '';\r
-    if ($URI[0] =~ /.*\/([^\/]+)\.cgi/) {\r
-       $helpfile = $1;\r
-    } else {\r
-       return '';\r
-    }\r
-    $helpfile .= '.help.html';\r
-\r
-    my $helpuri = '/doc/'.$language.'/'.$helpfile;\r
-    if (! -e $ENV{'DOCUMENT_ROOT'}.$helpuri) {\r
-       return '';\r
-    }\r
-    return $helpuri;\r
-}\r
-\r
-\r
-sub openpage {\r
-    my $title = shift;\r
-    my $boh = shift;\r
-    my $extrahead = shift;\r
-\r
-    @URI=split ('\?',  $ENV{'REQUEST_URI'} );\r
-    &readhash("${swroot}/main/settings", \%settings);\r
-    &genmenu();\r
-\r
-    my $h2 = gettitle($menu);\r
-    my $helpuri = get_helpuri();\r
-\r
-    $title = "IPFire - $title";\r
-    if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {\r
-        $title =  "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title"; \r
-    }\r
-\r
-    print <<END\r
-<!DOCTYPE html \r
-     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\r
-     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
-\r
-<html>\r
-  <head>\r
-  <title>$title</title>\r
-\r
-    $extrahead\r
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\r
-    <link rel="shortcut icon" href="/favicon.ico" />\r
-    <style type="text/css">\@import url(/include/style.css);</style>\r
-    <style type="text/css">\@import url(/include/menu.css);</style>\r
-    <style type="text/css">\@import url(/include/content.css);</style>\r
-\r
-    <script language="javascript" type="text/javascript">\r
-      \r
-        function swapVisibility(id) {\r
-            el = document.getElementById(id);\r
-           if(el.style.display != 'block') {\r
-               el.style.display = 'block'\r
-           }\r
-           else {\r
-               el.style.display = 'none'\r
-           }\r
-        }\r
-    </script>\r
-\r
-  </head>\r
-  <body>\r
-<!-- IPFIRE HEADER -->\r
-\r
-<div id="main">\r
-\r
-<div id="header">\r
-       <img id="logo-product" src="/images/logo_ipfire.gif">\r
-       <img id="logo-ipfire" src="/images/logo_ipfire2.gif">   \r
-   <div id="header-icons">\r
-END\r
-;\r
-\r
-    if ($helpuri ne '') {\r
-       print <<END\r
-           <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>\r
-END\r
-;\r
-    } else {\r
-       print '<img src="/images/help.gif">';\r
-    }\r
-\r
-print <<END\r
-   </div>\r
-</div>\r
-\r
-END\r
-;\r
-\r
-    &showmenu();\r
-\r
-print <<END\r
-<div id="content">\r
-  <table width="90%">\r
-    <tr>\r
-      <td valign="top">\r
-END\r
-;\r
-       \r
-    &showsubsection($menu);\r
-\r
-    print <<END\r
-\r
-      </td>\r
-        <td width="100%" valign="top">\r
-        <div id="page-content">\r
-            <h2>$h2</h2>\r
-END\r
-    ;\r
-    \r
-    &showsubsubsection($menu);\r
-\r
-    eval {\r
-       require 'ipfire-network.pl';\r
-       $supported = check_support();\r
-       warn_unsupported($supported);\r
-    };\r
-}\r
-\r
-sub closepage () {\r
-    my $status = &connectionstatus();\r
-    $uptime = `/usr/bin/uptime`;\r
-       \r
-    print <<END\r
-         <div align="center">\r
-            <p>\r
-             <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>\r
-            </p>\r
-            <p><a href="http://www.ipfire.org">IPFire</a> $version (c)</p>\r
-          </div>\r
-       </body>\r
-       <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">\r
-       <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">\r
-</html>\r
-END\r
-;\r
-}\r
-\r
-sub openbigbox\r
-{\r
-    my $width = $_[0];\r
-    my $align = $_[1];\r
-    my $sideimg = $_[2];\r
-\r
-    if ($errormessage) {\r
-       $bgcolor = "style='background-color: $colourerr;'";\r
-    } else {\r
-       $bgcolor = '';\r
-    }\r
-}\r
-\r
-sub closebigbox\r
-{\r
-#      print "</td></tr></table></td></tr></table>\n" \r
-}\r
-\r
-sub openbox\r
-{\r
-       $width = $_[0];\r
-       $align = $_[1];\r
-       $caption = $_[2];\r
-\r
-       if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }\r
-       \r
-       print "<table class=\"list\"><tr><td align=\"$align\">\n";\r
-}\r
-\r
-sub closebox\r
-{\r
-       print "</td></tr></table><br><br>";\r
-}\r
-\r
-sub writehash\r
-{\r
-       my $filename = $_[0];\r
-       my $hash = $_[1];\r
-       \r
-       # write cgi vars to the file.\r
-       open(FILE, ">${filename}") or die "Unable to write file $filename";\r
-       flock FILE, 2;\r
-       foreach $var (keys %$hash) \r
-       {\r
-               $val = $hash->{$var};\r
-               # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y\r
-               # location of the mouse are submitted as well, this was being written to the settings file causing\r
-               # some serious grief! This skips the variable.x and variable.y\r
-               if (!($var =~ /(.x|.y)$/)) {\r
-                       if ($val =~ / /) {\r
-                               $val = "\'$val\'"; }\r
-                       if (!($var =~ /^ACTION/)) {\r
-                               print FILE "${var}=${val}\n"; }\r
-               }\r
-       }\r
-       close FILE;\r
-}\r
-\r
-sub readhash\r
-{\r
-       my $filename = $_[0];\r
-       my $hash = $_[1];\r
-       my ($var, $val);\r
-\r
-       open(FILE, $filename) or die "Unable to read file $filename";\r
-       \r
-       while (<FILE>)\r
-       {\r
-               chop;\r
-               ($var, $val) = split /=/, $_, 2;\r
-               if ($var)\r
-               {\r
-                       $val =~ s/^\'//g;\r
-                       $val =~ s/\'$//g;\r
-\r
-                       # Untaint variables read from hash\r
-                       $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;\r
-                       $val =~ /([\w\W]*)/; $val = $1;\r
-                       $hash->{$var} = $val;\r
-               }\r
-       }\r
-       close FILE;\r
-}\r
-\r
-sub getcgihash {\r
-       my ($hash, $params) = @_;\r
-       my $cgi = CGI->new ();\r
-       $hash->{'__CGI__'} = $cgi;\r
-       return if ($ENV{'REQUEST_METHOD'} ne 'POST');\r
-       if (!$params->{'wantfile'}) {\r
-               $CGI::DISABLE_UPLOADS = 1;\r
-               $CGI::POST_MAX        = 512 * 1024;\r
-       } else {\r
-               $CGI::POST_MAX = 10 * 1024 * 1024;\r
-       }\r
-\r
-       $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;\r
-       my $referer = $1;\r
-       $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;\r
-       my $servername = $1;\r
-       return if ($referer ne $servername);\r
-\r
-       ### Modified for getting multi-vars, split by |\r
-       %temp = $cgi->Vars();\r
-        foreach my $key (keys %temp) {\r
-               $hash->{$key} = $temp{$key};\r
-               $hash->{$key} =~ s/\0/|/g;\r
-               $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;\r
-        }\r
-\r
-       if (($params->{'wantfile'})&&($params->{'filevar'})) {\r
-               $hash->{$params->{'filevar'}} = $cgi->upload\r
-                                               ($params->{'filevar'});\r
-       }\r
-       return;\r
-}\r
-\r
-sub log\r
-{\r
-       my $logmessage = $_[0];\r
-       $logmessage =~ /([\w\W]*)/;\r
-       $logmessage = $1;\r
-       system('/usr/bin/logger', '-t', 'ipfire', $logmessage);\r
-}\r
-\r
-sub age\r
-{\r
-       my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,\r
-               $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];\r
-       my $now = time;\r
-\r
-       my $totalsecs = $now - $mtime;\r
-       my $days = int($totalsecs / 86400);\r
-       my $totalhours = int($totalsecs / 3600);\r
-       my $hours = $totalhours % 24;\r
-       my $totalmins = int($totalsecs / 60);\r
-       my $mins = $totalmins % 60;\r
-       my $secs = $totalsecs % 60;\r
-\r
-       return "${days}d ${hours}h ${mins}m ${secs}s";\r
-}\r
-\r
-sub validip\r
-{\r
-       my $ip = $_[0];\r
-\r
-       if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {\r
-               return 0; }\r
-       else \r
-       {\r
-               @octets = ($1, $2, $3, $4);\r
-               foreach $_ (@octets)\r
-               {\r
-                       if (/^0./) {\r
-                               return 0; }\r
-                       if ($_ < 0 || $_ > 255) {\r
-                               return 0; }\r
-               }\r
-               return 1;\r
-       }\r
-}\r
-\r
-sub validmask\r
-{\r
-       my $mask = $_[0];\r
-\r
-       # secord part an ip?\r
-       if (&validip($mask)) {\r
-               return 1; }\r
-       # second part a number?\r
-       if (/^0/) {\r
-               return 0; }\r
-       if (!($mask =~ /^\d+$/)) {\r
-               return 0; }\r
-       if ($mask >= 0 && $mask <= 32) {\r
-               return 1; }\r
-       return 0;\r
-}\r
-\r
-sub validipormask\r
-{\r
-       my $ipormask = $_[0];\r
-\r
-       # see if it is a IP only.\r
-       if (&validip($ipormask)) {\r
-               return 1; }\r
-       # split it into number and mask.\r
-       if (!($ipormask =~ /^(.*?)\/(.*?)$/)) {\r
-               return 0; }\r
-       $ip = $1;\r
-       $mask = $2;\r
-       # first part not a ip?\r
-       if (!(&validip($ip))) {\r
-               return 0; }\r
-       return &validmask($mask);\r
-}\r
-\r
-sub validipandmask\r
-{\r
-       my $ipandmask = $_[0];\r
-\r
-       # split it into number and mask.\r
-       if (!($ipandmask =~ /^(.*?)\/(.*?)$/)) {\r
-               return 0; }\r
-       $ip = $1;\r
-       $mask = $2;\r
-       # first part not a ip?\r
-       if (!(&validip($ip))) {\r
-               return 0; }\r
-       return &validmask($mask);\r
-}\r
-\r
-sub validport\r
-{\r
-       $_ = $_[0];\r
-\r
-       if (!/^\d+$/) {\r
-               return 0; }\r
-       if (/^0./) {\r
-               return 0; }\r
-       if ($_ >= 1 && $_ <= 65535) {\r
-               return 1; }\r
-       return 0;\r
-}\r
-\r
-sub validmac\r
-{\r
-       my $checkmac = $_[0];\r
-       my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)\r
-       if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)\r
-       {\r
-               return 0;\r
-       }\r
-       return 1;\r
-}\r
-\r
-sub validhostname\r
-{\r
-       # Checks a hostname against RFC1035\r
-        my $hostname = $_[0];\r
-\r
-       # Each part should be at least two characters in length\r
-       # but no more than 63 characters\r
-       if (length ($hostname) < 2 || length ($hostname) > 63) {\r
-               return 0;}\r
-       # Only valid characters are a-z, A-Z, 0-9 and -\r
-       if ($hostname !~ /^[a-zA-Z0-9-]*$/) {\r
-               return 0;}\r
-       # First character can only be a letter or a digit\r
-       if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-               return 0;}\r
-       # Last character can only be a letter or a digit\r
-       if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-               return 0;}\r
-       return 1;\r
-}\r
-\r
-sub validdomainname\r
-{\r
-       # Checks a domain name against RFC1035\r
-        my $domainname = $_[0];\r
-       my @parts = split (/\./, $domainname);  # Split hostname at the '.'\r
-\r
-       foreach $part (@parts) {\r
-               # Each part should be at least two characters in length\r
-               # but no more than 63 characters\r
-               if (length ($part) < 2 || length ($part) > 63) {\r
-                       return 0;}\r
-               # Only valid characters are a-z, A-Z, 0-9 and -\r
-               if ($part !~ /^[a-zA-Z0-9-]*$/) {\r
-                       return 0;}\r
-               # First character can only be a letter or a digit\r
-               if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-                       return 0;}\r
-               # Last character can only be a letter or a digit\r
-               if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-                       return 0;}\r
-       }\r
-       return 1;\r
-}\r
-\r
-sub validfqdn\r
-{\r
-       # Checks a fully qualified domain name against RFC1035\r
-        my $fqdn = $_[0];\r
-       my @parts = split (/\./, $fqdn);        # Split hostname at the '.'\r
-       if (scalar(@parts) < 2) {               # At least two parts should\r
-               return 0;}                      # exist in a FQDN\r
-                                               # (i.e. hostname.domain)\r
-       foreach $part (@parts) {\r
-               # Each part should be at least two characters in length\r
-               # but no more than 63 characters\r
-               if (length ($part) < 2 || length ($part) > 63) {\r
-                       return 0;}\r
-               # Only valid characters are a-z, A-Z, 0-9 and -\r
-               if ($part !~ /^[a-zA-Z0-9-]*$/) {\r
-                       return 0;}\r
-               # First character can only be a letter or a digit\r
-               if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-                       return 0;}\r
-               # Last character can only be a letter or a digit\r
-               if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {\r
-                       return 0;}\r
-       }\r
-       return 1;\r
-}\r
-\r
-sub validportrange # used to check a port range \r
-{\r
-       my $port = $_[0]; # port values\r
-       $port =~ tr/-/:/; # replace all - with colons just in case someone used -\r
-       my $srcdst = $_[1]; # is it a source or destination port\r
-\r
-       if (!($port =~ /^(\d+)\:(\d+)$/)) {\r
-       \r
-               if (!(&validport($port))) {      \r
-                       if ($srcdst eq 'src'){\r
-                               return $tr{'source port numbers'};\r
-                       } else  {\r
-                               return $tr{'destination port numbers'};\r
-                       } \r
-               }\r
-       }\r
-       else \r
-       {\r
-               @ports = ($1, $2);\r
-               if ($1 >= $2){\r
-                       if ($srcdst eq 'src'){\r
-                               return $tr{'bad source range'};\r
-                       } else  {\r
-                               return $tr{'bad destination range'};\r
-                       } \r
-               }\r
-               foreach $_ (@ports)\r
-               {\r
-                       if (!(&validport($_))) {\r
-                               if ($srcdst eq 'src'){\r
-                                       return $tr{'source port numbers'}; \r
-                               } else  {\r
-                                       return $tr{'destination port numbers'};\r
-                               } \r
-                       }\r
-               }\r
-               return;\r
-       }\r
-}\r
-\r
-# Test if IP is within a subnet\r
-# Call: IpInSubnet (Addr, Subnet, Subnet Mask)\r
-#       Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1\r
-#       Everything in dottted notation\r
-# Return: TRUE/FALSE\r
-sub IpInSubnet\r
-{\r
-    $ip = unpack('N', inet_aton(shift));\r
-    $start = unpack('N', inet_aton(shift));\r
-    $mask  = unpack('N', inet_aton(shift));\r
-    $start &= $mask;  # base of subnet...\r
-    $end   = $start + ~$mask;\r
-    return (($ip >= $start) && ($ip <= $end));\r
-}\r
-\r
-sub validemail {\r
-    my $mail = shift;\r
-    return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );\r
-    return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);\r
-    return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );\r
-    return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );\r
-    return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );\r
-    return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );\r
-    return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );\r
-    return 1;\r
-}\r
-\r
-sub readhasharray {\r
-    my ($filename, $hash) = @_;\r
-\r
-    open(FILE, $filename) or die "Unable to read file $filename";\r
-\r
-    while (<FILE>) {\r
-       my ($key, $rest, @temp);\r
-       chomp;\r
-       ($key, $rest) = split (/,/, $_, 2);\r
-       if ($key =~ /^[0-9]+$/ && $rest) {\r
-           @temp = split (/,/, $rest);\r
-           $hash->{$key} = \@temp;\r
-        }\r
-    }\r
-    close FILE;\r
-    return;\r
-}\r
-\r
-sub writehasharray {\r
-    my ($filename, $hash) = @_;\r
-    my ($key, @temp);\r
-\r
-    open(FILE, ">$filename") or die "Unable to write to file $filename";\r
-\r
-    foreach $key (keys %$hash) {\r
-       if ( $hash->{$key} ) {\r
-           print FILE "$key";\r
-           foreach $i (0 .. $#{$hash->{$key}}) {\r
-               print FILE ",$hash->{$key}[$i]";\r
-           }\r
-       }\r
-       print FILE "\n";\r
-    }\r
-    close FILE;\r
-    return;\r
-}\r
-\r
-sub findhasharraykey {\r
-    foreach my $i (1 .. 1000000) {\r
-       if ( ! exists $_[0]{$i}) {\r
-            return $i;\r
-       }\r
-    }\r
-}\r
-\r
-sub cleanhtml\r
-{\r
-       my $outstring =$_[0];\r
-       $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';\r
-       $outstring =~ s/&/&amp;/g;\r
-       $outstring =~ s/\'/&#039;/g;\r
-       $outstring =~ s/\"/&quot;/g;\r
-       $outstring =~ s/</&lt;/g;\r
-       $outstring =~ s/>/&gt;/g;\r
-       return $outstring;\r
-}\r
-sub connectionstatus\r
-{\r
-        my $status;\r
-        opendir UPLINKS, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";\r
-                foreach my $uplink (sort grep !/^\./, readdir UPLINKS) {\r
-                    if ( -f "${swroot}/uplinks/${uplink}/active") {\r
-                        if ( ! $status ) {\r
-                                $timestr = &age("${swroot}/uplinks/${uplink}/active");\r
-                                $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";\r
-                        } else {\r
-                                $timestr = &age("${swroot}/uplinks/${uplink}/active");\r
-                                $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";\r
-                        }\r
-                    } elsif ( -f "${swroot}/uplinks/${uplink}/connecting") {\r
-                        if ( ! $status ) {\r
-                                $status = "$tr{'connecting'} $uplink";\r
-                        } else {\r
-                                $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";\r
-                        }\r
-                    }\r
-                    $lines++;\r
-                }\r
-                closedir(UPLINKS);\r
-                if ( ! $status ) {\r
-                        $status = "$tr{'idle'}";\r
-                }\r
-                $connstate = "<span class='ipcop_StatusBig'>$status</span>";\r
-    return $connstate;\r
-}\r
-\r
-sub srtarray \r
-# Darren Critchley - darrenc@telus.net - (c) 2003\r
-# &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)\r
-# This subroutine will take the following parameters:\r
-#   ColumnNumber = the column which you want to sort on, starts at 1\r
-#   AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic\r
-#   SortDirection = asc or dsc (lowercase) Ascending or Descending sort\r
-#   ArrayToBeSorted = the array that wants sorting\r
-#\r
-#   Returns an array that is sorted to your specs\r
-#\r
-#   If SortOrder is greater than the elements in array, then it defaults to the first element\r
-# \r
-{\r
-       my ($colno, $alpnum, $srtdir, @tobesorted) = @_;\r
-       my @tmparray;\r
-       my @srtedarray;\r
-       my $line;\r
-       my $newline;\r
-       my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array\r
-       if ($ttlitems < 1){ # if no items, don't waste our time lets leave\r
-               return (@tobesorted);\r
-       }\r
-       my @tmp = split(/\,/,$tobesorted[0]);\r
-       $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array\r
-\r
-       # Darren Critchley - validate parameters\r
-       if ($colno > $ttlitems){$colno = '1';}\r
-       $colno--; # remove one from colno to deal with arrays starting at 0\r
-       if($colno < 0){$colno = '0';}\r
-       if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }\r
-       if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }\r
-\r
-       foreach $line (@tobesorted)\r
-       {\r
-               chomp($line);\r
-               if ($line ne '') {\r
-                       my @temp = split(/\,/,$line);\r
-                       # Darren Critchley - juggle the fields so that the one we want to sort on is first\r
-                       my $tmpholder = $temp[0];\r
-                       $temp[0] = $temp[$colno];\r
-                       $temp[$colno] = $tmpholder;\r
-                       $newline = "";\r
-                       for ($ctr=0; $ctr < $ttlitems ; $ctr++) {\r
-                               $newline=$newline . $temp[$ctr] . ",";\r
-                       }\r
-                       chop($newline);\r
-                       push(@tmparray,$newline);\r
-               }\r
-       }\r
-       if ($alpnum eq 'n') {\r
-               @tmparray = sort {$a <=> $b} @tmparray;\r
-       } else {\r
-               @tmparray = (sort @tmparray);\r
-       }\r
-       foreach $line (@tmparray)\r
-       {\r
-               chomp($line);\r
-               if ($line ne '') {\r
-                       my @temp = split(/\,/,$line);\r
-                       my $tmpholder = $temp[0];\r
-                       $temp[0] = $temp[$colno];\r
-                       $temp[$colno] = $tmpholder;\r
-                       $newline = "";\r
-                       for ($ctr=0; $ctr < $ttlitems ; $ctr++){\r
-                               $newline=$newline . $temp[$ctr] . ",";\r
-                       }\r
-                       chop($newline);\r
-                       push(@srtedarray,$newline);\r
-               }\r
-       }\r
-\r
-       if ($srtdir eq 'dsc') {\r
-               @tmparray = reverse(@srtedarray);\r
-               return (@tmparray);\r
-       } else {\r
-               return (@srtedarray);\r
-       }\r
-}\r
-\r
-sub speedtouchversion\r
-{\r
-       if (-f "/proc/bus/usb/devices")\r
-       {\r
-               $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;\r
-               if ($speedtouch eq '') {\r
-                       $speedtouch= $tr{'connect the modem'};\r
-               }\r
-       } else {\r
-               $speedtouch='USB '.$tr{'not running'};\r
-       }\r
-       return $speedtouch\r
-}\r
-\r
-sub CheckSortOrder {\r
-#Sorting of allocated leases\r
-    if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {\r
-       my $newsort=$ENV{'QUERY_STRING'};\r
-        &readhash("${swroot}/dhcp/settings", \%dhcpsettings);\r
-        $act=$dhcpsettings{'SORT_LEASELIST'};\r
-        #Reverse actual ?\r
-        if ($act =~ $newsort) {\r
-            if ($act !~ 'Rev') {$Rev='Rev'};\r
-            $newsort.=$Rev\r
-        };\r
-\r
-        $dhcpsettings{'SORT_LEASELIST'}=$newsort;\r
-       &writehash("${swroot}/dhcp/settings", \%dhcpsettings);\r
-        $dhcpsettings{'ACTION'} = 'SORT';  # avoid the next test "First lauch"\r
-    }\r
-\r
-}\r
-\r
-sub PrintActualLeases\r
-{\r
-    &openbox('100%', 'left', $tr{'current dynamic leases'});\r
-    print <<END\r
-<table width='100%'>\r
-<tr>\r
-<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>\r
-<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>\r
-<td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>\r
-<td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>\r
-</tr>\r
-END\r
-    ;\r
-\r
-    open(LEASES,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";\r
-    while ($line = <LEASES>) {\r
-       next if( $line =~ /^\s*#/ );\r
-       chomp($line);\r
-       @temp = split (' ', $line);\r
-\r
-       if ($line =~ /^\s*lease/) {\r
-           $ip = $temp[1];\r
-           #All field are not necessarily read. Clear everything\r
-           $endtime = 0;\r
-           $ether = "";\r
-           $hostname = "";\r
-       }\r
-\r
-       if ($line =~ /^\s*ends/) {\r
-           $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;\r
-           $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);\r
-       }\r
-\r
-       if ($line =~ /^\s*hardware ethernet/) {\r
-           $ether = $temp[2];\r
-           $ether =~ s/;//g;\r
-       }\r
-\r
-       if ($line =~ /^\s*client-hostname/) {\r
-           $hostname = "$temp[1] $temp[2] $temp[3]";\r
-           $hostname =~ s/;//g;\r
-           $hostname =~ s/\"//g;\r
-       }\r
-\r
-       if ($line eq "}") {\r
-           @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);\r
-           $record = {};                                       # create a reference to empty hash\r
-           %{$record} = @record;                               # populate that hash with @record\r
-           $entries{$record->{'IPADDR'}} = $record;    # add this to a hash of hashes\r
-       }\r
-    }\r
-    close(LEASES);\r
-\r
-    my $id = 0;\r
-    foreach my $key (sort leasesort keys %entries) {\r
-\r
-       my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");\r
-\r
-       if ($id % 2) {\r
-           print "<tr bgcolor='$table1colour'>"; \r
-       }\r
-       else {\r
-           print "<tr bgcolor='$table2colour'>"; \r
-       }\r
-\r
-       print <<END\r
-<td align='center'>$entries{$key}->{IPADDR}</td>\r
-<td align='center'>$entries{$key}->{ETHER}</td>\r
-<td align='center'>&nbsp;$hostname </td>\r
-<td align='center'>\r
-END\r
-       ;\r
-\r
-       ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});\r
-       $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);\r
-\r
-       if ($entries{$key}->{ENDTIME} < time() ){\r
-           print "<strike>$enddate</strike>";\r
-       } else {\r
-           print "$enddate";\r
-       }\r
-       print "</td></tr>";\r
-       $id++;\r
-    }\r
-\r
-    print "</table>";\r
-    &closebox();\r
-}\r
-\r
-\r
-# This sub is used during display of actives leases\r
-sub leasesort {\r
-    if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)\r
-    {\r
-        $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);\r
-        if ($qs eq 'IPADDR') {\r
-            @a = split(/\./,$entries{$a}->{$qs});\r
-            @b = split(/\./,$entries{$b}->{$qs});\r
-            ($b[0]<=>$a[0]) ||\r
-            ($b[1]<=>$a[1]) ||\r
-            ($b[2]<=>$a[2]) ||\r
-            ($b[3]<=>$a[3]);\r
-        }else {\r
-            $entries{$b}->{$qs} cmp $entries{$a}->{$qs};\r
-        }\r
-    }\r
-    else #not reverse\r
-    {\r
-        $qs=$dhcpsettings{'SORT_LEASELIST'};\r
-        if ($qs eq 'IPADDR') {\r
-           @a = split(/\./,$entries{$a}->{$qs});\r
-           @b = split(/\./,$entries{$b}->{$qs});\r
-           ($a[0]<=>$b[0]) ||\r
-           ($a[1]<=>$b[1]) ||\r
-           ($a[2]<=>$b[2]) ||\r
-           ($a[3]<=>$b[3]);\r
-       }else {\r
-           $entries{$a}->{$qs} cmp $entries{$b}->{$qs};\r
-       }\r
-    }\r
-}\r
-\r
-sub get_uplinks() {\r
-    my @uplinks = ();\r
-    opendir(DIR, "${swroot}/uplinks/") || return \@uplinks;\r
-    foreach my $dir (readdir(DIR)) {\r
-       next if ($dir =~ /^\./);\r
-       next if (-f "${swroot}/uplinks/$dir");\r
-       push(@uplinks, $dir);\r
-    }\r
-    closedir(DIR);\r
-    return \@uplinks;\r
-}\r
-\r
-sub get_iface($) {\r
-    my $filename = shift;\r
-    chomp($filename);\r
-    open (F, $filename) || return "";\r
-    my $iface = <F>;\r
-    close(F);\r
-    chomp($iface);\r
-    return $iface;\r
-}\r
-\r
-sub get_red_ifaces_by_type($) {\r
-    my $type=shift;\r
-    my @gottypeiface = ();\r
-    my @gottypeuplink = ();\r
-    my @gottype = ();\r
-\r
-    my $ref=get_uplinks();\r
-    my @uplinks=@$ref;\r
-    my %set = ();\r
-    foreach my $link (@uplinks) {\r
-       eval {\r
-           &readhash("${swroot}/uplinks/$link/settings", \%set);\r
-       };\r
-       push(@gottype, $link);\r
-\r
-       my $iface = $set{'RED_DEV'};\r
-       if (!$iface) {\r
-           $iface = get_iface("${swroot}/uplinks/$link/interface");\r
-       }\r
-       next if (!$iface);\r
-\r
-       if ($set{'RED_TYPE'} eq $type) {\r
-           push(@gottypeiface, $iface);\r
-           push(@gottypeuplink, $link);\r
-       }\r
-    }\r
-    return (\@gottypeiface, \@gottypeuplink, \@gottype);\r
-}\r
-\r
-sub get_red_ifaces() {\r
-    return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;\r
-}\r
-\r
-sub get_zone_devices($) {\r
-    my $bridge = shift;\r
-    my @ifaces = ();\r
-    open (FILE, "${swroot}/ethernet/$bridge") || return "";\r
-    foreach my $line (<FILE>) {\r
-       chomp($line);\r
-       next if (!$line);\r
-       push(@ifaces, $line);\r
-    }\r
-    close(FILE);\r
-    return \@ifaces;\r
-}\r
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) The SmoothWall Team
+# Copyright (C) 2002 Alex Hudson - getcgihash() rewrite
+# Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()
+# Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions
+# Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()
+# Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()
+#
+package Header;
+
+use CGI();
+use Socket;
+use Time::Local;
+
+$|=1; # line buffering
+
+$Header::revision = 'final';
+$Header::swroot = '/var/ipfire';
+$Header::pagecolour = '#ffffff';
+#$Header::tablecolour = '#a0a0a0';
+$Header::tablecolour = '#FFFFFF';
+$Header::bigboxcolour = '#F6F4F4';
+$Header::boxcolour = '#EAE9EE';
+$Header::bordercolour = '#000000';
+$Header::table1colour = '#E0E0E0';
+$Header::table2colour = '#F0F0F0';
+$Header::colourred = '#993333';
+$Header::colourorange = '#FF9933';
+$Header::colouryellow = '#FFFF00';
+$Header::colourgreen = '#339933';
+$Header::colourblue = '#333399';
+$Header::colourfw = '#000000';
+$Header::colourvpn = '#990099';
+$Header::colourerr = '#FF0000';
+$Header::viewsize = 150;
+$Header::errormessage = '';
+my %menuhash = ();
+my $menu = \%menuhash;
+%settings = ();
+%ethsettings = ();
+@URI = ();
+$Header::supported=0;
+
+### Make sure this is an SSL request
+if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
+    print "Status: 302 Moved\r\n";
+    print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";
+    exit 0;
+}
+
+### Initialize environment
+&readhash("${swroot}/main/settings", \%settings);
+&readhash("${swroot}/ethernet/settings", \%ethsettings);
+$language = $settings{'LANGUAGE'};
+$hostname = $settings{'HOSTNAME'};
+$hostnameintitle = 0;
+
+### Initialize language
+if ($language =~ /^(\w+)$/) {$language = $1;}
+
+### Read English Files
+if ( -d "/var/ipfire/langs/en/" ) {
+    opendir(DIR, "/var/ipfire/langs/en/");
+    @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
+    foreach $name(@names) {
+        next if ($name eq ".");
+        next if ($name eq "..");
+        next if (!($name =~ /\.pl$/));
+        require "${swroot}/langs/en/${name}";
+    };
+};
+
+
+### Enable Language Files
+if ( -d "/var/ipfire/langs/${language}/" ) {
+    opendir(DIR, "/var/ipfire/langs/${language}/");
+    @names = readdir(DIR) or die "Cannot Read Directory: $!\n";
+    foreach $name(@names) {
+        next if ($name eq ".");
+        next if ($name eq "..");
+        next if (!($name =~ /\.pl$/));
+        require "${swroot}/langs/${language}/${name}";
+    };
+};
+
+
+require "${swroot}/langs/en.pl";
+require "${swroot}/langs/${language}.pl";
+
+sub orange_used () {
+    if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
+       return 1;
+    }
+    return 0;
+}
+
+sub blue_used () {
+    if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
+       return 1;
+    }
+    return 0;
+}
+
+sub is_modem {
+    if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
+       return 1;
+    }
+    return 0;
+}
+
+### Initialize menu
+sub genmenu {
+    my %subsystemhash = ();
+    my $subsystem = \%subsystemhash;
+
+    $subsystem->{'01.home'} = {
+                             'caption' => $tr{'alt home'},
+                             'uri' => '/cgi-bin/index.cgi',
+                             'title' => "$tr{'alt home'}",
+                             'enabled' => 1,
+                             };
+    $subsystem->{'02.netwizard'} = {
+                                  'caption' => $tr{'network configuration'},
+                                  'uri' => '/cgi-bin/netwizard.cgi',
+                                  'title' => "$tr{'network configuration'}",
+                                  'enabled' => 1,
+                                  };
+    $subsystem->{'03.passwords'} = {
+                                  'caption' => $tr{'sspasswords'},
+                                  'uri' => '/cgi-bin/changepw.cgi',
+                                  'title' => "$tr{'sspasswords'}",
+                                  'enabled' => 1,
+                                  };
+    $subsystem->{'04.ssh'} = {
+                            'caption' => $tr{'ssh access'},
+                            'uri' => '/cgi-bin/remote.cgi',
+                            'title' => "$tr{'ssh access'}",
+                            'enabled' => 1,
+                            };
+    $subsystem->{'05.gui'} = {
+                             'caption' => $tr{'gui settings'},
+                             'uri' => '/cgi-bin/gui.cgi',
+                             'title' => "$tr{'gui settings'}",
+                             'enabled' => 1,
+                             };
+    $subsystem->{'06.backup'} = {
+                               'caption' => $tr{'backup'},
+                               'uri' => '/cgi-bin/backup.cgi',
+                               'title' => "$tr{'backup'} / $tr{'restore'}",
+                               'enabled' => 0,
+                               };
+    $subsystem->{'07.shutdown'} = {
+                                 'caption' => $tr{'shutdown'},
+                                 'uri' => '/cgi-bin/shutdown.cgi',
+                                 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
+                                 'enabled' => 1,
+                                 };
+    $subsystem->{'08.credits'} = {
+                                 'caption' => $tr{'credits'},
+                                 'uri' => '/cgi-bin/credits.cgi',
+                                 'title' => "$tr{'credits'}",
+                                 'enabled' => 1,
+                                 };
+
+    my %substatushash = ();
+    my $substatus = \%substatushash;
+    $substatus->{'01.systemstatus'} = {
+                                'caption' => $tr{'sssystem status'},
+                                'uri' => '/cgi-bin/status.cgi',
+                                'title' => "$tr{'system status information'}",
+                                'enabled' => 1,
+                                };
+    $substatus->{'02.networkstatus'} = {
+                                 'caption' => $tr{'ssnetwork status'},
+                                 'uri' => '/cgi-bin/netstatus.cgi',
+                                 'title' => "$tr{'network status information'}",
+                                 'enabled' => 1,
+                                 };
+    $substatus->{'03.systemgraphs'} = {
+                                      'caption' => $tr{'system graphs'},
+                                      'uri' => '/cgi-bin/graphs.cgi',
+                                      'novars' => 1,
+                                      'title' => "$tr{'system graphs'}",
+                                      'enabled' => 1,
+                                      };
+    $substatus->{'04.trafficgraphs'} = {
+                                       'caption' => $tr{'sstraffic graphs'},
+                                       'uri' => '/cgi-bin/graphs.cgi',
+                                       'vars' => 'graph=network',
+                                       'title' => "$tr{'network traffic graphs'}",
+                                       'enabled' => 1,
+                                       };
+    $substatus->{'05.proxygraphs'} = {
+                                     'caption' => $tr{'ssproxy graphs'},
+                                     'uri' => '/cgi-bin/proxygraphs.cgi',
+                                     'title' => "$tr{'proxy access graphs'}",
+                                     'enabled' => 1,
+                                     };
+    $substatus->{'06.connections'} = {
+                                     'caption' => $tr{'connections'},
+                                     'uri' => '/cgi-bin/connections.cgi',
+                                     'title' => "$tr{'connections'}",
+                                     'enabled' => 1,
+                                     };
+    $substatus->{'99.iptfilters'} = {
+                                     'caption' => $tr{'iptfilters iptable rules'},
+                                     'uri' => '/cgi-bin/iptfilters.cgi',
+                                     'title' => "$tr{'iptfilters iptable rules'}",
+                                     'enabled' => 1,
+                                     };
+
+    my %subnetworkhash = ();
+    my $subnetwork = \%subnetworkhash;
+
+    $subnetwork->{'01.dialup'} = {
+                                 'caption' => $tr{'alt dialup'},
+                                 'uri' => '/cgi-bin/pppsetup.cgi',
+                                 'title' => "$tr{'dialup settings'}",
+                                 'enabled' => 0,
+                                 };
+    $subnetwork->{'02.hosts'} = {
+                                'caption' => $tr{'edit hosts'},
+                                'uri' => '/cgi-bin/hosts.cgi',
+                                'title' => "$tr{'host configuration'}",
+                                'enabled' => 1,
+                                };
+    $subnetwork->{'03.upload'} = {
+                                 'caption' => $tr{'upload'},
+                                 'uri' => '/cgi-bin/upload.cgi',
+                                 'title' => "$tr{'firmware upload'}",
+                                 'enabled' => 0,
+                                 };
+    $subnetwork->{'04.aliases'} = {
+                                 'caption' => $tr{'aliases'},
+                                 'uri' => '/cgi-bin/aliases.cgi',
+                                 'title' => "$tr{'external aliases configuration'}",
+                                 'enabled' => 1,
+                                 };
+    $subnetwork->{'05.nettraf'} = {
+                                 'caption' => $tr{'sstraffic'},
+                                 'uri' => '/cgi-bin/traffic.cgi',
+                                 'title' => "$tr{'sstraffic'}",
+                                'enabled' => 1,
+                                 };
+    $subnetwork->{'06.fwhits'} = {
+                                 'caption' => 'Firewallhits',
+                                 'uri' => '/cgi-bin/fwhits.cgi',
+                                 'title' => "IPFire Firewallhits",
+                                'enabled' => 1,
+                                 };
+    $subnetwork->{'07.openvpn'} = {
+                                 'caption' => 'OpenVPN',
+                                 'uri' => '/cgi-bin/ovpnmain.cgi',
+                                 'title' => "$tr{'virtual private networking'}",
+                                'enabled' => 1,
+                                 };
+    $subnetwork->{'08.ipsec'} = {
+                                 'caption' => 'IPSec',
+                                 'uri' => '/cgi-bin/vpnmain.cgi',
+                                 'title' => "$tr{'virtual private networking'}",
+                                 'enabled' => 1,
+                                 };
+
+
+    my %subserviceshash = ();
+    my $subservices = \%subserviceshash;
+
+    $subservices->{'01.proxy'} = {
+                               'caption' => $tr{'proxy'},
+                               'uri' => '/cgi-bin/proxy.cgi',
+                               'title' => "HTTP: $tr{'web proxy configuration'}",
+                               'enabled' => 1,
+                               };
+    $subservices->{'02.dhcp'} = {
+                                'caption' => $tr{'dhcp server'},
+                                'uri' => '/cgi-bin/dhcp.cgi',
+                                'title' => "$tr{'dhcp configuration'}",
+                                'enabled' => 1,
+                                };
+    $subservices->{'03.dyndns'} = {
+                                  'caption' => $tr{'dynamic dns'},
+                                  'uri' => '/cgi-bin/ddns.cgi',
+                                  'title' => "$tr{'dynamic dns client'}",
+                                  'enabled' => 1,
+                                };
+    $subservices->{'04.time'} = {
+                                  'caption' => $tr{'time server'},
+                                  'uri' => '/cgi-bin/time.cgi',
+                                  'title' => "$tr{'time server'}",
+                                  'enabled' => 1,
+                                };
+    $subservices->{'05.qos'} = {
+                                   'caption' => 'Quality of Service',
+                                   'uri' => '/cgi-bin/qos.cgi',
+                                   'title' => "$tr{'traffic shaping settings'}",
+                                   'enabled' => 1,
+                                   };
+    $subservices->{'06.ids'} = {'caption' => $tr{'intrusion detection'},
+                               'enabled' => 1,
+                               'uri' => '/cgi-bin/ids.cgi',
+                               'title' => "$tr{'intrusion detection system'} (Snort)",
+                               };
+
+
+    my %subfirewallhash = ();
+    my $subfirewall = \%subfirewallhash;
+
+    
+    $subfirewall->{'01.dnat'} = {
+                                'caption' => $tr{'ssport forwarding'},
+                                'uri' => '/cgi-bin/portfw.cgi',
+                                'title' => "$tr{'port forwarding configuration'}",
+                                'enabled' => 1,
+                                };
+    $subfirewall->{'02.xtaccess'} = {
+                                'caption' => $tr{'external access'},
+                                'uri' => '/cgi-bin/xtaccess.cgi',
+                                'title' => "$tr{'external access configuration'}",
+                                'enabled' => 1,
+                                };
+    $subfirewall->{'03.dmz'} = {
+                               'caption' => $tr{'ssdmz pinholes'},
+                               'uri' => '/cgi-bin/dmzholes.cgi',
+                               'title' => "$tr{'dmz pinhole configuration'}",
+                               'enabled' => 1,
+                                };
+    $subfirewall->{'04.outgoing'} = {
+                                    'caption' => $tr{'outgoing firewall'},
+                                    'uri' => '/cgi-bin/outgoingfw.cgi',
+                                    'title' => "$tr{'outgoing firewall'}",
+                                    'enabled' => 1,
+                                    };
+    
+
+    my %sublogshash = ();
+    my $sublogs = \%sublogshash;
+
+    $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
+                                'uri' => '/cgi-bin/logs.cgi/summary.dat',
+                                'title' => "$tr{'log summary'}",
+                                'enabled' => 1
+                                };
+    $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
+                                'uri' => '/cgi-bin/logs.cgi/config.dat',
+                                'title' => "$tr{'log settings'}",
+                                'enabled' => 1
+                                };
+    $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
+                                'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
+                                'title' => "$tr{'proxy log viewer'}",
+                                'enabled' => 1
+                                };
+    $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
+                                'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
+                                'title' => "$tr{'firewall log viewer'}",
+                                'enabled' => 1
+                                };
+    $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
+                           'uri' => '/cgi-bin/logs.cgi/ids.dat',
+                           'title' => "$tr{'intrusion detection system log viewer'}",
+                           'enabled' => 1
+                           };
+    $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},
+                                     'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',
+                                     'title' => "$tr{'content filter log viewer'}",
+                                     'enabled' => 1
+                                     };
+    $sublogs->{'07.urlfilter'} = {
+                                     'caption' => $tr{'urlfilter log'},
+                                     'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
+                                     'title' => "$tr{'urlfilter log'}",
+                                     'enabled' => 1,
+                                      };
+    $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
+                                     'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
+                                     'title' => "$tr{'openvpn log'}",
+                                     'enabled' => 1
+                                     };
+    $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
+                                     'uri' => '/cgi-bin/logs.cgi/log.dat',
+                                     'title' => "$tr{'system log viewer'}",
+                                     'enabled' => 1
+                                     };
+    $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
+                                      'uri' => '/cgi-bin/logs.cgi/userlog.dat',
+                                      'title' => "$tr{'user log viewer'}",
+                                      'enabled' => 1
+                                       };
+
+    my %subipfirehash = ();
+    my $subipfire = \%subipfirehash;
+    $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
+                                 'uri' => '/cgi-bin/pakfire.cgi',
+                                 'title' => "$tr{'paketmanager'}",
+                                 'enabled' => 1,
+                                 };
+    $subipfire->{'02.asterisk'} = {'caption' => $tr{'asterisk'},
+                                 'uri' => '/cgi-bin/asterisk.cgi',
+                                 'title' => "$tr{'asterisk'}",
+                                 'enabled' => 1,
+                                 };
+    $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
+                                 'uri' => '/cgi-bin/samba.cgi',
+                                 'title' => "$tr{'samba'}",
+                                 'enabled' => 1,
+                                 };
+    $subipfire->{'99.help'} = {'caption' => $tr{'help'},
+                                 'uri' => '/cgi-bin/help.cgi',
+                                 'title' => "$tr{'help'}",
+                                 'enabled' => 1,
+                                 };
+
+
+
+    $menu->{'01.system'} = {'caption' => $tr{'alt system'},
+                           'enabled' => 1,
+                           'subMenu' => $subsystem
+                           };
+    $menu->{'02.status'} = {'caption' => $tr{'status'},
+                           'enabled' => 1,
+                           'subMenu' => $substatus
+                           };
+    $menu->{'03.network'} = {'caption' => $tr{'network'},
+                            'enabled' => 1,
+                            'subMenu' => $subnetwork
+                            };
+    $menu->{'04.services'} = {'caption' => $tr{'alt services'},
+                             'enabled' => 1,
+                             'subMenu' => $subservices
+                             };
+    $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
+                             'enabled' => 1,
+                             'subMenu' => $subfirewall
+                             };
+    $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
+                          'enabled' => 1,
+                          'subMenu' => $subproxy
+                          };
+    $menu->{'07.ipfire'} = {'caption' => 'IPFire',
+                        'enabled' => 1,
+                        'subMenu' => $subvpn
+                        };
+    $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
+                         'enabled' => 1,
+                         'subMenu' => $sublogs
+                         };
+
+    if (! blue_used() && ! orange_used()) {
+       $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;
+    }
+    if (-e '/etc/FLASH') {
+       $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0;  #disable squid
+       $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0;  #disable ids
+       $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0;  #disable ids
+    }
+}
+
+sub showhttpheaders
+{
+       print "Pragma: no-cache\n";
+       print "Cache-control: no-cache\n";
+       print "Connection: close\n";
+       print "Content-type: text/html\n\n";
+}
+
+sub is_menu_visible($) {
+    my $link = shift;
+    $link =~ s#\?.*$##;
+    return (-e $ENV{'DOCUMENT_ROOT'}."/../$link");
+}
+
+
+sub getlink($) {
+    my $root = shift;
+    if (! $root->{'enabled'}) {
+       return '';
+    }
+    if ($root->{'uri'} !~ /^$/) {
+       my $vars = '';
+       if ($root->{'vars'} !~ /^$/) {
+           $vars = '?'. $root->{'vars'};
+       }
+       if (! is_menu_visible($root->{'uri'})) {
+           return '';
+       }
+       return $root->{'uri'}.$vars;
+    }
+    my $submenus = $root->{'subMenu'};
+    if (! $submenus) {
+       return '';
+    }
+    foreach my $item (sort keys %$submenus) {
+       my $link = getlink($submenus->{$item});
+       if ($link ne '') {
+           return $link;
+       }
+    }
+    return '';
+}
+
+
+sub compare_url($) {
+    my $conf = shift;
+
+    my $uri = $conf->{'uri'};
+    my $vars = $conf->{'vars'};
+    my $novars = $conf->{'novars'};
+
+    if ($uri eq '') {
+       return 0;
+    }
+    if ($uri ne $URI[0]) {
+       return 0;
+    }
+    if ($novars) {
+       if ($URI[1] !~ /^$/) {
+           return 0;
+       }
+    }
+    if (! $vars) {
+       return 1;
+    }
+    return ($URI[1] eq $vars);
+}
+
+
+sub gettitle($) {
+    my $root = shift;
+
+    if (! $root) {
+       return '';
+    }
+    foreach my $item (sort keys %$root) {
+       my $val = $root->{$item};
+       if (compare_url($val)) {
+           $val->{'selected'} = 1;
+           if ($val->{'title'} !~ /^$/) {
+               return $val->{'title'};
+           }
+           return 'EMPTY TITLE';
+       }
+
+       my $title = gettitle($val->{'subMenu'});
+       if ($title ne '') {
+           $val->{'selected'} = 1;
+           return $title;
+       }
+    }
+    return '';
+}
+
+
+sub showmenu() {
+    print <<EOF
+  <div id="menu-top">
+    <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 class="selected">';
+       } else {
+           print '<li>';
+       }
+
+       print <<EOF
+    <div class="rcorner">
+      <a href="$link">$menu->{$k1}{'caption'}</a>
+    </div>
+  </li>
+EOF
+;
+    }
+
+    print <<EOF
+    </ul>
+  </div>
+EOF
+;    
+}
+
+sub getselected($) {
+    my $root = shift;
+    if (!$root) {
+       return 0;
+    }
+
+    foreach my $item (%$root) {
+       if ($root->{$item}{'selected'}) {
+           return $root->{$item};
+       }
+    }
+}
+
+sub showsubsection($$) {
+    my $root = shift;
+    my $id = shift;
+    if ($id eq '') {
+       $id = 'menu-left';
+    }
+
+    if (! $root) {
+       return;
+    }
+    my $selected = getselected($root);
+    if (! $selected) {
+       return;
+    }
+    my $submenus = $selected->{'subMenu'};
+    if (! $submenus) {
+       return;
+    }
+
+    print <<EOF
+  <div id="$id">
+    <ul>
+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>';
+       }
+
+       print <<EOF
+      <a href="$link">$hash->{'caption'}</a>
+  </li>
+EOF
+;
+    }
+
+    print <<EOF
+    </ul>
+  </div>
+EOF
+;    
+
+}
+
+
+sub showsubsubsection($) {
+    my $root = shift;
+    if (!$root) {
+       return;
+    }
+    my $selected = getselected($root);
+    if (! $selected) {
+       return
+    }
+    if (! $selected->{'subMenu'}) {
+       return
+    }
+
+    showsubsection($selected->{'subMenu'}, 'menu-subtop');
+}
+
+
+sub get_helpuri() {
+    my $helpfile = '';
+    if ($URI[0] =~ /.*\/([^\/]+)\.cgi/) {
+       $helpfile = $1;
+    } else {
+       return '';
+    }
+    $helpfile .= '.help.html';
+
+    my $helpuri = '/doc/'.$language.'/'.$helpfile;
+    if (! -e $ENV{'DOCUMENT_ROOT'}.$helpuri) {
+       return '';
+    }
+    return $helpuri;
+}
+
+
+sub openpage {
+    my $title = shift;
+    my $boh = shift;
+    my $extrahead = shift;
+
+    @URI=split ('\?',  $ENV{'REQUEST_URI'} );
+    &readhash("${swroot}/main/settings", \%settings);
+    &genmenu();
+
+    my $h2 = gettitle($menu);
+    my $helpuri = get_helpuri();
+
+    $title = "IPFire - $title";
+    if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
+        $title =  "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title"; 
+    }
+
+    print <<END
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+  <head>
+  <title>$title</title>
+
+    $extrahead
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+    <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
+    <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
+    <link rel="shortcut icon" href="/favicon.ico" />
+    <style type="text/css">\@import url(/include/style.css);</style>
+    <style type="text/css">\@import url(/include/menu.css);</style>
+    <style type="text/css">\@import url(/include/content.css);</style>
+    <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'
+           }
+        }
+    </script>
+
+  </head>
+  <body>
+<!-- IPFIRE HEADER -->
+
+<div id="main">
+
+<div id="header">
+       <img id="logo-product" src="/images/logo_ipfire.gif">
+   <div id="header-icons">
+END
+;
+
+    if ($helpuri ne '') {
+       print <<END
+           <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
+END
+;
+    } else {
+       print '<img src="/images/help.gif">';
+    }
+
+print <<END
+   </div>
+</div>
+
+END
+;
+
+    &showmenu();
+
+print <<END
+<div id="content">
+  <table width="90%">
+    <tr>
+      <td valign="top">
+END
+;
+       
+    &showsubsection($menu);
+
+    print <<END
+
+      </td>
+        <td width="100%" valign="top">
+        <div id="page-content">
+            <h2>$h2</h2>
+END
+    ;
+    
+    &showsubsubsection($menu);
+
+    eval {
+       require 'ipfire-network.pl';
+       $supported = check_support();
+       warn_unsupported($supported);
+    };
+}
+
+sub closepage () {
+    my $status = &connectionstatus();
+    $uptime = `/usr/bin/uptime`;
+       
+    print <<END
+         <div align="center">
+            <p>
+             <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
+            </p>
+          </div>
+       </body>
+</html>
+END
+;
+}
+
+sub openbigbox
+{
+    my $width = $_[0];
+    my $align = $_[1];
+    my $sideimg = $_[2];
+
+    if ($errormessage) {
+       $bgcolor = "style='background-color: $colourerr;'";
+    } else {
+       $bgcolor = '';
+    }
+}
+
+sub closebigbox
+{
+#      print "</td></tr></table></td></tr></table>\n" 
+}
+
+sub openbox
+{
+       $width = $_[0];
+       $align = $_[1];
+       $caption = $_[2];
+
+       if ($caption) { print "<h3>$caption</h3>\n"; } else { print "&nbsp;"; }
+       
+       print "<table class=\"list\"><tr><td align=\"$align\">\n";
+}
+
+sub closebox
+{
+       print "</td></tr></table><br><br>";
+}
+
+sub writehash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       
+       # write cgi vars to the file.
+       open(FILE, ">${filename}") or die "Unable to write file $filename";
+       flock FILE, 2;
+       foreach $var (keys %$hash) 
+       {
+               $val = $hash->{$var};
+               # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
+               # location of the mouse are submitted as well, this was being written to the settings file causing
+               # some serious grief! This skips the variable.x and variable.y
+               if (!($var =~ /(.x|.y)$/)) {
+                       if ($val =~ / /) {
+                               $val = "\'$val\'"; }
+                       if (!($var =~ /^ACTION/)) {
+                               print FILE "${var}=${val}\n"; }
+               }
+       }
+       close FILE;
+}
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       open(FILE, $filename) or die "Unable to read file $filename";
+       
+       while (<FILE>)
+       {
+               chop;
+               ($var, $val) = split /=/, $_, 2;
+               if ($var)
+               {
+                       $val =~ s/^\'//g;
+                       $val =~ s/\'$//g;
+
+                       # Untaint variables read from hash
+                       $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                       $val =~ /([\w\W]*)/; $val = $1;
+                       $hash->{$var} = $val;
+               }
+       }
+       close FILE;
+}
+
+sub getcgihash {
+       my ($hash, $params) = @_;
+       my $cgi = CGI->new ();
+       $hash->{'__CGI__'} = $cgi;
+       return if ($ENV{'REQUEST_METHOD'} ne 'POST');
+       if (!$params->{'wantfile'}) {
+               $CGI::DISABLE_UPLOADS = 1;
+               $CGI::POST_MAX        = 512 * 1024;
+       } else {
+               $CGI::POST_MAX = 10 * 1024 * 1024;
+       }
+
+       $cgi->referer() =~ m/^https?\:\/\/([^\/]+)/;
+       my $referer = $1;
+       $cgi->url() =~ m/^https?\:\/\/([^\/]+)/;
+       my $servername = $1;
+       return if ($referer ne $servername);
+
+       ### Modified for getting multi-vars, split by |
+       %temp = $cgi->Vars();
+        foreach my $key (keys %temp) {
+               $hash->{$key} = $temp{$key};
+               $hash->{$key} =~ s/\0/|/g;
+               $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
+        }
+
+       if (($params->{'wantfile'})&&($params->{'filevar'})) {
+               $hash->{$params->{'filevar'}} = $cgi->upload
+                                               ($params->{'filevar'});
+       }
+       return;
+}
+
+sub log
+{
+       my $logmessage = $_[0];
+       $logmessage =~ /([\w\W]*)/;
+       $logmessage = $1;
+       system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
+}
+
+sub age
+{
+       my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
+               $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
+       my $now = time;
+
+       my $totalsecs = $now - $mtime;
+       my $days = int($totalsecs / 86400);
+       my $totalhours = int($totalsecs / 3600);
+       my $hours = $totalhours % 24;
+       my $totalmins = int($totalsecs / 60);
+       my $mins = $totalmins % 60;
+       my $secs = $totalsecs % 60;
+
+       return "${days}d ${hours}h ${mins}m ${secs}s";
+}
+
+sub validip
+{
+       my $ip = $_[0];
+
+       if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
+               return 0; }
+       else 
+       {
+               @octets = ($1, $2, $3, $4);
+               foreach $_ (@octets)
+               {
+                       if (/^0./) {
+                               return 0; }
+                       if ($_ < 0 || $_ > 255) {
+                               return 0; }
+               }
+               return 1;
+       }
+}
+
+sub validmask
+{
+       my $mask = $_[0];
+
+       # secord part an ip?
+       if (&validip($mask)) {
+               return 1; }
+       # second part a number?
+       if (/^0/) {
+               return 0; }
+       if (!($mask =~ /^\d+$/)) {
+               return 0; }
+       if ($mask >= 0 && $mask <= 32) {
+               return 1; }
+       return 0;
+}
+
+sub validipormask
+{
+       my $ipormask = $_[0];
+
+       # see if it is a IP only.
+       if (&validip($ipormask)) {
+               return 1; }
+       # split it into number and mask.
+       if (!($ipormask =~ /^(.*?)\/(.*?)$/)) {
+               return 0; }
+       $ip = $1;
+       $mask = $2;
+       # first part not a ip?
+       if (!(&validip($ip))) {
+               return 0; }
+       return &validmask($mask);
+}
+
+sub validipandmask
+{
+       my $ipandmask = $_[0];
+
+       # split it into number and mask.
+       if (!($ipandmask =~ /^(.*?)\/(.*?)$/)) {
+               return 0; }
+       $ip = $1;
+       $mask = $2;
+       # first part not a ip?
+       if (!(&validip($ip))) {
+               return 0; }
+       return &validmask($mask);
+}
+
+sub validport
+{
+       $_ = $_[0];
+
+       if (!/^\d+$/) {
+               return 0; }
+       if (/^0./) {
+               return 0; }
+       if ($_ >= 1 && $_ <= 65535) {
+               return 1; }
+       return 0;
+}
+
+sub validmac
+{
+       my $checkmac = $_[0];
+       my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
+       if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
+       {
+               return 0;
+       }
+       return 1;
+}
+
+sub validhostname
+{
+       # Checks a hostname against RFC1035
+        my $hostname = $_[0];
+
+       # Each part should be at least two characters in length
+       # but no more than 63 characters
+       if (length ($hostname) < 2 || length ($hostname) > 63) {
+               return 0;}
+       # Only valid characters are a-z, A-Z, 0-9 and -
+       if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
+               return 0;}
+       # First character can only be a letter or a digit
+       if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
+               return 0;}
+       # Last character can only be a letter or a digit
+       if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
+               return 0;}
+       return 1;
+}
+
+sub validdomainname
+{
+       # Checks a domain name against RFC1035
+        my $domainname = $_[0];
+       my @parts = split (/\./, $domainname);  # Split hostname at the '.'
+
+       foreach $part (@parts) {
+               # Each part should be at least two characters in length
+               # but no more than 63 characters
+               if (length ($part) < 2 || length ($part) > 63) {
+                       return 0;}
+               # Only valid characters are a-z, A-Z, 0-9 and -
+               if ($part !~ /^[a-zA-Z0-9-]*$/) {
+                       return 0;}
+               # First character can only be a letter or a digit
+               if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
+                       return 0;}
+               # Last character can only be a letter or a digit
+               if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
+                       return 0;}
+       }
+       return 1;
+}
+
+sub validfqdn
+{
+       # Checks a fully qualified domain name against RFC1035
+        my $fqdn = $_[0];
+       my @parts = split (/\./, $fqdn);        # Split hostname at the '.'
+       if (scalar(@parts) < 2) {               # At least two parts should
+               return 0;}                      # exist in a FQDN
+                                               # (i.e. hostname.domain)
+       foreach $part (@parts) {
+               # Each part should be at least two characters in length
+               # but no more than 63 characters
+               if (length ($part) < 2 || length ($part) > 63) {
+                       return 0;}
+               # Only valid characters are a-z, A-Z, 0-9 and -
+               if ($part !~ /^[a-zA-Z0-9-]*$/) {
+                       return 0;}
+               # First character can only be a letter or a digit
+               if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
+                       return 0;}
+               # Last character can only be a letter or a digit
+               if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
+                       return 0;}
+       }
+       return 1;
+}
+
+sub validportrange # used to check a port range 
+{
+       my $port = $_[0]; # port values
+       $port =~ tr/-/:/; # replace all - with colons just in case someone used -
+       my $srcdst = $_[1]; # is it a source or destination port
+
+       if (!($port =~ /^(\d+)\:(\d+)$/)) {
+       
+               if (!(&validport($port))) {      
+                       if ($srcdst eq 'src'){
+                               return $tr{'source port numbers'};
+                       } else  {
+                               return $tr{'destination port numbers'};
+                       } 
+               }
+       }
+       else 
+       {
+               @ports = ($1, $2);
+               if ($1 >= $2){
+                       if ($srcdst eq 'src'){
+                               return $tr{'bad source range'};
+                       } else  {
+                               return $tr{'bad destination range'};
+                       } 
+               }
+               foreach $_ (@ports)
+               {
+                       if (!(&validport($_))) {
+                               if ($srcdst eq 'src'){
+                                       return $tr{'source port numbers'}; 
+                               } else  {
+                                       return $tr{'destination port numbers'};
+                               } 
+                       }
+               }
+               return;
+       }
+}
+
+# Test if IP is within a subnet
+# Call: IpInSubnet (Addr, Subnet, Subnet Mask)
+#       Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
+#       Everything in dottted notation
+# Return: TRUE/FALSE
+sub IpInSubnet
+{
+    $ip = unpack('N', inet_aton(shift));
+    $start = unpack('N', inet_aton(shift));
+    $mask  = unpack('N', inet_aton(shift));
+    $start &= $mask;  # base of subnet...
+    $end   = $start + ~$mask;
+    return (($ip >= $start) && ($ip <= $end));
+}
+
+sub validemail {
+    my $mail = shift;
+    return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
+    return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
+    return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
+    return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
+    return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
+    return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
+    return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
+    return 1;
+}
+
+sub readhasharray {
+    my ($filename, $hash) = @_;
+
+    open(FILE, $filename) or die "Unable to read file $filename";
+
+    while (<FILE>) {
+       my ($key, $rest, @temp);
+       chomp;
+       ($key, $rest) = split (/,/, $_, 2);
+       if ($key =~ /^[0-9]+$/ && $rest) {
+           @temp = split (/,/, $rest);
+           $hash->{$key} = \@temp;
+        }
+    }
+    close FILE;
+    return;
+}
+
+sub writehasharray {
+    my ($filename, $hash) = @_;
+    my ($key, @temp);
+
+    open(FILE, ">$filename") or die "Unable to write to file $filename";
+
+    foreach $key (keys %$hash) {
+       if ( $hash->{$key} ) {
+           print FILE "$key";
+           foreach $i (0 .. $#{$hash->{$key}}) {
+               print FILE ",$hash->{$key}[$i]";
+           }
+       }
+       print FILE "\n";
+    }
+    close FILE;
+    return;
+}
+
+sub findhasharraykey {
+    foreach my $i (1 .. 1000000) {
+       if ( ! exists $_[0]{$i}) {
+            return $i;
+       }
+    }
+}
+
+sub cleanhtml
+{
+       my $outstring =$_[0];
+       $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
+       $outstring =~ s/&/&amp;/g;
+       $outstring =~ s/\'/&#039;/g;
+       $outstring =~ s/\"/&quot;/g;
+       $outstring =~ s/</&lt;/g;
+       $outstring =~ s/>/&gt;/g;
+       return $outstring;
+}
+sub connectionstatus
+{
+        my $status;
+        opendir UPLINKS, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
+                foreach my $uplink (sort grep !/^\./, readdir UPLINKS) {
+                    if ( -f "${swroot}/uplinks/${uplink}/active") {
+                        if ( ! $status ) {
+                                $timestr = &age("${swroot}/uplinks/${uplink}/active");
+                                $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
+                        } else {
+                                $timestr = &age("${swroot}/uplinks/${uplink}/active");
+                                $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
+                        }
+                    } elsif ( -f "${swroot}/uplinks/${uplink}/connecting") {
+                        if ( ! $status ) {
+                                $status = "$tr{'connecting'} $uplink";
+                        } else {
+                                $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
+                        }
+                    }
+                    $lines++;
+                }
+                closedir(UPLINKS);
+                if ( ! $status ) {
+                        $status = "$tr{'idle'}";
+                }
+                $connstate = "<span class='ipcop_StatusBig'>$status</span>";
+    return $connstate;
+}
+
+sub srtarray 
+# Darren Critchley - darrenc@telus.net - (c) 2003
+# &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
+# This subroutine will take the following parameters:
+#   ColumnNumber = the column which you want to sort on, starts at 1
+#   AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
+#   SortDirection = asc or dsc (lowercase) Ascending or Descending sort
+#   ArrayToBeSorted = the array that wants sorting
+#
+#   Returns an array that is sorted to your specs
+#
+#   If SortOrder is greater than the elements in array, then it defaults to the first element
+# 
+{
+       my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
+       my @tmparray;
+       my @srtedarray;
+       my $line;
+       my $newline;
+       my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
+       if ($ttlitems < 1){ # if no items, don't waste our time lets leave
+               return (@tobesorted);
+       }
+       my @tmp = split(/\,/,$tobesorted[0]);
+       $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
+
+       # Darren Critchley - validate parameters
+       if ($colno > $ttlitems){$colno = '1';}
+       $colno--; # remove one from colno to deal with arrays starting at 0
+       if($colno < 0){$colno = '0';}
+       if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
+       if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
+
+       foreach $line (@tobesorted)
+       {
+               chomp($line);
+               if ($line ne '') {
+                       my @temp = split(/\,/,$line);
+                       # Darren Critchley - juggle the fields so that the one we want to sort on is first
+                       my $tmpholder = $temp[0];
+                       $temp[0] = $temp[$colno];
+                       $temp[$colno] = $tmpholder;
+                       $newline = "";
+                       for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
+                               $newline=$newline . $temp[$ctr] . ",";
+                       }
+                       chop($newline);
+                       push(@tmparray,$newline);
+               }
+       }
+       if ($alpnum eq 'n') {
+               @tmparray = sort {$a <=> $b} @tmparray;
+       } else {
+               @tmparray = (sort @tmparray);
+       }
+       foreach $line (@tmparray)
+       {
+               chomp($line);
+               if ($line ne '') {
+                       my @temp = split(/\,/,$line);
+                       my $tmpholder = $temp[0];
+                       $temp[0] = $temp[$colno];
+                       $temp[$colno] = $tmpholder;
+                       $newline = "";
+                       for ($ctr=0; $ctr < $ttlitems ; $ctr++){
+                               $newline=$newline . $temp[$ctr] . ",";
+                       }
+                       chop($newline);
+                       push(@srtedarray,$newline);
+               }
+       }
+
+       if ($srtdir eq 'dsc') {
+               @tmparray = reverse(@srtedarray);
+               return (@tmparray);
+       } else {
+               return (@srtedarray);
+       }
+}
+
+sub speedtouchversion
+{
+       if (-f "/proc/bus/usb/devices")
+       {
+               $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
+               if ($speedtouch eq '') {
+                       $speedtouch= $tr{'connect the modem'};
+               }
+       } else {
+               $speedtouch='USB '.$tr{'not running'};
+       }
+       return $speedtouch
+}
+
+sub CheckSortOrder {
+#Sorting of allocated leases
+    if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
+       my $newsort=$ENV{'QUERY_STRING'};
+        &readhash("${swroot}/dhcp/settings", \%dhcpsettings);
+        $act=$dhcpsettings{'SORT_LEASELIST'};
+        #Reverse actual ?
+        if ($act =~ $newsort) {
+            if ($act !~ 'Rev') {$Rev='Rev'};
+            $newsort.=$Rev
+        };
+
+        $dhcpsettings{'SORT_LEASELIST'}=$newsort;
+       &writehash("${swroot}/dhcp/settings", \%dhcpsettings);
+        $dhcpsettings{'ACTION'} = 'SORT';  # avoid the next test "First lauch"
+    }
+
+}
+
+sub PrintActualLeases
+{
+    &openbox('100%', 'left', $tr{'current dynamic leases'});
+    print <<END
+<table width='100%'>
+<tr>
+<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
+<td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
+<td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
+<td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
+</tr>
+END
+    ;
+
+    open(LEASES,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
+    while ($line = <LEASES>) {
+       next if( $line =~ /^\s*#/ );
+       chomp($line);
+       @temp = split (' ', $line);
+
+       if ($line =~ /^\s*lease/) {
+           $ip = $temp[1];
+           #All field are not necessarily read. Clear everything
+           $endtime = 0;
+           $ether = "";
+           $hostname = "";
+       }
+
+       if ($line =~ /^\s*ends/) {
+           $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
+           $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
+       }
+
+       if ($line =~ /^\s*hardware ethernet/) {
+           $ether = $temp[2];
+           $ether =~ s/;//g;
+       }
+
+       if ($line =~ /^\s*client-hostname/) {
+           $hostname = "$temp[1] $temp[2] $temp[3]";
+           $hostname =~ s/;//g;
+           $hostname =~ s/\"//g;
+       }
+
+       if ($line eq "}") {
+           @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
+           $record = {};                                       # create a reference to empty hash
+           %{$record} = @record;                               # populate that hash with @record
+           $entries{$record->{'IPADDR'}} = $record;    # add this to a hash of hashes
+       }
+    }
+    close(LEASES);
+
+    my $id = 0;
+    foreach my $key (sort leasesort keys %entries) {
+
+       my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y");
+
+       if ($id % 2) {
+           print "<tr bgcolor='$table1colour'>"; 
+       }
+       else {
+           print "<tr bgcolor='$table2colour'>"; 
+       }
+
+       print <<END
+<td align='center'>$entries{$key}->{IPADDR}</td>
+<td align='center'>$entries{$key}->{ETHER}</td>
+<td align='center'>&nbsp;$hostname </td>
+<td align='center'>
+END
+       ;
+
+       ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME});
+       $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
+
+       if ($entries{$key}->{ENDTIME} < time() ){
+           print "<strike>$enddate</strike>";
+       } else {
+           print "$enddate";
+       }
+       print "</td></tr>";
+       $id++;
+    }
+
+    print "</table>";
+    &closebox();
+}
+
+
+# This sub is used during display of actives leases
+sub leasesort {
+    if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
+    {
+        $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
+        if ($qs eq 'IPADDR') {
+            @a = split(/\./,$entries{$a}->{$qs});
+            @b = split(/\./,$entries{$b}->{$qs});
+            ($b[0]<=>$a[0]) ||
+            ($b[1]<=>$a[1]) ||
+            ($b[2]<=>$a[2]) ||
+            ($b[3]<=>$a[3]);
+        }else {
+            $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
+        }
+    }
+    else #not reverse
+    {
+        $qs=$dhcpsettings{'SORT_LEASELIST'};
+        if ($qs eq 'IPADDR') {
+           @a = split(/\./,$entries{$a}->{$qs});
+           @b = split(/\./,$entries{$b}->{$qs});
+           ($a[0]<=>$b[0]) ||
+           ($a[1]<=>$b[1]) ||
+           ($a[2]<=>$b[2]) ||
+           ($a[3]<=>$b[3]);
+       }else {
+           $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
+       }
+    }
+}
+
+sub get_uplinks() {
+    my @uplinks = ();
+    opendir(DIR, "${swroot}/uplinks/") || return \@uplinks;
+    foreach my $dir (readdir(DIR)) {
+       next if ($dir =~ /^\./);
+       next if (-f "${swroot}/uplinks/$dir");
+       push(@uplinks, $dir);
+    }
+    closedir(DIR);
+    return \@uplinks;
+}
+
+sub get_iface($) {
+    my $filename = shift;
+    chomp($filename);
+    open (F, $filename) || return "";
+    my $iface = <F>;
+    close(F);
+    chomp($iface);
+    return $iface;
+}
+
+sub get_red_ifaces_by_type($) {
+    my $type=shift;
+    my @gottypeiface = ();
+    my @gottypeuplink = ();
+    my @gottype = ();
+
+    my $ref=get_uplinks();
+    my @uplinks=@$ref;
+    my %set = ();
+    foreach my $link (@uplinks) {
+       eval {
+           &readhash("${swroot}/uplinks/$link/settings", \%set);
+       };
+       push(@gottype, $link);
+
+       my $iface = $set{'RED_DEV'};
+       if (!$iface) {
+           $iface = get_iface("${swroot}/uplinks/$link/interface");
+       }
+       next if (!$iface);
+
+       if ($set{'RED_TYPE'} eq $type) {
+           push(@gottypeiface, $iface);
+           push(@gottypeuplink, $link);
+       }
+    }
+    return (\@gottypeiface, \@gottypeuplink, \@gottype);
+}
+
+sub get_red_ifaces() {
+    return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
+}
+
+sub get_zone_devices($) {
+    my $bridge = shift;
+    my @ifaces = ();
+    open (FILE, "${swroot}/ethernet/$bridge") || return "";
+    foreach my $line (<FILE>) {
+       chomp($line);
+       next if (!$line);
+       push(@ifaces, $line);
+    }
+    close(FILE);
+    return \@ifaces;
+}