From b32d9e92bee391e172236e4ee4d7661bfd5a1f11 Mon Sep 17 00:00:00 2001 From: Alexander Marx Date: Wed, 10 Feb 2016 10:20:52 +0100 Subject: [PATCH] Captive-Portal: Add logo upload feature Signed-off-by: Alexander Marx --- html/cgi-bin/captive.cgi | 119 +++++++++++++++++++++++++++++---------- langs/de/cgi-bin/de.pl | 4 ++ langs/en/cgi-bin/en.pl | 4 ++ 3 files changed, 97 insertions(+), 30 deletions(-) diff --git a/html/cgi-bin/captive.cgi b/html/cgi-bin/captive.cgi index a42e398154..c4373b57c6 100755 --- a/html/cgi-bin/captive.cgi +++ b/html/cgi-bin/captive.cgi @@ -19,8 +19,10 @@ # # ############################################################################### -use strict; +#use strict; use HTML::Entities(); +use File::Basename; + # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; @@ -41,7 +43,7 @@ my $clients="${General::swroot}/captive/clients"; my %voucherhash=(); my %clientshash=(); my $settingsfile="${General::swroot}/captive/settings"; - +my $logopath = "/srv/web/ipfire/html/captive/logo"; unless (-e $settingsfile) { system("touch $settingsfile"); } unless (-e $voucherout) { system("touch $voucherout"); } @@ -56,36 +58,70 @@ unless (-e $voucherout) { system("touch $voucherout"); } #actions if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ - #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'; + my $file = $cgiparams{'uploaded_file'}; + if ($file){ + #Check if extension is png + chomp $file; + my ($name, $path, $ext) = fileparse($file, qr/\.[^.]*$/); + if ($ext ne ".png"){ + $errormessage=$Lang::tr{'Captive wrong ext'}; + } } + if (!$errormessage){ + #Check if we need to upload a new logo + if($file){ + #Save File + my ($filehandle) = CGI::upload('uploaded_file'); + open (UPLOADFILE, ">$logopath/logo.png"); + binmode $filehandle; + while ( <$filehandle> ) { + print UPLOADFILE; + } + close (UPLOADFILE); + + #Open file to check if dimensions are within rang + open (PNG , "<$logopath/logo.png"); + local $/; + my $PNG1=; + close(PNG); + my ($width,$height)=&pngsize($PNG1); + if($width > 1920 || $height > 800 || $width < 1280 || $height < 4000){ + $errormessage.="$Lang::tr{'Captive invalid logosize'}
Filedimensions width: $width height: $height
"; + unlink("$logopath/logo.png"); + } + } - $settings{'ENABLE_GREEN'} = $cgiparams{'ENABLE_GREEN'}; - $settings{'ENABLE_BLUE'} = $cgiparams{'ENABLE_BLUE'}; - $settings{'AUTH'} = $cgiparams{'AUTH'}; - $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'}; - $settings{'UNLIMITED'} = $cgiparams{'UNLIMITED'}; - &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'}=""; + #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'}; + $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'}; + $settings{'UNLIMITED'} = $cgiparams{'UNLIMITED'}; + &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"); } - #execute binary to reload firewall rules - system("/usr/local/bin/captivectrl"); } if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive voucherout'}"){ @@ -195,7 +231,7 @@ sub config(){ #prints the config box on the website &Header::openbox('100%', 'left', $Lang::tr{'Captive config'}); print <\n +
\n END @@ -259,6 +295,16 @@ END &agbbox(); + #Logo Upload + print ""; + #Show Logo in webinterface with 1/2 size if set + if (-f "$logopath/logo.png"){ + print""; + print""; + }else{ + print""; + print""; + } print"
$Lang::tr{'Captive logo_upload'}
$Lang::tr{'Captive logo_set'}$logopath/logo.png
$Lang::tr{'Captive logo_set'}
$Lang::tr{'no'}
$Lang::tr{'Captive vouchervalid'}"; print "
"; print ""; @@ -546,6 +592,19 @@ sub validremark return 1; } +sub pngsize { + my $Buffer = shift; + my ($width,$height) = ( undef, undef ); + + if ($Buffer =~ /IHDR(.{8})/) { + my $PNG = $1; + ($width,$height) = unpack( "NN", $PNG ); + } else { + $width=$Lang::tr{'acct invalid png'}; + }; + return ($width,$height); +} + sub error{ #if an errormessage exits, show a box with errormessage if ($errormessage) { diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 4c8a809c8c..d05d26fe6c 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -19,8 +19,11 @@ 'Captive config' => 'Konfiguration', 'Captive err doublevoucher' => 'Ein Gutschein mit diesem Code ist bereits im Umlauf', 'Captive expire' => 'Ablauf', +'Captive invalid logosize' => 'Die hochgeladene Datei entspricht nicht den vorgegeben Dimensionen (min. 1280x400, max. 1920x800)', 'Captive invalid_voucher' => 'Dieser Code ist ungültig. Bitte versuchen Sie es erneut', 'Captive ip' => 'IP-Addresse', +'Captive logo_set' => 'Aktuelles Logo', +'Captive logo_upload' => 'Logo hochladen (png, max. 1920x800)', 'Captive mac' => 'MAC-Adresse', 'Captive menu' => 'Captive-Portal', 'Captive nr' => 'Nummer', @@ -29,6 +32,7 @@ 'Captive vout' => 'Ausgegebene Gutscheine', 'Captive title' => 'Titel der Anmeldeseite', 'Captive time' => 'Erlaubter Nutzungszeitraum nach aktivierung (Stunden)', +'Captive wrong ext' => 'Die hochgeladene Datei hat den falschen Dateityp', 'Captive voucher' => 'Gutschein', 'Captive voucherout' => 'Gutschein ausgeben', 'Captive vouchervalid' => 'Verbindungszeitraum', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 1d168fcee8..013885480a 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -19,8 +19,11 @@ 'Captive config' => 'Settings', 'Captive err doublevoucher' => 'A voucher with this code already exists', 'Captive expire' => 'Expire', +'Captive invalid logosize' => 'The uploaded file does not meet defined dimensions (min. 1280x400, max. 1920x800)', 'Captive invalid_voucher' => 'Invalid code. Please try again', 'Captive ip' => 'IP-Address', +'Captive logo_set' => 'Actual Logo', +'Captive logo_upload' => 'Upload logo (png, max. 1920x800)', 'Captive mac' => 'MAC-Address', 'Captive menu' => 'Captive Portal', 'Captive nr' => 'Number', @@ -29,6 +32,7 @@ 'Captive vout' => 'Issued vouchers', 'Captive title' => 'Title of logon site', 'Captive time' => 'Accesstime post activation (hours)', +'Captive wrong ext' => 'Uploaded file has wrong filetype', 'Captive voucher' => 'Voucher', 'Captive voucherout' => 'Ticket transfer', 'Captive vouchervalid' => 'Conenction timerange', -- 2.39.2
$Lang::tr{'hours'}$Lang::tr{'days'}$Lang::tr{'weeks'}$Lang::tr{'months'}