]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/cfgroot/header.pl
3 # This code is distributed under the terms of the GPL
5 # (c) The SmoothWall Team
6 # Copyright (C) 2002 Alex Hudson - getcgihash() rewrite
7 # Copyright (C) 2002 Bob Grant <bob@cache.ucr.edu> - validmac()
8 # Copyright (c) 2002/04/13 Steve Bootes - add alias section, helper functions
9 # Copyright (c) 2002/08/23 Mark Wormgoor <mark@wormgoor.com> validfqdn()
10 # Copyright (c) 2003/09/11 Darren Critchley <darrenc@telus.net> srtarray()
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::colourovpn
= '#339999';
36 $Header::colourfw
= '#000000';
37 $Header::colourvpn
= '#990099';
38 $Header::colourerr
= '#FF0000';
39 $Header::viewsize
= 150;
40 $Header::errormessage
= '';
42 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'}:444/$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}";
89 ### Read IPFire Buildversion
90 $FIREBUILD = "File not found: firebuild\n";
91 if (open(MYFile
, "<${swroot}/firebuild")) {
92 $FIREBUILD = <MYFile
>;
94 $FIREBUILD = "(Build: $FIREBUILD)";
98 require "${swroot}/langs/en.pl";
99 require "${swroot}/langs/${language}.pl";
100 eval `/bin/cat /srv/web/ipfire/html/themes/$settings{'THEME'}/include/functions.pl`;
103 if ($ethsettings{'CONFIG_TYPE'} =~ /^[1357]$/) {
110 if ($ethsettings{'CONFIG_TYPE'} =~ /^[4567]$/) {
117 if ($ethsettings{'CONFIG_TYPE'} =~ /^[0145]$/) {
125 my %subsystemhash = ();
126 my $subsystem = \
%subsystemhash;
128 $subsystem->{'10.home'} = {
129 'caption' => $tr{'alt home'},
130 'uri' => '/cgi-bin/index.cgi',
131 'title' => "$tr{'alt home'}",
134 $subsystem->{'20.dialup'} = {
135 'caption' => $tr{'alt dialup'},
136 'uri' => '/cgi-bin/pppsetup.cgi',
137 'title' => "$tr{'alt dialup'}",
140 $subsystem->{'30.passwords'} = {
141 'caption' => $tr{'sspasswords'},
142 'uri' => '/cgi-bin/changepw.cgi',
143 'title' => "$tr{'sspasswords'}",
146 $subsystem->{'40.ssh'} = {
147 'caption' => $tr{'ssh access'},
148 'uri' => '/cgi-bin/remote.cgi',
149 'title' => "$tr{'ssh access'}",
152 $subsystem->{'50.gui'} = {
153 'caption' => $tr{'gui settings'},
154 'uri' => '/cgi-bin/gui.cgi',
155 'title' => "$tr{'gui settings'}",
158 $subsystem->{'60.shutdown'} = {
159 'caption' => $tr{'shutdown'},
160 'uri' => '/cgi-bin/shutdown.cgi',
161 'title' => "$tr{'shutdown'} / $tr{'reboot'}",
164 $subsystem->{'99.credits'} = {
165 'caption' => $tr{'credits'},
166 'uri' => '/cgi-bin/credits.cgi',
167 'title' => "$tr{'credits'}",
171 my %substatushash = ();
172 my $substatus = \
%substatushash;
173 $substatus->{'10.systemstatus'} = {
174 'caption' => $tr{'sssystem status'},
175 'uri' => '/cgi-bin/status.cgi',
176 'title' => "$tr{'sssystem status'}",
179 $substatus->{'20.networkstatus'} = {
180 'caption' => $tr{'ssnetwork status'},
181 'uri' => '/cgi-bin/netstatus.cgi',
182 'title' => "$tr{'ssnetwork status'}",
185 $substatus->{'30.systemgraphs'} = {
186 'caption' => $tr{'system graphs'},
187 'uri' => '/cgi-bin/graphs.cgi',
189 'title' => "$tr{'system graphs'}",
192 $substatus->{'40.trafficgraphs'} = {
193 'caption' => $tr{'sstraffic graphs'},
194 'uri' => '/cgi-bin/graphs.cgi',
195 'vars' => 'graph=network',
196 'title' => "$tr{'sstraffic graphs'}",
199 $substatus->{'50.proxygraphs'} = {
200 'caption' => $tr{'ssproxy graphs'},
201 'uri' => '/cgi-bin/proxygraphs.cgi',
202 'title' => "$tr{'ssproxy graphs'}",
205 $substatus->{'60.fwhits'} = {
206 'caption' => 'Firewall-Diagramme',
207 'uri' => '/cgi-bin/fwhits.cgi',
208 'title' => "Firewall-Diagramme",
211 $substatus->{'70.hardwaregraphs'} = {
212 'caption' => "$tr{'hardware graphs'}",
213 'uri' => '/cgi-bin/hardwaregraphs.cgi',
214 'title' => "$tr{'hardware graphs'}",
217 $substatus->{'80.connections'} = {
218 'caption' => $tr{'connections'},
219 'uri' => '/cgi-bin/connections.cgi',
220 'title' => "$tr{'connections'}",
223 $substatus->{'90.nettraf'} = {
224 'caption' => $tr{'sstraffic'},
225 'uri' => '/cgi-bin/traffic.cgi',
226 'title' => "$tr{'sstraffic'}",
229 $substatus->{'99.iptable'} = {
230 'caption' => $tr{'iptable rules'},
231 'uri' => '/cgi-bin/iptables.cgi',
232 'title' => "$tr{'iptable rules'}",
236 my %subnetworkhash = ();
237 my $subnetwork = \
%subnetworkhash;
239 $subnetwork->{'10.netconf'} = {'caption' => "$tr{'net config'}",
240 'uri' => '/cgi-bin/netconfig.cgi',
241 'title' => "$tr{'net config'}",
244 $subnetwork->{'20.proxy'} = {'caption' => 'Webproxy',
245 'uri' => '/cgi-bin/proxy.cgi',
246 'title' => "Webproxy",
249 $subnetwork->{'30.urlfilter'} = {'caption' => 'URL-Filter',
250 'uri' => '/cgi-bin/urlfilter.cgi',
251 'title' => "URL-Filter",
254 $subnetwork->{'40.dhcp'} = {'caption' => $tr{'dhcp server'},
255 'uri' => '/cgi-bin/dhcp.cgi',
256 'title' => "$tr{'dhcp server'}",
259 $subnetwork->{'50.scheduler'} = {
260 'caption' => $tr{'connscheduler'},
261 'uri' => '/cgi-bin/connscheduler.cgi',
262 'title' => "$tr{'connscheduler'}",
265 $subnetwork->{'60.hosts'} = {
266 'caption' => $tr{'edit hosts'},
267 'uri' => '/cgi-bin/hosts.cgi',
268 'title' => "$tr{'edit hosts'}",
271 $subnetwork->{'70.upload'} = {
272 'caption' => $tr{'upload'},
273 'uri' => '/cgi-bin/upload.cgi',
274 'title' => "$tr{'upload'}",
277 $subnetwork->{'80.aliases'} = {
278 'caption' => $tr{'aliases'},
279 'uri' => '/cgi-bin/aliases.cgi',
280 'title' => "$tr{'aliases'}",
283 $subnetwork->{'90.wakeonlan'} = {
284 'caption' => $tr{'WakeOnLan'},
285 'uri' => '/cgi-bin/wakeonlan.cgi',
286 'title' => "$tr{'WakeOnLan'}",
290 my %subserviceshash = ();
291 my $subservices = \
%subserviceshash;
294 $subservices->{'10.openvpn'} = {
295 'caption' => 'OpenVPN',
296 'uri' => '/cgi-bin/ovpnmain.cgi',
297 'title' => "$tr{'virtual private networking'}",
300 $subservices->{'20.ipsec'} = {
301 'caption' => 'IPSec',
302 'uri' => '/cgi-bin/vpnmain.cgi',
303 'title' => "$tr{'virtual private networking'}",
306 $subservices->{'30.dyndns'} = {'caption' => $tr{'dynamic dns'},
307 'uri' => '/cgi-bin/ddns.cgi',
308 'title' => "$tr{'dynamic dns'}",
311 $subservices->{'40.time'} = {'caption' => $tr{'time server'},
312 'uri' => '/cgi-bin/time.cgi',
313 'title' => "$tr{'time server'}",
316 $subservices->{'50.qos'} = {'caption' => 'Quality of Service',
317 'uri' => '/cgi-bin/qos.cgi',
318 'title' => "Quality of Service",
321 $subservices->{'60.ids'} = {'caption' => $tr{'intrusion detection'},
323 'uri' => '/cgi-bin/ids.cgi',
324 'title' => "$tr{'intrusion detection system'}",
329 my %subfirewallhash = ();
330 my $subfirewall = \
%subfirewallhash;
333 $subfirewall->{'10.dnat'} = {
334 'caption' => $tr{'ssport forwarding'},
335 'uri' => '/cgi-bin/portfw.cgi',
336 'title' => "$tr{'ssport forwarding'}",
339 $subfirewall->{'20.xtaccess'} = {
340 'caption' => $tr{'external access'},
341 'uri' => '/cgi-bin/xtaccess.cgi',
342 'title' => "$tr{'external access'}",
345 $subfirewall->{'30.wireless'} = {
346 'caption' => $tr{'blue access'},
347 'uri' => '/cgi-bin/wireless.cgi',
348 'title' => "$tr{'blue access'}",
351 $subfirewall->{'40.dmz'} = {
352 'caption' => $tr{'ssdmz pinholes'},
353 'uri' => '/cgi-bin/dmzholes.cgi',
354 'title' => "$tr{'dmz pinhole configuration'}",
357 $subfirewall->{'50.outgoing'} = {
358 'caption' => $tr{'outgoing firewall'},
359 'uri' => '/cgi-bin/outgoingfw.cgi',
360 'title' => "$tr{'outgoing firewall'}",
363 $subfirewall->{'60.upnp'} = {
365 'uri' => '/cgi-bin/upnp.cgi',
366 'title' => "Universal Plug and Play",
369 $subfirewall->{'70.fwopts'} = {
370 'caption' => $tr{'options fw'},
371 'uri' => '/cgi-bin/optionsfw.cgi',
372 'title' => "$tr{'options fw'}",
376 my %sublogshash = ();
377 my $sublogs = \
%sublogshash;
379 $sublogs->{'10.summary'} = {'caption' => $tr{'log summary'},
380 'uri' => '/cgi-bin/logs.cgi/summary.dat',
381 'title' => "$tr{'log summary'}",
384 $sublogs->{'20.settings'} = {'caption' => $tr{'log settings'},
385 'uri' => '/cgi-bin/logs.cgi/config.dat',
386 'title' => "$tr{'log settings'}",
389 $sublogs->{'30.proxy'} = {'caption' => $tr{'proxy logs'},
390 'uri' => '/cgi-bin/logs.cgi/proxylog.dat',
391 'title' => "$tr{'proxy logs'}",
394 $sublogs->{'40.firewall'} = {'caption' => $tr{'firewall logs'},
395 'uri' => '/cgi-bin/logs.cgi/firewalllog.dat',
396 'title' => "$tr{'firewall logs'}",
399 $sublogs->{'50.ids'} = {'caption' => $tr{'ids logs'},
400 'uri' => '/cgi-bin/logs.cgi/ids.dat',
401 'title' => "$tr{'ids logs'}",
404 $sublogs->{'60.urlfilter'} = {
405 'caption' => $tr{'urlfilter logs'},
406 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
407 'title' => "$tr{'urlfilter log'}",
410 $sublogs->{'70.openvpn'} = {'caption' => $tr{'openvpn log'},
411 'uri' => '/cgi-bin/logs.cgi/openvpn.dat',
412 'title' => "$tr{'openvpn log'}",
415 $sublogs->{'80.system'} = {'caption' => $tr{'system logs'},
416 'uri' => '/cgi-bin/logs.cgi/log.dat',
417 'title' => "$tr{'system logs'}",
420 $sublogs->{'90.userlog'} = {'caption' => $tr{'user proxy logs'},
421 'uri' => '/cgi-bin/logs.cgi/userlog.dat',
422 'title' => "$tr{'user log'}",
426 my %subipfirehash = ();
427 my $subipfire = \
%subipfirehash;
428 $subipfire->{'10.pakfire'} = {'caption' => 'Pakfire',
429 'uri' => '/cgi-bin/pakfire.cgi',
430 'title' => "Pakfire",
433 $subipfire->{'20.asterisk'} = {'caption' => 'Asterisk',
434 'uri' => '/cgi-bin/asterisk.cgi',
435 'title' => "Asterisk",
438 $subipfire->{'30.samba'} = {'caption' => 'Samba',
439 'uri' => '/cgi-bin/samba.cgi',
443 $subipfire->{'99.help'} = {'caption' => $tr{'help'},
444 'uri' => '/cgi-bin/help.cgi',
445 'title' => "$tr{'help'}",
451 $menu->{'01.system'} = {'caption' => $tr{'alt system'},
453 'subMenu' => $subsystem
455 $menu->{'02.status'} = {'caption' => $tr{'status'},
457 'subMenu' => $substatus
459 $menu->{'03.network'} = {'caption' => $tr{'network'},
461 'subMenu' => $subnetwork
463 $menu->{'04.services'} = {'caption' => $tr{'alt services'},
465 'subMenu' => $subservices
467 $menu->{'05.firewall'} = {'caption' => $tr{'firewall'},
469 'subMenu' => $subfirewall
471 $menu->{'06.proxy'} = {'caption' => $tr{'alt proxy'},
473 'subMenu' => $subproxy
475 $menu->{'07.ipfire'} = {'caption' => 'IPFire',
477 'subMenu' => $subipfire
479 $menu->{'08.logs'} = {'caption' => $tr{'alt logs'},
481 'subMenu' => $sublogs
484 if (! blue_used
() && ! orange_used
()) {
485 $menu->{'05.firewall'}{'subMenu'}->{'40.dmz'}{'enabled'} = 0;
488 $menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
490 if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
491 $menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
497 print "Pragma: no-cache\n";
498 print "Cache-control: no-cache\n";
499 print "Connection: close\n";
500 print "Content-type: text/html\n\n";
503 sub is_menu_visible
($) {
506 return (-e
$ENV{'DOCUMENT_ROOT'}."/../$link");
512 if (! $root->{'enabled'}) {
515 if ($root->{'uri'} !~ /^$/) {
517 if ($root->{'vars'} !~ /^$/) {
518 $vars = '?'. $root->{'vars'};
520 if (! is_menu_visible
($root->{'uri'})) {
523 return $root->{'uri'}.$vars;
525 my $submenus = $root->{'subMenu'};
529 foreach my $item (sort keys %$submenus) {
530 my $link = getlink
($submenus->{$item});
542 my $uri = $conf->{'uri'};
543 my $vars = $conf->{'vars'};
544 my $novars = $conf->{'novars'};
549 if ($uri ne $URI[0]) {
553 if ($URI[1] !~ /^$/) {
560 return ($URI[1] eq $vars);
570 foreach my $item (sort keys %$root) {
571 my $val = $root->{$item};
572 if (compare_url
($val)) {
573 $val->{'selected'} = 1;
574 if ($val->{'title'} !~ /^$/) {
575 return $val->{'title'};
577 return 'EMPTY TITLE';
580 my $title = gettitle
($val->{'subMenu'});
582 $val->{'selected'} = 1;
591 my $filename = $_[0];
594 # write cgi vars to the file.
595 open(FILE
, ">${filename}") or die "Unable to write file $filename";
597 foreach $var (keys %$hash)
599 $val = $hash->{$var};
600 # Darren Critchley Jan 17, 2003 added the following because when submitting with a graphic, the x and y
601 # location of the mouse are submitted as well, this was being written to the settings file causing
602 # some serious grief! This skips the variable.x and variable.y
603 if (!($var =~ /(.x|.y)$/)) {
606 if (!($var =~ /^ACTION/)) {
607 print FILE
"${var}=${val}\n"; }
615 my $filename = $_[0];
619 open(FILE
, $filename) or die "Unable to read file $filename";
624 ($var, $val) = split /=/, $_, 2;
630 # Untaint variables read from hash
631 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
632 $val =~ /([\w\W]*)/; $val = $1;
633 $hash->{$var} = $val;
640 my ($hash, $params) = @_;
641 my $cgi = CGI
->new ();
642 $hash->{'__CGI__'} = $cgi;
643 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
644 if (!$params->{'wantfile'}) {
645 $CGI::DISABLE_UPLOADS
= 1;
646 $CGI::POST_MAX
= 512 * 1024;
648 $CGI::POST_MAX
= 10 * 1024 * 1024;
651 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
653 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
655 return if ($referer ne $servername);
657 ### Modified for getting multi-vars, split by |
658 %temp = $cgi->Vars();
659 foreach my $key (keys %temp) {
660 $hash->{$key} = $temp{$key};
661 $hash->{$key} =~ s/\0/|/g;
662 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
665 if (($params->{'wantfile'})&&($params->{'filevar'})) {
666 $hash->{$params->{'filevar'}} = $cgi->upload
667 ($params->{'filevar'});
674 my $logmessage = $_[0];
675 $logmessage =~ /([\w\W]*)/;
677 system('/usr/bin/logger', '-t', 'ipfire', $logmessage);
682 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
683 $atime, $mtime, $ctime, $blksize, $blocks) = stat $_[0];
686 my $totalsecs = $now - $mtime;
687 my $days = int($totalsecs / 86400);
688 my $totalhours = int($totalsecs / 3600);
689 my $hours = $totalhours % 24;
690 my $totalmins = int($totalsecs / 60);
691 my $mins = $totalmins % 60;
692 my $secs = $totalsecs % 60;
694 return "${days}d ${hours}h ${mins}m ${secs}s";
701 if (!($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)) {
705 @octets = ($1, $2, $3, $4);
710 if ($_ < 0 || $_ > 255) {
722 if (&validip
($mask)) {
724 # second part a number?
727 if (!($mask =~ /^\d+$/)) {
729 if ($mask >= 0 && $mask <= 32) {
736 my $ipormask = $_[0];
738 # see if it is a IP only.
739 if (&validip
($ipormask)) {
741 # split it into number and mask.
742 if (!($ipormask =~ /^(.*?)\/(.*?
)$/)) {
746 # first part not a ip?
747 if (!(&validip
($ip))) {
749 return &validmask
($mask);
754 my $ipandmask = $_[0];
756 # split it into number and mask.
757 if (!($ipandmask =~ /^(.*?)\/(.*?
)$/)) {
761 # first part not a ip?
762 if (!(&validip
($ip))) {
764 return &validmask
($mask);
775 if ($_ >= 1 && $_ <= 65535) {
782 my $checkmac = $_[0];
783 my $ot = '[0-9a-f]{2}'; # 2 Hex digits (one octet)
784 if ($checkmac !~ /^$ot:$ot:$ot:$ot:$ot:$ot$/i)
793 # Checks a hostname against RFC1035
794 my $hostname = $_[0];
796 # Each part should be at least two characters in length
797 # but no more than 63 characters
798 if (length ($hostname) < 2 || length ($hostname) > 63) {
800 # Only valid characters are a-z, A-Z, 0-9 and -
801 if ($hostname !~ /^[a-zA-Z0-9-]*$/) {
803 # First character can only be a letter or a digit
804 if (substr ($hostname, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
806 # Last character can only be a letter or a digit
807 if (substr ($hostname, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
814 # Checks a domain name against RFC1035
815 my $domainname = $_[0];
816 my @parts = split (/\./, $domainname); # Split hostname at the '.'
818 foreach $part (@parts) {
819 # Each part should be at least two characters in length
820 # but no more than 63 characters
821 if (length ($part) < 2 || length ($part) > 63) {
823 # Only valid characters are a-z, A-Z, 0-9 and -
824 if ($part !~ /^[a-zA-Z0-9-]*$/) {
826 # First character can only be a letter or a digit
827 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
829 # Last character can only be a letter or a digit
830 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
838 # Checks a fully qualified domain name against RFC1035
840 my @parts = split (/\./, $fqdn); # Split hostname at the '.'
841 if (scalar(@parts) < 2) { # At least two parts should
842 return 0;} # exist in a FQDN
843 # (i.e. hostname.domain)
844 foreach $part (@parts) {
845 # Each part should be at least two characters in length
846 # but no more than 63 characters
847 if (length ($part) < 2 || length ($part) > 63) {
849 # Only valid characters are a-z, A-Z, 0-9 and -
850 if ($part !~ /^[a-zA-Z0-9-]*$/) {
852 # First character can only be a letter or a digit
853 if (substr ($part, 0, 1) !~ /^[a-zA-Z0-9]*$/) {
855 # Last character can only be a letter or a digit
856 if (substr ($part, -1, 1) !~ /^[a-zA-Z0-9]*$/) {
862 sub validportrange
# used to check a port range
864 my $port = $_[0]; # port values
865 $port =~ tr/-/:/; # replace all - with colons just in case someone used -
866 my $srcdst = $_[1]; # is it a source or destination port
868 if (!($port =~ /^(\d+)\:(\d+)$/)) {
870 if (!(&validport
($port))) {
871 if ($srcdst eq 'src'){
872 return $tr{'source port numbers'};
874 return $tr{'destination port numbers'};
882 if ($srcdst eq 'src'){
883 return $tr{'bad source range'};
885 return $tr{'bad destination range'};
890 if (!(&validport
($_))) {
891 if ($srcdst eq 'src'){
892 return $tr{'source port numbers'};
894 return $tr{'destination port numbers'};
902 # Test if IP is within a subnet
903 # Call: IpInSubnet (Addr, Subnet, Subnet Mask)
904 # Subnet can be an IP of the subnet: 10.0.0.0 or 10.0.0.1
905 # Everything in dottted notation
909 $ip = unpack('N', inet_aton
(shift));
910 $start = unpack('N', inet_aton
(shift));
911 $mask = unpack('N', inet_aton
(shift));
912 $start &= $mask; # base of subnet...
913 $end = $start + ~$mask;
914 return (($ip >= $start) && ($ip <= $end));
919 return 0 if ( $mail !~ /^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/ );
920 return 0 if ( $mail =~ /^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/);
921 return 0 if ( $mail !~ /([0-9a-zA-Z]{1})\@./ );
922 return 0 if ( $mail !~ /.\@([0-9a-zA-Z]{1})/ );
923 return 0 if ( $mail =~ /.\.\-.|.\-\..|.\.\..|.\-\-./g );
924 return 0 if ( $mail =~ /.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./g );
925 return 0 if ( $mail !~ /\.([a-zA-Z]{2,3})$/ );
930 my ($filename, $hash) = @_;
932 open(FILE
, $filename) or die "Unable to read file $filename";
935 my ($key, $rest, @temp);
937 ($key, $rest) = split (/,/, $_, 2);
938 if ($key =~ /^[0-9]+$/ && $rest) {
939 @temp = split (/,/, $rest);
940 $hash->{$key} = \
@temp;
948 my ($filename, $hash) = @_;
951 open(FILE
, ">$filename") or die "Unable to write to file $filename";
953 foreach $key (keys %$hash) {
954 if ( $hash->{$key} ) {
956 foreach $i (0 .. $#{$hash->{$key}}) {
957 print FILE
",$hash->{$key}[$i]";
966 sub findhasharraykey
{
967 foreach my $i (1 .. 1000000) {
968 if ( ! exists $_[0]{$i}) {
976 my $outstring =$_[0];
977 $outstring =~ tr/,/ / if not defined $_[1] or $_[1] ne 'y';
978 $outstring =~ s/&/&/g;
979 $outstring =~ s/\'/'/g;
980 $outstring =~ s/\"/"/g;
981 $outstring =~ s/</</g;
982 $outstring =~ s/>/>/g;
988 my %pppsettings = ();
989 my %netsettings = ();
992 $pppsettings{'PROFILENAME'} = 'None';
993 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
994 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
997 if ( ! ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
998 $profileused="- $pppsettings{'PROFILENAME'}";
1001 if ( ( $pppsettings{'METHOD'} eq 'DHCP' && $netsettings{'RED_TYPE'} ne 'PPTP')
1002 || $netsettings{'RED_TYPE'} eq 'DHCP' ) {
1003 if (open(IFACE
, "${General::swroot}/red/iface")) {
1007 $iface =~ /([a-zA-Z0-9]*)/; $iface = $1;
1011 my ($timestr, $connstate);
1012 if ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'TYPE'} =~ /^isdn/) {
1013 # Count ISDN channels
1014 my ($idmap, $chmap, $drmap, $usage, $flags, $phone);
1018 open (FILE
, "/dev/isdninfo");
1020 $idmap = <FILE
>; chop $idmap;
1021 $chmap = <FILE
>; chop $chmap;
1022 $drmap = <FILE
>; chop $drmap;
1023 $usage = <FILE
>; chop $usage;
1024 $flags = <FILE
>; chop $flags;
1025 $phone = <FILE
>; chop $phone;
1027 $phone =~ s/^phone(\s*):(\s*)//;
1029 @phonenumbers = split / /, $phone;
1031 foreach (@phonenumbers) {
1038 ## Connection status
1042 } elsif ($count == 1) {
1048 if (-e
"${General::swroot}/red/active") {
1049 $timestr = &General
::age
("${General::swroot}/red/active");
1050 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} - $number channel (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1053 if (-e
"${General::swroot}/red/dial-on-demand") {
1054 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'dod waiting'} $profileused</span>";
1056 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1059 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connecting'} $profileused</span>";
1062 } elsif ($netsettings{'RED_TYPE'} eq "STATIC" || $pppsettings {'METHOD'} eq 'STATIC') {
1063 if (-e
"${General::swroot}/red/active") {
1064 $timestr = &General
::age
("${General::swroot}/red/active");
1065 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'connected'} (<span class='ipcop_StatusBigRed'>$timestr</span>) $profileused</span>";
1067 $connstate = "<span class='ipcop_StatusBig'>$Lang::tr{'idle'} $profileused</span>";
1069 } elsif ( ( (-e
"${General::swroot}/dhcpc/dhcpcd-$iface.pid") && $netsettings{'RED_TYPE'} ne 'PPTP' ) ||
1070 !system("/bin/ps -ef | /bin/grep -q '[p]ppd'") || !system("/bin/ps -ef | /bin/grep -q '[c]onnectioncheck'")) {
1071 if (-e
"${General::swroot}/red/active") {
1072 $timestr = &General
::age
("${General::swroot}/red/active");
1073 if ($pppsettings{'TYPE'} =~ /^(modem|bewanadsl|conexantpciadsl|eagleusbadsl)$/) {
1075 if ($pppsettings{'TYPE'} eq 'modem') {
1076 open(CONNECTLOG
, "/var/log/connect.log");
1077 while (<CONNECTLOG
>) {
1079 $speed = (split / /)[6];
1083 } elsif ($pppsettings{'TYPE'} eq 'bewanadsl') {
1084 $speed = `/usr/bin/unicorn_status | /bin/grep Rate | /usr/bin/cut -f2 -d ':'`;
1085 } elsif ($pppsettings{'TYPE'} eq 'conexantpciadsl') {
1086 $speed = `/bin/cat /proc/net/atm/CnxAdsl:* | /bin/grep 'Line Rates' | /bin/sed -e 's+Line Rates: Receive+Rx+' -e 's+Transmit+Tx+'`;
1087 } elsif ($pppsettings{'TYPE'} eq 'eagleusbadsl') {
1088 $speed = `/usr/sbin/eaglestat | /bin/grep Rate`;
1090 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused (\@$speed)";
1092 $connstate = "$Lang::tr{'connected'} ($timestr) $profileused";
1095 if (-e
"${General::swroot}/red/dial-on-demand") {
1096 $connstate = "$Lang::tr{'dod waiting'} $profileused";
1098 $connstate = "$Lang::tr{'connecting'} $profileused";
1102 $connstate = "$Lang::tr{'idle'} $profileused";
1108 # Darren Critchley - darrenc@telus.net - (c) 2003
1109 # &srtarray(SortOrder, AlphaNumeric, SortDirection, ArrayToBeSorted)
1110 # This subroutine will take the following parameters:
1111 # ColumnNumber = the column which you want to sort on, starts at 1
1112 # AlphaNumberic = a or n (lowercase) defines whether the sort should be alpha or numberic
1113 # SortDirection = asc or dsc (lowercase) Ascending or Descending sort
1114 # ArrayToBeSorted = the array that wants sorting
1116 # Returns an array that is sorted to your specs
1118 # If SortOrder is greater than the elements in array, then it defaults to the first element
1121 my ($colno, $alpnum, $srtdir, @tobesorted) = @_;
1126 my $ttlitems = scalar @tobesorted; # want to know the number of rows in the passed array
1127 if ($ttlitems < 1){ # if no items, don't waste our time lets leave
1128 return (@tobesorted);
1130 my @tmp = split(/\,/,$tobesorted[0]);
1131 $ttlitems = scalar @tmp; # this should be the number of elements in each row of the passed in array
1133 # Darren Critchley - validate parameters
1134 if ($colno > $ttlitems){$colno = '1';}
1135 $colno--; # remove one from colno to deal with arrays starting at 0
1136 if($colno < 0){$colno = '0';}
1137 if ($alpnum ne '') { $alpnum = lc($alpnum); } else { $alpnum = 'a'; }
1138 if ($srtdir ne '') { $srtdir = lc($srtdir); } else { $srtdir = 'src'; }
1140 foreach $line (@tobesorted)
1144 my @temp = split(/\,/,$line);
1145 # Darren Critchley - juggle the fields so that the one we want to sort on is first
1146 my $tmpholder = $temp[0];
1147 $temp[0] = $temp[$colno];
1148 $temp[$colno] = $tmpholder;
1150 for ($ctr=0; $ctr < $ttlitems ; $ctr++) {
1151 $newline=$newline . $temp[$ctr] . ",";
1154 push(@tmparray,$newline);
1157 if ($alpnum eq 'n') {
1158 @tmparray = sort {$a <=> $b} @tmparray;
1160 @tmparray = (sort @tmparray);
1162 foreach $line (@tmparray)
1166 my @temp = split(/\,/,$line);
1167 my $tmpholder = $temp[0];
1168 $temp[0] = $temp[$colno];
1169 $temp[$colno] = $tmpholder;
1171 for ($ctr=0; $ctr < $ttlitems ; $ctr++){
1172 $newline=$newline . $temp[$ctr] . ",";
1175 push(@srtedarray,$newline);
1179 if ($srtdir eq 'dsc') {
1180 @tmparray = reverse(@srtedarray);
1183 return (@srtedarray);
1187 sub speedtouchversion
1189 if (-f
"/proc/bus/usb/devices")
1191 $speedtouch=`/bin/cat /proc/bus/usb/devices | /bin/grep 'Vendor=06b9 ProdID=4061' | /usr/bin/cut -d ' ' -f6`;
1192 if ($speedtouch eq '') {
1193 $speedtouch= $tr{'connect the modem'};
1196 $speedtouch='USB '.$tr{'not running'};
1201 sub CheckSortOrder
{
1202 #Sorting of allocated leases
1203 if ($ENV{'QUERY_STRING'} =~ /^IPADDR|^ETHER|^HOSTNAME|^ENDTIME/ ) {
1204 my $newsort=$ENV{'QUERY_STRING'};
1205 &readhash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1206 $act=$dhcpsettings{'SORT_LEASELIST'};
1208 if ($act =~ $newsort) {
1209 if ($act !~ 'Rev') {$Rev='Rev'};
1213 $dhcpsettings{'SORT_LEASELIST'}=$newsort;
1214 &writehash
("${swroot}/dhcp/settings", \
%dhcpsettings);
1215 $dhcpsettings{'ACTION'} = 'SORT'; # avoid the next test "First lauch"
1220 sub PrintActualLeases
1222 &openbox
('100%', 'left', $tr{'current dynamic leases'});
1224 <table width='100%'>
1226 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?IPADDR'><b>$tr{'ip address'}</b></a></td>
1227 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ETHER'><b>$tr{'mac address'}</b></a></td>
1228 <td width='20%' align='center'><a href='$ENV{'SCRIPT_NAME'}?HOSTNAME'><b>$tr{'hostname'}</b></a></td>
1229 <td width='25%' align='center'><a href='$ENV{'SCRIPT_NAME'}?ENDTIME'><b>$tr{'lease expires'} (local time d/m/y)</b></a></td>
1230 <td width='5%' align='center'><b>Add to fix leases<b></td>
1235 open(LEASES
,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
1236 while ($line = <LEASES
>) {
1237 next if( $line =~ /^\s*#/ );
1239 @temp = split (' ', $line);
1241 if ($line =~ /^\s*lease/) {
1243 #All field are not necessarily read. Clear everything
1249 if ($line =~ /^\s*ends/) {
1250 $line =~ /(\d+)\/(\d
+)\
/(\d+) (\d+):(\d+):(\d+)/;
1251 $endtime = timegm
($6, $5, $4, $3, $2 - 1, $1 - 1900);
1254 if ($line =~ /^\s*hardware ethernet/) {
1259 if ($line =~ /^\s*client-hostname/) {
1260 $hostname = "$temp[1] $temp[2] $temp[3]";
1261 $hostname =~ s/;//g;
1262 $hostname =~ s/\"//g;
1266 @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
1267 $record = {}; # create a reference to empty hash
1268 %{$record} = @record; # populate that hash with @record
1269 $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
1275 foreach my $key (sort leasesort
keys %entries) {
1276 print "<form method='post' action='/cgi-bin/dhcp.cgi'>\n";
1277 my $hostname = &cleanhtml
($entries{$key}->{HOSTNAME
},"y");
1280 print "<tr bgcolor='$table1colour'>";
1283 print "<tr bgcolor='$table2colour'>";
1287 <td align='center'><input type='hidden' name='FIX_ADDR' value='$entries{$key}->{IPADDR}' />$entries{$key}->{IPADDR}</td>
1288 <td align='center'><input type='hidden' name='FIX_MAC' value='$entries{$key}->{ETHER}' />$entries{$key}->{ETHER}</td>
1289 <td align='center'><input type='hidden' name='FIX_REMARK' value='$hostname' /> $hostname</td>
1290 <td align='center'><input type='hidden' name='FIX_ENABLED' value='on' />
1294 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME
});
1295 $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
1297 if ($entries{$key}->{ENDTIME
} < time() ){
1298 print "<strike>$enddate</strike>";
1303 <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}2' /><input type='submit' name='SUBMIT' value='$Lang::tr{'add'}' />
1304 </td></td></tr></form>
1315 # This sub is used during display of actives leases
1317 if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1)
1319 $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3);
1320 if ($qs eq 'IPADDR') {
1321 @a = split(/\./,$entries{$a}->{$qs});
1322 @b = split(/\./,$entries{$b}->{$qs});
1328 $entries{$b}->{$qs} cmp $entries{$a}->{$qs};
1333 $qs=$dhcpsettings{'SORT_LEASELIST'};
1334 if ($qs eq 'IPADDR') {
1335 @a = split(/\./,$entries{$a}->{$qs});
1336 @b = split(/\./,$entries{$b}->{$qs});
1342 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
1349 opendir(DIR
, "${swroot}/uplinks/") || return \
@uplinks;
1350 foreach my $dir (readdir(DIR
)) {
1351 next if ($dir =~ /^\./);
1352 next if (-f
"${swroot}/uplinks/$dir");
1353 push(@uplinks, $dir);
1360 my $filename = shift;
1362 open (F
, $filename) || return "";
1369 sub get_red_ifaces_by_type
($) {
1371 my @gottypeiface = ();
1372 my @gottypeuplink = ();
1375 my $ref=get_uplinks
();
1378 foreach my $link (@uplinks) {
1380 &readhash
("${swroot}/uplinks/$link/settings", \
%set);
1382 push(@gottype, $link);
1384 my $iface = $set{'RED_DEV'};
1386 $iface = get_iface
("${swroot}/uplinks/$link/interface");
1390 if ($set{'RED_TYPE'} eq $type) {
1391 push(@gottypeiface, $iface);
1392 push(@gottypeuplink, $link);
1395 return (\
@gottypeiface, \
@gottypeuplink, \
@gottype);
1398 sub get_red_ifaces
() {
1399 return `cat ${swroot}/uplinks/*/interface 2>/dev/null`;
1402 sub get_zone_devices
($) {
1405 open (FILE
, "${swroot}/ethernet/$bridge") || return "";
1406 foreach my $line (<FILE
>) {
1409 push(@ifaces, $line);