]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/commitdiff
Captive-Portal: Add logo upload feature
authorAlexander Marx <alexander.marx@ipfire.org>
Wed, 10 Feb 2016 09:20:52 +0000 (10:20 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Sep 2017 17:54:45 +0000 (18:54 +0100)
Signed-off-by: Alexander Marx <alexander.marx@ipfire.org>
html/cgi-bin/captive.cgi
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl

index a42e398154882d7ce15d2e6a242462480ed4a3ac..c4373b57c6cb6b37c34387aee272a927e052708b 100755 (executable)
 #                                                                             #
 ###############################################################################
 
-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=<PNG>;
+                       close(PNG);
+                       my ($width,$height)=&pngsize($PNG1);
+                       if($width > 1920 || $height > 800 || $width < 1280 || $height < 4000){
+                               $errormessage.="$Lang::tr{'Captive invalid logosize'} <br>Filedimensions width: $width   height: $height<br>";
+                               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 <<END
-               <form method='post' action='$ENV{'SCRIPT_NAME'}'>\n
+               <form method='post' action='$ENV{'SCRIPT_NAME'}' enctype="multipart/form-data">\n
                <table width='100%' border="0">
                <tr>
 END
@@ -259,6 +295,16 @@ END
 
        &agbbox();
 
+       #Logo Upload
+       print "<tr><td>$Lang::tr{'Captive logo_upload'}</td><td><INPUT TYPE='file' NAME='uploaded_file' SIZE=30 MAXLENGTH=80></td></tr><tr>";
+       #Show Logo in webinterface with 1/2 size if set
+       if (-f "$logopath/logo.png"){
+               print"<td>$Lang::tr{'Captive logo_set'}</td>";
+               print"<td><img src='/captive/logo/logo.png' alt='$logopath/logo.png' width='25%' height='25%' /></td></tr>";
+       }else{
+               print"<td>$Lang::tr{'Captive logo_set'}</td>";
+               print"<td><br>$Lang::tr{'no'}</td></tr>";
+       }
        print"<tr><td>$Lang::tr{'Captive vouchervalid'}</td><td>";
        print "<br><table border='0' with=100%>";
        print "<th>$Lang::tr{'hours'}</th><th>$Lang::tr{'days'}</th><th>$Lang::tr{'weeks'}</th><th>$Lang::tr{'months'}</th>";
@@ -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) {
index 4c8a809c8c22f4d6ff91f9b22dbe1ca974223438..d05d26fe6c67e8a0d899156db5984266d89c2772 100644 (file)
 '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',
index 1d168fcee84436e03242696143793381e8b3838b..013885480a161283051a8a62052cdbeed4570b84 100644 (file)
 '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',