]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Captive-Portal: add web-part
authorAlexander Marx <alexander.marx@ipfire.org>
Thu, 28 Jan 2016 10:18:59 +0000 (11:18 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Sep 2017 17:54:03 +0000 (18:54 +0100)
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 <alexander.marx@ipfire.org>
config/httpd/vhosts.d/captive.conf [new file with mode: 0644]
config/menu/30-network.menu
html/cgi-bin/captive.cgi [new file with mode: 0755]
html/cgi-bin/captive/index.cgi [new file with mode: 0755]
html/html/captive/assets/captive.css [new file with mode: 0644]
html/html/captive/assets/favicon.ico [new file with mode: 0644]
html/html/captive/assets/internet.png [new file with mode: 0644]
html/html/captive/index.cgi [new file with mode: 0755]
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl

diff --git a/config/httpd/vhosts.d/captive.conf b/config/httpd/vhosts.d/captive.conf
new file mode 100644 (file)
index 0000000..0824b79
--- /dev/null
@@ -0,0 +1,29 @@
+Listen 1013
+
+<VirtualHost *: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
+
+       <Directory /srv/web/ipfire/html/captive>
+               Options ExecCGI
+               Order allow,deny
+               Allow from all
+    </Directory>
+
+    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
+
+       <Directory /srv/web/ipfire/cgi-bin/captive>
+               Options ExecCGI 
+       Order allow,deny
+               Allow from all
+       </Directory>
+</VirtualHost>
index 8e1336a3b6957e0c3756bd504188b63c2cf1ec0f..137fd686c3f9ad73f17cc401148c20c343390aad 100644 (file)
                                 '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 (executable)
index 0000000..2c5c8e4
--- /dev/null
@@ -0,0 +1,516 @@
+#!/usr/bin/perl
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2016  IPFire Team  <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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 <<END
+               <form method='post' action='$ENV{'SCRIPT_NAME'}'>\n
+               <table width='100%' border="0">
+               <tr>
+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 "<td width='30%'>$Lang::tr{'Captive active on'} <font color='$Header::colourgreen'>Green</font></td><td><input type='checkbox' name='ENABLE_GREEN' $checked{'ENABLE_GREEN'}{'on'} /></td></tr>";
+       }
+       if ($netsettings{'BLUE_DEV'}){
+               print "<td width='30%'>$Lang::tr{'Captive active on'} <font color='$Header::colourblue'>Blue</font></td><td><input type='checkbox' name='ENABLE_BLUE' $checked{'ENABLE_BLUE'}{'on'} /></td></tr>";
+       }
+       
+       print<<END
+               </tr>
+               <tr>
+                       <td>
+                               $Lang::tr{'Captive authentication'}
+                       </td>
+                       <td>
+                               <select name='AUTH' style='width:8em;'>
+END
+;
+       print "<option value='LICENSE' ";
+       print " selected='selected'" if ($settings{'AUTH'} eq 'LICENSE');
+       print ">$Lang::tr{'Captive auth_lic'}</option>";
+       
+       print "<option value='VOUCHER' ";
+       print " selected='selected'" if ($settings{'AUTH'} eq 'VOUCHER');
+       print ">$Lang::tr{'Captive auth_vou'}</option>";
+       
+       print<<END
+                               </select>       
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               $Lang::tr{'Captive time'}
+                       </td>
+                       <td>
+                               <select name='TIME' style='width:8em;'>
+END
+;
+       print "<option value='nolimit' ";
+       print " selected='selected'" if ($settings{'TIME'} eq 'nolimit');
+       print ">$Lang::tr{'Captive nolimit'}</option>";
+
+       print "<option value='1' ";
+       print " selected='selected'" if ($settings{'TIME'} eq '1');
+       print ">1</option>";
+       
+       print "<option value='3' ";
+       print " selected='selected'" if ($settings{'TIME'} eq '3');
+       print ">3</option>";
+       
+       print "<option value='8' ";
+       print " selected='selected'" if ($settings{'TIME'} eq '8');
+       print ">8</option>";
+       
+       
+print<<END
+                       </td>
+               </tr>
+               <tr>
+                       <td>
+                               $Lang::tr{'Captive vouchervalid'}
+                       </td>
+                       <td>
+                               <select name='EXPIRE' style='width:8em;'>
+END
+;
+       print "<option value='86400' ";
+       print " selected='selected'" if ($settings{'EXPIRE'} eq '86400');
+       print ">$Lang::tr{'Captive 1day'}</option>";
+
+       print "<option value='604800' ";
+       print " selected='selected'" if ($settings{'EXPIRE'} eq '604800');
+       print ">$Lang::tr{'Captive 1week'}</option>";
+       
+       print "<option value='2592000' ";
+       print " selected='selected'" if ($settings{'EXPIRE'} eq '2592000');
+       print ">$Lang::tr{'Captive 1month'}</option></td></tr>";
+
+print<<END
+               <tr>
+               <td><br>
+                       $Lang::tr{'Captive title'}
+               </td>
+               <td><br>
+                       <input type='text' name='TITLE' value="$settings{'TITLE'}" size='40'>
+               </td>
+END
+;
+
+       if($settings{'AUTH'} eq 'LICENSE'){ &agbbox();}
+print<<END
+               <tr>
+                       <td>
+                       </td>
+                       <td align='right'>
+                       <input type='submit' name='ACTION' value="$Lang::tr{'save'}"/>
+                       </td>
+               </tr>
+               </table>
+               <br><br>
+END
+;
+       print "</form>";
+       &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<<END
+       <tr>
+               <td>
+                       License agreement
+               </td>
+               <td>
+                       <br>
+                       <textarea cols="50" rows="10" name="AGB">$cgiparams{'AGB'}</textarea>
+               </td>
+       </tr>
+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
+       <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+       <table class='tbl'>
+       <tr>
+               <th align='center' width='30%'>$Lang::tr{'Captive voucher'}</th><th align='center' width='15%'>$Lang::tr{'hours'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th></tr>
+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 "<tr><td><center><b><font size='20'>$cgiparams{'CODE'}</font></b></center></td><td><center><b><font size='5'>$settings{'TIME'}</font></b></center></td><td><center><b><font size='5'>$expire</font></b></center></td></tr>";
+       print "<tr><td colspan='3'><br>$Lang::tr{'remark'}<input type='text' name='REMARK' align='left' size='60' style='font-size: 22px;'></td></tr>";
+       print "</table><br>";
+       print "<center><input type='submit' name='ACTION' value='$Lang::tr{'Captive voucherout'}'><input type='hidden' name='CODE' value='$cgiparams{'CODE'}'</center></form>";
+       &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
+               <center><table class='tbl'>
+               <tr>
+                       <th align='center' width='15%'><font size='1'>$Lang::tr{'Captive mac'}</th><th align='center' width='15%'>$Lang::tr{'Captive ip'}</th><th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th th align='center' width='15%'>$Lang::tr{'Captive activated'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th th align='center' width='15%'>$Lang::tr{'delete'}</th></tr>
+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" <tr>";
+                       $col="bgcolor='$color{'color20'}'";
+               }else{
+                       $col="bgcolor='$color{'color22'}'";
+                       print" <tr>";
+               }
+               print "<td $col><center>$clientshash{$key}[0]</td><td $col><center>$clientshash{$key}[1]</td><td $col><center>$clientshash{$key}[4]</td><td $col><center>$mday.$mon.$year ";
+               printf("%02d",$hour);
+               print ":";
+               printf("%02d",$min);
+               print "</center></td><td $col><center>$mday.$mon.$year ";
+               printf("%02d",$hourx);
+               print ":";
+               printf("%02d",$minx);
+               print "</td><td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherinuse' /><input type='hidden' name='key' value='$clientshash{$key}[0]' /></form></tr>";
+               $count++;
+       }
+       
+       print "</table>";
+       &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
+               <center><table class='tbl'>
+               <tr>
+                       <th align='center' width='15%'><font size='1'>$Lang::tr{'date'}</th><th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th align='center' width='5%'>$Lang::tr{'hours'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th align='center'>$Lang::tr{'remark'}</th><th align='center' width='15%'>$Lang::tr{'delete'}</th></tr>
+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" <tr>";
+                       $col="bgcolor='$color{'color20'}'";
+               }else{
+                       $col="bgcolor='$color{'color22'}'";
+                       print" <tr>";
+               }
+               print "<td $col><center>";
+               printf("%02d",$mday);
+               print ".";
+               printf("%02d",$mon);
+               print ".";
+               print"$year ";
+               
+               printf("%02d",$hour);
+               print ":";
+               printf("%02d",$min);
+               print "</td><td $col><center><b>$voucherhash{$key}[1]</b></td><td $col><center>$voucherhash{$key}[2]</td><td $col><center>";
+               printf("%02d",$mdayx);
+               print ".";
+               printf("%02d",$monx);
+               print ".";
+               print"$yearx ";
+               
+               printf("%02d",$hourx);
+               print ":";
+               printf("%02d",$minx);
+               print "</td>";
+               $voucherhash{$key}[4] = HTML::Entities::decode_entities($voucherhash{$key}[4]);
+               print "<td $col align='center'>$voucherhash{$key}[4]</td>";
+               print "<td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherout' /><input type='hidden' name='key' value='$voucherhash{$key}[0]' /></form></tr>";
+               $count++;
+       }
+       
+       print "</table>";
+       &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
+       <center><table class='tbl'>
+               <tr>
+                       <th align='center' width='15%'><font size='1'>$Lang::tr{'Captive mac'}</th><th align='center' width='15%'>$Lang::tr{'Captive ip'}</th><th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th th align='center' width='15%'>$Lang::tr{'Captive activated'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th th align='center' width='15%'>$Lang::tr{'delete'}</th></tr>
+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" <tr>";
+                               $col="bgcolor='$color{'color20'}'";
+                       }else{
+                               $col="bgcolor='$color{'color22'}'";
+                               print" <tr>";
+                       }
+                       print "<td $col><center>$clientshash{$key}[0]</td><td $col><center>$clientshash{$key}[1]</td><td $col><center>$clientshash{$key}[4]</td><td $col><center>$mday.$mon.$year ";
+                       printf("%02d",$hour);
+                       print ":";
+                       printf("%02d",$min);
+                       print "</center></td><td $col><center>$mday.$mon.$year ";
+                       printf("%02d",$hourx);
+                       print ":";
+                       printf("%02d",$minx);
+                       print "</td><td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherinuse' /><input type='hidden' name='key' value='$clientshash{$key}[0]' /></form></tr>";
+                       $count++;
+       }
+       
+       print "</table>";
+       &Header::closebox();
+}
+
+sub error{
+       #if an errormessage exits, show a box with errormessage
+       if ($errormessage) {
+               &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+               print "<class name='base'>$errormessage\n";
+               print "&nbsp;</class>\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 (executable)
index 0000000..d0b28f7
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 "<div id='title'><br>$errormessage<br></diV>";
+       }
+}
+
+sub head(){
+print<<END
+Content-type: text/html\n\n
+<html> 
+       <head>
+               <meta charset="utf-8">
+               <title>$settings{'TITLE'}</title>
+               <link href="../assets/captive.css" type="text/css" rel="stylesheet">
+       </head>
+END
+;
+}
+sub agb(){
+print<<END
+       <body>
+       <center>
+               <div class="title">
+                       <h1>$settings{'TITLE'}
+               </div>
+               <br>
+               <div class="agb">
+               <textarea style="width:100%;" rows='40'>
+END
+;
+&getagb();
+print<<END
+               </textarea>
+                       <center>
+                               <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+                                       <br><input type='hidden' name='redirect' value ='$url'><input type='submit' name='ACTION' value="$Lang::tr{'gpl i accept these terms and conditions'}"/>
+                               </form>
+                       </center>
+               </div>
+       </center>
+       </body>
+       </html>
+END
+;
+}
+
+sub voucher(){
+       print<<END
+       <body>
+       <center>
+               <div class="title">
+                       <h1>LOGIN</h1>
+               </div>
+               <br>
+               <div class="login">
+END
+;
+
+print<<END
+               <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+                       <center>
+                               <table>
+                                       <tr>
+                                               <td>
+                                                       <b>$Lang::tr{'Captive voucher'}</b>&nbsp<input type='text' maxlength="8" size='10' style="font-size: 24px;font-weight: bold;" name='VOUCHER'>
+                                               </td>
+                                               <td>
+                                                       <input type='submit' name='ACTION' value="$Lang::tr{'Captive activate'}"/>
+                                               </td>
+                                       </tr>
+                               </table>
+               </form>
+               </div>
+               <br>
+               <div class="agb">
+                       <textarea style="width:100%;" rows='40'>
+END
+;
+&getagb();
+print<<END
+                       </textarea>
+                       <br><br>
+               </div>
+       </body>
+       </html>
+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 (file)
index 0000000..7e8eac6
--- /dev/null
@@ -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 (file)
index 0000000..52da262
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 (file)
index 0000000..b4f20df
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 (executable)
index 0000000..cf84acf
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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";
index 0138cbc0290494136f43c5f43185e7202e10e85f..bbb83352d7f95210ead987e864ac24eeab953b55 100644 (file)
@@ -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 <u>eine</u> der untenstehenden Regeln aus.',
 'Class' => 'Klasse',
 'Class was deleted' => 'wurde mit eventuell vorhandenen Unterklassen gelöscht',
index b3aee5a2b749c1ee73e8080b6c834fe983913d0d..58286899da645563642d2c913810cb485da857c4 100644 (file)
@@ -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 <u>one</u> of the following rules.',
 'Class' => 'Class',
 'Class was deleted' => 'with potential subclasses was deleted',