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'} = {
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 <link rel="shortcut icon" href="/favicon.ico" />
731 <style type="text/css">\@import url(/include/style.css);</style>
732 <style type="text/css">\@import url(/include/menu.css);</style>
733 <style type="text/css">\@import url(/include/content.css);</style>
735 <script language="javascript" type="text/javascript">
737 function swapVisibility(id) {
738 el = document.getElementById(id);
739 if(el.style.display != 'block') {
740 el.style.display = 'block'
743 el.style.display = 'none'
750 <!-- IPFIRE HEADER -->
755 <img id="logo-product" src="/images/logo_ipfire.gif">
756 <div id="header-icons">
760 if ($helpuri ne '') {
762 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
766 print '<img src="/images/help.gif">';
786 &showsubsection
($menu);
791 <td width="100%" valign="top">
792 <div id="page-content">
797 &showsubsubsection
($menu);
800 require 'ipfire-network.pl';
801 $supported = check_support
();
802 warn_unsupported
($supported);
807 my $status = &connectionstatus
();
808 $uptime = `/usr/bin/uptime`;
813 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
817 <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">
818 <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">
831 $bgcolor = "style='background-color: $colourerr;'";
839 # print "</td></tr></table></td></tr></table>\n"
848 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
850 print "<table class=\"list\"><tr><td align=\"$align\">\n";
855 print "</td></tr></table><br><br>";
860 my $filename = $_[0];
863 # write cgi vars to the file.
864 open(FILE
, ">${filename}") or die "Unable to write file $filename";
866 foreach $var (keys %$hash)
868 $val = $hash->{$var};
869 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
870 # location of the mouse are submitted as well, this was being written to the settings file causing
871 # some serious grief! This skips the variable.x and variable.y
872 if (!($var =~ /(.x|.y)$/)) {
875 if (!($var =~ /^ACTION/)) {
876 print FILE
"${var}=${val}\n"; }
884 my $filename = $_[0];
888 open(FILE
, $filename) or die "Unable to read file $filename";
893 ($var, $val) = split /=/, $_, 2;
899 # Untaint variables read from hash
900 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
901 $val =~ /([\w\W]*)/; $val = $1;
902 $hash->{$var} = $val;
909 my ($hash, $params) = @_;
910 my $cgi = CGI
->new ();
911 $hash->{'__CGI__'} = $cgi;
912 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
913 if (!$params->{'wantfile'}) {
914 $CGI::DISABLE_UPLOADS
= 1;
915 $CGI::POST_MAX
= 512 * 1024;
917 $CGI::POST_MAX
= 10 * 1024 * 1024;
920 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
922 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
924 return if ($referer ne $servername);
926 ### Modified for getting multi-vars, split by |
927 %temp = $cgi->Vars();
928 foreach my $key (keys %temp) {
929 $hash->{$key} = $temp{$key};
930 $hash->{$key} =~ s/\0/|/g;
931 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
934 if (($params->{'wantfile'})&&($params->{'filevar'})) {
935 $hash->{$params->{'filevar'}} = $cgi->upload
936 ($params->{'filevar'});
943 my $logmessage = $_[0];
944 $logmessage =~ /([\w\W]*)/;
946 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
951 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
952 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
955 my $totalsecs = $now - $mtime;
956 my $days = int($totalsecs / 86400);
957 my $totalhours = int($totalsecs / 3600);
958 my $hours = $totalhours % 24;
959 my $totalmins = int($totalsecs / 60);
960 my $mins = $totalmins % 60;
961 my $secs = $totalsecs % 60;
963 return "${days}d ${hours}h ${mins}m ${secs}s";
970 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
974 @octets = ($1, $2, $3, $4);
979 if ($_ < 0 || $_ > 255) {
991 if (&validip
($mask)) {
993 # second part a number?
996 if (!($mask =~ /^\d+$/)) {
998 if ($mask >= 0 && $mask <= 32) {
1005 my $ipormask = $_[0];
1007 # see if it is a IP only.
1008 if (&validip
($ipormask)) {
1010 # split it into number and mask.
1011 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1015 # first part not a ip?
1016 if (!(&validip
($ip))) {
1018 return &validmask
($mask);
1023 my $ipandmask = $_[0];
1025 # split it into number and mask.
1026 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1030 # first part not a ip?
1031 if (!(&validip
($ip))) {
1033 return &validmask
($mask);
1044 if ($_ >= 1 && $_ <= 65535) {
1051 my $checkmac = $_[0];
1052 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1053 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1062 # Checks a hostname against RFC1035
1063 my $hostname = $_[0];
1065 # Each part should be at least two characters in length
1066 # but no more than 63 characters
1067 if (length ($hostname) < 2 || length ($hostname) > 63) {
1069 # Only valid characters are a-z, A-Z, 0-9 and -
1070 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1072 # First character can only be a letter or a digit
1073 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1075 # Last character can only be a letter or a digit
1076 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1083 # Checks a domain name against RFC1035
1084 my $domainname = $_[0];
1085 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1087 foreach $part (@parts) {
1088 # Each part should be at least two characters in length
1089 # but no more than 63 characters
1090 if (length ($part) < 2 || length ($part) > 63) {
1092 # Only valid characters are a-z, A-Z, 0-9 and -
1093 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1095 # First character can only be a letter or a digit
1096 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1098 # Last character can only be a letter or a digit
1099 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1107 # Checks a fully qualified domain name against RFC1035
1109 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1110 if (scalar(@parts) < 2) { # At least two parts should
1111 return 0;} # exist in a FQDN
1112 # (i.e. hostname.domain)
1113 foreach $part (@parts) {
1114 # Each part should be at least two characters in length
1115 # but no more than 63 characters
1116 if (length ($part) < 2 || length ($part) > 63) {
1118 # Only valid characters are a-z, A-Z, 0-9 and -
1119 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1121 # First character can only be a letter or a digit
1122 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1124 # Last character can only be a letter or a digit
1125 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1131 sub validportrange
# used to check a port range
1133 my $port = $_[0]; # port values
1134 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1135 my $srcdst = $_[1]; # is it a source or destination port
1137 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1139 if (!(&validport
($port))) {
1140 if ($srcdst eq 'src'){
1141 return $tr{'source port numbers'};
1143 return $tr{'destination port numbers'};
1151 if ($srcdst eq 'src'){
1152 return $tr{'bad source range'};
1154 return $tr{'bad destination range'};
1159 if (!(&validport
($_))) {
1160 if ($srcdst eq 'src'){
1161 return $tr{'source port numbers'};
1163 return $tr{'destination port numbers'};
1171 # Test if IP is within a subnet
1172 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1173 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1174 # Everything in dottted notation
1175 # Return: TRUE/FALSE
1178 $ip = unpack('N', inet_aton
(shift));
1179 $start = unpack('N', inet_aton
(shift));
1180 $mask = unpack('N', inet_aton
(shift));
1181 $start &= $mask; # base of subnet...
1182 $end = $start + ~$mask;
1183 return (($ip >= $start) && ($ip <= $end));
1188 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1189 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1190 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1191 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1192 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1193 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1194 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1199 my ($filename, $hash) = @_;
1201 open(FILE
, $filename) or die "Unable to read file $filename";
1204 my ($key, $rest, @temp);
1206 ($key, $rest) = split (/,/, $_, 2);
1207 if ($key =~ /^[0-9]+$/ && $rest) {
1208 @temp = split (/,/, $rest);
1209 $hash->{$key} = \
@temp;
1216 sub writehasharray
{
1217 my ($filename, $hash) = @_;
1220 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1222 foreach $key (keys %$hash) {
1223 if ( $hash->{$key} ) {
1225 foreach $i (0 .. $#{$hash->{$key}}) {
1226 print FILE
",$hash->{$key}[$i]";
1235 sub findhasharraykey
{
1236 foreach my $i (1 .. 1000000) {
1237 if ( ! exists $_[0]{$i}) {
1245 my $outstring =$_[0];
1246 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1247 $outstring =~ s/&/&/g;
1248 $outstring =~ s/\'/'/g;
1249 $outstring =~ s/\"/"/g;
1250 $outstring =~ s/</</g;
1251 $outstring =~ s/>/>/g;
1254 sub connectionstatus
1257 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1258 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1259 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1261 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1262 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1264 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1265 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1267 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1269 $status = "$tr{'connecting'} $uplink";
1271 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1278 $status = "$tr{'idle'}";
1280 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1285 # Darren Critchley - darrenc@telus.net - (c) 2003
1286 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1287 # This subroutine will take the following parameters:
1288 # ColumnNumber = the column which you want to sort on, starts at 1
1289 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1290 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1291 # ArrayToBeSorted = the array that wants sorting
1293 # Returns an array that is sorted to your specs
1295 # If SortOrder is greater than the elements in array, then it defaults to the first element
1298 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1303 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1304 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1305 return (@tobesorted);
1307 my @tmp = split(/\,/,$tobesorted[0]);
1308 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1310 # Darren Critchley - validate parameters
1311 if ($colno > $ttlitems){$colno = '1';}
1312 $colno--; # remove one from colno to deal with arrays starting at 0
1313 if($colno < 0){$colno = '0';}
1314 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1315 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1317 foreach $line (@tobesorted)
1321 my @temp = split(/\,/,$line);
1322 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1323 my $tmpholder = $temp[0];
1324 $temp[0] = $temp[$colno];
1325 $temp[$colno] = $tmpholder;
1327 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1328 $newline=$newline . $temp[$ctr] . ",";
1331 push(@tmparray,$newline);
1334 if ($alpnum eq 'n') {
1335 @tmparray = sort {$a <=> $b} @tmparray;
1337 @tmparray = (sort @tmparray);
1339 foreach $line (@tmparray)
1343 my @temp = split(/\,/,$line);
1344 my $tmpholder = $temp[0];
1345 $temp[0] = $temp[$colno];
1346 $temp[$colno] = $tmpholder;
1348 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1349 $newline=$newline . $temp[$ctr] . ",";
1352 push(@srtedarray,$newline);
1356 if ($srtdir eq 'dsc') {
1357 @tmparray = reverse(@srtedarray);
1360 return (@srtedarray);
1364 sub speedtouchversion
1366 if (-f
"/proc/bus/usb/devices")
1368 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1369 if ($speedtouch eq '') {
1370 $speedtouch= $tr{'connect the modem'};
1373 $speedtouch='USB '.$tr{'not running'};
1378 sub CheckSortOrder
{
1379 #Sorting of allocated leases
1380 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1381 my $newsort=$ENV{'QUERY_STRING'};
1382 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1383 $act=$dhcpsettings{'SORT_LEASELIST'};
1385 if ($act =~ $newsort) {
1386 if ($act !~ 'Rev') {$Rev='Rev'};
1390 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1391 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1392 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1397 sub PrintActualLeases
1399 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1401 <table width='100%'>
1403 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1404 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1405 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1406 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1411 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1412 while ($line = <LEASES
>) {
1413 next if( $line =~ /^\s*#/ );
1415 @temp = split (' ', $line);
1417 if ($line =~ /^\s*lease/) {
1419 #All field are not necessarily read. Clear everything
1425 if ($line =~ /^\s*ends/) {
1426 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1427 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1430 if ($line =~ /^\s*hardware ethernet/) {
1435 if ($line =~ /^\s*client-hostname/) {
1436 $hostname = "$temp[1] $temp[2] $temp[3]";
1437 $hostname =~ s/;//g;
1438 $hostname =~ s/\"//g;
1442 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1443 $record = {}; # create a reference to empty hash
1444 %{$record} = @record; # populate that hash with @record
1445 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1451 foreach my $key (sort leasesort
keys %entries) {
1453 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1456 print "<tr bgcolor='$table1colour'>";
1459 print "<tr bgcolor='$table2colour'>";
1463 <td align='center'>$entries{$key}->{IPADDR}</td>
1464 <td align='center'>$entries{$key}->{ETHER}</td>
1465 <td align='center'> $hostname </td>
1470 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1471 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1473 if ($entries{$key}->{ENDTIME
} < time() ){
1474 print "<strike>$enddate</strike>";
1487 # This sub is used during display of actives leases
1489 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1491 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1492 if ($qs eq 'IPADDR') {
1493 @a = split(/\./,$entries{$a}->{$qs});
1494 @b = split(/\./,$entries{$b}->{$qs});
1500 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1505 $qs=$dhcpsettings{'SORT_LEASELIST'};
1506 if ($qs eq 'IPADDR') {
1507 @a = split(/\./,$entries{$a}->{$qs});
1508 @b = split(/\./,$entries{$b}->{$qs});
1514 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1521 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1522 foreach my $dir (readdir(DIR
)) {
1523 next if ($dir =~ /^\./);
1524 next if (-f
"${swroot}/uplinks/$dir");
1525 push(@uplinks, $dir);
1532 my $filename = shift;
1534 open (F
, $filename) || return "";
1541 sub get_red_ifaces_by_type
($) {
1543 my @gottypeiface = ();
1544 my @gottypeuplink = ();
1547 my $ref=get_uplinks
();
1550 foreach my $link (@uplinks) {
1552 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1554 push(@gottype, $link);
1556 my $iface = $set{'RED_DEV'};
1558 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1562 if ($set{'RED_TYPE'} eq $type) {
1563 push(@gottypeiface, $iface);
1564 push(@gottypeuplink, $link);
1567 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1570 sub get_red_ifaces
() {
1571 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1574 sub get_zone_devices
($) {
1577 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1578 foreach my $line (<FILE
>) {
1581 push(@ifaces, $line);