Squid-accounting: New Version using dma mailservice
authorAlexander Marx <alexander.marx@ipfire.org>
Thu, 27 Aug 2015 12:20:30 +0000 (14:20 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Aug 2015 11:42:53 +0000 (12:42 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
lfs/squid-accounting
src/squid-accounting/accounting.cgi
src/squid-accounting/acct.de.pl
src/squid-accounting/acct.en.pl
src/squid-accounting/acct.pl

index a2ffd90..aa2ca50 100644 (file)
@@ -9,15 +9,15 @@
 
 include Config
 
-VER        = 1.0.3
+VER        = 1.0.4
 
 THISAPP    = squid-accounting-$(VER)
 DIR_APP    = $(DIR_SRC)/$(THISAPP)
 TARGET     = $(DIR_INFO)/$(THISAPP)
 PROG       = squid-accounting
-PAK_VER    = 6
+PAK_VER    = 7
 
-DEPS       = "perl-DBI perl-DBD-SQLite perl-File-ReadBackwards perl-PDF-API2 sendEmail"
+DEPS       = "perl-DBI perl-DBD-SQLite perl-File-ReadBackwards perl-PDF-API2"
 
 ###############################################################################
 # 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
-               
-       
+
        install -v -m 755 $(DIR_APP)/squid-accounting/accounting.cgi /srv/web/ipfire/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/accounting/
@@ -61,10 +60,9 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
        install -v -m 755 $(DIR_APP)/squid-accounting/dbinstall.pl /var/ipfire/accounting/
        install -v -m 644 $(DIR_APP)/squid-accounting/config/backup/includes/squid-accounting  \
                        /var/ipfire/backup/addons/includes/squid-accounting
-                       
+
 #activate hourly logging of proxy logfile
        ln -sf /usr/local/bin/acct.pl /etc/fcron.hourly/squid-accounting
-               
        chown -R nobody.nobody /var/ipfire/accounting
        @rm -rf $(DIR_APP)
        @$(POSTBUILD)
index 1ec9849..1064763 100755 (executable)
@@ -56,12 +56,17 @@ my $count=0;
 my $col;
 my $proxlog=$Lang::tr{'stopped'};
 my $proxsrv=$Lang::tr{'stopped'};
+my $mailfile="${General::swroot}/dma/mail.conf";
 
 &Header::getcgihash(\%cgiparams);
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
 &General::readhash("$settingsfile", \%settings) if(-f $settingsfile);
 
+if ( -f $mailfile){
+       &General::readhash($mailfile, \%mail);
+}
+
 #Find out which lang is set (used later to set decimal separator correctly)
 my $uplang=uc($mainsettings{'LANGUAGE'});
 setlocale LC_NUMERIC,"$mainsettings{'LANGUAGE'}_$uplang";
@@ -136,11 +141,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveButton on configsite
        if ($cgiparams{'USEMAIL'} eq 'on'){
                $errormessage=&checkmailsettings;
        }elsif($cgiparams{'USEMAIL'} ne 'on'){
-               $cgiparams{'txt_mailserver'}='';
-               $cgiparams{'txt_mailport'}='';
-               $cgiparams{'txt_mailuser'}='';
-               $cgiparams{'txt_mailpass'}='';
-               $cgiparams{'mail_tls'}='';
                $cgiparams{'txt_mailsender'}='';
                $cgiparams{'txt_mailsubject'}='';
                $mailtxt='';
@@ -155,11 +155,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveButton on configsite
                $settings{'CURRENCY'}   = $cgiparams{'txt_currency'};
                $settings{'SKIPURLS'}   = $skipurls;
                $settings{'USEMAIL'}    = $cgiparams{'USEMAIL'};
-               $settings{'MAILSRV'}    = $cgiparams{'txt_mailserver'};
-               $settings{'MAILPORT'}   = $cgiparams{'txt_mailport'};
-               $settings{'MAILUSER'}   = $cgiparams{'txt_mailuser'};
-               $settings{'MAILPASS'}   = $cgiparams{'txt_mailpass'};
-               $settings{'TLS'}                = $cgiparams{'mail_tls'};
                $settings{'MAILSENDER'} = $cgiparams{'txt_mailsender'};
                $settings{'MAILSUB'}    = $cgiparams{'txt_mailsubject'};
                $settings{'MAILTXT'}    = $mailtxt;
@@ -568,10 +563,6 @@ sub configsite{
        #If update set fieldvalues new
        if($cgiparams{'update'} eq 'on'){
                $settings{'USEMAIL'} = 'on';
-               $settings{'MAILSRV'} = $cgiparams{'txt_mailserver'};
-               $settings{'MAILPORT'} = $cgiparams{'txt_mailport'};
-               $settings{'MAILUSER'} = $cgiparams{'txt_mailuser'};
-               $settings{'MAILPASS'} = $cgiparams{'txt_mailpass'};
                $settings{'MAILSUB'} = $cgiparams{'txt_mailsubject'};
                $settings{'MAILTXT'} = $cgiparams{'txt_mailtxt'};
        }
@@ -580,14 +571,13 @@ sub configsite{
        $checked{'logging'}{$settings{'LOG'}}                                   = 'CHECKED';
        $checked{'multiuser'}{$settings{'MULTIUSER'}}                   = 'CHECKED';
        $checked{'usemail'}{$settings{'USEMAIL'}}                               = 'CHECKED';
-       $checked{'mail_tls'}{$settings{'TLS'}}                                  = 'CHECKED';
-       
+
        #Open site
        &Header::openpage($Lang::tr{'acct settings'}, 1, '');
        &Header::openbigbox('100%', 'center');
        &error;
        &Header::openbox('100%', 'left', $Lang::tr{'acct config'});
-       
+
        #### JAVA SCRIPT ####
        print<<END;
 <script>
@@ -631,57 +621,45 @@ END
                <td>$Lang::tr{'acct multiuser'}</td>
                <td><input type='checkbox' name='multiuser' $checked{'multiuser'}{'on'}></td>
                <td></td>
-       <tr>
+       </tr>
        <tr>
                <td>$Lang::tr{'acct mwst'}</td>
                <td><input type='text' name='txt_mwst' value='$settings{'MWST'}' style='width:22em;'></td>
                <td></td>
+       </tr>
        <tr>
                <td>$Lang::tr{'acct currency'}</td>
                <td><input type='text' name='txt_currency' value='$settings{'CURRENCY'}' style='width:22em;'></td>
                <td></td>
-       
+       </tr>
        <tr>
                <td valign='top'>$Lang::tr{'acct skipurl'}</td>
                <td style='padding-left:0.2em;'><textarea name="txt_skipurls" cols="20" rows="6" style='width:22em;'>$settings{'SKIPURLS'}</textarea></td>
                <td></td>
        </tr>
+END
+
+if ($mail{'USEMAIL'} eq 'on'){
+       if (!$settings{'MAILSENDER'}){
+               $settings{'MAILSENDER'} = $mail{'SENDER'};
+       }
+print <<END;
        <tr>
                <td>$Lang::tr{'acct usemail'}</td>
                <td><label><input type='checkbox' name='USEMAIL' id='MAIL' $checked{'usemail'}{'on'}></label></td>
                <td></td>
        </tr>
-       </table><br>
+END
+}
 
+print <<END;
+       </table><br>
        <div class="MAILSRV">
                <table style='width:100%;'>
                <tr>
-                       <td style='width:24em'>$Lang::tr{'acct mailaddr'}</td>
-                       <td><input type='text' name='txt_mailserver' value='$settings{'MAILSRV'}' style='width:22em;'></td>
-               </tr>
-               <tr>
-                       <td>$Lang::tr{'acct mailport'}</td>
-                       <td><input type='text' name='txt_mailport' value='$settings{'MAILPORT'}' size='3'></td>
-               </tr>
-               <tr>
-                       <td>$Lang::tr{'acct mailuser'}<img src='/blob.gif' alt='*' /></td>
-                       <td><input type='text' name='txt_mailuser' value='$settings{'MAILUSER'}' style='width:22em;'></td>
-               </tr>
-               <tr>
-                       <td>$Lang::tr{'acct mailpass'}<img src='/blob.gif' alt='*' /></td>
-                       <td><input type='password' name='txt_mailpass' value='$settings{'MAILPASS'}' style='width:22em;' ></td>
-               </tr>
-               <tr>
-                       <td>$Lang::tr{'acct tls'}</td>
-                       <td><input type='checkbox' name='mail_tls' $checked{'mail_tls'}{'on'}></td>
-               </tr>
-               <tr>
-                       <td>$Lang::tr{'acct mailsender'}</td>
+                       <td style='width:24em'>$Lang::tr{'acct mailsender'}</td>
                        <td><input type='text' name='txt_mailsender' value='$settings{'MAILSENDER'}' style='width:22em;'></td>
                </tr>
-               <tr>
-                       <td colspan='2'>&nbsp;</td>
-               </tr>
                <tr>
                        <td>$Lang::tr{'acct subject'}</td>
                        <td><input type='text' name='txt_mailsubject' value='$settings{'MAILSUB'}' style='width:22em;'></td>
@@ -693,7 +671,6 @@ END
                </table>
        </div>
 
-
        <table style='width:100%;'>
        <tr>
                <td colspan='3' display:inline align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
@@ -1119,28 +1096,28 @@ print<<END;
                                <td>
                                        <input type='radio' name='rdo_companytype' value='CUST' $checked{'rdo_companytype'}{'CUST'}>$Lang::tr{'acct customer'} &nbsp;
                                        <input type='radio' name='rdo_companytype' value='HOST' $checked{'rdo_companytype'}{'HOST'}>$Lang::tr{'acct hoster'}</td>
-                               <td style='width:8em;'>$Lang::tr{'acct bank'}</td>
+                               <td style='width:8em;'>$Lang::tr{'acct bank'}<img src='/blob.gif' alt='*' /></td>
                                <td>
                                        <input type='text' name='txt_bank' value='$cgiparams{'txt_bank'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td>$Lang::tr{'acct company'}</td>
+                               <td>$Lang::tr{'acct company'}<img src='/blob.gif' alt='*' /></td>
                                <td>
                                        <input type='text' name='txt_company' value='$cgiparams{'txt_company'}' style='width:25em;'></td>
-                               <td>$Lang::tr{'acct iban'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct iban'}</td>
                                <td>
                                        <input type='text' name='txt_iban' value='$cgiparams{'txt_iban'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td>$Lang::tr{'acct name1'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct name1'}</td>
                                <td>
                                        <input type='text' name='txt_name1' value='$cgiparams{'txt_name1'}' style='width:25em;'></td>
-                               <td>$Lang::tr{'acct bic'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct bic'}</td>
                                <td>
                                        <input type='text' name='txt_bic' maxlength='8' value='$cgiparams{'txt_bic'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td>$Lang::tr{'acct str'}</td>
+                               <td>$Lang::tr{'acct str'}<img src='/blob.gif' alt='*' /></td>
                                <td align='left'>
                                        <input type='text' name='txt_str' value='$cgiparams{'txt_str'}' style='width:25em;'></td>
                                <td>$Lang::tr{'acct blz'}</td>
@@ -1148,7 +1125,7 @@ print<<END;
                                        <input type='text' name='txt_blz' maxlength='8' value='$cgiparams{'txt_blz'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td>$Lang::tr{'acct str_nr'}</td>
+                               <td>$Lang::tr{'acct str_nr'}<img src='/blob.gif' alt='*' /></td>
                                <td><input type='text' name='txt_str_nr' value='$cgiparams{'txt_str_nr'}' style='width:25em;'></td>
                                <td>$Lang::tr{'acct kto'}</td>
                                <td>
@@ -1157,16 +1134,16 @@ print<<END;
 
                        
                        <tr>
-                               <td>$Lang::tr{'acct plz'}</td>
+                               <td>$Lang::tr{'acct plz'}<img src='/blob.gif' alt='*' /></td>
                                <td>
                                        <input type='text' name='txt_plz' value='$cgiparams{'txt_plz'}' style='width:25em;'></td>
-                               <td>$Lang::tr{'acct email'}</td>
+                               <td>$Lang::tr{'acct email'}<img src='/blob.gif' alt='*' /></td>
                                <td><input type='text' name='txt_email' value='$cgiparams{'txt_email'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td>$Lang::tr{'acct city'}</td>
+                               <td>$Lang::tr{'acct city'}<img src='/blob.gif' alt='*' /></td>
                                <td><input type='text' name='txt_city' value='$cgiparams{'txt_city'}' style='width:25em;'></td>
-                               <td>$Lang::tr{'acct inet'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct inet'}</td>
                                <td>
                                        <input type='text' name='txt_inet' value='$cgiparams{'txt_inet'}' style='width:25em;'></td>
                        </tr>
@@ -1180,25 +1157,25 @@ print<<END;
                        <tr>
                                <td></td>
                                <td></td>
-                               <td>$Lang::tr{'acct ustid'}</td>
+                               <td>$Lang::tr{'acct ustid'}<img src='/blob.gif' alt='*' /></td>
                                <td><input type='text' name='txt_ustid' value='$cgiparams{'txt_ustid'}' style='width:25em;'></td>
                        </tr>
                        <tr>
                                <td></td>
                                <td></td>
-                               <td>$Lang::tr{'acct tel'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct tel'}</td>
                                <td>
                                        <input type='text' name='txt_tel' value='$cgiparams{'txt_tel'}' style='width:25em;'></td>
                        </tr>
                        <tr>
                                <td></td>
                                <td></td>
-                               <td>$Lang::tr{'acct fax'}<img src='/blob.gif' alt='*' /></td>
+                               <td>$Lang::tr{'acct fax'}</td>
                                <td>
                                        <input type='text' name='txt_fax' value='$cgiparams{'txt_fax'}' style='width:25em;'></td>
                        </tr>
                        <tr>
-                               <td colspan='6'><img src='/blob.gif' alt='*' /><font size="1">$Lang::tr{'acct optional'}</font></td>
+                               <td colspan='6'><img src='/blob.gif' alt='*' /><font size="1">$Lang::tr{'acct not optional'}</font></td>
                        </tr>
                        <tr>
 END
@@ -2175,18 +2152,6 @@ END
 }
 
 sub checkmailsettings{
-       #Check if mailserver is an ip address or a domain
-       if ($cgiparams{'txt_mailserver'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){
-               if (! &General::validip($cgiparams{'txt_mailserver'})){
-                       $errormessage.="$Lang::tr{'acct invalid mailip'} $cgiparams{'txt_mailserver'}<br>";
-               }
-       }elsif(! &General::validfqdn($cgiparams{'txt_mailserver'})){
-                       $errormessage.="$Lang::tr{'acct invalid mailfqdn'} $cgiparams{'txt_mailserver'}<br>";
-       }
-       #Check valid mailserverport
-       if($cgiparams{'txt_mailport'} < 1 || $cgiparams{'txt_mailport'} > 65535){
-               $errormessage.="$Lang::tr{'acct invalid mailport'} $cgiparams{'txt_mailport'}<br>";
-       }
        #Check valid sender
        if(! $cgiparams{'txt_mailsender'}){
                $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct mailsender'}<br>";
index 2110cf7..0291a9d 100644 (file)
@@ -88,9 +88,9 @@
 'acct mwst' => 'Mehrwertsteuer in %',
 'acct name1' => 'Name 1',
 'acct name2' => 'Name 2',
+'acct not optional' => 'Diese Felder sind Pflichtfelder',
 'acct nr' => 'RG-Nr.',
 'acct oldestdb' => 'Erster DB-Eintrag',
-'acct optional' => 'Diese Felder sind optional',
 'acct parameter' => 'Parameter',
 'acct path' => 'Pfad',
 'acct pdf billtxt' => 'Rechnung',
index 3e3ed19..913f2a7 100644 (file)
@@ -90,7 +90,7 @@
 'acct name2' => 'Name 2',
 'acct nr' => 'RG-No.',
 'acct oldestdb' => 'Fist DB Entry',
-'acct optional' => 'These fields are optional',
+'acct not optional' => 'These fields are required',
 'acct parameter' => 'Parameter',
 'acct path' => 'Path',
 'acct pdf billtxt' => 'Bill',
index 7222689..68eb63c 100755 (executable)
@@ -27,6 +27,8 @@
 use Time::Local;
 use File::ReadBackwards;
 use strict;
+use MIME::Lite;
+
 #use warnings;
 
 require '/var/ipfire/general-functions.pl';
@@ -62,6 +64,11 @@ my ($mini,$max)=&ACCT::getminmax;
 my $now = localtime;
 my $proxylog;
 my $proxysrv;
+my $dmafile="${General::swroot}/dma/dma.conf";
+my $authfile="${General::swroot}/dma/auth.conf";
+my $mailfile="${General::swroot}/dma/mail.conf";
+my %mail=();
+my %dma=();
 
 ########
 # Main #
@@ -69,6 +76,7 @@ my $proxysrv;
 
 &checkproxy;
 
+
 #If we have a disabled file and the proxy is off, we don't need to check anything, exit!
 if((! -f $proxyenabled || $proxylog eq $Lang::tr{'stopped'}) && -f "${General::swroot}/accounting/disabled"){
        &ACCT::logger($settings{'LOG'}," Proxy or proxylogging disabled - exiting with no data collection\n");
@@ -92,7 +100,7 @@ if (-f $proxyenabled && $proxylog eq $Lang::tr{'running'}){
        $dbh=&ACCT::connectdb;
        my $m=sprintf("%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 == '12' && ($mon+1) == '1'){
+       if ($m = ($mon+1) || $m == '12' && ($mon+1) == '1'){
                #Logrotate
                my $year1=$year+1900;
                system ("tar", "cfz", "/var/log/accounting-$m-$year1.tar.gz", "/var/log/accounting.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 them 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 bills via mail...\n");
                        my $res=&ACCT::getbillgroups;
                        foreach my $line (@$res){
                                my ($grp) = @$line;
+                               open (FILE, "<", $dmafile) or die $!;
+                               foreach my $line (<FILE>) {
+                                       $line =~ m/^([A-Z]+)\s+?(.*)?$/;
+                                       my $key = $1;
+                                       my $val = $2;
+                                       $dma{$key}=$val;
+                               }
                                &sendbill($grp,$settings{'MWST'},$settings{'CURRENCY'});
                        }
                }else{
@@ -214,7 +233,7 @@ sub sendbill {
        $month = '0'.$actmonth if $actmonth < 10;
        $month = '12' if $actmonth == 0;
        my $actyear  = $now[5];
-       my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);                                   #FIXME month and year as variables!
+       my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);
        my @billar = &ACCT::GetTaValues($from,$till,$rggrp);
        my $address_cust = &ACCT::getTaAddress($rggrp,'CUST');
        my $address_host = &ACCT::getTaAddress($rggrp,'HOST');
@@ -229,23 +248,34 @@ sub sendbill {
 
        if ($back eq '0'){
                &ACCT::logger($settings{'LOG'},"Bill for $company_cust successfully created.\n");
-               my $file="'/var/ipfire/accounting/bill/$rggrp/$month-$actyear-$no.pdf'";
+               my $file="/var/ipfire/accounting/bill/$rggrp/$month-$actyear-$no.pdf";
                $settings{'MAILTXT'} =~ tr/\|/\r\n/ ;
-               my $cmd = "/usr/local/bin/sendEmail ";
-               $cmd .= " -f $settings{'MAILSENDER'}";                                                  #Sender
-               $cmd .= " -t $email";                                                                                   #Recipient
-               if ($ccmail){
-                       $cmd .= " -cc $ccmail";
-               }
-               #Send Mail via TLS?
-               if ($settings{'TLS'} eq 'on'){
-                       $cmd .= " -o tls=yes";                                                                          #TLS
-               }
-               $cmd .= " -u '$settings{'MAILSUB'}'";                                                   #Subject
-               $cmd .= " -m '$settings{'MAILTXT'}'";                                                   #Mailtext
-               $cmd .= " -s $settings{'MAILSRV'}:$settings{'MAILPORT'}";               #Mailserver:port
-               $cmd .= " -a $file";
-               my $res=system ($cmd);
+
+               #extract filename from path
+               my ($filename) = $file =~ m{([^/]+)$};
+
+               my $msg = MIME::Lite->new(
+                       From    => $mail{'SENDER'},
+                       To              => $email,
+                       Cc              => $ccmail,
+                       Subject => $settings{'MAILSUB'},
+                       Type    => 'multipart/mixed'
+               );
+
+               $msg->attach(
+                       Type    => 'TEXT',
+                       Data    => $settings{'MAILTXT'}
+               );
+
+               $msg->attach(
+                       Type            => 'application/pdf',
+                       Path            => $file,
+                       Filename        => $filename,
+                       Disposition     => 'attachment'
+               );
+
+               my $res=$msg->send_by_sendmail;
+
                if ($res == 0){
                        &ACCT::logger($settings{'LOG'},"Bill for $company_cust successfully sent.\n");
                }elsif ($res > 0){
@@ -255,13 +285,19 @@ sub sendbill {
                
        }else{
                &ACCT::logger($settings{'LOG'},"ERROR Bill for $company_cust could not be created.\n");
-               my $cmd = "/usr/local/bin/sendEmail ";
-               $cmd .= " -f $settings{'MAILSENDER'}";
-               $cmd .= " -t $settings{'MAILSENDER'}";
-               $cmd .= " -u Fehler Squid Accounting";
-               $cmd .= " -m 'Die Rechnung konnte nicht erzeugt und per Mail versendet werden' $company_cust";
-               $cmd .= " -s $settings{'MAILSRV'}:$settings{'MAILPORT'}";
-               my $res=system ($cmd);
+               my $msg = MIME::Lite->new(
+                       From    => $mail{'SENDER'},
+                       To              => $mail{'RECIPIENT'},
+                       Subject => "ERROR Squid Accounting",
+                       Type    => 'multipart/mixed'
+               );
+
+               $msg->attach(
+                       Type    => 'TEXT',
+                       Data    => "The bill could not be created for customer $company_cust"
+               );
+
+               $msg->send_by_sendmail;
                return 0;
        }
 }