]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/captive.cgi
ddns: Import latest upstream patches for ddns-013
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / captive.cgi
index 242549d33f2eec4391b693a655de279434084777..8204eb7b3b87e7dc0e5079513564913eea876917 100755 (executable)
@@ -42,7 +42,7 @@ my %session_times = (
        86400           => $Lang::tr{'24 hours'},
        604800          => $Lang::tr{'one week'},
        1209600         => $Lang::tr{'two weeks'},
-       18144000        => $Lang::tr{'one month'},
+       2592000         => $Lang::tr{'one month'},
        31536000        => $Lang::tr{'one year'},
        0               => "- $Lang::tr{'unlimited'} -",
 );
@@ -104,7 +104,7 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
        $settings{'ENABLE_GREEN'}               = $cgiparams{'ENABLE_GREEN'};
        $settings{'ENABLE_BLUE'}                = $cgiparams{'ENABLE_BLUE'};
        $settings{'AUTH'}                               = $cgiparams{'AUTH'};
-       $settings{'TITLE'}                              = $cgiparams{'TITLE'};
+       $settings{'TITLE'}                      = &Header::escape($cgiparams{'TITLE'});
        $settings{'COLOR'}                      = $cgiparams{'COLOR'};
        $settings{'SESSION_TIME'}               = $cgiparams{'SESSION_TIME'};
 
@@ -142,6 +142,10 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
        }
 }
 
+if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive delete logo'}") {
+       unlink $logo;
+}
+
 if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive generate coupons'}") {
        #check valid remark
        if ($cgiparams{'REMARK'} ne '' && !&validremark($cgiparams{'REMARK'})){
@@ -237,7 +241,7 @@ if ($cgiparams{'ACTION'} eq 'delete-client') {
 }
 
 #open webpage, print header and open box
-&Header::openpage($Lang::tr{'Captive menu'}, 1, '');
+&Header::openpage($Lang::tr{'Captive'}, 1, '');
 &Header::openbigbox();
 
 # If an error message exists, show a box with the error message
@@ -381,7 +385,10 @@ if (-e $logo) {
        print <<END;
                <tr>
                        <td>$Lang::tr{'Captive logo uploaded'}</td>
-                       <td>$Lang::tr{'yes'}</td>
+                       <td>
+                               $Lang::tr{'yes'}&nbsp;
+                               <input type='submit' name='ACTION' value="$Lang::tr{'Captive delete logo'}"/>
+                       </td>
                </tr>
 END
 }
@@ -507,6 +514,25 @@ END
        }
 }
 
+sub cleanup_expired_coupons
+{
+       my $acttime=time();
+       &General::readhasharray($clients, \%clientshash) if (-e $clients);
+       foreach my $key (keys %clientshash) {
+
+               #calculate endtime from clientshash
+               my $endtime;
+               if ($clientshash{$key}[3] > '0'){
+                       $endtime = $clientshash{$key}[2]+$clientshash{$key}[3];
+                       if ($acttime > $endtime) {
+                               delete $clientshash{$key};
+                       }
+               }
+       }
+       #write back hash
+       &General::writehasharray("$clients", \%clientshash);
+}
+
 sub show_coupons() {
        &General::readhasharray($coupons, \%couponhash) if (-e $coupons);
 
@@ -594,9 +620,9 @@ sub show_clients() {
                                <th align='center' width='5%'>$Lang::tr{'delete'}</th>
                        </tr>
 END
-
+       &cleanup_expired_coupons();
        &General::readhasharray($clients, \%clientshash) if (-e $clients);
-       foreach my $key (keys %clientshash) {
+       foreach my $key (sort {$clientshash{$a}[2] <=> $clientshash{$b}[2]} keys %clientshash) {
                #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]));
 
@@ -757,7 +783,7 @@ sub generate_pdf() {
                        $f_subheadline->translate($cx, ($y + $h - $cy) / 2.4 + $cy);
 
                        if ($settings{'TITLE'}) {
-                               $f_headline->text_center($settings{'TITLE'});
+                               $f_headline->text_center(decode("utf8", $settings{'TITLE'}));
                                $f_subheadline->text_center(decode("utf8", $Lang::tr{'Captive WiFi coupon'}));
                        } else {
                                $f_headline->text_center(decode("utf8", $Lang::tr{'Captive WiFi coupon'}));