From: Alexander Marx Date: Mon, 1 Feb 2016 15:14:50 +0000 (+0100) Subject: Captive-Portal: redesign Webinterface X-Git-Tag: v2.19-core115~60^2~81 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=e01c5ab71a78b4061cf98fd03be76112842a6bf2 Captive-Portal: redesign Webinterface Signed-off-by: Alexander Marx --- diff --git a/html/cgi-bin/captive.cgi b/html/cgi-bin/captive.cgi index 2c5c8e4cc7..1c4e9f74de 100755 --- a/html/cgi-bin/captive.cgi +++ b/html/cgi-bin/captive.cgi @@ -59,11 +59,14 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ $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{'EXPIRE'} = $cgiparams{'EXP_HOUR'}+$cgiparams{'EXP_DAY'}+$cgiparams{'EXP_WEEK'}+$cgiparams{'EXP_MONTH'}; + $settings{'EXP_HOUR'} = $cgiparams{'EXP_HOUR'}; + $settings{'EXP_DAY'} = $cgiparams{'EXP_DAY'}; + $settings{'EXP_WEEK'} = $cgiparams{'EXP_WEEK'}; + $settings{'EXP_MONTH'} = $cgiparams{'EXP_MONTH'}; $settings{'TITLE'} = $cgiparams{'TITLE'}; &General::writehash("$settingsfile", \%settings); - + #write Licensetext if defined if ($cgiparams{'AGB'}){ $cgiparams{'AGB'} = &Header::escape($cgiparams{'AGB'}); @@ -88,6 +91,11 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive voucherout'}"){ } } + #check valid remark + if ($cgiparams{'REMARK'} ne '' && !&validremark($cgiparams{'REMARK'})){ + $errormessage=$Lang::tr{'fwhost err remark'}; + } + #if no error detected, write to disk if (!$errormessage){ my $date=time(); #seconds in utc @@ -95,13 +103,12 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive voucherout'}"){ #first get new key from hash my $key=&General::findhasharraykey (\%voucherhash); #initialize all fields with '' - foreach my $i (0 .. 4) { $voucherhash{$key}[$i] = "";} + foreach my $i (0 .. 3) { $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'}); + $voucherhash{$key}[2] = $settings{'EXPIRE'}; + $voucherhash{$key}[3] = $cgiparams{'REMARK'}; #write values to disk &General::writehasharray("$voucherout", \%voucherhash); @@ -188,7 +195,7 @@ END $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'"; @@ -199,9 +206,22 @@ END if ($netsettings{'BLUE_DEV'}){ print "$Lang::tr{'Captive active on'} Blue"; } - + print< + +
+ $Lang::tr{'Captive title'} + +
+ + + +END +; + + +print< $Lang::tr{'Captive authentication'} @@ -213,75 +233,87 @@ END print ""; - + print ""; - + print< - - - $Lang::tr{'Captive time'} - - - -END -; - print ""; + if($settings{'AUTH'} eq 'LICENSE'){ + &agbbox(); + } - print ""; - - print ""; + print"$Lang::tr{'Captive vouchervalid'}"; + + print "
"; + print ""; + + #print hour-dropdownbox + my $hrs=3600; + print ""; -print< - - -END -; + print ""; + + print "
StundenTageWochenMonate
"; + + #print day-dropdownbox + my $days=3600*24; + print ""; + + #print week-dropdownbox + my $week=3600*24*7; + print ""; + + #print month-dropdownbox + my $month=3600*24*30; + print "
- $Lang::tr{'Captive title'} -

- -
    unlimited
"; - if($settings{'AUTH'} eq 'LICENSE'){ &agbbox();} 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< - + 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 ""; print "
$Lang::tr{'Captive voucher'}$Lang::tr{'hours'}$Lang::tr{'Captive expire'}
$Lang::tr{'Captive voucher'}$Lang::tr{'Captive expire'}$Lang::tr{'remark'}
$cgiparams{'CODE'}
$settings{'TIME'}
$expire

$Lang::tr{'remark'}
$cgiparams{'CODE'}
$expire

"; print "
"; &Header::closebox(); @@ -406,20 +437,17 @@ sub show_voucher_out(){ 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; + 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 ""; - $voucherhash{$key}[4] = HTML::Entities::decode_entities($voucherhash{$key}[4]); - print ""; + print ""; + print ""; + print ""; + print ""; 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 ""; $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 d0b28f7a96..3b9819fb87 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 bbb83352d7..3b3907fa71 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 58286899da..3b73da61b6 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 4bcdab5fb5..aae6f6064d 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}; }
$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'}
"; - 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]
$starttime
$voucherhash{$key}[1]
$endtime
$voucherhash{$key}[3]
$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 "