]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
3fd3a523e444acee3b22e17a30dae06e021c54db
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()
18 $|=1; # line buffering
20 $Header::revision
= 'final';
21 $Header::swroot
= '/var/ipfire';
22 $Header::pagecolour
= '#ffffff';
23 #$Header::tablecolour = '#a0a0a0';
24 $Header::tablecolour
= '#FFFFFF';
25 $Header::bigboxcolour
= '#F6F4F4';
26 $Header::boxcolour
= '#EAE9EE';
27 $Header::bordercolour
= '#000000';
28 $Header::table1colour
= '#E0E0E0';
29 $Header::table2colour
= '#F0F0F0';
30 $Header::colourred
= '#993333';
31 $Header::colourorange
= '#FF9933';
32 $Header::colouryellow
= '#FFFF00';
33 $Header::colourgreen
= '#339933';
34 $Header::colourblue
= '#333399';
35 $Header::colourfw
= '#000000';
36 $Header::colourvpn
= '#990099';
37 $Header::colourerr
= '#FF0000';
38 $Header::viewsize
= 150;
39 $Header::errormessage
= '';
41 my $menu = \
%menuhash;
47 ### Make sure this is an SSL request
48 if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
49 print "Status: 302 Moved\r\n";
50 print "Location: https://$ENV{'SERVER_ADDR'}:10443/$ENV{'PATH_INFO'}\r\n\r\n";
54 ### Initialize environment
55 &readhash
("${swroot}/main/settings", \
%settings);
56 &readhash
("${swroot}/ethernet/settings", \
%ethsettings);
57 $language = $settings{'LANGUAGE'};
58 $hostname = $settings{'HOSTNAME'};
61 ### Initialize language
62 if ($language =~ /^(\w+)$/) {$language = $1;}
64 ### Read English Files
65 if ( -d
"/var/ipfire/langs/en/" ) {
66 opendir(DIR
, "/var/ipfire/langs/en/");
67 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
68 foreach $name(@names) {
69 next if ($name eq ".");
70 next if ($name eq "..");
71 next if (!($name =~ /\.pl$/));
72 require "${swroot}/langs/en/${name}";
77 ### Enable Language Files
78 if ( -d
"/var/ipfire/langs/${language}/" ) {
79 opendir(DIR
, "/var/ipfire/langs/${language}/");
80 @names = readdir(DIR
) or die "Cannot Read Directory: $!\n";
81 foreach $name(@names) {
82 next if ($name eq ".");
83 next if ($name eq "..");
84 next if (!($name =~ /\.pl$/));
85 require "${swroot}/langs/${language}/${name}";
90 require "${swroot}/langs/en.pl";
91 require "${swroot}/langs/${language}.pl";
94 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
101 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
108 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
116 my %subsystemhash = ();
117 my $subsystem = \
%subsystemhash;
119 $subsystem->{'01.home'} = {
120 'caption' => $tr{'alt home'},
121 'uri' => '/cgi-bin/index.cgi',
122 'title' => "$tr{'alt home'}",
125 $subsystem->{'02.netwizard'} = {
126 'caption' => $tr{'network configuration'},
127 'uri' => '/cgi-bin/netwizard.cgi',
128 'title' => "$tr{'network configuration'}",
131 $subsystem->{'03.passwords'} = {
132 'caption' => $tr{'sspasswords'},
133 'uri' => '/cgi-bin/changepw.cgi',
134 'title' => "$tr{'sspasswords'}",
137 $subsystem->{'04.ssh'} = {
138 'caption' => $tr{'ssh access'},
139 'uri' => '/cgi-bin/remote.cgi',
140 'title' => "$tr{'ssh access'}",
143 $subsystem->{'05.gui'} = {
144 'caption' => $tr{'gui settings'},
145 'uri' => '/cgi-bin/gui.cgi',
146 'title' => "$tr{'gui settings'}",
149 $subsystem->{'06.backup'} = {
150 'caption' => $tr{'backup'},
151 'uri' => '/cgi-bin/backup.cgi',
152 'title' => "$tr{'backup'} / $tr{'restore'}",
155 $subsystem->{'07.shutdown'} = {
156 'caption' => $tr{'shutdown'},
157 'uri' => '/cgi-bin/shutdown.cgi',
158 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
161 $subsystem->{'08.credits'} = {
162 'caption' => $tr{'credits'},
163 'uri' => '/cgi-bin/credits.cgi',
164 'title' => "$tr{'credits'}",
168 my %substatushash = ();
169 my $substatus = \
%substatushash;
170 $substatus->{'01.systemstatus'} = {
171 'caption' => $tr{'sssystem status'},
172 'uri' => '/cgi-bin/status.cgi',
173 'title' => "$tr{'system status information'}",
176 $substatus->{'02.networkstatus'} = {
177 'caption' => $tr{'ssnetwork status'},
178 'uri' => '/cgi-bin/netstatus.cgi',
179 'title' => "$tr{'network status information'}",
182 $substatus->{'03.systemgraphs'} = {
183 'caption' => $tr{'system graphs'},
184 'uri' => '/cgi-bin/graphs.cgi',
186 'title' => "$tr{'system graphs'}",
189 $substatus->{'04.trafficgraphs'} = {
190 'caption' => $tr{'sstraffic graphs'},
191 'uri' => '/cgi-bin/graphs.cgi',
192 'vars' => 'graph=network',
193 'title' => "$tr{'network traffic graphs'}",
196 $substatus->{'05.proxygraphs'} = {
197 'caption' => $tr{'ssproxy graphs'},
198 'uri' => '/cgi-bin/proxygraphs.cgi',
199 'title' => "$tr{'proxy access graphs'}",
202 $substatus->{'06.connections'} = {
203 'caption' => $tr{'connections'},
204 'uri' => '/cgi-bin/connections.cgi',
205 'title' => "$tr{'connections'}",
208 $substatus->{'99.iptfilters'} = {
209 'caption' => $tr{'iptfilters iptable rules'},
210 'uri' => '/cgi-bin/iptfilters.cgi',
211 'title' => "$tr{'iptfilters iptable rules'}",
215 my %subnetworkhash = ();
216 my $subnetwork = \
%subnetworkhash;
218 $subnetwork->{'01.dialup'} = {
219 'caption' => $tr{'alt dialup'},
220 'uri' => '/cgi-bin/pppsetup.cgi',
221 'title' => "$tr{'dialup settings'}",
224 $subnetwork->{'02.hosts'} = {
225 'caption' => $tr{'edit hosts'},
226 'uri' => '/cgi-bin/hosts.cgi',
227 'title' => "$tr{'host configuration'}",
230 $subnetwork->{'03.upload'} = {
231 'caption' => $tr{'upload'},
232 'uri' => '/cgi-bin/upload.cgi',
233 'title' => "$tr{'firmware upload'}",
236 $subnetwork->{'04.aliases'} = {
237 'caption' => $tr{'aliases'},
238 'uri' => '/cgi-bin/aliases.cgi',
239 'title' => "$tr{'external aliases configuration'}",
242 $subnetwork->{'05.nettraf'} = {
243 'caption' => $tr{'sstraffic'},
244 'uri' => '/cgi-bin/traffic.cgi',
245 'title' => "$tr{'sstraffic'}",
248 $subnetwork->{'06.fwhits'} = {
249 'caption' => 'Firewallhits',
250 'uri' => '/cgi-bin/fwhits.cgi',
251 'title' => "IPFire Firewallhits",
254 $subnetwork->{'07.openvpn'} = {
255 'caption' => 'OpenVPN',
256 'uri' => '/cgi-bin/ovpnmain.cgi',
257 'title' => "$tr{'virtual private networking'}",
260 $subnetwork->{'08.ipsec'} = {
261 'caption' => 'IPSec',
262 'uri' => '/cgi-bin/vpnmain.cgi',
263 'title' => "$tr{'virtual private networking'}",
268 my %subserviceshash = ();
269 my $subservices = \
%subserviceshash;
271 $subservices->{'01.proxy'} = {
272 'caption' => $tr{'proxy'},
273 'uri' => '/cgi-bin/proxy.cgi',
274 'title' => "HTTP: $tr{'web proxy configuration'}",
277 $subservices->{'02.dhcp'} = {
278 'caption' => $tr{'dhcp server'},
279 'uri' => '/cgi-bin/dhcp.cgi',
280 'title' => "$tr{'dhcp configuration'}",
283 $subservices->{'03.dyndns'} = {
284 'caption' => $tr{'dynamic dns'},
285 'uri' => '/cgi-bin/ddns.cgi',
286 'title' => "$tr{'dynamic dns client'}",
289 $subservices->{'04.time'} = {
290 'caption' => $tr{'time server'},
291 'uri' => '/cgi-bin/time.cgi',
292 'title' => "$tr{'time server'}",
295 $subservices->{'05.qos'} = {
296 'caption' => 'Quality of Service',
297 'uri' => '/cgi-bin/qos.cgi',
298 'title' => "$tr{'traffic shaping settings'}",
301 $subservices->{'06.ids'} = {'caption' => $tr{'intrusion detection'},
303 'uri' => '/cgi-bin/ids.cgi',
304 'title' => "$tr{'intrusion detection system'} (Snort)",
308 my %subfirewallhash = ();
309 my $subfirewall = \
%subfirewallhash;
312 $subfirewall->{'01.dnat'} = {
313 'caption' => $tr{'ssport forwarding'},
314 'uri' => '/cgi-bin/portfw.cgi',
315 'title' => "$tr{'port forwarding configuration'}",
318 $subfirewall->{'02.xtaccess'} = {
319 'caption' => $tr{'external access'},
320 'uri' => '/cgi-bin/xtaccess.cgi',
321 'title' => "$tr{'external access configuration'}",
324 $subfirewall->{'03.dmz'} = {
325 'caption' => $tr{'ssdmz pinholes'},
326 'uri' => '/cgi-bin/dmzholes.cgi',
327 'title' => "$tr{'dmz pinhole configuration'}",
330 $subfirewall->{'04.outgoing'} = {
331 'caption' => $tr{'outgoing firewall'},
332 'uri' => '/cgi-bin/outgoingfw.cgi',
333 'title' => "$tr{'outgoing firewall'}",
338 my %sublogshash = ();
339 my $sublogs = \
%sublogshash;
341 $sublogs->{'01.summary'} = {'caption' => $tr{'log summary'},
342 'uri' => '/cgi-bin/logs.cgi/summary.dat',
343 'title' => "$tr{'log summary'}",
346 $sublogs->{'02.settings'} = {'caption' => $tr{'log settings'},
347 'uri' => '/cgi-bin/logs.cgi/config.dat',
348 'title' => "$tr{'log settings'}",
351 $sublogs->{'03.proxy'} = {'caption' => $tr{'proxy logs'},
352 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
353 'title' => "$tr{'proxy log viewer'}",
356 $sublogs->{'04.firewall'} = {'caption' => $tr{'firewall logs'},
357 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
358 'title' => "$tr{'firewall log viewer'}",
361 $sublogs->{'05.ids'} = {'caption' => $tr{'ids logs'},
362 'uri' => '/cgi-bin/logs.cgi/ids.dat',
363 'title' => "$tr{'intrusion detection system log viewer'}",
366 $sublogs->{'06.contentfilter'} = {'caption' => $tr{'content filter logs'},
367 'uri' => '/cgi-bin/logs.cgi/dansguardian.dat',
368 'title' => "$tr{'content filter log viewer'}",
371 $sublogs->{'07.urlfilter'} = {
372 'caption' => $tr{'urlfilter log'},
373 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
374 'title' => "$tr{'urlfilter log'}",
377 $sublogs->{'08.openvpn'} = {'caption' => $tr{'openvpn log'},
378 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
379 'title' => "$tr{'openvpn log'}",
382 $sublogs->{'09.system'} = {'caption' => $tr{'system logs'},
383 'uri' => '/cgi-bin/logs.cgi/log.dat',
384 'title' => "$tr{'system log viewer'}",
387 $sublogs->{'10.userlog'} = {'caption' => $tr{'user proxy logs'},
388 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
389 'title' => "$tr{'user log viewer'}",
393 my %subipfirehash = ();
394 my $subipfire = \
%subipfirehash;
395 $subipfire->{'01.pakfire'} = {'caption' => $tr{'pakfire'},
396 'uri' => '/cgi-bin/pakfire.cgi',
397 'title' => "$tr{'paketmanager'}",
400 $subipfire->{'02.asterisk'} = {'caption' => $tr{'asterisk'},
401 'uri' => '/cgi-bin/asterisk.cgi',
402 'title' => "$tr{'asterisk'}",
405 $subipfire->{'02.samba'} = {'caption' => $tr{'samba'},
406 'uri' => '/cgi-bin/samba.cgi',
407 'title' => "$tr{'samba'}",
410 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
411 'uri' => '/cgi-bin/help.cgi',
412 'title' => "$tr{'help'}",
418 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
420 'subMenu' => $subsystem
422 $menu->{'02.status'} = {'caption' => $tr{'status'},
424 'subMenu' => $substatus
426 $menu->{'03.network'} = {'caption' => $tr{'network'},
428 'subMenu' => $subnetwork
430 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
432 'subMenu' => $subservices
434 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
436 'subMenu' => $subfirewall
438 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
440 'subMenu' => $subproxy
442 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
446 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
448 'subMenu' => $sublogs
451 if (! blue_used
() && ! orange_used
()) {
452 $menu->{'05.firewall'}{'subMenu'}->{'03.dmz'}{'enabled'} = 0;
454 if (-e
'/etc/FLASH') {
455 $menu{'06.proxy'}{'subMenu'}->{'01.http'}{'subMenu'}->{'01.proxy'}{'enabled'} = 0; #disable squid
456 $menu{'04.services'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
457 $menu{'08.logs'}{'subMenu'}->{'05.ids'}{'enabled'} = 0; #disable ids
463 print "Pragma: no-cache\n";
464 print "Cache-control: no-cache\n";
465 print "Connection: close\n";
466 print "Content-type: text/html\n\n";
469 sub is_menu_visible
($) {
472 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
478 if (! $root->{'enabled'}) {
481 if ($root->{'uri'} !~ /^$/) {
483 if ($root->{'vars'} !~ /^$/) {
484 $vars = '?'. $root->{'vars'};
486 if (! is_menu_visible
($root->{'uri'})) {
489 return $root->{'uri'}.$vars;
491 my $submenus = $root->{'subMenu'};
495 foreach my $item (sort keys %$submenus) {
496 my $link = getlink
($submenus->{$item});
508 my $uri = $conf->{'uri'};
509 my $vars = $conf->{'vars'};
510 my $novars = $conf->{'novars'};
515 if ($uri ne $URI[0]) {
519 if ($URI[1] !~ /^$/) {
526 return ($URI[1] eq $vars);
536 foreach my $item (sort keys %$root) {
537 my $val = $root->{$item};
538 if (compare_url
($val)) {
539 $val->{'selected'} = 1;
540 if ($val->{'title'} !~ /^$/) {
541 return $val->{'title'};
543 return 'EMPTY TITLE';
546 my $title = gettitle
($val->{'subMenu'});
548 $val->{'selected'} = 1;
562 foreach my $k1 ( sort keys %$menu ) {
563 if (! $menu->{$k1}{'enabled'}) {
567 my $link = getlink
($menu->{$k1});
571 if (! is_menu_visible
($link)) {
574 if ($menu->{$k1}->{'selected'}) {
575 print '<li class="selected">';
581 <div class="rcorner">
582 <a href="$link">$menu->{$k1}{'caption'}</a>
602 foreach my $item (%$root) {
603 if ($root->{$item}{'selected'}) {
604 return $root->{$item};
609 sub showsubsection
($$) {
619 my $selected = getselected
($root);
623 my $submenus = $selected->{'subMenu'};
633 foreach my $item (sort keys %$submenus) {
634 my $hash = $submenus->{$item};
635 if (! $hash->{'enabled'}) {
639 my $link = getlink
($hash);
643 if (! is_menu_visible
($link)) {
646 if ($hash->{'selected'}) {
647 print '<li class="selected">';
653 <a href="$link">$hash->{'caption'}</a>
668 sub showsubsubsection
($) {
673 my $selected = getselected
($root);
677 if (! $selected->{'subMenu'}) {
681 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
687 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
692 $helpfile .= '.help.html';
694 my $helpuri = '/doc/'.$language.'/'.$helpfile;
695 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
705 my $extrahead = shift;
707 @URI=split ('\?', $ENV{'REQUEST_URI'} );
708 &readhash
("${swroot}/main/settings", \
%settings);
711 my $h2 = gettitle
($menu);
712 my $helpuri = get_helpuri
();
714 $title = "IPFire - $title";
715 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
716 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
721 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
722 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
726 <title>$title</title>
729 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
730 <meta http-equiv="Page-Enter" content="blendTrans(Duration=0.5,Transition=12)">
731 <meta http-equiv="Page-Exit" content="blendTrans(Duration=0.5,Transition=12)">
732 <link rel="shortcut icon" href="/favicon.ico" />
733 <style type="text/css">\@import url(/include/style.css);</style>
734 <style type="text/css">\@import url(/include/menu.css);</style>
735 <style type="text/css">\@import url(/include/content.css);</style>
736 <script language="javascript" type="text/javascript">
738 function swapVisibility(id) {
739 el = document.getElementById(id);
740 if(el.style.display != 'block') {
741 el.style.display = 'block'
744 el.style.display = 'none'
751 <!-- IPFIRE HEADER -->
756 <img id="logo-product" src="/images/logo_ipfire.gif">
757 <div id="header-icons">
761 if ($helpuri ne '') {
763 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
767 print '<img src="/images/help.gif">';
787 &showsubsection
($menu);
792 <td width="100%" valign="top">
793 <div id="page-content">
798 &showsubsubsection
($menu);
801 require 'ipfire-network.pl';
802 $supported = check_support
();
803 warn_unsupported
($supported);
808 my $status = &connectionstatus
();
809 $uptime = `/usr/bin/uptime`;
814 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
830 $bgcolor = "style='background-color: $colourerr;'";
838 # print "</td></tr></table></td></tr></table>\n"
847 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
849 print "<table class=\"list\"><tr><td align=\"$align\">\n";
854 print "</td></tr></table><br><br>";
859 my $filename = $_[0];
862 # write cgi vars to the file.
863 open(FILE
, ">${filename}") or die "Unable to write file $filename";
865 foreach $var (keys %$hash)
867 $val = $hash->{$var};
868 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
869 # location of the mouse are submitted as well, this was being written to the settings file causing
870 # some serious grief! This skips the variable.x and variable.y
871 if (!($var =~ /(.x|.y)$/)) {
874 if (!($var =~ /^ACTION/)) {
875 print FILE
"${var}=${val}\n"; }
883 my $filename = $_[0];
887 open(FILE
, $filename) or die "Unable to read file $filename";
892 ($var, $val) = split /=/, $_, 2;
898 # Untaint variables read from hash
899 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
900 $val =~ /([\w\W]*)/; $val = $1;
901 $hash->{$var} = $val;
908 my ($hash, $params) = @_;
909 my $cgi = CGI
->new ();
910 $hash->{'__CGI__'} = $cgi;
911 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
912 if (!$params->{'wantfile'}) {
913 $CGI::DISABLE_UPLOADS
= 1;
914 $CGI::POST_MAX
= 512 * 1024;
916 $CGI::POST_MAX
= 10 * 1024 * 1024;
919 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
921 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
923 return if ($referer ne $servername);
925 ### Modified for getting multi-vars, split by |
926 %temp = $cgi->Vars();
927 foreach my $key (keys %temp) {
928 $hash->{$key} = $temp{$key};
929 $hash->{$key} =~ s/\0/|/g;
930 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
933 if (($params->{'wantfile'})&&($params->{'filevar'})) {
934 $hash->{$params->{'filevar'}} = $cgi->upload
935 ($params->{'filevar'});
942 my $logmessage = $_[0];
943 $logmessage =~ /([\w\W]*)/;
945 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
950 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
951 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
954 my $totalsecs = $now - $mtime;
955 my $days = int($totalsecs / 86400);
956 my $totalhours = int($totalsecs / 3600);
957 my $hours = $totalhours % 24;
958 my $totalmins = int($totalsecs / 60);
959 my $mins = $totalmins % 60;
960 my $secs = $totalsecs % 60;
962 return "${days}d ${hours}h ${mins}m ${secs}s";
969 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
973 @octets = ($1, $2, $3, $4);
978 if ($_ < 0 || $_ > 255) {
990 if (&validip
($mask)) {
992 # second part a number?
995 if (!($mask =~ /^\d+$/)) {
997 if ($mask >= 0 && $mask <= 32) {
1004 my $ipormask = $_[0];
1006 # see if it is a IP only.
1007 if (&validip
($ipormask)) {
1009 # split it into number and mask.
1010 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1014 # first part not a ip?
1015 if (!(&validip
($ip))) {
1017 return &validmask
($mask);
1022 my $ipandmask = $_[0];
1024 # split it into number and mask.
1025 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1029 # first part not a ip?
1030 if (!(&validip
($ip))) {
1032 return &validmask
($mask);
1043 if ($_ >= 1 && $_ <= 65535) {
1050 my $checkmac = $_[0];
1051 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1052 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1061 # Checks a hostname against RFC1035
1062 my $hostname = $_[0];
1064 # Each part should be at least two characters in length
1065 # but no more than 63 characters
1066 if (length ($hostname) < 2 || length ($hostname) > 63) {
1068 # Only valid characters are a-z, A-Z, 0-9 and -
1069 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1071 # First character can only be a letter or a digit
1072 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1074 # Last character can only be a letter or a digit
1075 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1082 # Checks a domain name against RFC1035
1083 my $domainname = $_[0];
1084 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1086 foreach $part (@parts) {
1087 # Each part should be at least two characters in length
1088 # but no more than 63 characters
1089 if (length ($part) < 2 || length ($part) > 63) {
1091 # Only valid characters are a-z, A-Z, 0-9 and -
1092 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1094 # First character can only be a letter or a digit
1095 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1097 # Last character can only be a letter or a digit
1098 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1106 # Checks a fully qualified domain name against RFC1035
1108 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1109 if (scalar(@parts) < 2) { # At least two parts should
1110 return 0;} # exist in a FQDN
1111 # (i.e. hostname.domain)
1112 foreach $part (@parts) {
1113 # Each part should be at least two characters in length
1114 # but no more than 63 characters
1115 if (length ($part) < 2 || length ($part) > 63) {
1117 # Only valid characters are a-z, A-Z, 0-9 and -
1118 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1120 # First character can only be a letter or a digit
1121 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1123 # Last character can only be a letter or a digit
1124 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1130 sub validportrange
# used to check a port range
1132 my $port = $_[0]; # port values
1133 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1134 my $srcdst = $_[1]; # is it a source or destination port
1136 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1138 if (!(&validport
($port))) {
1139 if ($srcdst eq 'src'){
1140 return $tr{'source port numbers'};
1142 return $tr{'destination port numbers'};
1150 if ($srcdst eq 'src'){
1151 return $tr{'bad source range'};
1153 return $tr{'bad destination range'};
1158 if (!(&validport
($_))) {
1159 if ($srcdst eq 'src'){
1160 return $tr{'source port numbers'};
1162 return $tr{'destination port numbers'};
1170 # Test if IP is within a subnet
1171 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1172 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1173 # Everything in dottted notation
1174 # Return: TRUE/FALSE
1177 $ip = unpack('N', inet_aton
(shift));
1178 $start = unpack('N', inet_aton
(shift));
1179 $mask = unpack('N', inet_aton
(shift));
1180 $start &= $mask; # base of subnet...
1181 $end = $start + ~$mask;
1182 return (($ip >= $start) && ($ip <= $end));
1187 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1188 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1189 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1190 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1191 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1192 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1193 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1198 my ($filename, $hash) = @_;
1200 open(FILE
, $filename) or die "Unable to read file $filename";
1203 my ($key, $rest, @temp);
1205 ($key, $rest) = split (/,/, $_, 2);
1206 if ($key =~ /^[0-9]+$/ && $rest) {
1207 @temp = split (/,/, $rest);
1208 $hash->{$key} = \
@temp;
1215 sub writehasharray
{
1216 my ($filename, $hash) = @_;
1219 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1221 foreach $key (keys %$hash) {
1222 if ( $hash->{$key} ) {
1224 foreach $i (0 .. $#{$hash->{$key}}) {
1225 print FILE
",$hash->{$key}[$i]";
1234 sub findhasharraykey
{
1235 foreach my $i (1 .. 1000000) {
1236 if ( ! exists $_[0]{$i}) {
1244 my $outstring =$_[0];
1245 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1246 $outstring =~ s/&/&/g;
1247 $outstring =~ s/\'/'/g;
1248 $outstring =~ s/\"/"/g;
1249 $outstring =~ s/</</g;
1250 $outstring =~ s/>/>/g;
1253 sub connectionstatus
1256 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1257 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1258 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1260 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1261 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1263 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1264 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1266 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1268 $status = "$tr{'connecting'} $uplink";
1270 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1277 $status = "$tr{'idle'}";
1279 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1284 # Darren Critchley - darrenc@telus.net - (c) 2003
1285 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1286 # This subroutine will take the following parameters:
1287 # ColumnNumber = the column which you want to sort on, starts at 1
1288 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1289 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1290 # ArrayToBeSorted = the array that wants sorting
1292 # Returns an array that is sorted to your specs
1294 # If SortOrder is greater than the elements in array, then it defaults to the first element
1297 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1302 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1303 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1304 return (@tobesorted);
1306 my @tmp = split(/\,/,$tobesorted[0]);
1307 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1309 # Darren Critchley - validate parameters
1310 if ($colno > $ttlitems){$colno = '1';}
1311 $colno--; # remove one from colno to deal with arrays starting at 0
1312 if($colno < 0){$colno = '0';}
1313 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1314 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1316 foreach $line (@tobesorted)
1320 my @temp = split(/\,/,$line);
1321 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1322 my $tmpholder = $temp[0];
1323 $temp[0] = $temp[$colno];
1324 $temp[$colno] = $tmpholder;
1326 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1327 $newline=$newline . $temp[$ctr] . ",";
1330 push(@tmparray,$newline);
1333 if ($alpnum eq 'n') {
1334 @tmparray = sort {$a <=> $b} @tmparray;
1336 @tmparray = (sort @tmparray);
1338 foreach $line (@tmparray)
1342 my @temp = split(/\,/,$line);
1343 my $tmpholder = $temp[0];
1344 $temp[0] = $temp[$colno];
1345 $temp[$colno] = $tmpholder;
1347 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1348 $newline=$newline . $temp[$ctr] . ",";
1351 push(@srtedarray,$newline);
1355 if ($srtdir eq 'dsc') {
1356 @tmparray = reverse(@srtedarray);
1359 return (@srtedarray);
1363 sub speedtouchversion
1365 if (-f
"/proc/bus/usb/devices")
1367 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1368 if ($speedtouch eq '') {
1369 $speedtouch= $tr{'connect the modem'};
1372 $speedtouch='USB '.$tr{'not running'};
1377 sub CheckSortOrder
{
1378 #Sorting of allocated leases
1379 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1380 my $newsort=$ENV{'QUERY_STRING'};
1381 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1382 $act=$dhcpsettings{'SORT_LEASELIST'};
1384 if ($act =~ $newsort) {
1385 if ($act !~ 'Rev') {$Rev='Rev'};
1389 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1390 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1391 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1396 sub PrintActualLeases
1398 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1400 <table width='100%'>
1402 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1403 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1404 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1405 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1410 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1411 while ($line = <LEASES
>) {
1412 next if( $line =~ /^\s*#/ );
1414 @temp = split (' ', $line);
1416 if ($line =~ /^\s*lease/) {
1418 #All field are not necessarily read. Clear everything
1424 if ($line =~ /^\s*ends/) {
1425 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1426 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1429 if ($line =~ /^\s*hardware ethernet/) {
1434 if ($line =~ /^\s*client-hostname/) {
1435 $hostname = "$temp[1] $temp[2] $temp[3]";
1436 $hostname =~ s/;//g;
1437 $hostname =~ s/\"//g;
1441 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1442 $record = {}; # create a reference to empty hash
1443 %{$record} = @record; # populate that hash with @record
1444 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1450 foreach my $key (sort leasesort
keys %entries) {
1452 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1455 print "<tr bgcolor='$table1colour'>";
1458 print "<tr bgcolor='$table2colour'>";
1462 <td align='center'>$entries{$key}->{IPADDR}</td>
1463 <td align='center'>$entries{$key}->{ETHER}</td>
1464 <td align='center'> $hostname </td>
1469 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1470 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1472 if ($entries{$key}->{ENDTIME
} < time() ){
1473 print "<strike>$enddate</strike>";
1486 # This sub is used during display of actives leases
1488 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1490 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1491 if ($qs eq 'IPADDR') {
1492 @a = split(/\./,$entries{$a}->{$qs});
1493 @b = split(/\./,$entries{$b}->{$qs});
1499 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1504 $qs=$dhcpsettings{'SORT_LEASELIST'};
1505 if ($qs eq 'IPADDR') {
1506 @a = split(/\./,$entries{$a}->{$qs});
1507 @b = split(/\./,$entries{$b}->{$qs});
1513 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1520 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1521 foreach my $dir (readdir(DIR
)) {
1522 next if ($dir =~ /^\./);
1523 next if (-f
"${swroot}/uplinks/$dir");
1524 push(@uplinks, $dir);
1531 my $filename = shift;
1533 open (F
, $filename) || return "";
1540 sub get_red_ifaces_by_type
($) {
1542 my @gottypeiface = ();
1543 my @gottypeuplink = ();
1546 my $ref=get_uplinks
();
1549 foreach my $link (@uplinks) {
1551 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1553 push(@gottype, $link);
1555 my $iface = $set{'RED_DEV'};
1557 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1561 if ($set{'RED_TYPE'} eq $type) {
1562 push(@gottypeiface, $iface);
1563 push(@gottypeuplink, $link);
1566 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1569 sub get_red_ifaces
() {
1570 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1573 sub get_zone_devices
($) {
1576 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1577 foreach my $line (<FILE
>) {
1580 push(@ifaces, $line);