From aed55ef9f81ea07da49b5b051354911d87d428ce Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 1 May 2017 12:06:11 +0100 Subject: [PATCH] captive: Show a message when no coupon code was entered Signed-off-by: Michael Tremer --- doc/language_issues.en | 1 + html/cgi-bin/captive/index.cgi | 48 ++++++++++++++++++--------------- html/html/captive/template.html | 10 +++++-- langs/en/cgi-bin/en.pl | 1 + 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/doc/language_issues.en b/doc/language_issues.en index a3cde91665..ee4eb01519 100644 --- a/doc/language_issues.en +++ b/doc/language_issues.en @@ -14,6 +14,7 @@ WARNING: translation string unused: Captive invalid_voucher WARNING: translation string unused: Captive ip WARNING: translation string unused: Captive logo_set WARNING: translation string unused: Captive nr +WARNING: translation string unused: Captive please enter a coupon code WARNING: translation string unused: Captive time WARNING: translation string unused: Captive voactive WARNING: translation string unused: Captive voucher diff --git a/html/cgi-bin/captive/index.cgi b/html/cgi-bin/captive/index.cgi index 963b890e8c..482ea9016b 100755 --- a/html/cgi-bin/captive/index.cgi +++ b/html/cgi-bin/captive/index.cgi @@ -78,36 +78,42 @@ if ($cgiparams{'ACTION'} eq "SUBMIT") { if ($settings{"AUTH"} eq "COUPON") { &General::readhasharray($coupons, \%couponhash); - # Convert coupon input to uppercase - $cgiparams{'COUPON'} = uc $cgiparams{'COUPON'}; + if ($cgiparams{'COUPON'}) { + # Convert coupon input to uppercase + $cgiparams{'COUPON'} = uc $cgiparams{'COUPON'}; - # Walk through all valid coupons and find the right one - my $found = 0; - foreach my $coupon (keys %couponhash) { - if ($couponhash{$coupon}[1] eq $cgiparams{'COUPON'}) { - $found = 1; + # Walk through all valid coupons and find the right one + my $found = 0; + foreach my $coupon (keys %couponhash) { + if ($couponhash{$coupon}[1] eq $cgiparams{'COUPON'}) { + $found = 1; - # Copy expiry time - $clientshash{$key}[3] = $couponhash{$coupon}[2]; + # Copy expiry time + $clientshash{$key}[3] = $couponhash{$coupon}[2]; - # Save coupon code - $clientshash{$key}[4] = $cgiparams{'COUPON'}; + # Save coupon code + $clientshash{$key}[4] = $cgiparams{'COUPON'}; - # Copy coupon remark - $clientshash{$key}[5] = $couponhash{$coupon}[3]; + # Copy coupon remark + $clientshash{$key}[5] = $couponhash{$coupon}[3]; - # Delete used coupon - delete $couponhash{$coupon}; - &General::writehasharray($coupons, \%couponhash); + # Delete used coupon + delete $couponhash{$coupon}; + &General::writehasharray($coupons, \%couponhash); - last; + last; + } + } + + if ($found == 1) { + &General::log("Captive", "Internet access granted via coupon ($clientshash{$key}[4]) for $ip_address until $clientshash{$key}[3]"); + } else { + $errormessage = $Lang::tr{"Captive invalid coupon"}; } - } - if ($found == 1) { - &General::log("Captive", "Internet access granted via coupon ($clientshash{$key}[4]) for $ip_address until $clientshash{$key}[3]"); + # No coupon given } else { - $errormessage = $Lang::tr{"Captive invalid coupon"}; + $errormessage = $Lang::tr{"Captive please enter a coupon code"}; } # License diff --git a/html/html/captive/template.html b/html/html/captive/template.html index 504920c64f..a15c9a3ff3 100644 --- a/html/html/captive/template.html +++ b/html/html/captive/template.html @@ -38,7 +38,7 @@ "> - + error" type="text" name="COUPON"> "> @@ -46,10 +46,16 @@ value=""> + +

+ +

+
+
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index e243f6bcb0..f569f53b02 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -42,6 +42,7 @@ 'Captive noexpiretime' => 'No valid connection time range given', 'Captive nolimit' => 'unlimited', 'Captive nr' => 'Number', +'Captive please enter a coupon code' => 'Please enter a coupon code', 'Captive terms' => 'Terms & Conditions', 'Captive terms short' => 'T&Cs', 'Captive time' => 'Access time post activation (hours)', -- 2.39.2