$Lang::tr{'Captive vouchervalid'} ";
+
+ print " ";
+
print<
@@ -295,6 +327,7 @@ print<";
+
&Header::closebox();
#if settings is set to use vouchers, the voucher part has to be displayed
@@ -332,22 +365,20 @@ sub gencode(){
sub voucher(){
#show voucher part
- my $expire;
+ #calculate expiredate
+ my $expire = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$settings{'EXPIRE'}));
+
&Header::openbox('100%', 'left', $Lang::tr{'Captive voucher'});
print<
";
print " ";
&Header::closebox();
@@ -406,20 +437,17 @@ sub show_voucher_out(){
my $col;
&Header::openbox('100%', 'left', $Lang::tr{'Captive vout'});
print<
+
- $Lang::tr{'date'} $Lang::tr{'Captive voucher'} $Lang::tr{'hours'} $Lang::tr{'Captive expire'} $Lang::tr{'remark'} $Lang::tr{'delete'}
+ $Lang::tr{'date'} $Lang::tr{'Captive voucher'} $Lang::tr{'Captive expire'} $Lang::tr{'remark'} $Lang::tr{'delete'}
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;
+ my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($voucherhash{$key}[0]));
+ my $endtime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($voucherhash{$key}[0]+$voucherhash{$key}[2]));
+
if ($count % 2){
print" ";
$col="bgcolor='$color{'color20'}'";
@@ -427,29 +455,11 @@ END
$col="bgcolor='$color{'color22'}'";
print" ";
}
- print "";
- 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] = HTML::Entities::decode_entities($voucherhash{$key}[4]);
- print "$voucherhash{$key}[4] ";
+ print "$starttime ";
+ print "$voucherhash{$key}[1] ";
+ print "$endtime ";
+ print "$voucherhash{$key}[3] ";
print " ";
$count++;
}
@@ -474,11 +484,18 @@ END
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));
+ my ($secx,$minx,$hourx, $mdayx, $monx, $yearx) = localtime($clientshash{$key}[6]+$clientshash{$key}[7]);
+
$mon = '0'.++$mon if $mon<10;
$min = '0'.$min if $min<10;
$hour = '0'.$hour if $hour<10;
$year=$year+1900;
+
+ $monx = '0'.++$mon if $mon<10;
+ $minx = '0'.$min if $min<10;
+ $hourx = '0'.$hour if $hour<10;
+ $yearx=$year+1900;
+
if ($count % 2){
print" ";
$col="bgcolor='$color{'color20'}'";
@@ -486,14 +503,12 @@ END
$col="bgcolor='$color{'color22'}'";
print" ";
}
+
print "$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 " $mdayx.$monx.$yearx $clientshash{$key}[3]";
print " ";
$count++;
}
@@ -502,6 +517,26 @@ END
&Header::closebox();
}
+sub validremark
+{
+ # Checks a hostname against RFC1035
+ my $remark = $_[0];
+ # Each part should be at least two characters in length
+ # but no more than 63 characters
+ if (length ($remark) < 1 || length ($remark) > 255) {
+ return 0;}
+ # Only valid characters are a-z, A-Z, 0-9 and -
+ if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
+ return 0;}
+ # First character can only be a letter or a digit
+ if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
+ return 0;}
+ # Last character can only be a letter or a digit
+ if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
+ return 0;}
+ return 1;
+}
+
sub error{
#if an errormessage exits, show a box with errormessage
if ($errormessage) {
diff --git a/html/cgi-bin/captive/index.cgi b/html/cgi-bin/captive/index.cgi
index d0b28f7a9..3b9819fb8 100755
--- a/html/cgi-bin/captive/index.cgi
+++ b/html/cgi-bin/captive/index.cgi
@@ -23,6 +23,7 @@ use strict;
use CGI ':standard';
use URI::Escape;
use HTML::Entities();
+
# enable only the following on debugging purpose
#use warnings;
#use CGI::Carp 'fatalsToBrowser';
@@ -41,6 +42,7 @@ 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"); }
@@ -53,11 +55,6 @@ unless (-f $clients){ system("touch $clients"); }
#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} ||"";
@@ -69,15 +66,15 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'gpl i accept these terms and conditions'
&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();
-
+ foreach my $i (0 .. 5) { $clientshash{$key}[$i] = "";}
+
+ $clientshash{$key}[0] = $mac_address; #mac address of actual client
+ $clientshash{$key}[1] = $ip_address; #ip address of actual client
+ $clientshash{$key}[2] = time(); #actual time in unix seconds (timestamp of first conenction)
+ $clientshash{$key}[3] = $settings{'EXPIRE'}; #Expire time in seconds (1day, 1 week ....)
+ $clientshash{$key}[4] = $Lang::tr{'Captive auth_lic'}; #Type of license (license or voucher)
+ $clientshash{$key}[5] = '';
+
&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]");
@@ -102,25 +99,17 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive activate'}"){
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] = "";}
+ foreach my $i (0 .. 5) { $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}[2] = time();
+ $clientshash{$key1}[3] = $voucherhash{$key}[3];
$clientshash{$key1}[4] = $cgiparams{'VOUCHER'};
- $clientshash{$key1}[5] = $voucherhash{$key}[2];
- $clientshash{$key1}[6] = time();
- $clientshash{$key1}[7] = $voucherhash{$key}[4];
-
+ $clientshash{$key1}[5] = HTML::Entities::decode_entities($clientshash{$key1}[3]);
+
&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};
@@ -133,13 +122,13 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive activate'}"){
}
if($redir == 1){
+ sleep(4);
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();
@@ -147,7 +136,6 @@ if($redir == 1){
&start();
#Functions
-
sub start(){
if ($settings{'AUTH'} eq 'VOUCHER'){
&voucher();
@@ -174,6 +162,7 @@ Content-type: text/html\n\n
END
;
}
+
sub agb(){
print<
diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
index bbb83352d..3b3907fa7 100644
--- a/langs/de/cgi-bin/de.pl
+++ b/langs/de/cgi-bin/de.pl
@@ -30,7 +30,7 @@
'Captive time' => 'Erlaubter Nutzungszeitraum nach aktivierung (Stunden)',
'Captive voucher' => 'Gutschein',
'Captive voucherout' => 'Gutschein ausgeben',
-'Captive vouchervalid' => 'Gutschein gültig für',
+'Captive vouchervalid' => 'Verbindungszeitraum',
'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 58286899d..3b73da61b 100644
--- a/langs/en/cgi-bin/en.pl
+++ b/langs/en/cgi-bin/en.pl
@@ -30,7 +30,7 @@
'Captive time' => 'Accesstime post activation (hours)',
'Captive voucher' => 'Voucher',
'Captive voucherout' => 'Ticket transfer',
-'Captive vouchervalid' => 'Voucher usable for',
+'Captive vouchervalid' => 'Conenction timerange',
'Choose Rule' => 'Choose one of the following rules.',
'Class' => 'Class',
'Class was deleted' => 'with potential subclasses was deleted',
diff --git a/src/scripts/captive-cleanup b/src/scripts/captive-cleanup
index 4bcdab5fb..aae6f6064 100755
--- a/src/scripts/captive-cleanup
+++ b/src/scripts/captive-cleanup
@@ -35,7 +35,7 @@ if (-f $settingsfile && -f $clients && ! -z $clients){
&General::readhasharray("$clients", \%clientshash);
$time = time();
foreach my $key (keys %clientshash) {
- $expiretime=($clientshash{$key}[5]*3600)+$clientshash{$key}[6];
+ $expiretime=($clientshash{$key}[2])+$clientshash{$key}[3];
if ($expiretime < $time){
delete $clientshash{key};
}