From: Alexander Marx Date: Wed, 6 Aug 2014 13:10:41 +0000 (+0200) Subject: squid-accounting: create billpreview file as temporary file X-Git-Tag: v2.15-core82~6^2~15^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a5f5ccfc4f49b825e17ae1334aa13512b1d41bc2;p=ipfire-2.x.git squid-accounting: create billpreview file as temporary file --- diff --git a/src/squid-accounting/accounting.cgi b/src/squid-accounting/accounting.cgi index a5a9376720..eabb0c2956 100755 --- a/src/squid-accounting/accounting.cgi +++ b/src/squid-accounting/accounting.cgi @@ -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, "; 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); } diff --git a/src/squid-accounting/acct-lib.pl b/src/squid-accounting/acct-lib.pl index 96456c9b0b..f0081b7ef9 100644 --- a/src/squid-accounting/acct-lib.pl +++ b/src/squid-accounting/acct-lib.pl @@ -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'; }