From c7e78cc62e6699f00962caf440ed25270c461334 Mon Sep 17 00:00:00 2001 From: Alexander Marx Date: Tue, 2 Feb 2016 14:30:13 +0100 Subject: [PATCH] Captive-Portal: several design changes Signed-off-by: Alexander Marx --- html/cgi-bin/captive.cgi | 107 ++++++++++++++++++--------------- html/cgi-bin/captive/index.cgi | 4 +- langs/de/cgi-bin/de.pl | 1 + langs/en/cgi-bin/en.pl | 1 + lfs/web-user-interface | 2 +- 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/html/cgi-bin/captive.cgi b/html/cgi-bin/captive.cgi index 1c4e9f74de..0a16dc12b1 100755 --- a/html/cgi-bin/captive.cgi +++ b/html/cgi-bin/captive.cgi @@ -55,7 +55,14 @@ unless (-e $voucherout) { system("touch $voucherout"); } #actions if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ - #saves the Captiveportal settings to disk + #saves the Captiveportal settings to disk + if ($cgiparams{'UNLIMITED'} eq 'on'){ + $cgiparams{'EXP_HOUR'} = '0'; + $cgiparams{'EXP_DAY'} = '0'; + $cgiparams{'EXP_WEEK'} = '0'; + $cgiparams{'EXP_MONTH'} = '0'; + } + $settings{'ENABLE_GREEN'} = $cgiparams{'ENABLE_GREEN'}; $settings{'ENABLE_BLUE'} = $cgiparams{'ENABLE_BLUE'}; $settings{'AUTH'} = $cgiparams{'AUTH'}; @@ -65,6 +72,7 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ $settings{'EXP_WEEK'} = $cgiparams{'EXP_WEEK'}; $settings{'EXP_MONTH'} = $cgiparams{'EXP_MONTH'}; $settings{'TITLE'} = $cgiparams{'TITLE'}; + $settings{'UNLIMITED'} = $cgiparams{'UNLIMITED'}; &General::writehash("$settingsfile", \%settings); #write Licensetext if defined @@ -200,6 +208,10 @@ END $checked{'ENABLE_BLUE'}{'on'} = ''; $checked{'ENABLE_BLUE'}{$settings{'ENABLE_BLUE'}} = "checked='checked'"; + $checked{'UNLIMITED'}{'off'} = ''; + $checked{'UNLIMITED'}{'on'} = ''; + $checked{'UNLIMITED'}{$settings{'UNLIMITED'}} = "checked='checked'"; + if ($netsettings{'GREEN_DEV'}){ print "$Lang::tr{'Captive active on'} Green"; } @@ -219,7 +231,6 @@ END END ; - print< @@ -252,7 +263,7 @@ END print"$Lang::tr{'Captive vouchervalid'}"; print "
"; - print ""; + print ""; #print hour-dropdownbox my $hrs=3600; @@ -310,7 +321,7 @@ END } print ""; - print ""; + print ""; print "
StundenTageWochenMonate$Lang::tr{'hours'}$Lang::tr{'days'}$Lang::tr{'weeks'}$Lang::tr{'months'}    unlimited    $Lang::tr{'Captive nolimit'}
"; @@ -366,8 +377,13 @@ sub gencode(){ sub voucher(){ #show voucher part #calculate expiredate - my $expire = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$settings{'EXPIRE'})); - + my $expire; + if ($settings{'UNLIMITED'} eq 'on'){ + $expire = $Lang::tr{'Captive nolimit'}; + }else{ + $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< @@ -395,18 +411,20 @@ sub show_license_connections(){ 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; + my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2])); + my $endtime; + if ($clientshash{$key}[3] eq '0'){ + $endtime=$Lang::tr{'Captive nolimit'}; + }else{ + $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3])); + } + if ($count % 2){ print" "; $col="bgcolor='$color{'color20'}'"; @@ -414,15 +432,9 @@ END $col="bgcolor='$color{'color22'}'"; print" "; } - print ""; + print ""; $count++; } @@ -439,15 +451,20 @@ sub show_voucher_out(){ print<
$Lang::tr{'Captive mac'}$Lang::tr{'Captive ip'}$Lang::tr{'Captive voucher'}$Lang::tr{'Captive activated'}$Lang::tr{'Captive expire'}$Lang::tr{'delete'}
$Lang::tr{'Captive voucher'}$Lang::tr{'Captive activated'}$Lang::tr{'Captive expire'}$Lang::tr{'Captive mac'}$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 "
$clientshash{$key}[4]
$starttime "; + print "
$endtime "; + print "
$clientshash{$key}[0]
- + END ; &General::readhasharray("$voucherout", \%voucherhash); foreach my $key (keys %voucherhash) { 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])); - + my $endtime; + if ($voucherhash{$key}[2] eq '0'){ + $endtime=$Lang::tr{'Captive nolimit'}; + }else{ + $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'}'"; @@ -455,15 +472,15 @@ END $col="bgcolor='$color{'color22'}'"; print" "; } - - print ""; + print ""; + print ""; print ""; print ""; print ""; $count++; } - + print "
$Lang::tr{'date'}$Lang::tr{'Captive voucher'}$Lang::tr{'Captive expire'}$Lang::tr{'remark'}$Lang::tr{'delete'}
$Lang::tr{'Captive voucher'}$Lang::tr{'date'}$Lang::tr{'Captive expire'}$Lang::tr{'remark'}$Lang::tr{'delete'}
$starttime
$voucherhash{$key}[1]
$starttime
$endtime
$voucherhash{$key}[3]
"; &Header::closebox(); } @@ -475,26 +492,23 @@ sub show_voucher_in_use(){ 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, $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; + #calculate time from clientshash (starttime) + my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2])); + #calculate endtime from clientshash + my $endtime; + if ($clientshash{$key}[3] eq '0'){ + $endtime=$Lang::tr{'Captive nolimit'}; + }else{ + $endtime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3])); + } if ($count % 2){ print" "; @@ -504,15 +518,12 @@ END 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'}
$Lang::tr{'Captive voucher'}$Lang::tr{'Captive activated'}$Lang::tr{'Captive expire'}$Lang::tr{'Captive mac'}$Lang::tr{'remark'}$Lang::tr{'delete'}
$clientshash{$key}[0]
$clientshash{$key}[1]
$clientshash{$key}[4]
$mday.$mon.$year "; - printf("%02d",$hour); - print ":"; - printf("%02d",$min); - print "
$mdayx.$monx.$yearx $clientshash{$key}[3]"; + print "
$clientshash{$key}[4]
$starttime "; + print "
$endtime
$clientshash{$key}[0]
$clientshash{$key}[5]
"; print "
"; &Header::closebox(); } diff --git a/html/cgi-bin/captive/index.cgi b/html/cgi-bin/captive/index.cgi index 3b9819fb87..dd45931996 100755 --- a/html/cgi-bin/captive/index.cgi +++ b/html/cgi-bin/captive/index.cgi @@ -105,9 +105,9 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive activate'}"){ $clientshash{$key1}[0] = $mac_address; $clientshash{$key1}[1] = $ip_address; $clientshash{$key1}[2] = time(); - $clientshash{$key1}[3] = $voucherhash{$key}[3]; + $clientshash{$key1}[3] = $voucherhash{$key}[2]; $clientshash{$key1}[4] = $cgiparams{'VOUCHER'}; - $clientshash{$key1}[5] = HTML::Entities::decode_entities($clientshash{$key1}[3]); + $clientshash{$key1}[5] = HTML::Entities::decode_entities($voucherhash{$key}[3]); &General::writehasharray("$clients", \%clientshash); &General::log("Captive", "Internet Access granted via voucher no. $clientshash{$key1}[4] for $ip_address until $clientshash{$key}[3] Remark: $clientshash{$key1}[7]"); diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 3b3907fa71..4c8a809c8c 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -19,6 +19,7 @@ 'Captive config' => 'Konfiguration', 'Captive err doublevoucher' => 'Ein Gutschein mit diesem Code ist bereits im Umlauf', 'Captive expire' => 'Ablauf', +'Captive invalid_voucher' => 'Dieser Code ist ungültig. Bitte versuchen Sie es erneut', 'Captive ip' => 'IP-Addresse', 'Captive mac' => 'MAC-Adresse', 'Captive menu' => 'Captive-Portal', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 3b73da61b6..1d168fcee8 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -19,6 +19,7 @@ 'Captive config' => 'Settings', 'Captive err doublevoucher' => 'A voucher with this code already exists', 'Captive expire' => 'Expire', +'Captive invalid_voucher' => 'Invalid code. Please try again', 'Captive ip' => 'IP-Address', 'Captive mac' => 'MAC-Address', 'Captive menu' => 'Captive Portal', diff --git a/lfs/web-user-interface b/lfs/web-user-interface index 919acbe76d..0f581008d7 100644 --- a/lfs/web-user-interface +++ b/lfs/web-user-interface @@ -64,7 +64,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) chown -R root:root /srv/web/ipfire chmod -R 755 /srv/web/ipfire/cgi-bin chmod -R 644 /srv/web/ipfire/html - chmod 755 /srv/web/ipfire/html /srv/web/ipfire/html/{index.cgi,redirect.cgi,dial.cgi,images,include,themes,themes/*,themes/*/*} + chmod 755 /srv/web/ipfire/html /srv/web/ipfire/html/{index.cgi,redirect.cgi,dial.cgi,images,include,themes,themes/*,themes/*/*,captive/*} ln -svf ipfire /srv/web/ipfire/html/themes/ipfire-rounded # Reset permissions of redirect templates and theme directories -- 2.39.2