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'}",
249 $subnetwork->{'06.openvpn'} = {
250 'caption' => 'OpenVPN',
251 'uri' => '/cgi-bin/ovpnmain.cgi',
252 'title' => "$tr{'virtual private networking'}",
255 $subnetwork->{'07.ipsec'} = {
257 'uri
' => '/cgi-bin/vpnmain
.cgi
',
258 'title
' => "$tr{'virtual private networking
'}",
263 my %subserviceshash = ();
264 my $subservices = \%subserviceshash;
266 $subservices->{'01.proxy
'} = {
267 'caption
' => $tr{'proxy
'},
268 'uri
' => '/cgi-bin/proxy
.cgi
',
269 'title
' => "HTTP: $tr{'web proxy configuration
'}",
272 $subservices->{'02.dhcp
'} = {
273 'caption
' => $tr{'dhcp server
'},
274 'uri
' => '/cgi-bin/dhcp
.cgi
',
275 'title
' => "$tr{'dhcp configuration
'}",
278 $subservices->{'03.dyndns
'} = {
279 'caption
' => $tr{'dynamic dns
'},
280 'uri
' => '/cgi-bin/ddns
.cgi
',
281 'title
' => "$tr{'dynamic dns client
'}",
284 $subservices->{'04.time'} = {
285 'caption
' => $tr{'time server
'},
286 'uri
' => '/cgi-bin/time.cgi
',
287 'title
' => "$tr{'time server
'}",
290 $subservices->{'05.qos
'} = {
291 'caption
' => 'Quality of Service
',
292 'uri
' => '/cgi-bin/qos
.cgi
',
293 'title
' => "$tr{'traffic shaping settings
'}",
296 $subservices->{'06.ids
'} = {'caption
' => $tr{'intrusion detection
'},
298 'uri
' => '/cgi-bin/ids.cgi
',
299 'title
' => "$tr{'intrusion detection
system'} (Snort)",
303 my %subfirewallhash = ();
304 my $subfirewall = \%subfirewallhash;
307 $subfirewall->{'01.dnat
'} = {
308 'caption
' => $tr{'ssport forwarding
'},
309 'uri
' => '/cgi-bin/portfw
.cgi
',
310 'title
' => "$tr{'port forwarding configuration
'}",
313 $subfirewall->{'02.xtaccess
'} = {
314 'caption
' => $tr{'external access
'},
315 'uri
' => '/cgi-bin/xtaccess
.cgi
',
316 'title
' => "$tr{'external access configuration
'}",
319 $subfirewall->{'03.dmz
'} = {
320 'caption
' => $tr{'ssdmz pinholes
'},
321 'uri
' => '/cgi-bin/dmzholes
.cgi
',
322 'title
' => "$tr{'dmz pinhole configuration
'}",
325 $subfirewall->{'04.outgoing
'} = {
326 'caption
' => $tr{'outgoing firewall
'},
327 'uri
' => '/cgi-bin/outgoingfw
.cgi
',
328 'title
' => "$tr{'outgoing firewall
'}",
333 my %sublogshash = ();
334 my $sublogs = \%sublogshash;
336 $sublogs->{'01.summary
'} = {'caption
' => $tr{'log summary
'},
337 'uri
' => '/cgi-bin/logs.cgi
/summary
.dat
',
338 'title
' => "$tr{'log summary
'}",
341 $sublogs->{'02.settings
'} = {'caption
' => $tr{'log settings
'},
342 'uri
' => '/cgi-bin/logs.cgi
/config
.dat
',
343 'title
' => "$tr{'log settings
'}",
346 $sublogs->{'03.proxy
'} = {'caption
' => $tr{'proxy logs
'},
347 'uri
' => '/cgi-bin/logs.cgi
/proxylog
.dat
',
348 'title
' => "$tr{'proxy
log viewer
'}",
351 $sublogs->{'04.firewall
'} = {'caption
' => $tr{'firewall logs
'},
352 'uri
' => '/cgi-bin/logs.cgi
/firewalllog
.dat
',
353 'title
' => "$tr{'firewall
log viewer
'}",
356 $sublogs->{'05.ids
'} = {'caption
' => $tr{'ids logs
'},
357 'uri
' => '/cgi-bin/logs.cgi
/ids
.dat
',
358 'title
' => "$tr{'intrusion detection
system log viewer
'}",
361 $sublogs->{'06.contentfilter
'} = {'caption
' => $tr{'content filter logs
'},
362 'uri
' => '/cgi-bin/logs.cgi
/dansguardian
.dat
',
363 'title
' => "$tr{'content filter
log viewer
'}",
366 $sublogs->{'07.urlfilter
'} = {
367 'caption
' => $tr{'urlfilter
log'},
368 'uri
' => '/cgi-bin/logs.cgi
/urlfilter
.dat
',
369 'title
' => "$tr{'urlfilter
log'}",
372 $sublogs->{'08.openvpn
'} = {'caption
' => $tr{'openvpn
log'},
373 'uri
' => '/cgi-bin/logs.cgi
/openvpn
.dat
',
374 'title
' => "$tr{'openvpn
log'}",
377 $sublogs->{'09.system'} = {'caption
' => $tr{'system logs
'},
378 'uri
' => '/cgi-bin/logs.cgi
/log.dat
',
379 'title
' => "$tr{'system log viewer
'}",
382 $sublogs->{'10.userlog
'} = {'caption
' => $tr{'user proxy logs
'},
383 'uri
' => '/cgi-bin/logs.cgi
/userlog
.dat
',
384 'title
' => "$tr{'user
log viewer
'}",
388 my %subipfirehash = ();
389 my $subipfire = \%subipfirehash;
390 $subipfire->{'01.pakfire
'} = {'caption
' => $tr{'pakfire
'},
391 'uri
' => '/cgi-bin/pakfire
.cgi
',
392 'title
' => "$tr{'paketmanager
'}",
395 $subipfire->{'02.asterisk
'} = {'caption
' => $tr{'asterisk
'},
396 'uri
' => '/cgi-bin/asterisk
.cgi
',
397 'title
' => "$tr{'asterisk
'}",
400 $subipfire->{'02.samba
'} = {'caption
' => $tr{'samba
'},
401 'uri
' => '/cgi-bin/samba
.cgi
',
402 'title
' => "$tr{'samba
'}",
405 $subipfire->{'99.help
'} = {'caption
' => $tr{'help
'},
406 'uri
' => '/cgi-bin/help
.cgi
',
407 'title
' => "$tr{'help
'}",
413 $menu->{'01.system'} = {'caption
' => $tr{'alt
system'},
415 'subMenu
' => $subsystem
417 $menu->{'02.status
'} = {'caption
' => $tr{'status
'},
419 'subMenu
' => $substatus
421 $menu->{'03.network
'} = {'caption
' => $tr{'network
'},
423 'subMenu
' => $subnetwork
425 $menu->{'04.services
'} = {'caption
' => $tr{'alt services
'},
427 'subMenu
' => $subservices
429 $menu->{'05.firewall
'} = {'caption
' => $tr{'firewall
'},
431 'subMenu
' => $subfirewall
433 $menu->{'06.proxy
'} = {'caption
' => $tr{'alt proxy
'},
435 'subMenu
' => $subproxy
437 $menu->{'07.ipfire
'} = {'caption
' => 'IPFire
',
441 $menu->{'08.logs
'} = {'caption
' => $tr{'alt logs
'},
443 'subMenu
' => $sublogs
446 if (! blue_used() && ! orange_used()) {
447 $menu->{'05.firewall
'}{'subMenu
'}->{'03.dmz
'}{'enabled
'} = 0;
449 if (-e '/etc/FLASH
') {
450 $menu{'06.proxy
'}{'subMenu
'}->{'01.http
'}{'subMenu
'}->{'01.proxy
'}{'enabled
'} = 0; #disable squid
451 $menu{'04.services
'}{'subMenu
'}->{'05.ids
'}{'enabled
'} = 0; #disable ids
452 $menu{'08.logs
'}{'subMenu
'}->{'05.ids
'}{'enabled
'} = 0; #disable ids
458 print "Pragma: no-cache\n";
459 print "Cache-control: no-cache\n";
460 print "Connection: close\n";
461 print "Content-type: text/html\n\n";
464 sub is_menu_visible($) {
467 return (-e $ENV{'DOCUMENT_ROOT
'}."/../$link");
473 if (! $root->{'enabled
'}) {
476 if ($root->{'uri
'} !~ /^$/) {
478 if ($root->{'vars
'} !~ /^$/) {
479 $vars = '?
'. $root->{'vars
'};
481 if (! is_menu_visible($root->{'uri
'})) {
484 return $root->{'uri
'}.$vars;
486 my $submenus = $root->{'subMenu
'};
490 foreach my $item (sort keys %$submenus) {
491 my $link = getlink($submenus->{$item});
503 my $uri = $conf->{'uri
'};
504 my $vars = $conf->{'vars
'};
505 my $novars = $conf->{'novars
'};
510 if ($uri ne $URI[0]) {
514 if ($URI[1] !~ /^$/) {
521 return ($URI[1] eq $vars);
531 foreach my $item (sort keys %$root) {
532 my $val = $root->{$item};
533 if (compare_url($val)) {
534 $val->{'selected
'} = 1;
535 if ($val->{'title
'} !~ /^$/) {
536 return $val->{'title
'};
538 return 'EMPTY TITLE
';
541 my $title = gettitle($val->{'subMenu
'});
543 $val->{'selected
'} = 1;
557 foreach my $k1 ( sort keys %$menu ) {
558 if (! $menu->{$k1}{'enabled'}) {
562 my $link = getlink
($menu->{$k1});
566 if (! is_menu_visible
($link)) {
569 if ($menu->{$k1}->{'selected'}) {
570 print '<li class="selected">';
576 <div class="rcorner">
577 <a href="$link">$menu->{$k1}{'caption'}</a>
597 foreach my $item (%$root) {
598 if ($root->{$item}{'selected'}) {
599 return $root->{$item};
604 sub showsubsection
($$) {
614 my $selected = getselected
($root);
618 my $submenus = $selected->{'subMenu'};
628 foreach my $item (sort keys %$submenus) {
629 my $hash = $submenus->{$item};
630 if (! $hash->{'enabled'}) {
634 my $link = getlink
($hash);
638 if (! is_menu_visible
($link)) {
641 if ($hash->{'selected'}) {
642 print '<li class="selected">';
648 <a href="$link">$hash->{'caption'}</a>
663 sub showsubsubsection
($) {
668 my $selected = getselected
($root);
672 if (! $selected->{'subMenu'}) {
676 showsubsection
($selected->{'subMenu'}, 'menu-subtop');
682 if ($URI[0] =~ /.*\/([^\
/]+)\.cgi/) {
687 $helpfile .= '.help.html';
689 my $helpuri = '/doc/'.$language.'/'.$helpfile;
690 if (! -e
$ENV{'DOCUMENT_ROOT'}.$helpuri) {
700 my $extrahead = shift;
702 @URI=split ('\?', $ENV{'REQUEST_URI'} );
703 &readhash
("${swroot}/main/settings", \
%settings);
706 my $h2 = gettitle
($menu);
707 my $helpuri = get_helpuri
();
709 $title = "IPFire - $title";
710 if ($settings{'WINDOWWITHHOSTNAME'} eq 'on') {
711 $title = "$settings{'HOSTNAME'}.$settings{'DOMAINNAME'} - $title";
716 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
717 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
721 <title>$title</title>
724 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
725 <link rel="shortcut icon" href="/favicon.ico" />
726 <style type="text/css">\@import url(/include/style.css);</style>
727 <style type="text/css">\@import url(/include/menu.css);</style>
728 <style type="text/css">\@import url(/include/content.css);</style>
730 <script language="javascript" type="text/javascript">
732 function swapVisibility(id) {
733 el = document.getElementById(id);
734 if(el.style.display != 'block') {
735 el.style.display = 'block'
738 el.style.display = 'none'
745 <!-- IPFIRE HEADER -->
750 <img id="logo-product" src="/images/logo_ipfire.gif">
751 <div id="header-icons">
755 if ($helpuri ne '') {
757 <a href="$helpuri" target="_blank"><img border="0" src="/images/help.gif"></a>
761 print '<img src="/images/help.gif">';
781 &showsubsection
($menu);
786 <td width="100%" valign="top">
787 <div id="page-content">
792 &showsubsubsection
($menu);
795 require 'ipfire-network.pl';
796 $supported = check_support
();
797 warn_unsupported
($supported);
802 my $status = &connectionstatus
();
803 $uptime = `/usr/bin/uptime`;
808 <div style="font-size: 9px"><b>Status:</b> $status <b>Uptime:</b>$uptime</div>
812 <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0,Transition=12)">
813 <meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0,Transition=12)">
826 $bgcolor = "style='background-color: $colourerr;'";
834 # print "</td></tr></table></td></tr></table>\n"
843 if ($caption) { print "<h3>$caption</h3>\n"; } else { print " "; }
845 print "<table class=\"list\"><tr><td align=\"$align\">\n";
850 print "</td></tr></table><br><br>";
855 my $filename = $_[0];
858 # write cgi vars to the file.
859 open(FILE
, ">${filename}") or die "Unable to write file $filename";
861 foreach $var (keys %$hash)
863 $val = $hash->{$var};
864 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
865 # location of the mouse are submitted as well, this was being written to the settings file causing
866 # some serious grief! This skips the variable.x and variable.y
867 if (!($var =~ /(.x|.y)$/)) {
870 if (!($var =~ /^ACTION/)) {
871 print FILE
"${var}=${val}\n"; }
879 my $filename = $_[0];
883 open(FILE
, $filename) or die "Unable to read file $filename";
888 ($var, $val) = split /=/, $_, 2;
894 # Untaint variables read from hash
895 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
896 $val =~ /([\w\W]*)/; $val = $1;
897 $hash->{$var} = $val;
904 my ($hash, $params) = @_;
905 my $cgi = CGI
->new ();
906 $hash->{'__CGI__'} = $cgi;
907 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
908 if (!$params->{'wantfile'}) {
909 $CGI::DISABLE_UPLOADS
= 1;
910 $CGI::POST_MAX
= 512 * 1024;
912 $CGI::POST_MAX
= 10 * 1024 * 1024;
915 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
917 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
919 return if ($referer ne $servername);
921 ### Modified for getting multi-vars, split by |
922 %temp = $cgi->Vars();
923 foreach my $key (keys %temp) {
924 $hash->{$key} = $temp{$key};
925 $hash->{$key} =~ s/\0/|/g;
926 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
929 if (($params->{'wantfile'})&&($params->{'filevar'})) {
930 $hash->{$params->{'filevar'}} = $cgi->upload
931 ($params->{'filevar'});
938 my $logmessage = $_[0];
939 $logmessage =~ /([\w\W]*)/;
941 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
946 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
947 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
950 my $totalsecs = $now - $mtime;
951 my $days = int($totalsecs / 86400);
952 my $totalhours = int($totalsecs / 3600);
953 my $hours = $totalhours % 24;
954 my $totalmins = int($totalsecs / 60);
955 my $mins = $totalmins % 60;
956 my $secs = $totalsecs % 60;
958 return "${days}d ${hours}h ${mins}m ${secs}s";
965 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
969 @octets = ($1, $2, $3, $4);
974 if ($_ < 0 || $_ > 255) {
986 if (&validip
($mask)) {
988 # second part a number?
991 if (!($mask =~ /^\d+$/)) {
993 if ($mask >= 0 && $mask <= 32) {
1000 my $ipormask = $_[0];
1002 # see if it is a IP only.
1003 if (&validip
($ipormask)) {
1005 # split it into number and mask.
1006 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
1010 # first part not a ip?
1011 if (!(&validip
($ip))) {
1013 return &validmask
($mask);
1018 my $ipandmask = $_[0];
1020 # split it into number and mask.
1021 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
1025 # first part not a ip?
1026 if (!(&validip
($ip))) {
1028 return &validmask
($mask);
1039 if ($_ >= 1 && $_ <= 65535) {
1046 my $checkmac = $_[0];
1047 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
1048 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
1057 # Checks a hostname against RFC1035
1058 my $hostname = $_[0];
1060 # Each part should be at least two characters in length
1061 # but no more than 63 characters
1062 if (length ($hostname) < 2 || length ($hostname) > 63) {
1064 # Only valid characters are a-z, A-Z, 0-9 and -
1065 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
1067 # First character can only be a letter or a digit
1068 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1070 # Last character can only be a letter or a digit
1071 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1078 # Checks a domain name against RFC1035
1079 my $domainname = $_[0];
1080 my @parts = split (/\./, $domainname); # Split hostname at the '.'
1082 foreach $part (@parts) {
1083 # Each part should be at least two characters in length
1084 # but no more than 63 characters
1085 if (length ($part) < 2 || length ($part) > 63) {
1087 # Only valid characters are a-z, A-Z, 0-9 and -
1088 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1090 # First character can only be a letter or a digit
1091 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1093 # Last character can only be a letter or a digit
1094 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1102 # Checks a fully qualified domain name against RFC1035
1104 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
1105 if (scalar(@parts) < 2) { # At least two parts should
1106 return 0;} # exist in a FQDN
1107 # (i.e. hostname.domain)
1108 foreach $part (@parts) {
1109 # Each part should be at least two characters in length
1110 # but no more than 63 characters
1111 if (length ($part) < 2 || length ($part) > 63) {
1113 # Only valid characters are a-z, A-Z, 0-9 and -
1114 if ($part !~ /^[a-zA-Z0-9-]*$/) {
1116 # First character can only be a letter or a digit
1117 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
1119 # Last character can only be a letter or a digit
1120 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
1126 sub validportrange
# used to check a port range
1128 my $port = $_[0]; # port values
1129 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
1130 my $srcdst = $_[1]; # is it a source or destination port
1132 if (!($port =~ /^(\d+)\:(\d+)$/)) {
1134 if (!(&validport
($port))) {
1135 if ($srcdst eq 'src'){
1136 return $tr{'source port numbers'};
1138 return $tr{'destination port numbers'};
1146 if ($srcdst eq 'src'){
1147 return $tr{'bad source range'};
1149 return $tr{'bad destination range'};
1154 if (!(&validport
($_))) {
1155 if ($srcdst eq 'src'){
1156 return $tr{'source port numbers'};
1158 return $tr{'destination port numbers'};
1166 # Test if IP is within a subnet
1167 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
1168 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
1169 # Everything in dottted notation
1170 # Return: TRUE/FALSE
1173 $ip = unpack('N', inet_aton
(shift));
1174 $start = unpack('N', inet_aton
(shift));
1175 $mask = unpack('N', inet_aton
(shift));
1176 $start &= $mask; # base of subnet...
1177 $end = $start + ~$mask;
1178 return (($ip >= $start) && ($ip <= $end));
1183 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
1184 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
1185 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
1186 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
1187 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
1188 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
1189 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
1194 my ($filename, $hash) = @_;
1196 open(FILE
, $filename) or die "Unable to read file $filename";
1199 my ($key, $rest, @temp);
1201 ($key, $rest) = split (/,/, $_, 2);
1202 if ($key =~ /^[0-9]+$/ && $rest) {
1203 @temp = split (/,/, $rest);
1204 $hash->{$key} = \
@temp;
1211 sub writehasharray
{
1212 my ($filename, $hash) = @_;
1215 open(FILE
, ">$filename") or die "Unable to write to file $filename";
1217 foreach $key (keys %$hash) {
1218 if ( $hash->{$key} ) {
1220 foreach $i (0 .. $#{$hash->{$key}}) {
1221 print FILE
",$hash->{$key}[$i]";
1230 sub findhasharraykey
{
1231 foreach my $i (1 .. 1000000) {
1232 if ( ! exists $_[0]{$i}) {
1240 my $outstring =$_[0];
1241 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
1242 $outstring =~ s/&/&/g;
1243 $outstring =~ s/\'/'/g;
1244 $outstring =~ s/\"/"/g;
1245 $outstring =~ s/</</g;
1246 $outstring =~ s/>/>/g;
1249 sub connectionstatus
1252 opendir UPLINKS
, "/var/ipfire/uplinks" or die "Cannot read uplinks: $!";
1253 foreach my $uplink (sort grep !/^\./, readdir UPLINKS
) {
1254 if ( -f
"${swroot}/uplinks/${uplink}/active") {
1256 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1257 $status = "$tr{'connected'}: $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1259 $timestr = &age
("${swroot}/uplinks/${uplink}/active");
1260 $status = "$status , $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1262 } elsif ( -f
"${swroot}/uplinks/${uplink}/connecting") {
1264 $status = "$tr{'connecting'} $uplink";
1266 $status = "$status , $tr{'connecting'} $uplink (<span class='ipcop_StatusBigRed'>$timestr</span>) ";
1273 $status = "$tr{'idle'}";
1275 $connstate = "<span class='ipcop_StatusBig'>$status</span>";
1280 # Darren Critchley - darrenc@telus.net - (c) 2003
1281 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1282 # This subroutine will take the following parameters:
1283 # ColumnNumber = the column which you want to sort on, starts at 1
1284 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1285 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1286 # ArrayToBeSorted = the array that wants sorting
1288 # Returns an array that is sorted to your specs
1290 # If SortOrder is greater than the elements in array, then it defaults to the first element
1293 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1298 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1299 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1300 return (@tobesorted);
1302 my @tmp = split(/\,/,$tobesorted[0]);
1303 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1305 # Darren Critchley - validate parameters
1306 if ($colno > $ttlitems){$colno = '1';}
1307 $colno--; # remove one from colno to deal with arrays starting at 0
1308 if($colno < 0){$colno = '0';}
1309 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1310 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1312 foreach $line (@tobesorted)
1316 my @temp = split(/\,/,$line);
1317 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1318 my $tmpholder = $temp[0];
1319 $temp[0] = $temp[$colno];
1320 $temp[$colno] = $tmpholder;
1322 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1323 $newline=$newline . $temp[$ctr] . ",";
1326 push(@tmparray,$newline);
1329 if ($alpnum eq 'n') {
1330 @tmparray = sort {$a <=> $b} @tmparray;
1332 @tmparray = (sort @tmparray);
1334 foreach $line (@tmparray)
1338 my @temp = split(/\,/,$line);
1339 my $tmpholder = $temp[0];
1340 $temp[0] = $temp[$colno];
1341 $temp[$colno] = $tmpholder;
1343 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1344 $newline=$newline . $temp[$ctr] . ",";
1347 push(@srtedarray,$newline);
1351 if ($srtdir eq 'dsc') {
1352 @tmparray = reverse(@srtedarray);
1355 return (@srtedarray);
1359 sub speedtouchversion
1361 if (-f
"/proc/bus/usb/devices")
1363 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1364 if ($speedtouch eq '') {
1365 $speedtouch= $tr{'connect the modem'};
1368 $speedtouch='USB '.$tr{'not running'};
1373 sub CheckSortOrder
{
1374 #Sorting of allocated leases
1375 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1376 my $newsort=$ENV{'QUERY_STRING'};
1377 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1378 $act=$dhcpsettings{'SORT_LEASELIST'};
1380 if ($act =~ $newsort) {
1381 if ($act !~ 'Rev') {$Rev='Rev'};
1385 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1386 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1387 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1392 sub PrintActualLeases
1394 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1396 <table width='100%'>
1398 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1399 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1400 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1401 <td width='30%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1406 open(LEASES
,"/var/lib/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1407 while ($line = <LEASES
>) {
1408 next if( $line =~ /^\s*#/ );
1410 @temp = split (' ', $line);
1412 if ($line =~ /^\s*lease/) {
1414 #All field are not necessarily read. Clear everything
1420 if ($line =~ /^\s*ends/) {
1421 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1422 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1425 if ($line =~ /^\s*hardware ethernet/) {
1430 if ($line =~ /^\s*client-hostname/) {
1431 $hostname = "$temp[1] $temp[2] $temp[3]";
1432 $hostname =~ s/;//g;
1433 $hostname =~ s/\"//g;
1437 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1438 $record = {}; # create a reference to empty hash
1439 %{$record} = @record; # populate that hash with @record
1440 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1446 foreach my $key (sort leasesort
keys %entries) {
1448 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1451 print "<tr bgcolor='$table1colour'>";
1454 print "<tr bgcolor='$table2colour'>";
1458 <td align='center'>$entries{$key}->{IPADDR}</td>
1459 <td align='center'>$entries{$key}->{ETHER}</td>
1460 <td align='center'> $hostname </td>
1465 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1466 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1468 if ($entries{$key}->{ENDTIME
} < time() ){
1469 print "<strike>$enddate</strike>";
1482 # This sub is used during display of actives leases
1484 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1486 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1487 if ($qs eq 'IPADDR') {
1488 @a = split(/\./,$entries{$a}->{$qs});
1489 @b = split(/\./,$entries{$b}->{$qs});
1495 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1500 $qs=$dhcpsettings{'SORT_LEASELIST'};
1501 if ($qs eq 'IPADDR') {
1502 @a = split(/\./,$entries{$a}->{$qs});
1503 @b = split(/\./,$entries{$b}->{$qs});
1509 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1516 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1517 foreach my $dir (readdir(DIR
)) {
1518 next if ($dir =~ /^\./);
1519 next if (-f
"${swroot}/uplinks/$dir");
1520 push(@uplinks, $dir);
1527 my $filename = shift;
1529 open (F
, $filename) || return "";
1536 sub get_red_ifaces_by_type
($) {
1538 my @gottypeiface = ();
1539 my @gottypeuplink = ();
1542 my $ref=get_uplinks
();
1545 foreach my $link (@uplinks) {
1547 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1549 push(@gottype, $link);
1551 my $iface = $set{'RED_DEV'};
1553 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1557 if ($set{'RED_TYPE'} eq $type) {
1558 push(@gottypeiface, $iface);
1559 push(@gottypeuplink, $link);
1562 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1565 sub get_red_ifaces
() {
1566 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1569 sub get_zone_devices
($) {
1572 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1573 foreach my $line (<FILE
>) {
1576 push(@ifaces, $line);