]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/cfgroot/header.pl
3 # This code is distributed under the terms of the GPL
5 # (c) The SmoothWall Team
6 # Copyright (C) 2002 Alex Hudson - getcgihash() rewrite
7 # Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()
8 # Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions
9 # Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()
10 # Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()
12 # $Id: header.pl,v 1.34.2.39 2004/11/26 15:51:27 alanh Exp $
20 $|=1; # line buffering
23 my $read_ver = `cat /etc/ipfire-release`;
24 if ($read_ver =~ /^$/) {
25 return "IPFire (unknown version)";
30 $Header::version
= get_version
();
31 $Header::revision
= 'final';
32 $Header::swroot
= '/var/ipfire';
33 $Header::pagecolour
= '#ffffff';
34 #$Header::tablecolour = '#a0a0a0';
35 $Header::tablecolour
= '#FFFFFF';
36 $Header::bigboxcolour
= '#F6F4F4';
37 $Header::boxcolour
= '#EAE9EE';
38 $Header::bordercolour
= '#000000';
39 $Header::table1colour
= '#E0E0E0';
40 $Header::table2colour
= '#F0F0F0';
41 $Header::colourred
= '#993333';
42 $Header::colourorange
= '#FF9933';
43 $Header::colouryellow
= '#FFFF00';
44 $Header::colourgreen
= '#339933';
45 $Header::colourblue
= '#333399';
46 $Header::colourfw
= '#000000';
47 $Header::colourvpn
= '#990099';
48 $Header::colourerr
= '#FF0000';
49 $Header::viewsize
= 150;
50 $Header::errormessage
= '';
52 my $menu = \
%menuhash;
58 ### Make sure this is an SSL request
59 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
60 print "Status: 302 Moved\r\n";
61 print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";
65 ### Initialize environment
66 &readhash
("${swroot}/main/settings", \
%settings);
67 &readhash
("${swroot}/ethernet/settings", \
%ethsettings);
68 $language = $settings{'LANGUAGE'};
69 $hostname = $settings{'HOSTNAME'};
72 ### Initialize language
73 if ($language =~ /^(\w+)$/) {$language = $1;}
75 ### Read English Files
76 if ( -d
"/var/ipfire/langs/en/" ) {
77 opendir(DIR
, "/var/ipfire/langs/en/");
78 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
79 foreach $name(@names) {
80 next if ($name eq ".");
81 next if ($name eq "..");
82 next if (!($name =~ /\.pl$/));
83 require "${swroot}/langs/en/${name}";
88 ### Enable Language Files
89 if ( -d
"/var/ipfire/langs/${language}/" ) {
90 opendir(DIR
, "/var/ipfire/langs/${language}/");
91 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
92 foreach $name(@names) {
93 next if ($name eq ".");
94 next if ($name eq "..");
95 next if (!($name =~ /\.pl$/));
96 require "${swroot}/langs/${language}/${name}";
101 require "${swroot}/langs/en.pl";
102 require "${swroot}/langs/${language}.pl";
105 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
112 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
119 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
127 my %subsystemhash = ();
128 my $subsystem = \
%subsystemhash;
130 $subsystem->{'01.home'} = {
131 'caption' => $tr{'alt home'},
132 'uri' => '/cgi-bin/index.cgi',
133 'title' => "$tr{'alt home'}",
136 $subsystem->{'02.netwizard'} = {
137 'caption' => $tr{'network configuration'},
138 'uri' => '/cgi-bin/netwizard.cgi',
139 'title' => "$tr{'network configuration'}",
142 $subsystem->{'03.updates'} = {
143 'caption' => $tr{'updates'},
144 'uri' => '/cgi-bin/updates.cgi',
145 'title' => "$tr{'updates'}",
148 $subsystem->{'04.passwords'} = {
149 'caption' => $tr{'sspasswords'},
150 'uri' => '/cgi-bin/changepw.cgi',
151 'title' => "$tr{'sspasswords'}",
154 $subsystem->{'05.ssh'} = {
155 'caption' => $tr{'ssh access'},
156 'uri' => '/cgi-bin/remote.cgi',
157 'title' => "$tr{'ssh access'}",
160 $subsystem->{'06.gui'} = {
161 'caption' => $tr{'gui settings'},
162 'uri' => '/cgi-bin/gui.cgi',
163 'title' => "$tr{'gui settings'}",
166 $subsystem->{'07.backup'} = {
167 'caption' => $tr{'backup'},
168 'uri' => '/cgi-bin/backup.cgi',
169 'title' => "$tr{'backup'} / $tr{'restore'}",
172 $subsystem->{'08.shutdown'} = {
173 'caption' => $tr{'shutdown'},
174 'uri' => '/cgi-bin/shutdown.cgi',
175 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
178 $subsystem->{'09.credits'} = {
179 'caption' => $tr{'credits'},
180 'uri' => '/cgi-bin/credits.cgi',
181 'title' => "$tr{'credits'}",
185 my %substatushash = ();
186 my $substatus = \
%substatushash;
187 $substatus->{'01.systemstatus'} = {
188 'caption' => $tr{'sssystem status'},
189 'uri' => '/cgi-bin/status.cgi',
190 'title' => "$tr{'system status information'}",
193 $substatus->{'02.networkstatus'} = {
194 'caption' => $tr{'ssnetwork status'},
195 'uri' => '/cgi-bin/netstatus.cgi',
196 'title' => "$tr{'network status information'}",
199 $substatus->{'03.systemgraphs'} = {
200 'caption' => $tr{'system graphs'},
201 'uri' => '/cgi-bin/graphs.cgi',
203 'title' => "$tr{'system graphs'}",
206 $substatus->{'04.trafficgraphs'} = {
207 'caption' => $tr{'sstraffic graphs'},
208 'uri' => '/cgi-bin/graphs.cgi',
209 'vars' => 'graph=network',
210 'title' => "$tr{'network traffic graphs'}",
213 $substatus->{'05.proxygraphs'} = {
214 'caption' => $tr{'ssproxy graphs'},
215 'uri' => '/cgi-bin/proxygraphs.cgi',
216 'title' => "$tr{'proxy access graphs'}",
219 $substatus->{'06.connections'} = {
220 'caption' => $tr{'connections'},
221 'uri' => '/cgi-bin/connections.cgi',
222 'title' => "$tr{'connections'}",
225 $substatus->{'99.iptfilters'} = {
226 'caption' => $tr{'iptfilters iptable rules'},
227 'uri' => '/cgi-bin/iptfilters.cgi',
228 'title' => "$tr{'iptfilters iptable rules'}",
232 my %subnetworkhash = ();
233 my $subnetwork = \
%subnetworkhash;
235 $subnetwork->{'01.dialup'} = {
236 'caption' => $tr{'alt dialup'},
237 'uri' => '/cgi-bin/pppsetup.cgi',
238 'title' => "$tr{'dialup settings'}",
241 $subnetwork->{'02.hosts'} = {
242 'caption' => $tr{'edit hosts'},
243 'uri' => '/cgi-bin/hosts.cgi',
244 'title' => "$tr{'host configuration'}",
247 $subnetwork->{'03.upload'} = {
248 'caption' => $tr{'upload'},
249 'uri' => '/cgi-bin/upload.cgi',
250 'title' => "$tr{'firmware upload'}",
253 $subnetwork->{'04.aliases'} = {
254 'caption' => $tr{'aliases'},
255 'uri' => '/cgi-bin/aliases.cgi',
256 'title' => "$tr{'external aliases configuration'}",
261 my %subserviceshash = ();
262 my $subservices = \
%subserviceshash;
264 $subservices->{'01.dhcp'} = {
265 'caption' => $tr{'dhcp server'},
266 'uri' => '/cgi-bin/dhcp.cgi',
267 'title' => "$tr{'dhcp configuration'}",
270 $subservices->{'02.dyndns'} = {
271 'caption' => $tr{'dynamic dns'},
272 'uri' => '/cgi-bin/ddns.cgi',
273 'title' => "$tr{'dynamic dns client'}",
276 $subservices->{'03.time'} = {
277 'caption' => $tr{'time server'},
278 'uri' => '/cgi-bin/time.cgi',
279 'title' => "$tr{'time server'}",
282 $subservices->{'04.shaping'} = {
283 'caption' => $tr{'traffic shaping'},
284 'uri' => '/cgi-bin/shaping.cgi',
285 'title' => "$tr{'traffic shaping settings'}",
288 $subservices->{'05.ids'} = {'caption' => $tr{'intrusion detection'},
290 'uri' => '/cgi-bin/ids.cgi',
291 'title' => "$tr{'intrusion detection system'} (Snort)",
295 my %subfirewallhash = ();
296 my $subfirewall = \
%subfirewallhash;
299 $subfirewall->{'01.dnat'} = {
300 'caption' => $tr{'ssport forwarding'},
301 'uri' => '/cgi-bin/portfw.cgi',
302 'title' => "$tr{'port forwarding configuration'}",
305 $subfirewall->{'02.xtaccess'} = {
306 'caption' => $tr{'external access'},
307 'uri' => '/cgi-bin/xtaccess.cgi',
308 'title' => "$tr{'external access configuration'}",
311 $subfirewall->{'03.dmz'} = {
312 'caption' => $tr{'ssdmz pinholes'},
313 'uri' => '/cgi-bin/dmzholes.cgi',
314 'title' => "$tr{'dmz pinhole configuration'}",
317 $subfirewall->{'04.outgoing'} = {
318 'caption' => $tr{'outgoing firewall'},
319 'uri' => '/cgi-bin/outgoingfw.cgi',
320 'title' => "$tr{'outgoing firewall'}",
326 my %subhttphash = ();
327 my $subhttp = \
%subhttphash;
328 $subhttp->{'01.proxy'} = {
329 'caption' => $tr{'proxy'},
330 'uri' => '/cgi-bin/advproxy.cgi',
331 'title' => "HTTP: $tr{'web proxy configuration'}",
334 $subhttp->{'02.contentfilter'} = {
335 'caption' => $tr{'content filter'},
336 'uri' => '/cgi-bin/dansguardian.cgi',
337 'title' => "HTTP: $tr{'content filter'}",
340 $subhttp->{'03.antivirus'} = {
341 'caption' => $tr{'antivirus'},
342 'uri' => '/cgi-bin/httpantivirus.cgi',
343 'title' => "HTTP: $tr{'antivirus'}",
346 $subhttp->{'04.proxymanagment'} = {
347 'caption' => $tr{'DS Managment'},
348 'uri' => '/cgi-bin/proxygm.cgi',
349 'title' => "HTTP: $tr{'DS Managment'}",
352 $subhttp->{'05.activatedgroups'} = {
353 'caption' => $tr{'activated Groups'},
354 'uri' => '/cgi-bin/proxyag.cgi',
355 'title' => "HTTP: $tr{'activated Groups'}",
358 $subhttp->{'06.advancedproxy'} = {
359 'caption' => $tr{'Proxy Advanced'},
360 'uri' => '/cgi-bin/proxyad.cgi',
361 'title' => "HTTP: $tr{'Proxy Advanced'}",
366 my %subproxyhash = ();
367 my $subproxy = \
%subproxyhash;
369 $subproxy->{'01.http'} = {'caption' => $tr{'HTTP'},
371 'subMenu' => $subhttp
373 $subproxy->{'02.ftp'} = {'caption' => 'FTP',
380 my %subopenvpnhash = ();
381 my $subopenvpn = \
%subopenvpnhash;
382 $subopenvpn->{'01.server'} = {'caption' => $tr{'openvpn'},
383 'uri' => '/cgi-bin/openvpn.cgi',
384 'title' => "$tr{'virtual private networking'}",
387 $subopenvpn->{'02.client'} = {'caption' => $tr{'openvpnclient'},
388 'uri' => '/cgi-bin/openvpnclient.cgi',
389 'title' => "$tr{'virtual private networking'}",
394 my $subvpn = \
%subvpnhash;
396 $subvpn->{'01.openvpn'} = {'caption' => $tr{'openvpn'},
397 'subMenu' => $subopenvpn,
400 $subvpn->{'02.ipsec'} = {'caption' => $tr{'ipsec'},
401 'uri' => '/cgi-bin/vpnmain.cgi',
402 'title' => "$tr{'virtual private networking'}",
406 my %sublogshash = ();
407 my $sublogs = \
%sublogshash;
409 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
410 'uri' => '/cgi-bin/logs.cgi/summary.dat',
411 'title' => "$tr{'log summary'}",
414 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
415 'uri' => '/cgi-bin/logs.cgi/config.dat',
416 'title' => "$tr{'log settings'}",
419 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
420 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
421 'title' => "$tr{'proxy log viewer'}",
424 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
425 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
426 'title' => "$tr{'firewall log viewer'}",
429 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
430 'uri' => '/cgi-bin/logs.cgi/ids.dat',
431 'title' => "$tr{'intrusion detection system log viewer'}",
434 $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},
435 'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',
436 'title' => "$tr{'content filter log viewer'}",
439 $sublogs->{'07.urlfilter'} = {
440 'caption' => $tr{'urlfilter log'},
441 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
442 'title' => "$tr{'urlfilter log'}",
445 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
446 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
447 'title' => "$tr{'openvpn log'}",
450 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
451 'uri' => '/cgi-bin/logs.cgi/log.dat',
452 'title' => "$tr{'system log viewer'}",
455 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
456 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
457 'title' => "$tr{'user log viewer'}",
461 my %subipfirehash = ();
462 my $subipfire = \
%subipfirehash;
463 $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
464 'uri' => '/cgi-bin/pakfire.cgi',
465 'title' => "$tr{'paketmanager'}",
468 $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
469 'uri' => '/cgi-bin/samba.cgi',
470 'title' => "$tr{'samba'}",
476 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
478 'subMenu' => $subsystem
480 $menu->{'02.status'} = {'caption' => $tr{'status'},
482 'subMenu' => $substatus
484 $menu->{'03.network'} = {'caption' => $tr{'network'},
486 'subMenu' => $subnetwork
488 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
490 'subMenu' => $subservices
492 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
494 'subMenu' => $subfirewall
496 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
498 'subMenu' => $subproxy
500 $menu->{'07.vpn'} = {'caption' => 'VPN',
504 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
506 'subMenu' => $sublogs
508 $menu->{'09.ipfire'} = {'caption' => 'IPFire'},
510 'subMenu' => $subipfire
515 if (! blue_used
() && ! orange_used
()) {
516 $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;
518 if (-e
'/etc/FLASH') {
519 $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0; #disable squid
520 $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
521 $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
527 print "Pragma: no-cache\n";
528 print "Cache-control: no-cache\n";
529 print "Connection: close\n";
530 print "Content-type: text/html\n\n";
533 sub is_menu_visible
($) {
536 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
542 if (! $root->{'enabled'}) {
545 if ($root->{'uri'} !~ /^$/) {
547 if ($root->{'vars'} !~ /^$/) {
548 $vars = '?'. $root->{'vars'};
550 if (! is_menu_visible
($root->{'uri'})) {
553 return $root->{'uri'}.$vars;
555 my $submenus = $root->{'subMenu'};
559 foreach my $item (sort keys %$submenus) {
560 my $link = getlink
($submenus->{$item});
572 my $uri = $conf->{'uri'};
573 my $vars = $conf->{'vars'};
574 my $novars = $conf->{'novars'};
579 if ($uri ne $URI[0]) {
583 if ($URI[1] !~ /^$/) {
590 return ($URI[1] eq $vars);
600 foreach my $item (sort keys %$root) {
601 my $val = $root->{$item};
602 if (compare_url
($val)) {
603 $val->{'selected'} = 1;
604 if ($val->{'title'} !~ /^$/) {
605 return $val->{'title'};
607 return 'EMPTY TITLE';
610 my $title = gettitle
($val->{'subMenu'});
612 $val->{'selected'} = 1;
626 foreach my $k1 ( sort keys %$menu ) {
627 if (! $menu->{$k1}{'enabled'}) {
631 my $link = getlink
($menu->{$k1});
635 if (! is_menu_visible
($link)) {
638 if ($menu->{$k1}->{'selected'}) {
639 print '<li class="selected">';
645 <div class="rcorner">
646 <a href="$link">$menu->{$k1}{'caption'}</a>
666 foreach my $item (%$root) {
667 if ($root->{$item}{'selected'}) {
668 return $root->{$item};
673 sub showsubsection
($$) {
683 my $selected = getselected
($root);
687 my $submenus = $selected->{'subMenu'};
697 foreach my $item (sort keys %$submenus) {
698 my $hash = $submenus->{$item};
699 if (! $hash->{'enabled'}) {
703 my $link = getlink
($hash);
707 if (! is_menu_visible
($link)) {
710 if ($hash->{'selected'}) {
711 print '<li class="selected">';
717 <a href="$link">$hash->{'caption'}</a>
732 sub showsubsubsection
($) {
737 my $selected = getselected
($root);
741 if (! $selected->{'subMenu'}) {
745 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
751 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
756 $helpfile .= '.help.html';
758 my $helpuri = '/doc/'.$language.'/'.$helpfile;
759 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
769 my $extrahead = shift;
771 @URI=split ('\?', $ENV{'REQUEST_URI'} );
772 &readhash
("${swroot}/main/settings", \
%settings);
775 my $h2 = gettitle
($menu);
776 my $helpuri = get_helpuri
();
778 $title = "IPFire - $title";
779 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
780 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
785 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
786 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
790 <title>$title</title>
793 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
794 <link rel="shortcut icon" href="/favicon.ico" />
795 <style type="text/css">\@import url(/include/style.css);</style>
796 <style type="text/css">\@import url(/include/menu.css);</style>
797 <style type="text/css">\@import url(/include/content.css);</style>
799 <script language="javascript" type="text/javascript">
801 function swapVisibility(id) {
802 el = document.getElementById(id);
803 if(el.style.display != 'block') {
804 el.style.display = 'block'
807 el.style.display = 'none'
814 <!-- IPFIRE HEADER -->
819 <img id="logo-product" src="/images/logo_ipfire.gif">
820 <div id="header-icons">
824 if ($helpuri ne '') {
826 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
830 print '<img src="/images/help.gif">';
850 &showsubsection
($menu);
855 <td width="100%" valign="top">
856 <div id="page-content">
861 &showsubsubsection
($menu);
864 require 'ipfire-network.pl';
865 $supported = check_support
();
866 warn_unsupported
($supported);
871 my $status = &connectionstatus
();
872 $uptime = `/usr/bin/uptime`;
877 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
879 <p><a href="http://www.ipfire.org">IPFire</a> $version (c)</p>
882 <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">
883 <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">
896 $bgcolor = "style='background-color: $colourerr;'";
904 # print "</td></tr></table></td></tr></table>\n"
913 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
915 print "<table class=\"list\"><tr><td align=\"$align\">\n";
920 print "</td></tr></table><br><br>";
925 my $filename = $_[0];
928 # write cgi vars to the file.
929 open(FILE
, ">${filename}") or die "Unable to write file $filename";
931 foreach $var (keys %$hash)
933 $val = $hash->{$var};
934 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
935 # location of the mouse are submitted as well, this was being written to the settings file causing
936 # some serious grief! This skips the variable.x and variable.y
937 if (!($var =~ /(.x|.y)$/)) {
940 if (!($var =~ /^ACTION/)) {
941 print FILE
"${var}=${val}\n"; }
949 my $filename = $_[0];
953 open(FILE
, $filename) or die "Unable to read file $filename";
958 ($var, $val) = split /=/, $_, 2;
964 # Untaint variables read from hash
965 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
966 $val =~ /([\w\W]*)/; $val = $1;
967 $hash->{$var} = $val;
974 my ($hash, $params) = @_;
975 my $cgi = CGI
->new ();
976 $hash->{'__CGI__'} = $cgi;
977 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
978 if (!$params->{'wantfile'}) {
979 $CGI::DISABLE_UPLOADS
= 1;
980 $CGI::POST_MAX
= 512 * 1024;
982 $CGI::POST_MAX
= 10 * 1024 * 1024;
985 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
987 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
989 return if ($referer ne $servername);
991 ### Modified for getting multi-vars, split by |
992 %temp = $cgi->Vars();
993 foreach my $key (keys %temp) {
994 $hash->{$key} = $temp{$key};
995 $hash->{$key} =~ s/\0/|/g;
996 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
999 if (($params->{'wantfile'})&&($params->{'filevar'})) {
1000 $hash->{$params->{'filevar'}} = $cgi->upload
1001 ($params->{'filevar'});
1008 my $logmessage = $_[0];
1009 $logmessage =~ /([\w\W]*)/;
1011 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
1016 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1017 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
1020 my $totalsecs = $now - $mtime;
1021 my $days = int($totalsecs / 86400);
1022 my $totalhours = int($totalsecs / 3600);
1023 my $hours = $totalhours % 24;
1024 my $totalmins = int($totalsecs / 60);
1025 my $mins = $totalmins % 60;
1026 my $secs = $totalsecs % 60;
1028 return "${days}d ${hours}h ${mins}m ${secs}s";
1035 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
1039 @octets = ($1, $2, $3, $4);
1040 foreach $_ (@octets)
1044 if ($_ < 0 || $_ > 255) {
1055 # secord part an ip?
1056 if (&validip
($mask)) {
1058 # second part a number?
1061 if (!($mask =~ /^\d+$/)) {
1063 if ($mask >= 0 && $mask <= 32) {
1070 my $ipormask = $_[0];
1072 # see if it is a IP only.
1073 if (&validip
($ipormask)) {
1075 # split it into number and mask.
1076 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1080 # first part not a ip?
1081 if (!(&validip
($ip))) {
1083 return &validmask
($mask);
1088 my $ipandmask = $_[0];
1090 # split it into number and mask.
1091 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1095 # first part not a ip?
1096 if (!(&validip
($ip))) {
1098 return &validmask
($mask);
1109 if ($_ >= 1 && $_ <= 65535) {
1116 my $checkmac = $_[0];
1117 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1118 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1127 # Checks a hostname against RFC1035
1128 my $hostname = $_[0];
1130 # Each part should be at least two characters in length
1131 # but no more than 63 characters
1132 if (length ($hostname) < 2 || length ($hostname) > 63) {
1134 # Only valid characters are a-z, A-Z, 0-9 and -
1135 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1137 # First character can only be a letter or a digit
1138 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1140 # Last character can only be a letter or a digit
1141 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1148 # Checks a domain name against RFC1035
1149 my $domainname = $_[0];
1150 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1152 foreach $part (@parts) {
1153 # Each part should be at least two characters in length
1154 # but no more than 63 characters
1155 if (length ($part) < 2 || length ($part) > 63) {
1157 # Only valid characters are a-z, A-Z, 0-9 and -
1158 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1160 # First character can only be a letter or a digit
1161 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1163 # Last character can only be a letter or a digit
1164 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1172 # Checks a fully qualified domain name against RFC1035
1174 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1175 if (scalar(@parts) < 2) { # At least two parts should
1176 return 0;} # exist in a FQDN
1177 # (i.e. hostname.domain)
1178 foreach $part (@parts) {
1179 # Each part should be at least two characters in length
1180 # but no more than 63 characters
1181 if (length ($part) < 2 || length ($part) > 63) {
1183 # Only valid characters are a-z, A-Z, 0-9 and -
1184 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1186 # First character can only be a letter or a digit
1187 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1189 # Last character can only be a letter or a digit
1190 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1196 sub validportrange
# used to check a port range
1198 my $port = $_[0]; # port values
1199 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1200 my $srcdst = $_[1]; # is it a source or destination port
1202 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1204 if (!(&validport
($port))) {
1205 if ($srcdst eq 'src'){
1206 return $tr{'source port numbers'};
1208 return $tr{'destination port numbers'};
1216 if ($srcdst eq 'src'){
1217 return $tr{'bad source range'};
1219 return $tr{'bad destination range'};
1224 if (!(&validport
($_))) {
1225 if ($srcdst eq 'src'){
1226 return $tr{'source port numbers'};
1228 return $tr{'destination port numbers'};
1236 # Test if IP is within a subnet
1237 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1238 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1239 # Everything in dottted notation
1240 # Return: TRUE/FALSE
1243 $ip = unpack('N', inet_aton
(shift));
1244 $start = unpack('N', inet_aton
(shift));
1245 $mask = unpack('N', inet_aton
(shift));
1246 $start &= $mask; # base of subnet...
1247 $end = $start + ~$mask;
1248 return (($ip >= $start) && ($ip <= $end));
1253 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1254 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1255 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1256 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1257 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1258 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1259 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1264 my ($filename, $hash) = @_;
1266 open(FILE
, $filename) or die "Unable to read file $filename";
1269 my ($key, $rest, @temp);
1271 ($key, $rest) = split (/,/, $_, 2);
1272 if ($key =~ /^[0-9]+$/ && $rest) {
1273 @temp = split (/,/, $rest);
1274 $hash->{$key} = \
@temp;
1281 sub writehasharray
{
1282 my ($filename, $hash) = @_;
1285 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1287 foreach $key (keys %$hash) {
1288 if ( $hash->{$key} ) {
1290 foreach $i (0 .. $#{$hash->{$key}}) {
1291 print FILE
",$hash->{$key}[$i]";
1300 sub findhasharraykey
{
1301 foreach my $i (1 .. 1000000) {
1302 if ( ! exists $_[0]{$i}) {
1310 my $outstring =$_[0];
1311 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1312 $outstring =~ s/&/&/g;
1313 $outstring =~ s/\'/'/g;
1314 $outstring =~ s/\"/"/g;
1315 $outstring =~ s/</</g;
1316 $outstring =~ s/>/>/g;
1319 sub connectionstatus
1322 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1323 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1324 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1326 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1327 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1329 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1330 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1332 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1334 $status = "$tr{'connecting'} $uplink";
1336 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1343 $status = "$tr{'idle'}";
1345 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1350 # Darren Critchley - darrenc@telus.net - (c) 2003
1351 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1352 # This subroutine will take the following parameters:
1353 # ColumnNumber = the column which you want to sort on, starts at 1
1354 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1355 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1356 # ArrayToBeSorted = the array that wants sorting
1358 # Returns an array that is sorted to your specs
1360 # If SortOrder is greater than the elements in array, then it defaults to the first element
1363 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1368 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1369 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1370 return (@tobesorted);
1372 my @tmp = split(/\,/,$tobesorted[0]);
1373 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1375 # Darren Critchley - validate parameters
1376 if ($colno > $ttlitems){$colno = '1';}
1377 $colno--; # remove one from colno to deal with arrays starting at 0
1378 if($colno < 0){$colno = '0';}
1379 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1380 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1382 foreach $line (@tobesorted)
1386 my @temp = split(/\,/,$line);
1387 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1388 my $tmpholder = $temp[0];
1389 $temp[0] = $temp[$colno];
1390 $temp[$colno] = $tmpholder;
1392 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1393 $newline=$newline . $temp[$ctr] . ",";
1396 push(@tmparray,$newline);
1399 if ($alpnum eq 'n') {
1400 @tmparray = sort {$a <=> $b} @tmparray;
1402 @tmparray = (sort @tmparray);
1404 foreach $line (@tmparray)
1408 my @temp = split(/\,/,$line);
1409 my $tmpholder = $temp[0];
1410 $temp[0] = $temp[$colno];
1411 $temp[$colno] = $tmpholder;
1413 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1414 $newline=$newline . $temp[$ctr] . ",";
1417 push(@srtedarray,$newline);
1421 if ($srtdir eq 'dsc') {
1422 @tmparray = reverse(@srtedarray);
1425 return (@srtedarray);
1429 sub speedtouchversion
1431 if (-f
"/proc/bus/usb/devices")
1433 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1434 if ($speedtouch eq '') {
1435 $speedtouch= $tr{'connect the modem'};
1438 $speedtouch='USB '.$tr{'not running'};
1443 sub CheckSortOrder
{
1444 #Sorting of allocated leases
1445 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1446 my $newsort=$ENV{'QUERY_STRING'};
1447 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1448 $act=$dhcpsettings{'SORT_LEASELIST'};
1450 if ($act =~ $newsort) {
1451 if ($act !~ 'Rev') {$Rev='Rev'};
1455 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1456 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1457 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1462 sub PrintActualLeases
1464 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1466 <table width='100%'>
1468 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1469 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1470 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1471 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1476 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1477 while ($line = <LEASES
>) {
1478 next if( $line =~ /^\s*#/ );
1480 @temp = split (' ', $line);
1482 if ($line =~ /^\s*lease/) {
1484 #All field are not necessarily read. Clear everything
1490 if ($line =~ /^\s*ends/) {
1491 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1492 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1495 if ($line =~ /^\s*hardware ethernet/) {
1500 if ($line =~ /^\s*client-hostname/) {
1501 $hostname = "$temp[1] $temp[2] $temp[3]";
1502 $hostname =~ s/;//g;
1503 $hostname =~ s/\"//g;
1507 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1508 $record = {}; # create a reference to empty hash
1509 %{$record} = @record; # populate that hash with @record
1510 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1516 foreach my $key (sort leasesort
keys %entries) {
1518 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1521 print "<tr bgcolor='$table1colour'>";
1524 print "<tr bgcolor='$table2colour'>";
1528 <td align='center'>$entries{$key}->{IPADDR}</td>
1529 <td align='center'>$entries{$key}->{ETHER}</td>
1530 <td align='center'> $hostname </td>
1535 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1536 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1538 if ($entries{$key}->{ENDTIME
} < time() ){
1539 print "<strike>$enddate</strike>";
1552 # This sub is used during display of actives leases
1554 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1556 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1557 if ($qs eq 'IPADDR') {
1558 @a = split(/\./,$entries{$a}->{$qs});
1559 @b = split(/\./,$entries{$b}->{$qs});
1565 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1570 $qs=$dhcpsettings{'SORT_LEASELIST'};
1571 if ($qs eq 'IPADDR') {
1572 @a = split(/\./,$entries{$a}->{$qs});
1573 @b = split(/\./,$entries{$b}->{$qs});
1579 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1586 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1587 foreach my $dir (readdir(DIR
)) {
1588 next if ($dir =~ /^\./);
1589 next if (-f
"${swroot}/uplinks/$dir");
1590 push(@uplinks, $dir);
1597 my $filename = shift;
1599 open (F
, $filename) || return "";
1606 sub get_red_ifaces_by_type
($) {
1608 my @gottypeiface = ();
1609 my @gottypeuplink = ();
1612 my $ref=get_uplinks
();
1615 foreach my $link (@uplinks) {
1617 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1619 push(@gottype, $link);
1621 my $iface = $set{'RED_DEV'};
1623 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1627 if ($set{'RED_TYPE'} eq $type) {
1628 push(@gottypeiface, $iface);
1629 push(@gottypeuplink, $link);
1632 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1635 sub get_red_ifaces
() {
1636 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1639 sub get_zone_devices
($) {
1642 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1643 foreach my $line (<FILE
>) {
1646 push(@ifaces, $line);