From mboxrd@z Thu Jan 1 00:00:00 1970 From: git@ipfire.org To: ipfire-scm@lists.ipfire.org Subject: [git.ipfire.org] IPFire 2.x development tree branch, next, updated. 0f14446a89c090cd985ee544b19fdfa0afe04dad Date: Fri, 28 Aug 2015 13:44:22 +0200 Message-ID: <20150828114423.10325223AA@argus.ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5083234584525292670==" List-Id: --===============5083234584525292670== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "IPFire 2.x development tree". The branch, next has been updated via 0f14446a89c090cd985ee544b19fdfa0afe04dad (commit) from afd6e1931defb60665b40438d8e54db6de46246f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0f14446a89c090cd985ee544b19fdfa0afe04dad Author: Alexander Marx Date: Thu Aug 27 14:20:30 2015 +0200 Squid-accounting: New Version using dma mailservice =20 Signed-off-by: Michael Tremer ----------------------------------------------------------------------- Summary of changes: lfs/squid-accounting | 12 ++-- src/squid-accounting/accounting.cgi | 109 ++++++++++++----------------------= -- src/squid-accounting/acct.de.pl | 2 +- src/squid-accounting/acct.en.pl | 2 +- src/squid-accounting/acct.pl | 88 ++++++++++++++++++++--------- 5 files changed, 106 insertions(+), 107 deletions(-) Difference in files: diff --git a/lfs/squid-accounting b/lfs/squid-accounting index a2ffd90..aa2ca50 100644 --- a/lfs/squid-accounting +++ b/lfs/squid-accounting @@ -9,15 +9,15 @@ =20 include Config =20 -VER =3D 1.0.3 +VER =3D 1.0.4 =20 THISAPP =3D squid-accounting-$(VER) DIR_APP =3D $(DIR_SRC)/$(THISAPP) TARGET =3D $(DIR_INFO)/$(THISAPP) PROG =3D squid-accounting -PAK_VER =3D 6 +PAK_VER =3D 7 =20 -DEPS =3D "perl-DBI perl-DBD-SQLite perl-File-ReadBackwards perl-PDF-AP= I2 sendEmail" +DEPS =3D "perl-DBI perl-DBD-SQLite perl-File-ReadBackwards perl-PDF-AP= I2" =20 ############################################################################= ### # Top-level Rules @@ -50,8 +50,7 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) chmod 777 /var/log/accounting.log #Set permissions for logo and graphs chmod -R 777 /srv/web/ipfire/html/accounting - =09 -=09 + install -v -m 755 $(DIR_APP)/squid-accounting/accounting.cgi /srv/web/ipfir= e/cgi-bin/ install -v -m 755 $(DIR_APP)/squid-accounting/acct.pl /usr/local/bin/ install -v -m 644 $(DIR_APP)/squid-accounting/acct-lib.pl /var/ipfire/accou= nting/ @@ -61,10 +60,9 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) install -v -m 755 $(DIR_APP)/squid-accounting/dbinstall.pl /var/ipfire/acco= unting/ install -v -m 644 $(DIR_APP)/squid-accounting/config/backup/includes/squid-= accounting \ /var/ipfire/backup/addons/includes/squid-accounting - =09 + #activate hourly logging of proxy logfile ln -sf /usr/local/bin/acct.pl /etc/fcron.hourly/squid-accounting - =09 chown -R nobody.nobody /var/ipfire/accounting @rm -rf $(DIR_APP) @$(POSTBUILD) diff --git a/src/squid-accounting/accounting.cgi b/src/squid-accounting/accou= nting.cgi index 1ec9849..1064763 100755 --- a/src/squid-accounting/accounting.cgi +++ b/src/squid-accounting/accounting.cgi @@ -56,12 +56,17 @@ my $count=3D0; my $col; my $proxlog=3D$Lang::tr{'stopped'}; my $proxsrv=3D$Lang::tr{'stopped'}; +my $mailfile=3D"${General::swroot}/dma/mail.conf"; =20 &Header::getcgihash(\%cgiparams); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/i= nclude/colors.txt", \%color); &General::readhash("$settingsfile", \%settings) if(-f $settingsfile); =20 +if ( -f $mailfile){ + &General::readhash($mailfile, \%mail); +} + #Find out which lang is set (used later to set decimal separator correctly) my $uplang=3Duc($mainsettings{'LANGUAGE'}); setlocale LC_NUMERIC,"$mainsettings{'LANGUAGE'}_$uplang"; @@ -136,11 +141,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveB= utton on configsite if ($cgiparams{'USEMAIL'} eq 'on'){ $errormessage=3D&checkmailsettings; }elsif($cgiparams{'USEMAIL'} ne 'on'){ - $cgiparams{'txt_mailserver'}=3D''; - $cgiparams{'txt_mailport'}=3D''; - $cgiparams{'txt_mailuser'}=3D''; - $cgiparams{'txt_mailpass'}=3D''; - $cgiparams{'mail_tls'}=3D''; $cgiparams{'txt_mailsender'}=3D''; $cgiparams{'txt_mailsubject'}=3D''; $mailtxt=3D''; @@ -155,11 +155,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveB= utton on configsite $settings{'CURRENCY'} =3D $cgiparams{'txt_currency'}; $settings{'SKIPURLS'} =3D $skipurls; $settings{'USEMAIL'} =3D $cgiparams{'USEMAIL'}; - $settings{'MAILSRV'} =3D $cgiparams{'txt_mailserver'}; - $settings{'MAILPORT'} =3D $cgiparams{'txt_mailport'}; - $settings{'MAILUSER'} =3D $cgiparams{'txt_mailuser'}; - $settings{'MAILPASS'} =3D $cgiparams{'txt_mailpass'}; - $settings{'TLS'} =3D $cgiparams{'mail_tls'}; $settings{'MAILSENDER'} =3D $cgiparams{'txt_mailsender'}; $settings{'MAILSUB'} =3D $cgiparams{'txt_mailsubject'}; $settings{'MAILTXT'} =3D $mailtxt; @@ -568,10 +563,6 @@ sub configsite{ #If update set fieldvalues new if($cgiparams{'update'} eq 'on'){ $settings{'USEMAIL'} =3D 'on'; - $settings{'MAILSRV'} =3D $cgiparams{'txt_mailserver'}; - $settings{'MAILPORT'} =3D $cgiparams{'txt_mailport'}; - $settings{'MAILUSER'} =3D $cgiparams{'txt_mailuser'}; - $settings{'MAILPASS'} =3D $cgiparams{'txt_mailpass'}; $settings{'MAILSUB'} =3D $cgiparams{'txt_mailsubject'}; $settings{'MAILTXT'} =3D $cgiparams{'txt_mailtxt'}; } @@ -580,14 +571,13 @@ sub configsite{ $checked{'logging'}{$settings{'LOG'}} =3D 'CHECKED'; $checked{'multiuser'}{$settings{'MULTIUSER'}} =3D 'CHECKED'; $checked{'usemail'}{$settings{'USEMAIL'}} =3D 'CHECKED'; - $checked{'mail_tls'}{$settings{'TLS'}} =3D 'CHECKED'; -=09 + #Open site &Header::openpage($Lang::tr{'acct settings'}, 1, ''); &Header::openbigbox('100%', 'center'); &error; &Header::openbox('100%', 'left', $Lang::tr{'acct config'}); -=09 + #### JAVA SCRIPT #### print< @@ -631,58 +621,46 @@ END $Lang::tr{'acct multiuser'} - + $Lang::tr{'acct mwst'} + $Lang::tr{'acct currency'} -=09 + $Lang::tr{'acct skipurl'} +END + +if ($mail{'USEMAIL'} eq 'on'){ + if (!$settings{'MAILSENDER'}){ + $settings{'MAILSENDER'} =3D $mail{'SENDER'}; + } +print < $Lang::tr{'acct usemail'} -
+END +} =20 +print <
- - - - - - - - - - - - - - - - - - - - - + - - - @@ -693,7 +671,6 @@ END
$Lang::tr{'acct mailaddr'}
$Lang::tr{'acct mailport'}
$Lang::tr{'acct mailuser'}3D'*'
$Lang::tr{'acct mailpass'}3D'*'
$Lang::tr{'acct tls'}
$Lang::tr{'acct mailsender'}$Lang::tr{'acct mailsender'}
 
$Lang::tr{'acct subject'}
=20 - @@ -1119,28 +1096,28 @@ print< $Lang::tr{'acct customer'}   $Lang::tr{'acct hoster'} - + - + - + - + - + - + @@ -1148,7 +1125,7 @@ print< - + + - + - + - + @@ -1180,25 +1157,25 @@ print< - + - + - + - + END @@ -2175,18 +2152,6 @@ END } =20 sub checkmailsettings{ - #Check if mailserver is an ip address or a domain - if ($cgiparams{'txt_mailserver'} =3D~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){ - if (! &General::validip($cgiparams{'txt_mailserver'})){ - $errormessage.=3D"$Lang::tr{'acct invalid mailip'} $cgiparams{'txt_mailse= rver'}
"; - } - }elsif(! &General::validfqdn($cgiparams{'txt_mailserver'})){ - $errormessage.=3D"$Lang::tr{'acct invalid mailfqdn'} $cgiparams{'txt_mail= server'}
"; - } - #Check valid mailserverport - if($cgiparams{'txt_mailport'} < 1 || $cgiparams{'txt_mailport'} > 65535){ - $errormessage.=3D"$Lang::tr{'acct invalid mailport'} $cgiparams{'txt_mailp= ort'}
"; - } #Check valid sender if(! $cgiparams{'txt_mailsender'}){ $errormessage.=3D"$Lang::tr{'acct empty field'} $Lang::tr{'acct mailsender= '}
"; diff --git a/src/squid-accounting/acct.de.pl b/src/squid-accounting/acct.de.pl index 2110cf7..0291a9d 100644 --- a/src/squid-accounting/acct.de.pl +++ b/src/squid-accounting/acct.de.pl @@ -88,9 +88,9 @@ 'acct mwst' =3D> 'Mehrwertsteuer in %', 'acct name1' =3D> 'Name 1', 'acct name2' =3D> 'Name 2', +'acct not optional' =3D> 'Diese Felder sind Pflichtfelder', 'acct nr' =3D> 'RG-Nr.', 'acct oldestdb' =3D> 'Erster DB-Eintrag', -'acct optional' =3D> 'Diese Felder sind optional', 'acct parameter' =3D> 'Parameter', 'acct path' =3D> 'Pfad', 'acct pdf billtxt' =3D> 'Rechnung', diff --git a/src/squid-accounting/acct.en.pl b/src/squid-accounting/acct.en.pl index 3e3ed19..913f2a7 100644 --- a/src/squid-accounting/acct.en.pl +++ b/src/squid-accounting/acct.en.pl @@ -90,7 +90,7 @@ 'acct name2' =3D> 'Name 2', 'acct nr' =3D> 'RG-No.', 'acct oldestdb' =3D> 'Fist DB Entry', -'acct optional' =3D> 'These fields are optional', +'acct not optional' =3D> 'These fields are required', 'acct parameter' =3D> 'Parameter', 'acct path' =3D> 'Path', 'acct pdf billtxt' =3D> 'Bill', diff --git a/src/squid-accounting/acct.pl b/src/squid-accounting/acct.pl index 7222689..68eb63c 100755 --- a/src/squid-accounting/acct.pl +++ b/src/squid-accounting/acct.pl @@ -27,6 +27,8 @@ use Time::Local; use File::ReadBackwards; use strict; +use MIME::Lite; + #use warnings; =20 require '/var/ipfire/general-functions.pl'; @@ -62,6 +64,11 @@ my ($mini,$max)=3D&ACCT::getminmax; my $now =3D localtime; my $proxylog; my $proxysrv; +my $dmafile=3D"${General::swroot}/dma/dma.conf"; +my $authfile=3D"${General::swroot}/dma/auth.conf"; +my $mailfile=3D"${General::swroot}/dma/mail.conf"; +my %mail=3D(); +my %dma=3D(); =20 ######## # Main # @@ -69,6 +76,7 @@ my $proxysrv; =20 &checkproxy; =20 + #If we have a disabled file and the proxy is off, we don't need to check any= thing, exit! if((! -f $proxyenabled || $proxylog eq $Lang::tr{'stopped'}) && -f "${Genera= l::swroot}/accounting/disabled"){ &ACCT::logger($settings{'LOG'}," Proxy or proxylogging disabled - exiting w= ith no data collection\n"); @@ -92,7 +100,7 @@ if (-f $proxyenabled && $proxylog eq $Lang::tr{'running'}){ $dbh=3D&ACCT::connectdb; my $m=3Dsprintf("%d",(localtime((time-3600)))[4]+1); &ACCT::logger($settings{'LOG'},"month before one hour $m, now is ".($mon+1)= ."\n"); - if ($m < ($mon+1) || $m =3D=3D '12' && ($mon+1) =3D=3D '1'){ + if ($m =3D ($mon+1) || $m =3D=3D '12' && ($mon+1) =3D=3D '1'){ #Logrotate my $year1=3D$year+1900; system ("tar", "cfz", "/var/log/accounting-$m-$year1.tar.gz", "/var/log/ac= counting.log"); @@ -103,11 +111,22 @@ if (-f $proxyenabled && $proxylog eq $Lang::tr{'running= '}){ #move all db entries older than this month to second table and cumulate th= em daily &ACCT::movedbdata; &ACCT::logger($settings{'LOG'},"New Month. Old trafficvalues moved to ACCT= _HIST Table\n"); - if ($settings{'USEMAIL'} eq 'on'){ + #check if mail is enabled + if ( -f $mailfile){ + &General::readhash($mailfile, \%mail); + } + if ($mail{'USEMAIL'} eq 'on'){ &ACCT::logger($settings{'LOG'},"Mailserver is activated - Now sending bil= ls via mail...\n"); my $res=3D&ACCT::getbillgroups; foreach my $line (@$res){ my ($grp) =3D @$line; + open (FILE, "<", $dmafile) or die $!; + foreach my $line () { + $line =3D~ m/^([A-Z]+)\s+?(.*)?$/; + my $key =3D $1; + my $val =3D $2; + $dma{$key}=3D$val; + } &sendbill($grp,$settings{'MWST'},$settings{'CURRENCY'}); } }else{ @@ -214,7 +233,7 @@ sub sendbill { $month =3D '0'.$actmonth if $actmonth < 10; $month =3D '12' if $actmonth =3D=3D 0; my $actyear =3D $now[5]; - my ($from,$till)=3D&ACCT::getmonth($actmonth,$actyear); #FIXME month an= d year as variables! + my ($from,$till)=3D&ACCT::getmonth($actmonth,$actyear); my @billar =3D &ACCT::GetTaValues($from,$till,$rggrp); my $address_cust =3D &ACCT::getTaAddress($rggrp,'CUST'); my $address_host =3D &ACCT::getTaAddress($rggrp,'HOST'); @@ -229,23 +248,34 @@ sub sendbill { =20 if ($back eq '0'){ &ACCT::logger($settings{'LOG'},"Bill for $company_cust successfully create= d.\n"); - my $file=3D"'/var/ipfire/accounting/bill/$rggrp/$month-$actyear-$no.pdf'"; + my $file=3D"/var/ipfire/accounting/bill/$rggrp/$month-$actyear-$no.pdf"; $settings{'MAILTXT'} =3D~ tr/\|/\r\n/ ; - my $cmd =3D "/usr/local/bin/sendEmail "; - $cmd .=3D " -f $settings{'MAILSENDER'}"; #Sender - $cmd .=3D " -t $email"; #Recipient - if ($ccmail){ - $cmd .=3D " -cc $ccmail"; - } - #Send Mail via TLS? - if ($settings{'TLS'} eq 'on'){ - $cmd .=3D " -o tls=3Dyes"; #TLS - } - $cmd .=3D " -u '$settings{'MAILSUB'}'"; #Subject - $cmd .=3D " -m '$settings{'MAILTXT'}'"; #Mailtext - $cmd .=3D " -s $settings{'MAILSRV'}:$settings{'MAILPORT'}"; #Mailserver:p= ort - $cmd .=3D " -a $file"; - my $res=3Dsystem ($cmd); + + #extract filename from path + my ($filename) =3D $file =3D~ m{([^/]+)$}; + + my $msg =3D MIME::Lite->new( + From =3D> $mail{'SENDER'}, + To =3D> $email, + Cc =3D> $ccmail, + Subject =3D> $settings{'MAILSUB'}, + Type =3D> 'multipart/mixed' + ); + + $msg->attach( + Type =3D> 'TEXT', + Data =3D> $settings{'MAILTXT'} + ); + + $msg->attach( + Type =3D> 'application/pdf', + Path =3D> $file, + Filename =3D> $filename, + Disposition =3D> 'attachment' + ); + + my $res=3D$msg->send_by_sendmail; + if ($res =3D=3D 0){ &ACCT::logger($settings{'LOG'},"Bill for $company_cust successfully sent.= \n"); }elsif ($res > 0){ @@ -255,13 +285,19 @@ sub sendbill { =09 }else{ &ACCT::logger($settings{'LOG'},"ERROR Bill for $company_cust could not be = created.\n"); - my $cmd =3D "/usr/local/bin/sendEmail "; - $cmd .=3D " -f $settings{'MAILSENDER'}"; - $cmd .=3D " -t $settings{'MAILSENDER'}"; - $cmd .=3D " -u Fehler Squid Accounting"; - $cmd .=3D " -m 'Die Rechnung konnte nicht erzeugt und per Mail versendet w= erden' $company_cust"; - $cmd .=3D " -s $settings{'MAILSRV'}:$settings{'MAILPORT'}"; - my $res=3Dsystem ($cmd); + my $msg =3D MIME::Lite->new( + From =3D> $mail{'SENDER'}, + To =3D> $mail{'RECIPIENT'}, + Subject =3D> "ERROR Squid Accounting", + Type =3D> 'multipart/mixed' + ); + + $msg->attach( + Type =3D> 'TEXT', + Data =3D> "The bill could not be created for customer $company_cust" + ); + + $msg->send_by_sendmail; return 0; } } hooks/post-receive -- IPFire 2.x development tree --===============5083234584525292670==--
$Lang::tr{'acct bank'}$Lang::tr{'acct bank'}
$Lang::tr{'acct company'}$Lang::tr{'acct company'}3D'*' $Lang::tr{'acct iban'}3D'*'$Lang::tr{'acct iban'}
$Lang::tr{'acct name1'}3D'*'$Lang::tr{'acct name1'} $Lang::tr{'acct bic'}3D'*'$Lang::tr{'acct bic'}
$Lang::tr{'acct str'}$Lang::tr{'acct str'}3D'*' $Lang::tr{'acct blz'}
$Lang::tr{'acct str_nr'}$Lang::tr{'acct str_nr'}3D'*' $Lang::tr{'acct kto'} @@ -1157,16 +1134,16 @@ print< - $Lang::tr{'acct plz'}$Lang::tr{'acct plz'}3D'*' $Lang::tr{'acct email'}$Lang::tr{'acct email'}3D'*'
$Lang::tr{'acct city'}$Lang::tr{'acct city'}3D'*' $Lang::tr{'acct inet'}3D'*'$Lang::tr{'acct inet'}
$Lang::tr{'acct ustid'}$Lang::tr{'acct ustid'}3D'*'
$Lang::tr{'acct tel'}3D'*'$Lang::tr{'acct tel'}
$Lang::tr{'acct fax'}3D'*'$Lang::tr{'acct fax'}
3D'*'$L= ang::tr{'acct optional'}3D'*'$L= ang::tr{'acct not optional'}