]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/commitdiff
squid-accounting: create billpreview file as temporary file
authorAlexander Marx <alexander.marx@ipfire.org>
Wed, 6 Aug 2014 13:10:41 +0000 (15:10 +0200)
committerAlexander Marx <alexander.marx@ipfire.org>
Wed, 6 Aug 2014 13:10:41 +0000 (15:10 +0200)
src/squid-accounting/accounting.cgi
src/squid-accounting/acct-lib.pl

index a5a93767201ce50ad099ded24ea95432a5e45d1b..eabb0c2956641bcb17676797f7ab9658fe2883c0 100755 (executable)
@@ -92,15 +92,16 @@ if ($cgiparams{'BILLACTION'} eq "open_preview"){
        my $actyear  = $now[5];
        my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);
        my @billar = &ACCT::GetTaValues($from,$till,$rggrp);
-       &ACCT::pdf2(\@billar,$actmonth,$actyear,$mwst,$address_cust,$address_host,$billpos,$rggrp,$cur,"on");
+       my $tempfile=&ACCT::pdf2(\@billar,$actmonth,$actyear,$mwst,$address_cust,$address_host,$billpos,$rggrp,$cur,"on");
        #Show PDF preview
-       open(DLFILE, "</var/ipfire/accounting/bill/tmp.pdf") or die "Unable to open tmp.pdf: $!";
+       open(DLFILE, "<$tempfile") or die "Unable to open tmp.pdf: $!";
        my @fileholder = <DLFILE>;
        print "Content-Type:application/pdf\n";
-       my @fileinfo = stat("/var/ipfire/accounting/bill/tmp.pdf");
+       my @fileinfo = stat($tempfile);
        print "Content-Length:$fileinfo[7]\n";
        print "Content-Disposition:attachment;filename='tmp.pdf';\n\n";
        print @fileholder;
+       unlink ($tempfile);
        exit (0);
 }
 
index 96456c9b0bf9c11626eacac5594bfe846f882c38..f0081b7ef9551049e8ef027dc63e879a6aa496a8 100644 (file)
@@ -27,6 +27,7 @@ use PDF::API2;
 use utf8;
 use Encode;
 use File::Copy;
+use File::Temp qw/ tempfile tempdir /;
 
 ###############################################################################
 my $dbh;
@@ -430,7 +431,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
@@ -791,6 +792,9 @@ sub pdf2 {
        if ($preview ne 'on'){
                &fillBill($path.$grp,$name,$no,$grp);
        }
+       if($preview eq 'on'){
+               return $filename;
+       }
        return '0';
 }