From: Alexander Marx Date: Thu, 28 Jan 2016 10:18:59 +0000 (+0100) Subject: Captive-Portal: add web-part X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3c4f8b71146b6c2fa8721963fd387eaad5bb9b0;p=people%2Fms%2Fipfire-2.x.git Captive-Portal: add web-part Introduce new Captive-Portal. Here we add the menu, apache configuration (vhost), IPFire configuration website and Captive-Portal Access site. Also the languagefiles are updated. Signed-off-by: Alexander Marx --- diff --git a/config/httpd/vhosts.d/captive.conf b/config/httpd/vhosts.d/captive.conf new file mode 100644 index 0000000000..0824b79561 --- /dev/null +++ b/config/httpd/vhosts.d/captive.conf @@ -0,0 +1,29 @@ +Listen 1013 + + + DocumentRoot /srv/web/ipfire/html/captive + ServerAdmin alexander.marx@oab.de + ErrorLog /var/log/httpd/captive/error_log + TransferLog /var/log/httpd/captive/access_log + + + Options ExecCGI + Order allow,deny + Allow from all + + + ScriptAlias /cgi-bin/ /srv/web/ipfire/cgi-bin/captive/ + Alias /assets/ /srv/web/ipfire/html/captive/assets/ + + ScriptAlias /favicon.ico /srv/web/ipfire/html/captive/assets/favicon.ico + + # All unknown URIs will be redirected to the first + # redirector script. + ScriptAliasMatch .* /srv/web/ipfire/html/captive/index.cgi + + + Options ExecCGI + Order allow,deny + Allow from all + + diff --git a/config/menu/30-network.menu b/config/menu/30-network.menu index c50508f818..f0ea98f474 100644 --- a/config/menu/30-network.menu +++ b/config/menu/30-network.menu @@ -23,6 +23,11 @@ 'title' => "$Lang::tr{'dhcp server'}", 'enabled' => 1, }; + $subnetwork->{'32.captive'} = {'caption' => $Lang::tr{'Captive menu'}, + 'uri' => '/cgi-bin/captive.cgi', + 'title' => $Lang::tr{'Captive menu'}, + 'enabled' => 1, + }; $subnetwork->{'40.scheduler'} = { 'caption' => $Lang::tr{'connscheduler'}, 'uri' => '/cgi-bin/connscheduler.cgi', diff --git a/html/cgi-bin/captive.cgi b/html/cgi-bin/captive.cgi new file mode 100755 index 0000000000..2c5c8e4cc7 --- /dev/null +++ b/html/cgi-bin/captive.cgi @@ -0,0 +1,516 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2016 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +use strict; +use HTML::Entities(); +# enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; +unless (-e "${General::swroot}/captive/settings") { system("touch ${General::swroot}/captive/settings"); } +my %settings=(); +my %mainsettings; +my %color; +my %cgiparams=(); +my %netsettings=(); +my %checked=(); +my $errormessage=''; +my $voucherout="${General::swroot}/captive/voucher_out"; +my $clients="${General::swroot}/captive/clients"; +my %voucherhash=(); +my %clientshash=(); +my $settingsfile="${General::swroot}/captive/settings"; + +unless (-e $voucherout) { system("touch $voucherout"); } + +&Header::getcgihash(\%cgiparams); + +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); +&General::readhash("$settingsfile", \%settings) if(-f $settingsfile); +&General::readhash("${General::swroot}/ethernet/settings", \%netsettings); + +&Header::showhttpheaders(); + +#actions +if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ + #saves the Captiveportal settings to disk + $settings{'ENABLE_GREEN'} = $cgiparams{'ENABLE_GREEN'}; + $settings{'ENABLE_BLUE'} = $cgiparams{'ENABLE_BLUE'}; + $settings{'AUTH'} = $cgiparams{'AUTH'}; + $settings{'TIME'} = $cgiparams{'TIME'}; + $settings{'EXPIRE'} = $cgiparams{'EXPIRE'}; + $settings{'TITLE'} = $cgiparams{'TITLE'}; + &General::writehash("$settingsfile", \%settings); + + #write Licensetext if defined + if ($cgiparams{'AGB'}){ + $cgiparams{'AGB'} = &Header::escape($cgiparams{'AGB'}); + open( FH, ">:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!"); + print FH $cgiparams{'AGB'}; + close( FH ); + $cgiparams{'AGB'}=""; + } + #execute binary to reload firewall rules + system("/usr/local/bin/captivectrl"); +} + +if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive voucherout'}"){ + #generates a voucher and writes it to /var/ipfire/voucher_out + + #check if we already have a voucher with same code + &General::readhasharray("$voucherout", \%voucherhash); + foreach my $key (keys %voucherhash) { + if($voucherhash{$key}[1] eq $cgiparams{'CODE'}){ + $errormessage=$Lang::tr{'Captive err doublevoucher'}; + last; + } + } + + #if no error detected, write to disk + if (!$errormessage){ + my $date=time(); #seconds in utc + + #first get new key from hash + my $key=&General::findhasharraykey (\%voucherhash); + #initialize all fields with '' + foreach my $i (0 .. 4) { $voucherhash{$key}[$i] = "";} + #define fields + $voucherhash{$key}[0] = $date; + $voucherhash{$key}[1] = $cgiparams{'CODE'}; + $voucherhash{$key}[2] = $settings{'TIME'}; + $voucherhash{$key}[3] = $settings{'EXPIRE'}; + $voucherhash{$key}[4] = &Header::escape($cgiparams{'REMARK'}); + #write values to disk + &General::writehasharray("$voucherout", \%voucherhash); + + #now prepare log entry, get expiring date for voucher and decode remark for logfile + my $expdate=localtime(time()+$voucherhash{$key}[3]); + my $rem=HTML::Entities::decode_entities($voucherhash{$key}[4]); + + #write logfile entry + &General::log("Captive", "Generated new voucher $voucherhash{$key}[1] $voucherhash{$key}[2] hours valid expires on $expdate remark $rem"); + } +} + +if ($cgiparams{'ACTION'} eq 'delvoucherout'){ + #deletes an already generated but unused voucher + + #read all generated vouchers + &General::readhasharray("$voucherout", \%voucherhash); + foreach my $key (keys %voucherhash) { + if($cgiparams{'key'} eq $voucherhash{$key}[0]){ + #write logenty with decoded remark + my $rem=HTML::Entities::decode_entities($voucherhash{$key}[4]); + &General::log("Captive", "Delete unused voucher $voucherhash{$key}[1] $voucherhash{$key}[2] hours valid expires on $voucherhash{$key}[3] remark $rem"); + #delete line from hash + delete $voucherhash{$key}; + last; + } + } + #write back hash + &General::writehasharray("$voucherout", \%voucherhash); +} + +if ($cgiparams{'ACTION'} eq 'delvoucherinuse'){ + #delete voucher and connection in use + + #read all active clients + &General::readhasharray("$clients", \%clientshash); + foreach my $key (keys %clientshash) { + if($cgiparams{'key'} eq $clientshash{$key}[0]){ + #prepare log entry with decoded remark + my $rem=HTML::Entities::decode_entities($clientshash{$key}[7]); + #write logentry + &General::log("Captive", "Delete voucher in use $clientshash{$key}[1] $clientshash{$key}[2] hours valid expires on $clientshash{$key}[3] remark $rem - Connection will be terminated"); + #delete line from hash + delete $clientshash{$key}; + last; + } + } + #write back hash + &General::writehasharray("$clients", \%clientshash); + #reload firewallrules to kill connection of client + system("/usr/local/bin/captivectrl"); +} + +#open webpage, print header and open box +&Header::openpage($Lang::tr{'Captive menu'}, 1, ''); +&Header::openbigbox(); + +#call error() to see if we have to print an errormessage on website +&error(); + +#call config() to display the configuration box +&config(); + +sub getagb(){ + #open textfile from /var/ipfire/captive/agb.txt + open( my $handle, "<:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!"); + while(<$handle>){ + #read line by line and print on screen + $cgiparams{'AGB'}.= HTML::Entities::decode_entities($_); + } + close( $handle ); +} + +sub config(){ + #prints the config box on the website + &Header::openbox('100%', 'left', $Lang::tr{'Captive config'}); + print <\n + + +END +; + #check which parameters have to be enabled (from settings file) + $checked{'ENABLE_GREEN'}{'off'} = ''; + $checked{'ENABLE_GREEN'}{'on'} = ''; + $checked{'ENABLE_GREEN'}{$settings{'ENABLE_GREEN'}} = "checked='checked'"; + + $checked{'ENABLE_BLUE'}{'off'} = ''; + $checked{'ENABLE_BLUE'}{'on'} = ''; + $checked{'ENABLE_BLUE'}{$settings{'ENABLE_BLUE'}} = "checked='checked'"; + + if ($netsettings{'GREEN_DEV'}){ + print ""; + } + if ($netsettings{'BLUE_DEV'}){ + print ""; + } + + print< + + + + + + + + + + "; + +print< + + +END +; + + if($settings{'AUTH'} eq 'LICENSE'){ &agbbox();} +print< + + + +
$Lang::tr{'Captive active on'} Green
$Lang::tr{'Captive active on'} Blue
+ $Lang::tr{'Captive authentication'} + +
+ $Lang::tr{'Captive time'} + +
+ $Lang::tr{'Captive vouchervalid'} + +

+ $Lang::tr{'Captive title'} +

+ +
+ + +
+

+END +; + print ""; + &Header::closebox(); + + #if settings is set to use vouchers, the voucher part has to be displayed + if ($settings{'AUTH'} eq 'VOUCHER'){ + &voucher(); + }else{ + #otherwise we show the licensepart + &show_license_connections(); + } +} + +sub agbbox(){ + &getagb(); +print< + + License agreement + + +
+ + + +END +; +} + +sub gencode(){ + #generate a random code only letters from A-Z except 'O' and 0-9 + my @chars = ("A".."N", "P".."Z", "0".."9"); + my $randomstring; + $randomstring .= $chars[rand @chars] for 1..8; + return $randomstring; +} + +sub voucher(){ + #show voucher part + my $expire; + &Header::openbox('100%', 'left', $Lang::tr{'Captive voucher'}); +print< + + + +END +; + if ($settings{'EXPIRE'} eq '86400') { $expire = $Lang::tr{'Captive 1day'};} + if ($settings{'EXPIRE'} eq '604800') { $expire = $Lang::tr{'Captive 1week'};} + if ($settings{'EXPIRE'} eq '2592000') { $expire = $Lang::tr{'Captive 1month'};} + if ($settings{'TIME'} eq 'nolimit') { $settings{'TIME'} = $Lang::tr{'Captive nolimit'};} + $cgiparams{'CODE'} = &gencode(); + print ""; + print ""; + print "
$Lang::tr{'Captive voucher'}$Lang::tr{'hours'}$Lang::tr{'Captive expire'}
$cgiparams{'CODE'}
$settings{'TIME'}
$expire

$Lang::tr{'remark'}

"; + print "
"; + &Header::closebox(); + if (! -z $voucherout) { &show_voucher_out();} + if (! -z $clients) { &show_voucher_in_use();} +} + +sub show_license_connections(){ + #if there are active clients, show the box with active connections + return if ( -z $clients || ! -f $clients ); + my $count=0; + my $col; + &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'}); +print< + + +END +; + #read all clients from hash and show table + &General::readhasharray("$clients", \%clientshash); + foreach my $key (keys %clientshash){ + my ($sec, $min, $hour, $mday, $mon, $year) = localtime($clientshash{$key}[6]); + my ($secx,$minx,$hourx) = localtime($clientshash{$key}[6]+($clientshash{$key}[5]*3600)); + $mon = '0'.++$mon if $mon<10; + $min = '0'.$min if $min<10; + $hour = '0'.$hour if $hour<10; + $year=$year+1900; + if ($count % 2){ + print" "; + $col="bgcolor='$color{'color20'}'"; + }else{ + $col="bgcolor='$color{'color22'}'"; + print" "; + } + print ""; + $count++; + } + + print "
$Lang::tr{'Captive mac'}$Lang::tr{'Captive ip'}$Lang::tr{'Captive voucher'}$Lang::tr{'Captive activated'}$Lang::tr{'Captive expire'}$Lang::tr{'delete'}
$clientshash{$key}[0]
$clientshash{$key}[1]
$clientshash{$key}[4]
$mday.$mon.$year "; + printf("%02d",$hour); + print ":"; + printf("%02d",$min); + print "
$mday.$mon.$year "; + printf("%02d",$hourx); + print ":"; + printf("%02d",$minx); + print "
"; + &Header::closebox(); +} + +sub show_voucher_out(){ + #if there are already generated but unsused vouchers, print a table + return if ( -z $voucherout); + my $count=0; + my $col; + &Header::openbox('100%', 'left', $Lang::tr{'Captive vout'}); + print< + + +END +; + &General::readhasharray("$voucherout", \%voucherhash); + foreach my $key (keys %voucherhash) + { + my ($sec, $min, $hour, $mday, $mon, $year) = localtime($voucherhash{$key}[0]); + my ($secx, $minx, $hourx, $mdayx, $monx, $yearx) = localtime($voucherhash{$key}[0]+$voucherhash{$key}[3]); + $mon++; + $year=$year+1900; + $monx++; + $yearx=$yearx+1900; + if ($count % 2){ + print" "; + $col="bgcolor='$color{'color20'}'"; + }else{ + $col="bgcolor='$color{'color22'}'"; + print" "; + } + print ""; + $voucherhash{$key}[4] = HTML::Entities::decode_entities($voucherhash{$key}[4]); + print ""; + print ""; + $count++; + } + + print "
$Lang::tr{'date'}$Lang::tr{'Captive voucher'}$Lang::tr{'hours'}$Lang::tr{'Captive expire'}$Lang::tr{'remark'}$Lang::tr{'delete'}
"; + printf("%02d",$mday); + print "."; + printf("%02d",$mon); + print "."; + print"$year "; + + printf("%02d",$hour); + print ":"; + printf("%02d",$min); + print "
$voucherhash{$key}[1]
$voucherhash{$key}[2]
"; + printf("%02d",$mdayx); + print "."; + printf("%02d",$monx); + print "."; + print"$yearx "; + + printf("%02d",$hourx); + print ":"; + printf("%02d",$minx); + print "
$voucherhash{$key}[4]
"; + &Header::closebox(); +} + +sub show_voucher_in_use(){ + #if there are active clients which use vouchers show table + return if ( -z $clients || ! -f $clients ); + my $count=0; + my $col; + &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'}); +print< + + +END +; + &General::readhasharray("$clients", \%clientshash); + foreach my $key (keys %clientshash) + { + my ($sec, $min, $hour, $mday, $mon, $year) = localtime($clientshash{$key}[6]); + my ($secx,$minx,$hourx) = localtime($clientshash{$key}[6]+($clientshash{$key}[5]*3600)); + $mon = '0'.++$mon if $mon<10; + $min = '0'.$min if $min<10; + $hour = '0'.$hour if $hour<10; + $year=$year+1900; + if ($count % 2){ + print" "; + $col="bgcolor='$color{'color20'}'"; + }else{ + $col="bgcolor='$color{'color22'}'"; + print" "; + } + print ""; + $count++; + } + + print "
$Lang::tr{'Captive mac'}$Lang::tr{'Captive ip'}$Lang::tr{'Captive voucher'}$Lang::tr{'Captive activated'}$Lang::tr{'Captive expire'}$Lang::tr{'delete'}
$clientshash{$key}[0]
$clientshash{$key}[1]
$clientshash{$key}[4]
$mday.$mon.$year "; + printf("%02d",$hour); + print ":"; + printf("%02d",$min); + print "
$mday.$mon.$year "; + printf("%02d",$hourx); + print ":"; + printf("%02d",$minx); + print "
"; + &Header::closebox(); +} + +sub error{ + #if an errormessage exits, show a box with errormessage + if ($errormessage) { + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage\n"; + print " \n"; + &Header::closebox(); + } +} + +&Header::closebigbox(); +&Header::closepage(); diff --git a/html/cgi-bin/captive/index.cgi b/html/cgi-bin/captive/index.cgi new file mode 100755 index 0000000000..d0b28f7a96 --- /dev/null +++ b/html/cgi-bin/captive/index.cgi @@ -0,0 +1,287 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2016 Alexander Marx alexander.marx@ipfire.org # +# # +# This program is free software you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +use strict; +use CGI ':standard'; +use URI::Escape; +use HTML::Entities(); +# enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; + +#Set Variables +my %voucherhash=(); +my %clientshash=(); +my %cgiparams=(); +my %settings=(); +my $voucherout="${General::swroot}/captive/voucher_out"; +my $clients="${General::swroot}/captive/clients"; +my $settingsfile="${General::swroot}/captive/settings"; +my $redir=0; +my $errormessage; +my $url=param('redirect'); +#Create /var/ipfire/captive/clients if not exist +unless (-f $clients){ system("touch $clients"); } + +#Get GUI variables +&getcgihash(\%cgiparams); + +#Read settings +&General::readhash("$settingsfile", \%settings) if(-f $settingsfile); + +#Actions +if ($cgiparams{'ACTION'} eq "$Lang::tr{'gpl i accept these terms and conditions'}"){ + my $key = &General::findhasharraykey(\%clientshash); + my($sec,$min,$hour) = gmtime(time); + my $hour1=$hour+$settings{'TIME'}; + $min="0".$min if ($min < 10); + $hour="0".$hour if ($hour < 10); + $hour1="0".$hour1 if ($hour1 < 10); + + #Get Clients IP-Address + my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||""; + + #Ask arp to give the corresponding MAC-Address + my $mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4); + $mac_address =~ s/\n+\z//; + + &General::readhasharray("$clients", \%clientshash); + + if (!$errormessage){ + foreach my $i (0 .. 6) { $clientshash{$key}[$i] = "";} + $clientshash{$key}[0] = $mac_address; + $clientshash{$key}[1] = $ip_address; + $clientshash{$key}[2] = $hour.":".$min; + $clientshash{$key}[3] = $hour1.":".$min; + $clientshash{$key}[4] = $Lang::tr{'Captive auth_lic'}; + $clientshash{$key}[5] = $settings{'TIME'}; + $clientshash{$key}[6] = time(); + + &General::writehasharray("$clients", \%clientshash); + system("/usr/local/bin/captivectrl"); + &General::log("Captive", "Internet Access granted via license-agreement for $ip_address until $clientshash{$key}[3]"); + $redir=1; + } +} + +if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive activate'}"){ + my $ip_address; + my $mac_address; + + #Convert voucherinput to uppercase + $cgiparams{'VOUCHER'} = uc $cgiparams{'VOUCHER'}; + #Get Clients IP-Address + $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||""; + #Ask arp to give the corresponding MAC-Address + $mac_address = qx(arp -a|grep $ip_address|cut -d ' ' -f 4); + $mac_address =~ s/\n+\z//; + #Check if voucher is valid and write client to clients file, delete voucher from voucherout + &General::readhasharray("$voucherout", \%voucherhash); + &General::readhasharray("$clients", \%clientshash); + foreach my $key (keys %voucherhash) { + if($voucherhash{$key}[1] eq $cgiparams{'VOUCHER'}){ + #Voucher valid, write to clients, then delete from voucherout + my ($sec,$min,$hour)=gmtime(time()); + my $hour1; + $min="0".$min if ($min < 10); + $hour="0".$hour if ($hour < 10); + $hour1=$hour+$voucherhash{$key}[2]; + $hour1="0".$hour1 if ($hour1 < 10); + my $key1 = &General::findhasharraykey(\%clientshash); + foreach my $i (0 .. 7) { $clientshash{$key1}[$i] = "";} + $clientshash{$key1}[0] = $mac_address; + $clientshash{$key1}[1] = $ip_address; + $clientshash{$key1}[2] = $hour.":".$min; + $clientshash{$key1}[3] = $hour1.":".$min; + $clientshash{$key1}[4] = $cgiparams{'VOUCHER'}; + $clientshash{$key1}[5] = $voucherhash{$key}[2]; + $clientshash{$key1}[6] = time(); + $clientshash{$key1}[7] = $voucherhash{$key}[4]; + + &General::writehasharray("$clients", \%clientshash); + $clientshash{$key1}[7]=HTML::Entities::decode_entities($clientshash{$key1}[7]); + &General::log("Captive", "Internet Access granted via voucher no. $clientshash{$key1}[4] for $ip_address until $clientshash{$key}[3] Remark: $clientshash{$key1}[7]"); + + delete $voucherhash{$key}; + &General::writehasharray("$voucherout", \%voucherhash); + last; + } + } + system("/usr/local/bin/captivectrl"); + $redir=1; +} + +if($redir == 1){ + print "Status: 302 Moved Temporarily\n"; + print "Location: $url\n"; + print "Connection: close\n"; + print "\n"; + exit 0; +} + + +#Open HTML Page, load header and css +&head(); +&error(); +&start(); + +#Functions + +sub start(){ + if ($settings{'AUTH'} eq 'VOUCHER'){ + &voucher(); + }else{ + &agb(); + } +} + +sub error(){ + if ($errormessage){ + print "

$errormessage
"; + } +} + +sub head(){ +print< + + + $settings{'TITLE'} + + +END +; +} +sub agb(){ +print< +
+
+

$settings{'TITLE'} +

+
+
+ +
+
+
+
+
+
+
+ + +END +; +} + +sub voucher(){ + print< +
+
+

LOGIN

+
+
+ +
+
+ +

+
+ + +END +; +} + +sub getcgihash { + my ($hash, $params) = @_; + my $cgi = CGI->new (); + $hash->{'__CGI__'} = $cgi; + return if ($ENV{'REQUEST_METHOD'} ne 'POST'); + if (!$params->{'wantfile'}) { + $CGI::DISABLE_UPLOADS = 1; + $CGI::POST_MAX = 1024 * 1024; + } else { + $CGI::POST_MAX = 10 * 1024 * 1024; + } + $cgi->referer() =~ m/^http?\:\/\/([^\/]+)/; + my $referer = $1; + $cgi->url() =~ m/^http?\:\/\/([^\/]+)/; + my $servername = $1; + return if ($referer ne $servername); + + ### Modified for getting multi-vars, split by | + my %temp = $cgi->Vars(); + foreach my $key (keys %temp) { + $hash->{$key} = $temp{$key}; + $hash->{$key} =~ s/\0/|/g; + $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/; + } + + if (($params->{'wantfile'})&&($params->{'filevar'})) { + $hash->{$params->{'filevar'}} = $cgi->upload + ($params->{'filevar'}); + } + return; +} + +sub getagb(){ + open( my $handle, "<:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!"); + while(<$handle>){ + $_ = HTML::Entities::decode_entities($_); + print $_; + } + close( $handle ); +} diff --git a/html/html/captive/assets/captive.css b/html/html/captive/assets/captive.css new file mode 100644 index 0000000000..7e8eac6b3f --- /dev/null +++ b/html/html/captive/assets/captive.css @@ -0,0 +1,76 @@ +h1{ + font-family: sans-serif; +} + +body { + height: 100%; + background-image: url("internet.png"); + background-size: cover; /* <------ */ + background-repeat: no-repeat; + background-position: center center; +} + +.title{ + position: relative; + background: #f5f5f5; + border: 1px solid #FFF; + width: 40em; + height: 6em; + left: 1em; + top: 2em; + padding-left: 2em; + padding-right: 2em; + padding-top: 0,5em; + opacity: 0.9; + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + box-shadow: 1px 2px 4px rgba(0,0,0,.4); +} + +.login{ + position: relative; + background: #f5f5f5; + border: 1px solid #FFF; + width: 40em; + left: 1em; + top: 2em; + margin-top: 0,2em; + padding-left: 2em; + padding-right: 2em; + padding-top: 1em; + text-align: left; + font-family: sans-serif; + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + box-shadow: 1px 2px 4px rgba(0,0,0,.4); +} + +.agb{ + position: relative; + background: #f5f5f5; + border: 1px solid #FFF; + width: 40em; + left: 1em; + top: 2em; + margin-top: 0,2em; + padding-left: 2em; + padding-right: 2em; + padding-top: 1em; + text-align: left; + font-family: sans-serif; + opacity: 0.9; + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + box-shadow: 1px 2px 4px rgba(0,0,0,.4); +} + +#agbtext{ + font-size: 12px; + font-weight: normal; + resize: none; + overflow-y: scroll; +} + diff --git a/html/html/captive/assets/favicon.ico b/html/html/captive/assets/favicon.ico new file mode 100644 index 0000000000..52da262f76 Binary files /dev/null and b/html/html/captive/assets/favicon.ico differ diff --git a/html/html/captive/assets/internet.png b/html/html/captive/assets/internet.png new file mode 100644 index 0000000000..b4f20df25b Binary files /dev/null and b/html/html/captive/assets/internet.png differ diff --git a/html/html/captive/index.cgi b/html/html/captive/index.cgi new file mode 100755 index 0000000000..cf84acf71e --- /dev/null +++ b/html/html/captive/index.cgi @@ -0,0 +1,66 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2016 Alexander Marx alexander.marx@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +use strict; +use URI::Escape; +use CGI::Carp qw(fatalsToBrowser); + +require '/var/ipfire/general-functions.pl'; + +my $url = "http://$ENV{'SERVER_NAME'}$ENV{'REQUEST_URI'}"; +my $safe_url = uri_escape($url); +my $settings="${General::swroot}/captive/settings"; +my $ethernet="${General::swroot}/ethernet/settings"; +my %settingshash=(); +my %ethernethash=(); +my $green_ip; +my $green_mask; +my $blue_ip; +my $blue_mask; +my $target; +#Read settings +&General::readhash("$settings", \%settingshash) if(-f $settings); +&General::readhash("$ethernet", \%ethernethash) if(-f $ethernet); + +#Get Clients IP-Address +my $ip_address = $ENV{X_FORWARDED_FOR} || $ENV{REMOTE_ADDR} ||""; + +if($settingshash{'ENABLE_GREEN'} eq "on" && $ethernethash{'GREEN_ADDRESS'} ne ''){ + $green_ip=$ethernethash{'GREEN_ADDRESS'}; + $green_mask=$ethernethash{'GREEN_NETMASK'}; + + if (&General::IpInSubnet($ip_address,$ethernethash{'GREEN_ADDRESS'},$ethernethash{'GREEN_NETMASK'})){ + $target = $green_ip; + } +}elsif($settingshash{'ENABLE_BLUE'} eq "on" &&$ethernethash{'BLUE_ADDRESS'} ne '' ){ + $blue_ip=$ethernethash{'BLUE_ADDRESS'}; + $blue_mask=$ethernethash{'BLUE_NETMASK'}; + + if (&General::IpInSubnet($ip_address,$ethernethash{'BLUE_ADDRESS'},$ethernethash{'BLUE_NETMASK'})){ + $target = $blue_ip; + } +}else{ + exit 0; +} + +print "Status: 302 Moved Temporarily\n"; +print "Location: http://$target:1013/cgi-bin/index.cgi?redirect=$safe_url\n"; +print "Connection: close\n\n"; diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 7c330bb0fe..3ccfe631a5 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -7,6 +7,30 @@ 'Add Rule' => 'Regel hinzufügen', 'Add a route' => 'Eine Route hinzufügen', 'Async logging enabled' => 'Aktiviere asynchrones Schreiben des Syslogs', +'Captive 1day' => '1 Tag', +'Captive 1week' => '1 Woche', +'Captive 1month' => '1 Monat', +'Captive activate' => 'Aktivieren', +'Captive activated' => 'Aktiviert', +'Captive active on' => 'Aktiviert auf', +'Captive auth_lic' => 'Lizenz', +'Captive auth_vou' => 'Gutschein', +'Captive authentication' => 'Art der Anmeldung', +'Captive config' => 'Konfiguration', +'Captive err doublevoucher' => 'Ein Gutschein mit diesem Code ist bereits im Umlauf', +'Captive expire' => 'Ablauf', +'Captive ip' => 'IP-Addresse', +'Captive mac' => 'MAC-Adresse', +'Captive menu' => 'Captive-Portal', +'Captive nr' => 'Nummer', +'Captive nolimit' => 'Unbegrenzt', +'Captive voactive' => 'Aktive Gutscheine', +'Captive vout' => 'Ausgegebene Gutscheine', +'Captive title' => 'Titel der Anmeldeseite', +'Captive time' => 'Erlaubter Nutzungszeitraum nach aktivierung (Stunden)', +'Captive voucher' => 'Gutschein', +'Captive voucherout' => 'Gutschein ausgeben', +'Captive vouchervalid' => 'Gutschein gültig für', 'Choose Rule' => 'Wählen Sie eine der untenstehenden Regeln aus.', 'Class' => 'Klasse', 'Class was deleted' => 'wurde mit eventuell vorhandenen Unterklassen gelöscht', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 23f63102bf..580c2e4e1f 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -7,6 +7,30 @@ 'Add Rule' => 'Add rule', 'Add a route' => 'Add a route', 'Async logging enabled' => 'Enable asynchronous writing of the syslog file', +'Captive 1day' => '1 day', +'Captive 1week' => '1 week', +'Captive 1month' => '1 month', +'Captive activate' => 'Activate', +'Captive activated' => 'Activated', +'Captive active on' => 'Activated on', +'Captive auth_lic' => 'License', +'Captive auth_vou' => 'Voucher', +'Captive authentication' => 'Type of access', +'Captive config' => 'Settings', +'Captive err doublevoucher' => 'A voucher with this code already exists', +'Captive expire' => 'Expire', +'Captive ip' => 'IP-Address', +'Captive mac' => 'MAC-Address', +'Captive menu' => 'Captive Portal', +'Captive nr' => 'Number', +'Captive nolimit' => 'no limit', +'Captive voactive' => 'Active Vouchers', +'Captive vout' => 'Issued vouchers', +'Captive title' => 'Title of logon site', +'Captive time' => 'Accesstime post activation (hours)', +'Captive voucher' => 'Voucher', +'Captive voucherout' => 'Ticket transfer', +'Captive vouchervalid' => 'Voucher usable for', 'Choose Rule' => 'Choose one of the following rules.', 'Class' => 'Class', 'Class was deleted' => 'with potential subclasses was deleted',