]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/squid-accounting/acct-lib.pl
core89: Create temporary files in update to avoid reboot
[ipfire-2.x.git] / src / squid-accounting / acct-lib.pl
old mode 100755 (executable)
new mode 100644 (file)
index 96456c9..7969a50
@@ -27,6 +27,7 @@ use PDF::API2;
 use utf8;
 use Encode;
 use File::Copy;
+use File::Temp qw/ tempfile tempdir /;
 
 ###############################################################################
 my $dbh;
@@ -336,7 +337,12 @@ sub getmonth{
                my $monat=$_[0]-1 if($_[0]);
                my $tag=1;
                my $time1=timelocal(0,0,0,$tag,$monat,$jahr);
-               my $time2=timelocal(0,0,0,$tag,($monat+1),$jahr);
+               my $time2=0;
+               if (($monat+1) == 12){
+                       $time2=timelocal(0,0,0,$tag,0,$jahr+1);
+               }else{
+                       $time2=timelocal(0,0,0,$tag,$monat+1,$jahr);
+               }
                --$time2;
                return ($time1,$time2);
 }
@@ -386,6 +392,7 @@ sub pdf2 {
        my @billar              = @{$_[0]}; #DATA from sendbill (just host/values)
        my $month               = $_[1];
        $month                  = '0'.$month if $month < 10;
+       $month                  = '12' if $month == 0;
        my $year                = $_[2];
        my $mwst                = $_[3];
        my @address_cust= @{$_[4]}; #Array which contains customer and hoster adresses and some additional info from billgroup
@@ -430,7 +437,7 @@ sub pdf2 {
 
        #Check if we are creating a preview or a real bill
        if($preview eq 'on'){
-               $filename="$path/tmp.pdf";
+               $filename="$path/".tempfile( SUFFIX => ".pdf", );
        }
        ####################################################################
        #Prepare DATA from arrays
@@ -459,7 +466,6 @@ sub pdf2 {
        $lines->linewidth('0.5');
 
        #Fill BILL DATA into PDF
-       setlocale(LC_ALL, "$mainsettings{'LANGUAGE'}_$uplang");
        foreach (@billar) {
                my ($a1,$a2) = split( /\,/, $_ );
                $a2=sprintf"%.2f",($a2/1024/1024);
@@ -791,6 +797,9 @@ sub pdf2 {
        if ($preview ne 'on'){
                &fillBill($path.$grp,$name,$no,$grp);
        }
+       if($preview eq 'on'){
+               return $filename;
+       }
        return '0';
 }