pakfire: use correct tree on x86_64.
[ipfire-2.x.git] / src / squid-accounting / accounting.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 #                                                                             #
4 # IPFire.org - A linux based firewall                                         #
5 # Copyright (C) 2014  IPFire Team  <alexander.marx@ipfire.org>                #
6 #                                                                             #
7 # This program is free software: you can redistribute it and/or modify        #
8 # it under the terms of the GNU General Public License as published by        #
9 # the Free Software Foundation, either version 3 of the License, or           #
10 # (at your option) any later version.                                         #
11 #                                                                             #
12 # This program is distributed in the hope that it will be useful,             #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
15 # GNU General Public License for more details.                                #
16 #                                                                             #
17 # You should have received a copy of the GNU General Public License           #
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
19 #                                                                             #
20 ###############################################################################
21
22
23 use Time::Local;
24 use File::Find;
25 use File::Path;
26 use GD::Graph::area;
27 use GD::Graph::bars;
28 use LWP::UserAgent;
29 use POSIX;
30 use locale;
31
32 # enable only the following on debugging purpose
33 #use warnings;
34 #use CGI::Carp 'fatalsToBrowser';
35
36 require '/var/ipfire/general-functions.pl';
37 require "${General::swroot}/lang.pl";
38 require "${General::swroot}/header.pl";
39 require "${General::swroot}/accounting/acct-lib.pl";
40
41 unless (-e "${General::swroot}/accounting/settings.conf")       { system("touch ${General::swroot}/accounting/settings.conf"); }
42
43 my $settingsfile="${General::swroot}/accounting/settings.conf";
44 my $proxyenabled="${General::swroot}/proxy/enable";
45 my $logopath="/srv/web/ipfire/html/accounting/logo";
46 my %settings=();
47 my %mainsettings;
48 my %color;
49 my %cgiparams=();
50 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)=localtime();
51 my $dbh;
52 my %checked=();
53 my $errormessage='';
54 my @ips;
55 my $count=0;
56 my $col;
57 my $proxlog=$Lang::tr{'stopped'};
58 my $proxsrv=$Lang::tr{'stopped'};
59 my $mailfile="${General::swroot}/dma/mail.conf";
60
61 &Header::getcgihash(\%cgiparams);
62 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
63 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
64 &General::readhash("$settingsfile", \%settings) if(-f $settingsfile);
65
66 if ( -f $mailfile){
67         &General::readhash($mailfile, \%mail);
68 }
69
70 #Find out which lang is set (used later to set decimal separator correctly)
71 my $uplang=uc($mainsettings{'LANGUAGE'});
72 setlocale LC_NUMERIC,"$mainsettings{'LANGUAGE'}_$uplang";
73
74 if ($cgiparams{'BILLVIEW'} eq "show"){
75         my $file=$cgiparams{'file'};
76         my $name=$cgiparams{'name'};
77         open(DLFILE, "<$file") or die "Unable to open $file: $!";
78         my @fileholder = <DLFILE>;
79         print "Content-Type:application/pdf\n";
80         my @fileinfo = stat("$file");
81         print "Content-Length:$fileinfo[7]\n";
82         print "Content-Disposition:attachment;filename='$name';\n\n";
83         print @fileholder;
84         exit (0);
85 }
86 if ($cgiparams{'BILLACTION'} eq "open_preview"){ 
87         #Generate preview Bill
88         my $rggrp=$cgiparams{'txt_billgroup'};
89         my $address_cust = &ACCT::getTaAddress($rggrp,'CUST');
90         my $address_host = &ACCT::getTaAddress($rggrp,'HOST');
91         my $billpos             = &ACCT::getextrabillpos($rggrp);
92         my $mwst=$settings{'MWST'};
93         my $cur = $settings{'CURRENCY'};
94         my @now = localtime(time);
95         $now[5] = $now[5] + 1900;
96         my $actmonth = $now[4]+1;
97         my $actyear  = $now[5];
98         my ($from,$till)=&ACCT::getmonth($actmonth,$actyear);
99         my @billar = &ACCT::GetTaValues($from,$till,$rggrp);
100         my $tempfile=&ACCT::pdf2(\@billar,$actmonth,$actyear,$mwst,$address_cust,$address_host,$billpos,$rggrp,$cur,"on");
101         #Show PDF preview
102         open(DLFILE, "<$tempfile") or die "Unable to open tmp.pdf: $!";
103         my @fileholder = <DLFILE>;
104         print "Content-Type:application/pdf\n";
105         my @fileinfo = stat($tempfile);
106         print "Content-Length:$fileinfo[7]\n";
107         print "Content-Disposition:attachment;filename='tmp.pdf';\n\n";
108         print @fileholder;
109         unlink ($tempfile);
110         exit (0);
111 }
112
113 &Header::showhttpheaders();
114
115 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct config'}"){ #ConfigButton from Menu
116         &configsite;
117 }
118 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct addresses'}"){ #AddressmgmntButton from Menu
119         &addressmgmnt;
120 }
121 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct billgroup'}"){ #BillgroupButton from Menu
122         &billgroupsite;
123 }
124 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct maintenance'}"){ #MaintenanceButton from Menu
125         &expertsite;
126 }
127 if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ #SaveButton on configsite
128         my @val=split('\r\n',$cgiparams{'txt_skipurls'});
129         my $skipurls;
130         foreach my $line (@val){
131                 $skipurls.="|".$line;
132         }
133         $skipurls=$skipurls."|";
134         $skipurls=~ s/\|\|/\|/g;
135         my @txt=split('\r\n',$cgiparams{'txt_mailtxt'});
136         my $mailtxt;
137         foreach my $txt (@txt){
138                 $mailtxt.="|".$txt;
139         }
140         #Check fields
141         if ($cgiparams{'USEMAIL'} eq 'on'){
142                 $errormessage=&checkmailsettings;
143         }elsif($cgiparams{'USEMAIL'} ne 'on'){
144                 $cgiparams{'txt_mailsender'}='';
145                 $cgiparams{'txt_mailsubject'}='';
146                 $mailtxt='';
147         }
148         if(!$errormessage){
149                 open (TXT, ">$settingsfile") or die("Die Datei konnte nicht geöffnet werden: $!\n");
150                 close TXT;
151                 $settings{'LOG'}                = $cgiparams{'logging'};
152                 $settings{'EXPERT'}             = $cgiparams{'expert'};
153                 $settings{'MULTIUSER'}  = $cgiparams{'multiuser'};
154                 $settings{'MWST'}               = $cgiparams{'txt_mwst'};
155                 $settings{'CURRENCY'}   = $cgiparams{'txt_currency'};
156                 $settings{'SKIPURLS'}   = $skipurls;
157                 $settings{'USEMAIL'}    = $cgiparams{'USEMAIL'};
158                 $settings{'MAILSENDER'} = $cgiparams{'txt_mailsender'};
159                 $settings{'MAILSUB'}    = $cgiparams{'txt_mailsubject'};
160                 $settings{'MAILTXT'}    = $mailtxt;
161                 &General::writehash("$settingsfile", \%settings);
162         }else{
163                 $cgiparams{'update'}='on';
164                 &configsite;
165         }
166 }
167 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct view'}"){ #If special month and year is given on mainsite
168         &mainsite($cgiparams{'month'},$cgiparams{'year'});
169         exit 0;
170 }
171 if ($cgiparams{'ACTION'} eq "$Lang::tr{'acct commit'}"){ #Maintenance function 
172         &ACCT::logger($settings{'LOG'},"Clear DB (all data) committed).\n");
173         &ACCT::cleardbtraf;
174         &expertsite;
175 }
176 if ($cgiparams{'ACTION2'} eq "$Lang::tr{'acct commit'}"){ #Maintenance function 
177         &ACCT::logger($settings{'LOG'},"Clear DB (only traffic data) committed).\n");
178         &ACCT::cleardb;
179         &expertsite;
180 }
181 if ($cgiparams{'ACTION1'} eq "$Lang::tr{'acct commit'}"){ #Maintenance Function
182         #Get Timestamp
183         my ($a,$b)=&ACCT::getmonth($cgiparams{'expmonth'},$cgiparams{'expyear'});
184         &ACCT::delbefore(($a-1));
185         &expertsite;
186 }
187 if ($cgiparams{'ACTION'} eq "viewgraph"){ #Graph icon on hosttable (viewhosttable)
188         &graphsite($cgiparams{'month'},$cgiparams{'year'},$cgiparams{'host'});
189 }
190 if ($cgiparams{'ACTION1'} eq "$Lang::tr{'save'}"){ #SaveButton when adding Address
191         $errormessage=&checkaddress;
192         
193         if ($errormessage){
194                 &addressmgmnt($errormessage);
195         }else{
196                 &ACCT::writeaddr(
197                                         $cgiparams{'txt_company'},
198                                         $cgiparams{'rdo_companytype'},
199                                         $cgiparams{'txt_name1'},
200                                         $cgiparams{'txt_str'},
201                                         $cgiparams{'txt_str_nr'},
202                                         $cgiparams{'txt_plz'},
203                                         $cgiparams{'txt_city'},
204                                         $cgiparams{'txt_bank'},
205                                         $cgiparams{'txt_iban'},
206                                         $cgiparams{'txt_bic'},
207                                         $cgiparams{'txt_blz'},
208                                         $cgiparams{'txt_kto'},
209                                         $cgiparams{'txt_email'},
210                                         $cgiparams{'txt_inet'},
211                                         $cgiparams{'txt_hrb'},
212                                         $cgiparams{'txt_ustid'},
213                                         $cgiparams{'txt_tel'},
214                                         $cgiparams{'txt_fax'},
215                                         );
216                 &ACCT::logger($settings{'LOG'},"Created new address $cgiparams{'txt_company'} as $cgiparams{'rdo_companytype'}.\n");
217                 %cgiparams=();
218         }
219         &addressmgmnt;
220 }
221 if ($cgiparams{'ACTION'} eq "edit_addr"){ #Pencil icon in Address overwiev on Addressmgmnt site
222         $cgiparams{'update'} = 'on';
223         $cgiparams{'oldcompname'}=$cgiparams{'txt_company'};
224         &addressmgmnt;
225 }
226 if ($cgiparams{'ACTION'} eq "$Lang::tr{'update'}"){ #UpdateButton when editing Address
227         $cgiparams{'update'} = 'on';
228         $errormessage=&checkaddress;
229         if ($errormessage){
230                 &addressmgmnt($errormessage);
231         }else{
232                 &ACCT::updateaddr(
233                                         $cgiparams{'rdo_companytype'},
234                                         $cgiparams{'txt_company'},
235                                         $cgiparams{'txt_name1'},
236                                         $cgiparams{'txt_str'},
237                                         $cgiparams{'txt_str_nr'},
238                                         $cgiparams{'txt_plz'},
239                                         $cgiparams{'txt_city'},
240                                         $cgiparams{'txt_bank'},
241                                         $cgiparams{'txt_iban'},
242                                         $cgiparams{'txt_bic'},
243                                         $cgiparams{'txt_blz'},
244                                         $cgiparams{'txt_kto'},
245                                         $cgiparams{'txt_email'},
246                                         $cgiparams{'txt_inet'},
247                                         $cgiparams{'txt_hrb'},
248                                         $cgiparams{'txt_ustid'},
249                                         $cgiparams{'txt_tel'},
250                                         $cgiparams{'txt_fax'},
251                                         $cgiparams{'oldcompname'}
252                                         );
253                 my $res=&ACCT::getbillgroups;
254                 foreach my $line (@$res){
255                         my($name,$host,$cust)=@$line;
256                         if($host eq $cgiparams{'oldcompname'}){
257                                 &ACCT::updatebillgrouphost($cgiparams{'oldcompname'},$cgiparams{'txt_company'});
258                         }elsif ($cust eq $cgiparams{'oldcompname'}){
259                                 &ACCT::updatebillgroupcust($cgiparams{'oldcompname'},$cgiparams{'txt_company'});
260                         }
261                 }
262                 
263                 &ACCT::logger($settings{'LOG'},"Edited address $cgiparams{'oldcompname'}.\n");
264                 %cgiparams=();
265         }
266         &addressmgmnt;
267 }
268 if ($cgiparams{'ACTION'} eq "del_addr"){ #Trash icon in Address overview on Addressmgmnt site
269         my $res=&ACCT::checkbillgrp;
270         foreach my $line (@$res){
271                 my ($grp,$host,$cust) = @$line;
272                 if ($cgiparams{'txt_company'} eq $host){
273                         $errormessage="$Lang::tr{'acct err hostdel'} $grp";
274                 }
275                 if ($cgiparams{'txt_company'} eq $cust){
276                         $errormessage="$Lang::tr{'acct err custdel'} $grp";
277                 }
278         }
279         if (! $errormessage){
280                 &ACCT::deladdr($cgiparams{'txt_company'});
281                 &ACCT::logger($settings{'LOG'},"Deleted address $cgiparams{'txt_company'}.\n");
282         }
283         $cgiparams{'txt_company'}='';
284         &addressmgmnt;
285 }
286 if ($cgiparams{'BILLACTION'} eq "$Lang::tr{'save'}"){ #SaveButton when adding BillingGroups
287         #check if a group with the same name already exists in DB
288         my $res=&ACCT::getbillgroups;
289         foreach my $row (@$res) {
290                 my ($group)=@$row;
291                 if ($group eq $cgiparams{'txt_billgroup'}){
292                         $errormessage.=$Lang::tr{'acct billgroupexists'};
293                 }
294         }
295         #Check if a selected user is in another group already
296         if ($settings{'MULTIUSER'} ne 'on'){
297                 #split hosts into array
298                 my @user=split(/\|/,$cgiparams{'sel_hosts'});
299                 my $res=&ACCT::checkusergrp;
300                 foreach my $val (@$res){
301                         my ($grp,$usr)=@$val;
302                         foreach my $wanted (@user){
303                                 if($usr eq $wanted){
304                                         $errormessage.="$usr $Lang::tr{'acct usermulti'} $grp<br>";
305                                 }
306                         }
307                 }
308         }
309         #validate namefield
310         if(!&validtextfield($cgiparams{'txt_billgroup'})){
311                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'name'}<br>";
312         }
313         #FIXME: Validate CENT amount (num with .)
314         #if used colon, replace with .
315         $cgiparams{'txt_cent'} =~ tr/,/./;
316         if(!&validnumfield($cgiparams{'txt_cent'})){
317                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct cent'}<br>";
318         }
319         #fill array
320         my @ips=split (/\|/,$cgiparams{'sel_hosts'});
321
322         #Check if we use extra bill positions
323         if($cgiparams{'txt_amount'} || $cgiparams{'txt_name'}|| $cgiparams{'txt_price'}){
324                 if (!$cgiparams{'txt_amount'} || !$cgiparams{'txt_name'} || !$cgiparams{'txt_price'}){
325                         $errormessage.="$Lang::tr{'acct invalid billpos'}<br>";
326                 }
327                 #check all fields
328                 if (!$errormessage){
329                         if(! &validnumfield($cgiparams{'txt_amount'})){
330                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct amount'}<br>";
331                         }elsif(! &validtextfield($cgiparams{'txt_name'})){
332                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct name'}<br>";
333                         }elsif(! &validnumfield($cgiparams{'txt_price'})){
334                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct price pp'}<br>";
335                         }
336                 }
337         }
338
339         if ($errormessage){
340                 &billgroupsite($errormessage);
341         }else{
342                 #check if we use extra positions
343                 if ($cgiparams{'txt_amount'}){
344                         &ACCT::savebillpos(
345                                                 $cgiparams{'txt_posbillgroup'},
346                                                 $cgiparams{'txt_amount'},
347                                                 $cgiparams{'txt_name'},
348                                                 $cgiparams{'txt_price'});
349                         &ACCT::logger($settings{'LOG'},"Saved new fixed billposition $cgiparams{'txt_name'} into billgroup $cgiparams{'txt_posbillgroup'} .\n");
350                 }
351                 
352                 #save new group
353                 &ACCT::savebillgroup(
354                                         $cgiparams{'txt_billgroup'},
355                                         $cgiparams{'txt_billtext1'},
356                                         $cgiparams{'dd_host'},
357                                         $cgiparams{'dd_cust'},
358                                         $cgiparams{'txt_cent'},
359                                         \@ips);
360                 &ACCT::logger($settings{'LOG'},"Saved new billgroup $cgiparams{'txt_billgroup'}.\n");
361                 %cgiparams=();
362         }
363         &billgroupsite;
364 }
365 if ($cgiparams{'BILLACTION'} eq "$Lang::tr{'update'}"){ #UpdateButton when editing BillingGroups
366
367
368         my $filename=$cgiparams{'uploaded_file'};
369         if($filename){
370                 #First check if logo dir exists
371                 if (! -d "$logopath/$cgiparams{'logo_grp'}"){
372                         mkpath("$logopath/$cgiparams{'logo_grp'}",0,01777);
373                 }
374                 #Save File
375                 my ($filehandle) = CGI::upload('uploaded_file');
376                 open (UPLOADFILE, ">$logopath/$cgiparams{'logo_grp'}/logo.png");
377                 binmode $filehandle;
378                 while ( <$filehandle> ) {
379                         print UPLOADFILE;
380                 }
381                 close (UPLOADFILE);
382
383                 #Check dimensions of uploaded file
384                 open (PNG , "<$logopath/$cgiparams{'logo_grp'}/logo.png") ;
385                 local $/;
386                 my $PNG1=<PNG> ;
387                 close(PNG) ;
388                 my ($width,$height)=&ACCT::pngsize($PNG1) ;
389
390                 if (! &validnumfield($width)){
391                         $errormessage.="$Lang::tr{'acct invalid png'}<br>";
392                         unlink("$logopath/$cgiparams{'logo_grp'}/logo.png");
393                 }elsif($width > 400 || $height > 150){
394                         $errormessage.="$Lang::tr{'acct invalid pngsize'} width: $width   height: $height<br>";
395                         unlink("$logopath/$cgiparams{'logo_grp'}/logo.png");
396                 }
397
398         }
399         #Check if a group with the same name already exists in DB
400         my $res=&ACCT::getbillgroups;
401         foreach my $row (@$res) {
402                 my ($group)=@$row;
403                 if (($group eq $cgiparams{'txt_billgroup'}) && ($cgiparams{'oldname'} ne $cgiparams{'txt_billgroup'})){
404                         $errormessage.=$Lang::tr{'acct billgroupexists'};
405                 }
406         }
407         #Check if a selected user is in another group already
408         if ($settings{'MULTIUSER'} ne 'on'){
409                 #split hosts into array
410                 my @user=split(/\|/,$cgiparams{'sel_hosts'});
411                 my $res=&ACCT::checkusergrp;
412                 foreach my $val (@$res){
413                         my ($grp,$usr)=@$val;
414                         foreach my $wanted (@user){
415                                 if($usr eq $wanted && $grp ne $cgiparams{'txt_billgroup'}){
416                                         $errormessage.="$usr $Lang::tr{'acct usermulti'} $grp<br>";
417                                 }
418                         }
419                 }
420         }
421         #Validate namefield
422         if(!&validtextfield($cgiparams{'txt_billgroup'})){
423                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'name'}";
424         }
425         #Validate CENT amount (num with .)
426         #if used colon, replace with .
427         $cgiparams{'txt_cent'} =~ tr/,/./;
428         if(!&validnumfield($cgiparams{'txt_cent'})){
429                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct cent'}<br>";
430         }
431
432         #Fill array
433         my @ips=split ( /\|/,$cgiparams{'sel_hosts'});
434
435         #Check if we use extra bill positions
436         if($cgiparams{'txt_amount'} || $cgiparams{'txt_name'}|| $cgiparams{'txt_price'}){
437                 if (!$cgiparams{'txt_amount'} || !$cgiparams{'txt_name'} || !$cgiparams{'txt_price'}){
438                         $errormessage.="$Lang::tr{'acct invalid billpos'}<br>";
439                 }
440                 #Check all fields
441                 if (!$errormessage){
442                         if(! &validnumfield($cgiparams{'txt_amount'})){
443                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct amount'}<br>";
444                         }elsif(! &validtextfield($cgiparams{'txt_name'})){
445                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct name'}<br>";
446                         }elsif(! &validnumfield($cgiparams{'txt_price'})){
447                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct price pp'}<br>";
448                         }
449                 }
450         }
451         #Check if we added some CC mail recipients
452         if($cgiparams{'txt_ccmail'}){
453                 $cgiparams{'txt_ccmail'}=~ s/ //g;
454                 #Split line into single addresses and check each one
455                 my @ccaddr = split(",",$cgiparams{'txt_ccmail'});
456                 foreach my $cc (@ccaddr){
457                         if (! &General::validemail($cc)){
458                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct ccmail'} $cc<br>";
459                         }
460                 }
461         }
462         if ($errormessage){
463                 $cgiparams{'update'} = 'on';
464                 &billgroupsite();
465         }else{
466                 #update fixedbillpositions if defined
467                 if ($cgiparams{'oldname'} ne $cgiparams{'txt_billgroup'}){
468                         &ACCT::updatebillpos($cgiparams{'oldname'},$cgiparams{'txt_billgroup'});
469                 }
470                 #Check if we use extra positions
471                 if ($cgiparams{'txt_amount'}){
472                         &ACCT::savebillpos(
473                                                 $cgiparams{'txt_billgroup'},
474                                                 $cgiparams{'txt_amount'},
475                                                 $cgiparams{'txt_name'},
476                                                 $cgiparams{'txt_price'});
477                 }
478                 #Check if we have NEW cc Mails
479                 if($cgiparams{'txt_ccmail'} ne $cgiparams{'oldccmail'}){
480                         &ACCT::updateccaddr($cgiparams{'txt_ccmail'},$cgiparams{'dd_cust'});
481                 }
482                 &ACCT::deletebillgroup($cgiparams{'oldname'}); 
483                 &ACCT::savebillgroup(
484                                         $cgiparams{'txt_billgroup'},
485                                         $cgiparams{'txt_billtext1'},
486                                         $cgiparams{'dd_host'},
487                                         $cgiparams{'dd_cust'},
488                                         $cgiparams{'txt_cent'},
489                                         \@ips);
490                 %cgiparams=();
491         }
492         &billgroupsite;
493 }
494 if ($cgiparams{'BILLACTION'} eq "edit_billgroup"){ #Pencil icon in Billgroup table
495         $cgiparams{'update'} = 'on';
496         &billgroupsite;
497 }
498 if ($cgiparams{'BILLACTION'} eq "delete_billgroup"){ #Trash icon in Billgroup table
499         &deletefiles($cgiparams{'txt_billgroup'});
500         &ACCT::delbillpos($cgiparams{'txt_billgroup'});
501         &ACCT::deletebillgroup($cgiparams{'txt_billgroup'});
502         &ACCT::logger($settings{'LOG'},"Deleted billgroup $cgiparams{'txt_billgroup'}.\n");
503         &billgroupsite;
504 }
505 if ($cgiparams{'BILLACTION'} eq "open_billgroup"){ #Folder icon on billgrouptable (viewtablebillgroup)
506         &billoverview($cgiparams{'txt_billgroup'});
507 }
508 if ($cgiparams{'BILLPOS'} eq "delpos"){ #Trash icon in Billpos table
509         $cgiparams{'update'} = 'on';
510         &ACCT::delbillpos_single($cgiparams{'txt_billpos'},$cgiparams{'txt_billgroup'});
511         &ACCT::logger($settings{'LOG'},"Deleted fixed billposition  $cgiparams{'txt_billpos'} from billgroup $cgiparams{'txt_billgroup'}.\n");
512         &billgroupsite;
513 }
514 if ($cgiparams{'BILLPOS'} eq "$Lang::tr{'save'}"){ #Savebutton in Billpos table
515         $cgiparams{'update'}='on';
516         #Check if we use extra bill positions
517         if($cgiparams{'txt_amount'} || $cgiparams{'txt_name'}|| $cgiparams{'txt_price'}){
518                 if (!$cgiparams{'txt_amount'} || !$cgiparams{'txt_name'} || !$cgiparams{'txt_price'}){
519                         $errormessage.="$Lang::tr{'acct invalid billpos'}<br>";
520                 }
521                 #check all fields
522                 if (!$errormessage){
523                         #if used colon, replace with .
524                         $cgiparams{'txt_price'} =~ tr/,/./;
525                         if(! &validnumfield($cgiparams{'txt_amount'})){
526                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct amount'}<br>";
527                         }elsif(! &validtextfield($cgiparams{'txt_name'})){
528                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct name'}<br>";
529                         }elsif(! &validnumfield($cgiparams{'txt_price'})){
530                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct price pp'}<br>";
531                         }
532                 }
533         }
534         if ($errormessage){
535                 &billgroupsite($errormessage);
536         }else{
537                 #check if we use extra positions
538                 if ($cgiparams{'txt_amount'}){
539                         &ACCT::savebillpos(
540                                                 $cgiparams{'txt_billgroup'},
541                                                 $cgiparams{'txt_amount'},
542                                                 $cgiparams{'txt_name'},
543                                                 $cgiparams{'txt_price'});
544                 }
545                 &ACCT::logger($settings{'LOG'},"Added fixed billposition  $cgiparams{'txt_amount'} $cgiparams{'txt_name'} with price $cgiparams{'txt_price'} to billgroup $cgiparams{'txt_billgroup'}.\n");
546         }
547         %cgiparams=();
548         &billgroupsite;
549 }
550
551
552 #Check if we already have settings
553 if ( -z $settingsfile){
554         &configsite;
555 }else{
556         &mainsite(($mon+1),($year+1900));
557         exit 0;
558 }
559
560 sub configsite{
561         my $proxymessage='';
562         my $blockactivation='';
563         #If update set fieldvalues new
564         if($cgiparams{'update'} eq 'on'){
565                 $settings{'USEMAIL'} = 'on';
566                 $settings{'MAILSUB'} = $cgiparams{'txt_mailsubject'};
567                 $settings{'MAILTXT'} = $cgiparams{'txt_mailtxt'};
568         }
569         #find preselections
570         $checked{'expert'}{$settings{'EXPERT'}}                                 = 'CHECKED';
571         $checked{'logging'}{$settings{'LOG'}}                                   = 'CHECKED';
572         $checked{'multiuser'}{$settings{'MULTIUSER'}}                   = 'CHECKED';
573         $checked{'usemail'}{$settings{'USEMAIL'}}                               = 'CHECKED';
574
575         #Open site
576         &Header::openpage($Lang::tr{'acct settings'}, 1, '');
577         &Header::openbigbox('100%', 'center');
578         &error;
579         &Header::openbox('100%', 'left', $Lang::tr{'acct config'});
580
581         #### JAVA SCRIPT ####
582         print<<END;
583 <script>
584         \$(document).ready(function() {
585                 // Show/Hide elements when NAT checkbox is checked.
586                 if (\$("#MAIL").attr("checked")) {
587                         
588                 } else {
589                         \$(".MAILSRV").hide();
590                 }
591
592                 // Show NAT area when "use nat" checkbox is clicked
593                 \$("#MAIL").change(function() {
594                         \$(".MAILSRV").toggle();
595                         
596                 });
597         });
598 </script>
599 END
600 ####################### 
601         $settings{'SKIPURLS'} =~ tr/|/\r\n/;
602         $settings{'MAILTXT'} =~ tr/|/\r\n/;
603         my $col="style='background-color:$color{'color22'}'";
604         print<<END;
605         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
606         <table style='width:100%'>
607         <tr>
608                 <th colspan='3'></th>
609         </tr>
610         <tr>
611                 <td style='width:24em'>$Lang::tr{'acct logging'}</td>
612                 <td><input type='checkbox' name='logging' $checked{'logging'}{'on'}></td>
613                 <td></td>
614         </tr>
615         <tr>
616                 <td>$Lang::tr{'acct expert'}</td>
617                 <td><input type='checkbox' name='expert' $checked{'expert'}{'on'}></td>
618                 <td></td>
619         </tr>
620         <tr>
621                 <td>$Lang::tr{'acct multiuser'}</td>
622                 <td><input type='checkbox' name='multiuser' $checked{'multiuser'}{'on'}></td>
623                 <td></td>
624         </tr>
625         <tr>
626                 <td>$Lang::tr{'acct mwst'}</td>
627                 <td><input type='text' name='txt_mwst' value='$settings{'MWST'}' style='width:22em;'></td>
628                 <td></td>
629         </tr>
630         <tr>
631                 <td>$Lang::tr{'acct currency'}</td>
632                 <td><input type='text' name='txt_currency' value='$settings{'CURRENCY'}' style='width:22em;'></td>
633                 <td></td>
634         </tr>
635         <tr>
636                 <td valign='top'>$Lang::tr{'acct skipurl'}</td>
637                 <td style='padding-left:0.2em;'><textarea name="txt_skipurls" cols="20" rows="6" style='width:22em;'>$settings{'SKIPURLS'}</textarea></td>
638                 <td></td>
639         </tr>
640 END
641
642 if ($mail{'USEMAIL'} eq 'on'){
643         if (!$settings{'MAILSENDER'}){
644                 $settings{'MAILSENDER'} = $mail{'SENDER'};
645         }
646 print <<END;
647         <tr>
648                 <td>$Lang::tr{'acct usemail'}</td>
649                 <td><label><input type='checkbox' name='USEMAIL' id='MAIL' $checked{'usemail'}{'on'}></label></td>
650                 <td></td>
651         </tr>
652 END
653 }
654
655 print <<END;
656         </table><br>
657         <div class="MAILSRV">
658                 <table style='width:100%;'>
659                 <tr>
660                         <td style='width:24em'>$Lang::tr{'acct mailsender'}</td>
661                         <td><input type='text' name='txt_mailsender' value='$settings{'MAILSENDER'}' style='width:22em;'></td>
662                 </tr>
663                 <tr>
664                         <td>$Lang::tr{'acct subject'}</td>
665                         <td><input type='text' name='txt_mailsubject' value='$settings{'MAILSUB'}' style='width:22em;'></td>
666                 </tr>
667                 <tr>
668                 <td valign='top' >$Lang::tr{'acct mailtxt'}</td>
669                 <td style='padding-left:0.2em;'><textarea name="txt_mailtxt" cols="34" rows="6" style='width: 22em;'>$settings{'MAILTXT'}</textarea></td>
670                 
671                 </table>
672         </div>
673
674         <table style='width:100%;'>
675         <tr>
676                 <td colspan='3' display:inline align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
677         </tr>
678         </table>
679         <br>
680         </form>
681 END
682 &Header::closebox();
683 #BackButton
684         print<<END;
685         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
686         <table style='width:100%;'>
687         <tr>
688                 <td></td>
689                 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
690         </tr>
691         </table>
692         </form>
693 END
694         &Header::closebigbox();
695         &Header::closepage();
696         exit 0;
697 }
698
699 sub deletefiles{
700         my $grp=shift;
701         rmtree ("$logopath/$grp");
702         rmtree ("${General::swroot}/accounting/bill/$grp");
703 }
704
705 sub mainsite{
706         my $mon=$_[0];
707         my $year=$_[1];
708         if ($_[0]){$mon=$_[0];}
709         &Header::openpage($Lang::tr{'acct title'}, 1, '');
710         &Header::openbigbox('100%', 'center');
711         &checkproxy;
712         &statusbox;
713         &menu;
714         &viewtablehosts(($mon),$year);
715         &Header::closebigbox();
716         &Header::closepage();
717 }
718
719 sub expertsite{
720         &Header::openpage($Lang::tr{'acct maintenance'}, 1, '');
721         &Header::openbigbox('100%', 'center');
722
723         #Get size of Databasefile
724         my $sizedb= -s "/var/ipfire/accounting/acct.db";
725         $sizedb = sprintf"%.2f", $sizedb/(1024*1024);
726         #Get size of Directory, where all bills are stored
727         my $sizerrd = 0;
728         find(sub { $sizerrd += -s if -f $_ }, "${General::swroot}/accounting/bill");
729         $sizerrd = sprintf"%.2f", $sizerrd/(1024*1024);
730
731         &ACCT::connectdb;
732         #Get latest and earliest entry of DB
733         my  ($min,$max) = &ACCT::getminmax;
734         $min=&getdate($min);
735         $max=&getdate($max);
736         #Print status table
737         &Header::openbox('100%', 'left', $Lang::tr{'acct status'});
738         print<<END;
739         <table style='width:100%;' cellspacong='0' class='tbl'>
740         <tr>
741                 <th align='left' width='30%'>$Lang::tr{'name'}</th>
742                 <th align='left'>$Lang::tr{'acct value'}</th>
743         </tr>
744         <tr>
745                 <td>$Lang::tr{'acct dbsize'}</td>
746                 <td>$sizedb MB</td>
747         </tr>
748         <tr>
749                 <td>$Lang::tr{'acct rrdsize'}</td>
750                 <td>$sizerrd MB</td>
751         </tr>
752         <tr>
753                 <td>$Lang::tr{'acct oldestdb'}</td>
754                 <td>$min</td>
755         </tr>
756         <tr>
757                 <td>$Lang::tr{'acct latestdb'}</td>
758                 <td>$max</td>
759         </tr>
760         </table>
761         <br>
762 END
763         &Header::closebox();
764         #print Database maintenance table
765         &Header::openbox('100%', 'left', $Lang::tr{'acct dbmaintenance'});
766         print<<END;
767         <br>
768         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
769         <table style='width:100%;' cellspacing='0' class='tbl'>
770         <tr>
771                 <th>$Lang::tr{'acct task'}</th>
772                 <th>$Lang::tr{'acct parameter'}</th>
773                 <th>$Lang::tr{'acct action'}</th>
774         </tr>
775         <tr>
776                 <td>$Lang::tr{'acct emptydb'}</td>
777                 <td></td>
778                 <td><input type='submit' name='ACTION2' value='$Lang::tr{'acct commit'}' style='width:10em'></td>
779         </tr>
780         <tr>
781                 <td>$Lang::tr{'acct emptydbtraf'}</td>
782                 <td></td>
783                 <td><input type='submit' name='ACTION' value='$Lang::tr{'acct commit'}' style='width:10em'></td>
784         </tr>
785         <tr>
786                 <td>$Lang::tr{'acct delbefore'} (ACCT,ACCT_HIST)</td>
787                 <td><select name='expmonth'>
788 END
789         for(my $i=1;$i<13;$i++){
790                 print"<option>$i</option>";
791         }
792         print"</select><select name='expyear'>";
793         for(my $i=2014;$i<=($year+1900);$i++){
794                 print"<option>$i</option>";
795         }
796         print<<END;
797                 </select></td>
798                 <td><input type='submit' name='ACTION1' value='$Lang::tr{'acct commit'}' style='width:10em'></td>
799         </tr>
800         </table>
801         </form>
802 END
803         &Header::closebox();
804 #BackButton
805         print<<END;
806         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
807         <table style='width:100%;'>
808         <tr>
809                 <td></td>
810                 <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
811         </tr>
812         </table>
813         </form>
814 END
815
816
817         &Header::closebigbox();
818         &Header::closepage();
819         &ACCT::closedb;
820         exit 0;
821 }
822
823 sub getdate{
824         #GET  : Timestamp in seconds since 1.1.1970
825         #GIVES: Date in Format dd.mm.yyyy HH:MM:SS 
826         my $val = $_[0];
827         my $y=sprintf("%02d",(localtime($val))[5]-100);
828         my $Y=sprintf("%04d",(localtime($val))[5]+1900);
829         my $m=sprintf("%02d",(localtime($val))[4]+1);
830         my $d=sprintf("%02d",(localtime($val))[3]);
831         my $H=sprintf("%02d",(localtime($val))[2]);
832         my $M=sprintf("%02d",(localtime($val))[1]);
833         my $S=sprintf("%02d",(localtime($val))[0]);
834         
835         return "$d.$m.$Y $H:$M:$S";
836 }
837
838 sub menu{
839         &Header::openbox('100%', 'left', $Lang::tr{'menu'});
840         print<<END;
841         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
842         <table style='width: 100%;'>
843         <tr>
844                 <td style='display:inline;'>
845                         <input type='submit' name='ACTION' value='$Lang::tr{'acct config'}'>
846                         <input type='submit' name='ACTION' value='$Lang::tr{'acct addresses'}'>
847                         <input type='submit' name='ACTION' value='$Lang::tr{'acct billgroup'}'>
848 END
849         if ($settings{'EXPERT'} eq 'on'){
850                 print "<input type='submit' name='ACTION' value='$Lang::tr{'acct maintenance'}'>";
851         }
852         print<<END;
853                 </td>
854         </tr>
855         </table>
856         </form>
857 END
858         &Header::closebox();
859 }
860
861 sub graphsite{
862         my $grmon=$_[0];
863         my $gryear=$_[1];
864         my $grhost=$_[2];
865
866         &Header::openpage("$Lang::tr{'acct host detail'} $grhost", 1, '');
867         &Header::openbigbox('100%', 'center');
868         &Header::openbox('100%', 'left', );
869
870         &generatemonthgraph($grmon,$gryear,$grhost);
871
872         &Header::closebox();
873         &Header::closebigbox();
874         &Header::closepage();
875         exit 0;
876 }
877
878 sub generatemonthgraph{
879         my $grmon=$_[0];
880         my $gryear=$_[1];
881         my $grhost=$_[2];
882         my ($from,$till) = &ACCT::getmonth($grmon,$gryear);
883         my @values=();
884         my $sth;
885         my $cnt=0;
886         #If we want to show Data from within last 2 months, get DATA from ACCT
887         if ( $grmon == ($mon)+1 && $gryear == ($year+1900)){
888                 $sth=&ACCT::getmonthgraphdata("ACCT",$from,$till,$grhost);
889         }else{
890                 #If we want to show data from a date older than last two months, use ACCT_HIST
891                 $sth=&ACCT::getmonthgraphdata("ACCT_HIST",$from,$till,$grhost);
892         }
893         foreach( @$sth ) {
894                 $cnt++;
895                 foreach my $i (0..$#$_) {
896                                 push (@{$values[$i]},($_->[$i]));
897                 }
898         }
899
900         for my $graph (GD::Graph::area->new(600,200))
901         {
902                 my $name = $cgiparams{'host'};
903                 $graph->set(
904                         bgclr => 'white',
905                         fgclr => 'black',
906                         boxclr => '#eeeeee',
907                         accentclr => 'dblue',
908                         valuesclr => '#ffff77',
909                         labelclr => 'black',
910                         axislabelcl =>'black',
911                         legendclr =>'black',
912                         valuesclr =>'black',
913                         textclr =>'black',
914                         dclrs => [qw(lgreen lred)],
915                         x_label => $Lang::tr{'date'},
916                         y_label => $Lang::tr{'acct mb'},
917                         title => $name,
918                         y_long_ticks => 1,
919                         #x_label_skip => 3, #skip every 3 x-axis title 
920                         x_label_position => 0,
921                         transparent => 0,
922                 );
923
924                 $graph->set_legend("$Lang::tr{'acct traffic'}");
925                 $graph->set(x_labels_vertical => 1, values_vertical => 1);
926                 my $gd=$graph->plot(\@values);
927                 open(IMG, '>/srv/web/ipfire/html/accounting/tmpgraph.png') or die $!;
928                 binmode IMG;
929                 print IMG $gd->png;
930         }
931         #Show Box with monthly graph for this host
932         &Header::openbox('100%', 'left', $Lang::tr{'acct traffic monthly'});
933         print "<center><img src='/accounting/tmpgraph.png' alt='$grhost'></center>";
934         print "<b>$cgiparams{'traffic'}</b>";
935         &Header::closebox();
936         print<<END;
937         <table style='width:100%;'>
938                 <tr>
939                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
940                         <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
941                         </form>
942                 </tr>
943         </table>
944 END
945 }
946
947 sub generatehourgraph{
948         my $grmon=$_[0];
949         my $gryear=$_[1];
950         my $grhost=$_[2];
951         my ($from,$till) = &ACCT::getmonth($grmon,$gryear);
952         my @values=();
953         my $sth;
954         my $cnt=0;
955         #If we want to show Data from within last 2 months, get DATA from ACCT
956         if ( ! $grmon < ($mon+1) && $gryear == ($year+1900)){
957                 $sth=&ACCT::getgraphdata("ACCT",$from,$till,$grhost);
958         }else{
959                 #If we want to show data from a date older than last two months, use ACCT_HIST
960                 $sth=&ACCT::getgraphdata("ACCT_HIST",$from,$till,$grhost);
961         }
962         foreach( @$sth ) {
963                 $cnt++;
964                 foreach my $i (0..$#$_) {
965                         #print "$_->[$i] "
966                         if ($i == 1){
967                                 push (@{$values[$i]},($_->[$i]/1024/1024));
968                         }else{
969                                 push (@{$values[$i]},$_->[$i]);
970                         }
971                 }
972         }
973
974         print"<br><br><br>";
975         
976         for my $graph (GD::Graph::area->new(600,200))
977         {
978                 my $name = $cgiparams{'host'};
979                 print STDERR "Processing $name mit sosse\n";
980         
981                 $graph->set(
982                                                 x_label => 'X Label',
983                                                 y_label => 'Y label',
984                                                 title => 'An Area Graph',
985                                                 #y_max_value => 40,
986                                                 #y_tick_number => 8,
987                                                 #y_label_skip => 2,
988                                                 #accent_treshold => 41,
989                                                 transparent => 0,
990                 );
991         
992                 $graph->set_legend( 'one', 'two' );
993                 my $gd=$graph->plot(\@values);
994                 open(IMG, '>/srv/web/ipfire/html/test/file.png') or die $!;
995                 binmode IMG;
996                 print IMG $gd->png;
997         } 
998         sleep 1;
999         print "<img src='/test/file.png' alt='Tanzmaus'>";
1000 }
1001
1002 sub statusbox{
1003         my $bgcolor1='';
1004         my $bgcolor2='';
1005         my $message;
1006         if ($proxsrv eq $Lang::tr{'stopped'}){
1007                 $bgcolor1="bgcolor='${Header::colourred}' align='center'";
1008                 $message="<br>$Lang::tr{'acct proxy_enable'}";
1009         }else{
1010                 $bgcolor1="bgcolor='${Header::colourgreen}' align='center'";
1011         }
1012         if ($proxlog eq $Lang::tr{'stopped'}){
1013                 $bgcolor2="bgcolor='${Header::colourred}' align='center'";
1014                 $message=$message."<br>$Lang::tr{'acct proxylog_enable'}";
1015         }else{
1016                 $bgcolor2="bgcolor='${Header::colourgreen}' align='center'";
1017         }
1018         &Header::openbox('100%', 'left', );
1019         print<<EOF;
1020         <center><table width='50%' class='tbl'>
1021         <tr>
1022                 <th>$Lang::tr{'service'}</th>
1023                 <th>$Lang::tr{'status'}</th>
1024         </tr>
1025         <tr>
1026                 <td bgcolor='$color{'color22'}'>$Lang::tr{'proxy'}</td>
1027                 <td $bgcolor1><font color='white'>$proxsrv</td>
1028         <tr>
1029         <tr>
1030                 <td bgcolor='$color{'color20'}'>$Lang::tr{'logging'}</td>
1031                 <td $bgcolor2><font color='white'>$proxlog</td>
1032         </tr>
1033 EOF
1034         if ($message){
1035                 print"<tr><td colspan='2'><font color='red'>$message<br>$Lang::tr{'acct nodata'}</td></tr>";
1036         }
1037         print"</table>";
1038         &Header::closebox();
1039 }
1040
1041 sub calcbytes{
1042         #GET:   Value (bytes)
1043         #GIVES: Value (in MB,GB,TB) With Type ("MB","GB","TB")
1044         my $val=$_[0];
1045         my $type;
1046         if (($val/1024) < 1024){
1047                 #Calc KB
1048                 $val=sprintf "%.2f",$val/1024;
1049                 $type=$Lang::tr{'acct kb'};
1050         }elsif (($val/(1024*1024)) < 1024){ 
1051                 #Calc MB
1052                 $val=sprintf "%.2f",$val/(1024*1024);
1053                 $type=$Lang::tr{'acct mb'};
1054         }elsif(($val/(1024*1024*1024)) < 1024){
1055                 #Calc GB 
1056                 $val=sprintf "%.2f",$val/(1024*1024*1024);
1057                 $type=$Lang::tr{'acct gb'};
1058         }elsif(($val/(1024*1024*1024*1024)) < 1024){
1059                 #Calc TB
1060                 $val=sprintf "%.2f",$val/(1024*1024*1024*1024);
1061                 $type=$Lang::tr{'acct tb'};
1062         }
1063         return ($val,$type);
1064 }
1065
1066 sub addressmgmnt{
1067         #This function shows the site "address management"
1068         &Header::openpage("$Lang::tr{'acct addresses'}", 1, '');
1069         &Header::openbigbox('100%', 'center');
1070         &error;
1071         my $col1;
1072         my $host=0;
1073         my $cust=0;
1074         #Get all Addresses from DB
1075         my $res = &ACCT::getaddresses;
1076
1077 &Header::openbox('100%', 'left',$Lang::tr{'acct edit_addr'} );
1078
1079 #When no address preselected, set COMPANYTYPE to "CUST"
1080 if ($cgiparams{'rdo_companytype'} eq ''){
1081         $cgiparams{'rdo_companytype'} = 'CUST';
1082 }
1083 $checked{'rdo_companytype'}{$cgiparams{'rdo_companytype'}}                              = 'CHECKED';
1084
1085 #NEW AddressBox
1086 print<<END;
1087         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1088                 <table style=width:100%;'>
1089                         <tr>
1090                                 <td style='width:8em;'></td>
1091                                 <td></td>
1092                                 <td colspan='2'><font size="1">$Lang::tr{'acct hint_hoster'}:</font></td>
1093                         </tr>
1094                         <tr>
1095                                 <td>$Lang::tr{'acct companytype'}</td>
1096                                 <td>
1097                                         <input type='radio' name='rdo_companytype' value='CUST' $checked{'rdo_companytype'}{'CUST'}>$Lang::tr{'acct customer'} &nbsp;
1098                                         <input type='radio' name='rdo_companytype' value='HOST' $checked{'rdo_companytype'}{'HOST'}>$Lang::tr{'acct hoster'}</td>
1099                                 <td style='width:8em;'>$Lang::tr{'acct bank'}<img src='/blob.gif' alt='*' /></td>
1100                                 <td>
1101                                         <input type='text' name='txt_bank' value='$cgiparams{'txt_bank'}' style='width:25em;'></td>
1102                         </tr>
1103                         <tr>
1104                                 <td>$Lang::tr{'acct company'}<img src='/blob.gif' alt='*' /></td>
1105                                 <td>
1106                                         <input type='text' name='txt_company' value='$cgiparams{'txt_company'}' style='width:25em;'></td>
1107                                 <td>$Lang::tr{'acct iban'}</td>
1108                                 <td>
1109                                         <input type='text' name='txt_iban' value='$cgiparams{'txt_iban'}' style='width:25em;'></td>
1110                         </tr>
1111                         <tr>
1112                                 <td>$Lang::tr{'acct name1'}</td>
1113                                 <td>
1114                                         <input type='text' name='txt_name1' value='$cgiparams{'txt_name1'}' style='width:25em;'></td>
1115                                 <td>$Lang::tr{'acct bic'}</td>
1116                                 <td>
1117                                         <input type='text' name='txt_bic' maxlength='8' value='$cgiparams{'txt_bic'}' style='width:25em;'></td>
1118                         </tr>
1119                         <tr>
1120                                 <td>$Lang::tr{'acct str'}<img src='/blob.gif' alt='*' /></td>
1121                                 <td align='left'>
1122                                         <input type='text' name='txt_str' value='$cgiparams{'txt_str'}' style='width:25em;'></td>
1123                                 <td>$Lang::tr{'acct blz'}</td>
1124                                 <td>
1125                                         <input type='text' name='txt_blz' maxlength='8' value='$cgiparams{'txt_blz'}' style='width:25em;'></td>
1126                         </tr>
1127                         <tr>
1128                                 <td>$Lang::tr{'acct str_nr'}<img src='/blob.gif' alt='*' /></td>
1129                                 <td><input type='text' name='txt_str_nr' value='$cgiparams{'txt_str_nr'}' style='width:25em;'></td>
1130                                 <td>$Lang::tr{'acct kto'}</td>
1131                                 <td>
1132                                         <input type='text' name='txt_kto' value='$cgiparams{'txt_kto'}' style='width:25em;'></td>
1133                         </tr>
1134
1135                         
1136                         <tr>
1137                                 <td>$Lang::tr{'acct plz'}<img src='/blob.gif' alt='*' /></td>
1138                                 <td>
1139                                         <input type='text' name='txt_plz' value='$cgiparams{'txt_plz'}' style='width:25em;'></td>
1140                                 <td>$Lang::tr{'acct email'}<img src='/blob.gif' alt='*' /></td>
1141                                 <td><input type='text' name='txt_email' value='$cgiparams{'txt_email'}' style='width:25em;'></td>
1142                         </tr>
1143                         <tr>
1144                                 <td>$Lang::tr{'acct city'}<img src='/blob.gif' alt='*' /></td>
1145                                 <td><input type='text' name='txt_city' value='$cgiparams{'txt_city'}' style='width:25em;'></td>
1146                                 <td>$Lang::tr{'acct inet'}</td>
1147                                 <td>
1148                                         <input type='text' name='txt_inet' value='$cgiparams{'txt_inet'}' style='width:25em;'></td>
1149                         </tr>
1150                         <tr>
1151                                 <td></td>
1152                                 <td></td>
1153                                 <td>$Lang::tr{'acct hrb'}<img src='/blob.gif' alt='*' /></td>
1154                                 <td>
1155                                         <input type='text' name='txt_hrb' value='$cgiparams{'txt_hrb'}' style='width:25em;'></td>
1156                         </tr>
1157                         <tr>
1158                                 <td></td>
1159                                 <td></td>
1160                                 <td>$Lang::tr{'acct ustid'}<img src='/blob.gif' alt='*' /></td>
1161                                 <td><input type='text' name='txt_ustid' value='$cgiparams{'txt_ustid'}' style='width:25em;'></td>
1162                         </tr>
1163                         <tr>
1164                                 <td></td>
1165                                 <td></td>
1166                                 <td>$Lang::tr{'acct tel'}</td>
1167                                 <td>
1168                                         <input type='text' name='txt_tel' value='$cgiparams{'txt_tel'}' style='width:25em;'></td>
1169                         </tr>
1170                         <tr>
1171                                 <td></td>
1172                                 <td></td>
1173                                 <td>$Lang::tr{'acct fax'}</td>
1174                                 <td>
1175                                         <input type='text' name='txt_fax' value='$cgiparams{'txt_fax'}' style='width:25em;'></td>
1176                         </tr>
1177                         <tr>
1178                                 <td colspan='6'><img src='/blob.gif' alt='*' /><font size="1">$Lang::tr{'acct not optional'}</font></td>
1179                         </tr>
1180                         <tr>
1181 END
1182         if($cgiparams{'update'} eq 'on'){
1183                 print"<input type='hidden' name='oldcompname' value='$cgiparams{'oldcompname'}'>";
1184                 print "<td colspan='6' align='right' display:inline><input type='submit' name='ACTION' value='$Lang::tr{'update'}'></td>";
1185         }else{
1186                 print "<td colspan='6' align='right' display:inline><input type='submit' name='ACTION1' value='$Lang::tr{'save'}'></td>";
1187         }
1188         print"</tr></table></form>";
1189 &Header::closebox();
1190 #Upper BackButton
1191 print<<END;
1192         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1193         <table style='width:100%;'>
1194                 <tr>
1195                         <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
1196                 </tr>
1197         </table>
1198         </form>
1199 END
1200 #Check if we need to show HOSTBOX and/or CUSTBOX
1201 foreach my $row (@$res) {
1202         my ($gr,$comp,$type,$name1,$str,$nr,$plz,$city,$bank,$iban,$bic,$blz,$kto,$email,$inet,$hrb,$ustid,$tel,$fax) = @$row;
1203         if ($type eq 'HOST'){
1204                 $host=1;
1205         }
1206         if ($type eq 'CUST'){
1207                 $cust=1;
1208         }
1209 }
1210 #Show HOSTER Addresses if any
1211         if ($host){
1212                 $count=0;
1213                 #EXISTING HOST BOX
1214                 &Header::openbox('100%', 'left',$Lang::tr{'acct exst_host_addr'} );
1215                 my $float;
1216                 print "<table style='width:100%'>";
1217                 foreach my $row (@$res) {
1218                         #SET colors for tablerows
1219                         $col="style='background-color:$color{'color22'}'";
1220                         $col1="style='background-color:#e2d8d8'";
1221                         my ($gr,$comp,$type,$name1,$str,$nr,$plz,$city,$bank,$iban,$bic,$blz,$kto,$email,$inet,$hrb,$ustid,$tel,$fax) = @$row;
1222                         if ($cgiparams{'oldcompname'} eq $comp){
1223                                 $col="style='background-color:yellow'";
1224                                 $col1="style='background-color:yellow'";
1225                         }
1226                         if ($type eq 'HOST'){
1227                                 $count++;
1228                                 if($count % 2){
1229                                         print"<tr><td width='50%' valign='top' align='center'>";
1230                                 }else{
1231                                         print"</td><td width='50%' valign='top' align='center'>";
1232                                 }
1233                                 print<<END;
1234                                 <table style='width:90%;' cellspacing='0' class='tbl'>
1235                                 <tr>
1236                                         <th align='left' width='50%'>$Lang::tr{'acct company'}</th>
1237                                         <th align='left' width='10%' >$Lang::tr{'acct bank'}</th>
1238                                         <th width='38%' ></th>
1239                                         <th align='right' width='1%' style="PADDING: 0px">
1240                                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1241                                         <input type='image' src='/images/edit.gif' alt=$Lang::tr{'acct edit'} title='$Lang::tr{'acct edit'}' />
1242                                         <input type='hidden' name='ACTION' value='edit_addr'>
1243                                         <input type='hidden' name='rdo_companytype' value='$type'>
1244                                         <input type='hidden' name='txt_company' value='$comp'>
1245                                         <input type='hidden' name='txt_name1' value='$name1'>
1246                                         <input type='hidden' name='txt_str' value='$str'>
1247                                         <input type='hidden' name='txt_str_nr' value='$nr'>
1248                                         <input type='hidden' name='txt_plz' value='$plz'>
1249                                         <input type='hidden' name='txt_city' value='$city'>
1250                                         <input type='hidden' name='txt_bank' value='$bank'>
1251                                         <input type='hidden' name='txt_iban' value='$iban'>
1252                                         <input type='hidden' name='txt_bic' value='$bic'>
1253                                         <input type='hidden' name='txt_blz' value='$blz'>
1254                                         <input type='hidden' name='txt_kto' value='$kto'>
1255                                         <input type='hidden' name='txt_email' value='$email'>
1256                                         <input type='hidden' name='txt_inet' value='$inet'>
1257                                         <input type='hidden' name='txt_hrb' value='$hrb'>
1258                                         <input type='hidden' name='txt_ustid' value='$ustid'>
1259                                         <input type='hidden' name='txt_tel' value='$tel'>
1260                                         <input type='hidden' name='txt_fax' value='$fax'>
1261                                         </form></th>
1262                                         <th width='1%' style="PADDING: 0px">
1263                                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1264                                         <input type='image' src='/images/delete.gif' alt=$Lang::tr{'acct deladr'} title=$Lang::tr{'acct deladr'} />
1265                                         <input type='hidden' name='txt_company' value='$comp'>
1266                                         <input type='hidden' name='ACTION' value='del_addr'>
1267                                         </form>
1268                                         </th>
1269                                 </tr>
1270                                 <tr>
1271                                         <td $col><b>$comp</b></td>
1272                                         <td $col1></td>
1273                                         <td colspan='3' $col1></td>
1274                                 </tr>
1275                                 <tr>
1276                                         <td $col>$name1</td>
1277                                         <td $col1 width='35%'>$Lang::tr{'acct bank'}</td>
1278                                         <td colspan='3' $col1>$bank</td>
1279                                 </tr>
1280                                 <tr>
1281                                         <td $col></td>
1282                                         <td $col1>$Lang::tr{'acct iban'}</td>
1283                                         <td colspan='3' $col1>$iban</td>
1284                                 </tr>
1285                                 <tr>
1286                                         <td $col>$str $nr</td>
1287                                         <td $col1>$Lang::tr{'acct bic'}</td>
1288                                         <td colspan='3' $col1>$bic</td>
1289                                 </tr>
1290                                 <tr>
1291                                         <td $col>$plz $city</td>
1292                                         <td $col1>$Lang::tr{'acct blz'}</td>
1293                                         <td colspan='3' $col1>$blz</td>
1294                                 </tr>
1295                                 <tr>
1296                                         <td $col></td>
1297                                         <td $col1>$Lang::tr{'acct kto'}</td>
1298                                         <td colspan='3' $col1>$kto</td>
1299                                 </tr>
1300                                 </table>
1301                                 <br>
1302                         </td>
1303 END
1304                                 if (! $count % 2){
1305                                         print"</tr>";
1306                                 }
1307                         }
1308                 }
1309                 if ( ($count % 2)){
1310                         print"<td width='50%' valign='top' align='center'></td></tr>";
1311                 }
1312                 print "</table>";
1313                 &Header::closebox();
1314         }else{
1315                 &Header::openbox('100%', 'left',$Lang::tr{'acct exst_host_addr'} );
1316                 print $Lang::tr{'acct host empty'};
1317                 &Header::closebox();
1318         }
1319 #Show CUSTOMER Addresses if any
1320         if($cust){
1321                 $count=0;
1322                 #EXISTING CUSTOMER BOX
1323                 &Header::openbox('100%', 'left',$Lang::tr{'acct exst_cust_addr'} );
1324                 print "<table style='width:100%;'><tr>";
1325                 foreach my $row (@$res) {
1326                         #SET colors for tablerows
1327                         $col="style='background-color:$color{'color22'}'";
1328                         my ($gr,$comp,$type,$name1,$str,$nr,$plz,$city,$bank,$iban,$bic,$blz,$kto,$email,$inet,$hrb,$ustid,$tel,$fax) = @$row;
1329                         if ($cgiparams{'oldcompname'} eq $comp){
1330                                 $col="style='background-color:yellow'";
1331                         }
1332                         if ($type eq 'CUST'){
1333                                 $count++;
1334                                 print"<td width='15%' valign='top' align='center'>";
1335                                 
1336                                 print<<END;
1337                                 <table style='width:90%;' cellspacing='0' class='tbl'>
1338                                 <tr>
1339                                         <th align='left'>
1340                                                 $Lang::tr{'acct company'}
1341                                         </th>
1342                                         <th width='1%' style="PADDING: 0px">
1343                                                 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1344                                                 <input type='image' src='/images/edit.gif' alt='$Lang::tr{'acct edit'}' title='$Lang::tr{'acct edit'}' />
1345                                                 <input type='hidden' name='ACTION' value='edit_addr'>
1346                                                 <input type='hidden' name='rdo_companytype' value='$type'>
1347                                                 <input type='hidden' name='txt_company' value='$comp'>
1348                                                 <input type='hidden' name='txt_name1' value='$name1'>
1349                                                 <input type='hidden' name='txt_str' value='$str'>
1350                                                 <input type='hidden' name='txt_str_nr' value='$nr'>
1351                                                 <input type='hidden' name='txt_plz' value='$plz'>
1352                                                 <input type='hidden' name='txt_city' value='$city'>
1353                                                 <input type='hidden' name='txt_bank' value='$bank'>
1354                                                 <input type='hidden' name='txt_iban' value='$iban'>
1355                                                 <input type='hidden' name='txt_bic' value='$bic'>
1356                                                 <input type='hidden' name='txt_blz' value='$blz'>
1357                                                 <input type='hidden' name='txt_kto' value='$kto'>
1358                                                 <input type='hidden' name='txt_email' value='$email'>
1359                                                 <input type='hidden' name='txt_inet' value='$inet'>
1360                                                 <input type='hidden' name='txt_hrb' value='$hrb'>
1361                                                 <input type='hidden' name='txt_ustid' value='$ustid'>
1362                                                 <input type='hidden' name='txt_tel' value='$tel'>
1363                                                 <input type='hidden' name='txt_fax' value='$fax'>
1364                                                 </form>
1365                                         </th>
1366                                         <th width='1%' style="padding: 0px">
1367                                                 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1368                                                 <input type='image' src='/images/delete.gif' alt=$Lang::tr{'acct deladr'} title=$Lang::tr{'acct deladr'} />
1369                                                 <input type='hidden' name='ACTION' value='del_addr' />
1370                                                 <input type='hidden' name='txt_company' value='$comp' />
1371                                                 </form>
1372                                         </th>
1373                                 </tr>
1374                                 <tr>
1375                                         <td colspan='3' $col><b>$comp</b></td>
1376                                 </tr>
1377                                 <tr>
1378                                         <td colspan='3' $col>$name1</td>
1379                                 </tr>
1380                                 <tr>
1381                                         <td colspan='3' $col>$str $nr</td>
1382                                 </tr>
1383                                 <tr>
1384                                         <td colspan='3' $col>$plz $city</td>
1385                                 </tr>
1386                                 </table><br>
1387                                 </td>
1388         
1389 END
1390                                 if(! ($count % 3)) {
1391                                         print"</tr><tr>";
1392                                 }
1393                         }
1394                         
1395                 }
1396                 if ($count %2){
1397                         print"<td width='15%' valign='top' align='center'></td></tr>";
1398                 }
1399                 print"</table>";
1400                 &Header::closebox();
1401         }else{
1402                 &Header::openbox('100%', 'left',$Lang::tr{'acct exst_cust_addr'} );
1403                 print $Lang::tr{'acct cust empty'};
1404                 &Header::closebox();
1405         }
1406         &Header::closebigbox();
1407         &Header::closepage();
1408         exit 0;
1409 }
1410
1411 sub checkfield{
1412         my $field=$_[0];
1413         my $fieldvalue=$_[1];
1414         my $errormessage=$_[2];
1415         
1416         if (!&validtextfield($fieldvalue)){
1417                 if(!$fieldvalue){
1418                         $errormessage.="$Lang::tr{'acct empty field'} $field<br>";
1419                 }else{
1420                         $errormessage.="$Lang::tr{'acct invalid'} $field<br>";
1421                 }
1422         }
1423         return $errormessage;
1424 }
1425
1426 sub checkaddress{
1427         #Check if an address with the same name alread exists
1428         if ($cgiparams{'update'} ne 'on'){
1429                 my $res=&ACCT::getaddresses;
1430                 foreach my $row (@$res) {
1431                         my ($anz,$name)=@$row;
1432                         if ($name eq $cgiparams{'txt_company'}){
1433                                 $errormessage.=$Lang::tr{'acct companyexists'};
1434                         }
1435                 }
1436         }
1437         #Check Companyfield
1438         $errormessage=&checkfield($Lang::tr{'acct company'},$cgiparams{'txt_company'},$errormessage);
1439
1440         #Check Name1
1441         if($cgiparams{'txt_name1'}){
1442                 $errormessage=&checkfield($Lang::tr{'acct name1'},$cgiparams{'txt_name1'},$errormessage);
1443         }
1444
1445         #Check Name2
1446         if($cgiparams{'txt_name2'}){
1447                 $errormessage=&checkfield($Lang::tr{'acct name2'},$cgiparams{'txt_name2'},$errormessage);
1448         }
1449
1450         #Check STREET
1451         $errormessage=&checkfield($Lang::tr{'acct str'},$cgiparams{'txt_str'},$errormessage);
1452
1453         #Check STREET-NR
1454         if (! $cgiparams{'txt_str_nr'}){
1455                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct str_nr'}<br>";
1456         }else{
1457                 if(! &validalphanumfield($cgiparams{'txt_str_nr'})){
1458                         $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct str_nr'}<br>";
1459                 }
1460         }
1461
1462         #Check POSTAL-CODE
1463         if (! $cgiparams{'txt_plz'}){
1464                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct plz'}<br>";
1465         }else{
1466                 if(! &validnumfield($cgiparams{'txt_plz'})){
1467                         $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct plz'}<br>";
1468                 }
1469         }
1470
1471         #Check CITY
1472         $errormessage=&checkfield($Lang::tr{'acct city'},$cgiparams{'txt_city'},$errormessage);
1473
1474         #Check E-MAIL
1475         if(! $cgiparams{'txt_email'}){
1476                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct email'}<br>";
1477         }else{
1478                 if (! &General::validemail($cgiparams{'txt_email'})){
1479                         $errormessage.="<br>$Lang::tr{'acct invalid'} $Lang::tr{'acct email'}";
1480                 }
1481         }
1482
1483         #Check all fields required for companytype "HOST"
1484         if ($cgiparams{'rdo_companytype'} eq 'HOST'){
1485                 #Check BANK
1486                 $errormessage=&checkfield($Lang::tr{'acct bank'},$cgiparams{'txt_bank'},$errormessage);
1487                 
1488                 #Check IBAN - optional
1489                 if($cgiparams{'txt_iban'}){
1490                         if(!&validalphanumfield($cgiparams{'txt_iban'})){
1491                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct iban'}<br>";
1492                         }
1493                 }
1494                 if($cgiparams{'txt_bic'}){
1495                         if(!&validalphanumfield($cgiparams{'txt_bic'})){
1496                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct bic'}<br>";
1497                         }
1498                 }
1499                 if(($cgiparams{'txt_iban'} && $cgiparams{'txt_blz'})||(!$cgiparams{'txt_iban'} && $cgiparams{'txt_blz'})){
1500                         #Check BLZ
1501                         if(! &validnumfield($cgiparams{'txt_blz'})){
1502                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct blz'}<br>";
1503                         }
1504                         #Check BANKACCOUNT
1505                         if($cgiparams{'txt_kto'}){
1506                                 if(! &validnumfield($cgiparams{'txt_kto'})){
1507                                         $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct kto'}<br>";
1508                                 }
1509                         }elsif(!$cgiparams{'txt_kto'}){
1510                                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct kto'}<br>";
1511                         }
1512                 }elsif(!$cgiparams{'txt_iban'} && !$cgiparams{'txt_blz'}){
1513                         $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct blz'}<br>";
1514                         #Check BANKACCOUNT
1515                         if($cgiparams{'txt_kto'}){
1516                                 if(! &validnumfield($cgiparams{'txt_kto'})){
1517                                         $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct kto'}<br>";
1518                                 }
1519                         }elsif(!$cgiparams{'txt_kto'}){
1520                                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct kto'}<br>";
1521                         }
1522                 }
1523
1524                 #Check Internet
1525                 if($cgiparams{'txt_inet'}){
1526                         if ($cgiparams{'txt_inet'} =~ m/([a-z]+:\/\/)??([a-z0-9\-]+\.){1}(([a-z0-9\-]+\.){0,})([a-z0-9\-]+){1}/o) {
1527                                         $cgiparams{'txt_inet'}=$2.$3.$5;
1528                                 } else {
1529                                         $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct inet'}<br>";
1530                                 }
1531                 }
1532                 #Check Hrb
1533                 if($cgiparams{'txt_hrb'}){
1534                         $errormessage=&checkfield($Lang::tr{'acct hrb'},$cgiparams{'txt_hrb'},$errormessage);
1535                 }
1536                 
1537         }
1538
1539         #Check Phone
1540         if($cgiparams{'txt_tel'}){
1541                         if (!&validphonefield($cgiparams{'txt_tel'})){
1542                                 $errormessage.="$Lang::tr{'acct invalid'} $Lang::tr{'acct tel'}<br>";
1543                         }
1544         }
1545
1546         return $errormessage;
1547 }
1548
1549 sub checkproxy{
1550         if(-f "${General::swroot}/proxy/enable"){
1551                 $proxsrv=$Lang::tr{'running'};
1552         }else{
1553                 $proxsrv=$Lang::tr{'stopped'};
1554         }
1555         my $srce = "${General::swroot}/proxy/squid.conf";
1556         my $string1 = 'access\.log';
1557         open(FH, $srce);
1558         while(my $line = <FH>) {
1559                 if($line =~ m/$string1/) {
1560                         $proxlog=$Lang::tr{'running'};
1561                 }
1562         }
1563         close FH;
1564         return;
1565 }
1566
1567 sub validtextfield{
1568         #GET: Input from a Textfield
1569         #GIVES: True if valid, false if not valid
1570         my $remark = $_[0];
1571
1572         # Each part should be at least two characters in length
1573         # but no more than 63 characters
1574         if (length ($remark) < 1 || length ($remark) > 255) {
1575                 return 0;}
1576         # Only valid characters are a-z, A-Z, 0-9 and -
1577         if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\&\|\ß_()\/\s]*$/) {
1578                 return 0;}
1579         # First character can only be a letter or a digit
1580         if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9(]*$/) {
1581                 return 0;}
1582         # Last character can only be a letter or a digit
1583         if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
1584                 return 0;}
1585         return 1;
1586 }
1587
1588 sub validnumfield{
1589         #GET: Input from a numeric field
1590         #GIVES: True if valid, false if not valid
1591         my $num = $_[0];
1592
1593         # Each part should be at least two characters in length
1594         # but no more than 63 characters
1595         if (length ($num) < 1 || length ($num) > 255) {
1596                 return 0;}
1597         # Only valid characters are a-z, A-Z, 0-9 and -
1598         if ($num !~ /^[0-9.]*$/) {
1599                 return 0;}
1600         # First character can only be a letter or a digit
1601         if (substr ($num, 0, 1) !~ /^[0-9]*$/) {
1602                 return 0;}
1603         # Last character can only be a letter or a digit
1604         if (substr ($num, -1, 1) !~ /^[0-9]*$/) {
1605                 return 0;}
1606         return 1;
1607 }
1608
1609 sub validphonefield{
1610         #GET: Input from a numeric field
1611         #GIVES: True if valid, false if not valid
1612         my $num = $_[0];
1613
1614         # Each part should be at least two characters in length
1615         # but no more than 63 characters
1616         if (length ($num) < 1 || length ($num) > 255) {
1617                 return 0;}
1618         # Only valid characters are a-z, A-Z, 0-9 and -
1619         if ($num !~ /^[0-9-()\+ ]*$/) {
1620                 return 0;}
1621         # First character can only be a letter or a digit
1622         if (substr ($num, 0, 1) !~ /^[0-9(\+]*$/) {
1623                 return 0;}
1624         # Last character can only be a digit
1625         if (substr ($num, -1, 1) !~ /^[0-9]*$/) {
1626                 return 0;}
1627         return 1;
1628 }
1629
1630 sub validalphanumfield{
1631         #GET: Input from a numeric field
1632         #GIVES: True if valid, false if not valid
1633         my $remark = $_[0];
1634
1635         # Each part should be at least two characters in length
1636         # but no more than 63 characters
1637         if (length ($remark) < 1 || length ($remark) > 255) {
1638                 return 0;}
1639         # Only valid characters are a-z, A-Z, 0-9 and -
1640         if ($remark !~ /^[0-9a-zA-Z]*$/) {
1641                 return 0;}
1642         # First character can only be a letter or a digit
1643         if (substr ($remark, 0, 1) !~ /^[0-9A-Za-z]*$/) {
1644                 return 0;}
1645         # Last character can only be a letter or a digit
1646         if (substr ($remark, -1, 1) !~ /^[0-9a-zA-Z]*$/) {
1647                 return 0;}
1648         return 1;
1649 }
1650
1651 sub error{
1652         if ($errormessage) {
1653                 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
1654                 print "<class name='base'>$errormessage\n";
1655                 print "&nbsp;</class>\n";
1656                 &Header::closebox();
1657         }
1658 }
1659
1660 sub billgroupsite{
1661         &Header::openpage("$Lang::tr{'acct billgroup'}", 1, '');
1662         &Header::openbigbox('100%', 'center');
1663         &error;
1664         my $host;
1665         my $cust;
1666         my @oldhosts;
1667         my $grp;
1668         my $mailrcpt;
1669         my $ccmailrcpt;
1670         #Get addresses from DB
1671         my $res = &ACCT::getaddresses;
1672         #Check if we need to show NEW-BillGROUP-BOX or Hint
1673         foreach my $row (@$res) {
1674                 my ($gr,$comp,$type,$name1,$str,$nr,$plz,$city,$bank,$iban,$bic,$blz,$kto,$email,$inet,$hrb,$ust,$tel,$fax,$ccmail) = @$row;
1675                 $grp=$gr;
1676                 $mailrcpt=$email;
1677                 $ccmailrcpt=$ccmail;
1678                 if ($type eq 'HOST'){
1679                         $host=1;
1680                 }
1681                 if ($type eq 'CUST'){
1682                         $cust=1;
1683                 }
1684         }
1685 if ($host && $cust){
1686         #Fill CCMAIL
1687         if (!$cgiparams{'txt_ccmail'}){
1688                 $cgiparams{'txt_ccmail'}=$ccmailrcpt;
1689         }
1690         &Header::openbox('100%', 'left',"$Lang::tr{'acct edit_addr'}" );
1691         print<<END;
1692         <form method='post' action='$ENV{'SCRIPT_NAME'}' ENCTYPE='multipart/form-data'>
1693                 <table style='width:100%;'>
1694                         <tr>
1695                                 <td style='width: 22em;'>$Lang::tr{'name'}</td>
1696                                 <td><input type='text' name='txt_billgroup' value='$cgiparams{'txt_billgroup'}' style='width: 24em;'></td>
1697                         </tr>
1698                         <tr>
1699                                 <td><br></td>
1700                         </tr>
1701                         <tr>
1702                                 <td valign='top'>$Lang::tr{'acct billtext1'}<img src='/blob.gif' alt='*' /></td>
1703                                 <td><textarea name='txt_billtext1' cols='40' rows='5'  style='width: 24em;' maxlength='300'>$cgiparams{'txt_billtext1'}</textarea></td>
1704                         </tr>
1705                         <tr><td><br></td></tr>
1706 END
1707         #Print Dropdown Menu for HOSTER and CUSTOMER
1708         print "<tr><td>$Lang::tr{'acct hoster'}</td><td><select name='dd_host' style='width: 24.3em;'>";
1709         foreach my $row (@$res) {
1710                 my ($gr,$comp,$type) = @$row;
1711                 if ($type eq 'HOST'){
1712                         if($cgiparams{'dd_host'} eq $comp){
1713                                 print"<option selected>$comp</option>";
1714                         }else{
1715                                 print"<option>$comp</option>";
1716                         }
1717                 }
1718         }
1719         print "</select></td></tr><tr><td><br></td></tr>";
1720         print "<tr><td>$Lang::tr{'acct customer'}</td><td><select name='dd_cust' style='width: 24.3em;'>";
1721         foreach my $row (@$res) {
1722                 my ($gr,$comp,$type) = @$row;
1723                 if ($type eq 'CUST'){
1724                         if($cgiparams{'dd_cust'} eq $comp){
1725                                 print"<option selected>$comp</option>";
1726                         }else{
1727                                 print"<option>$comp</option>";
1728                         }
1729                 }
1730         }
1731         print "</select></td></tr>";
1732         print "<tr><td><br></td></tr>";
1733         #Print multiselectbox for hosts/users which should be part of this group
1734         my $hosts=&ACCT::gethosts;
1735         print"<tr><td valign='top'>$Lang::tr{'acct members'}</td><td><select name='sel_hosts' multiple size='8' style='width: 24em;' >";
1736         #If update, split $cgiparams{'sel_hosts'} and preselect values from selectbox
1737         if($cgiparams{'update'} eq 'on'){
1738                 $cgiparams{'oldname'}=$cgiparams{'txt_billgroup'};
1739                 @oldhosts=split(/\|/,$cgiparams{'sel_hosts'});
1740         }
1741         foreach my $row (@$hosts) {
1742                 my ($val)=@$row;
1743                 my $sel=0;
1744                 foreach my $old (@oldhosts){
1745                         if ($old eq $val){
1746                                 $sel=1;
1747                         }
1748                 }
1749                 if ($sel){
1750                         print"<option selected>$val</option>";
1751                 }else{
1752                         print"<option>$val</option>";
1753                 }
1754         }
1755         print"</select></td></tr>";
1756         print "<tr><td><br></td></tr>";
1757         #set right decimal seperator for cent value
1758         setlocale(LC_NUMERIC,"$mainsettings{'LANGUAGE'}_$uplang");
1759         my $val=sprintf"%.3f",$cgiparams{'txt_cent'};
1760         print"<tr><td>$Lang::tr{'acct cent'}</td><td><input type='text' name='txt_cent' value='$val' size='3'>$settings{'CURRENCY'} </td></tr>";
1761         #Optional note
1762         print"<tr><td colspan='2' align='left'><img src='/blob.gif' alt='*' /><font size='1'>$Lang::tr{'acct optional'}</font></td></tr>";
1763         print"<tr><td colspan='2' align='right'><br><br>";
1764         print"</td></tr></table>";
1765
1766         #LOGO Upload if update eq 'on'
1767         if ($cgiparams{'update'} eq 'on'){
1768                 print<<END;
1769                 <table style='width:100%;'>
1770                 <tr>
1771                         <td style='width: 22em;'>$Lang::tr{'acct logo upload'}</td>
1772                         <td><INPUT TYPE="file" NAME="uploaded_file" SIZE=30 MAXLENGTH=80></td>
1773                         <input type='hidden' name='logo_grp' value='$cgiparams{'txt_billgroup'}' />
1774                 </tr>
1775                 <tr>
1776                         <td><br>$Lang::tr{'acct logo'}</td>
1777 END
1778                 #Show Logo in webinterface with 1/2 size if set
1779                 if (-f "$logopath/$cgiparams{'txt_billgroup'}/logo.png"){
1780                         print"<td><img src='/accounting/logo/$cgiparams{'txt_billgroup'}/logo.png' alt='$logopath/$cgiparams{'txt_billgroup'}/logo.png' width='25%' height='25%' /></td></tr>";
1781                 }else{
1782                         print"<td><br>$Lang::tr{'no'}</td></tr>";
1783                 }
1784                 #Show optional CC Mailadresses
1785                 print<<END;
1786                 <tr>
1787                         <td><br>$Lang::tr{'acct mailrcpt'}</td>
1788                         <td><br>$mailrcpt</td>
1789                 </tr>
1790                 <tr>
1791                         <td><br>$Lang::tr{'acct ccmail'}</td>
1792                         <td><br><input type='text' name='txt_ccmail' value='$cgiparams{'txt_ccmail'}' style='width: 24.3em;'></td>
1793                 </tr>
1794                 
1795                 
1796                 
1797 END
1798                 print"</table>";
1799         }
1800         print"<table style='width:100%;'><tr><td align='right'>";
1801         #Print SAVE or EDIT Button
1802         if($cgiparams{'update'} eq 'on'){
1803                 print "<input type='submit' name='BILLACTION' value='$Lang::tr{'update'}'>";
1804                 print "<input type='hidden' name='oldname' value='$cgiparams{'oldname'}'>";
1805                 print "<input type='hidden' name='oldccmail' value='$ccmailrcpt'>";
1806         }else{
1807                 print "<input type='submit' name='BILLACTION' value='$Lang::tr{'save'}'>";
1808         }
1809         print"</td></tr></table><br></form><br>";
1810         &Header::closebox();
1811 #BackButton
1812         print<<END;
1813         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1814         <table style='width:100%;'>
1815                 <tr>
1816                         <td align='right'>
1817                                 <input type='submit' name='ACTION' value='$Lang::tr{'back'}'>
1818                         </td>
1819                 </tr>
1820         </table>
1821         </form>
1822 END
1823         #Show Box for fixed positions if update
1824         if ($cgiparams{'update'} eq 'on'){
1825                 &viewtablebillpos($cgiparams{'txt_billgroup'});
1826         }
1827         if($grp >0){
1828                 &viewtablebillgroups;
1829         }
1830
1831 }else{
1832         &Header::openbox('100%', 'left',"$Lang::tr{'hint'}" );
1833         print "$Lang::tr{'acct hint billgrp'}";
1834         &Header::closebox();
1835         #BackButton
1836 print<<END;
1837         <table style='width:100%;'>
1838                 <tr>
1839                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1840                         <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
1841                         </form>
1842                 </tr>
1843         </table>
1844 END
1845 }
1846         &Header::closebigbox();
1847         &Header::closepage();
1848         exit 0;
1849 }
1850
1851 sub viewtablebillgroups{
1852         $count=0;
1853         &Header::openbox('100%', 'left',"$Lang::tr{'acct billgroup'}" );
1854         #Get DATA from table BILLINGGRP
1855         my $res = &ACCT::getbillgroups;
1856
1857         #Print table billinggroup
1858         print<<END;
1859                 <table style='width:100%;' cellspacing='0' class='tbl'>
1860                 <tr>
1861                         <th align='left'>$Lang::tr{'name'}</th>
1862                         <th align='left'>$Lang::tr{'acct hoster'}</th>
1863                         <th align='left'>$Lang::tr{'acct customer'}</th>
1864                         <th align='left'>$Lang::tr{'acct members'}</th>
1865                         <th align='left' colspan='5'></th>
1866                 </tr>
1867 END
1868         foreach my $line (@$res){
1869                 $count++;
1870                 if($count % 2){
1871                         $col="style='background-color:$color{'color22'}'";
1872                 }else{
1873                         $col="style='background-color:$color{'color20'}'";
1874                 }
1875                 my ($name,$host,$cust,$txt,$amount,$cent) = @$line;
1876                 print<<END;
1877                 <tr>
1878                         <td $col>$name</td>
1879                         <td $col>$host</td>
1880                         <td $col>$cust</td>
1881                         <td $col>$amount</td>
1882                         <td width='1%'  $col>
1883 END
1884                         my $members=&ACCT::listhosts($name);
1885                         my @mem=split(/\|/,$members);
1886                         my $msg;
1887                         foreach my $m (@mem){
1888                                 $msg.=$m."\n";
1889                         }
1890                 print"<img src='/images/computer.png' alt=$Lang::tr{'acct members'} title='".$msg."' /></td>";
1891                 print<<END;
1892                 
1893                 <td width='1%' $col>
1894                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1895                         <input type='image' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
1896                         <input type='hidden' name='BILLACTION' value='edit_billgroup'>
1897                         <input type='hidden' name='txt_billgroup' value='$name'>
1898                         <input type='hidden' name='txt_billtext1' value='$txt'>
1899                         <input type='hidden' name='dd_host' value='$host'>
1900                         <input type='hidden' name='dd_cust' value='$cust'>
1901                         <input type='hidden' name='sel_hosts' value='$members'>
1902                         <input type='hidden' name='txt_cent' value='$cent'>
1903                         </form>
1904                 </td>
1905                 
1906                 <td width='1%' $col>
1907                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1908                         <input type='image' src='/images/folder-open.png' alt='$Lang::tr{'edit'}' title='$Lang::tr{'acct billarchive'}' />
1909                         <input type='hidden' name='BILLACTION' value='open_billgroup'>
1910                         <input type='hidden' name='txt_billgroup' value='$name'>
1911                         </form>
1912                 </td>
1913                 
1914                 <td width='1%' $col>
1915                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1916                         <input type='image' src='/images/document-new.png' alt='$Lang::tr{'acct preview'}' title='$Lang::tr{'acct preview'}' />
1917                         <input type='hidden' name='BILLACTION' value='open_preview'>
1918                         <input type='hidden' name='txt_billgroup' value='$name'>
1919                         </form>
1920                 </td>
1921                 <td width='1%' $col>
1922                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1923                         <input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title="$Lang::tr{'delete'}" />
1924                         <input type='hidden' name='BILLACTION' value='delete_billgroup'>
1925                         <input type='hidden' name='txt_billgroup' value='$name'>
1926                         </form>
1927                 </td>
1928                 </tr>
1929 END
1930         }
1931         print "</table>";
1932         &ACCT::closedb;
1933         &Header::closebox();
1934 }
1935
1936 sub viewtablehosts{
1937         $dbh=&ACCT::connectdb;
1938         &Header::openbox('100%', 'left', $Lang::tr{'acct hosts'});
1939         my $mon1=$_[0];
1940         my $year1=$_[1];
1941         my ($from,$till)=&ACCT::getmonth($mon1,$year1);
1942         $count=0;
1943         #Menu to display another month
1944         print<<END;
1945         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
1946         <table style='width:100%;'>
1947         <tr>
1948                 <td style='width:5%; text-align:center;'>$Lang::tr{'acct month'}</td>
1949                 <td style='width:10%; text-align: center;'>$Lang::tr{'acct year'}</td>
1950                 <td></td>
1951         </tr>
1952         <tr>
1953                 <td><select name='month'>
1954 END
1955         for (my $i=1;$i<13;$i++){
1956                 if(($_[0]) eq $i){
1957                         print"<option selected>$i</option>";
1958                 }else{
1959                         print"<option>$i</option>";
1960                 }
1961         }
1962         print<<END;
1963                 </select></td>
1964                 <td style='text-align: center;'><select name='year'>
1965 END
1966         for (my $j=2014;$j<=($year1);$j++){
1967                 if(($_[1]) eq $j){
1968                         print"<option selected>$j</option>";
1969                 }else{
1970                         print"<option>$j</option>";
1971                 }
1972         }
1973         print<<END;
1974                 </select></td>
1975                 <td><input type='submit' name='ACTION' value='$Lang::tr{'acct view'}'></td>
1976         </tr>
1977         </table></form>
1978         <br>
1979 END
1980         #View table with all hosts
1981         print<<END;
1982         <table style='width:100%;' class='tbl'>
1983         <tr>
1984                 <th>$Lang::tr{'name'}</th>
1985                 <th>$Lang::tr{'acct traffic'}</th>
1986                 <th>$Lang::tr{'from'}</th>
1987                 <th>$Lang::tr{'to'}</th>
1988                 <th></th>
1989         </tr>
1990 END
1991         my $res;
1992         if (($mon)+1 == $mon1 && ($year)+1900 == $year1){
1993                 $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(TIME_RUN),max(TIME_RUN),NAME from ACCT where TIME_RUN between ".$from." and ".$till." group by NAME;");
1994         }else{
1995                 $res = $dbh->selectall_arrayref("SELECT SUM(BYTES),min(strftime('%s',TIME_RUN)),max(strftime('%s',TIME_RUN)),NAME from ACCT_HIST where date(TIME_RUN) > date($from,'unixepoch') and date(TIME_RUN) < date($till,'unixepoch') group by NAME;");
1996         }
1997         my $sumbytes;
1998         my $type;
1999         my $lineval;
2000         if (@$res){
2001                 foreach my $row (@$res) {
2002                         $count++;
2003                         $lineval='';
2004                         $type='';
2005                         if($count % 2){
2006                                 $col="background-color:$color{'color22'};";
2007                         }else{
2008                                 $col="background-color:$color{'color20'};";
2009                         }
2010                         my ($bytes, $mintime, $maxtime, $name) = @$row;
2011                         $sumbytes +=$bytes;
2012                         ($lineval,$type) = &calcbytes($bytes);
2013                         #Print Line
2014                         print"<tr><td style='$col'>$name</td><td style='$col text-align: right;'>$lineval $type</td><td style='$col text-align: center;'>".&getdate($mintime)."</td><td style='$col text-align: center;'>".&getdate($maxtime)."</td>";
2015                         print<<END;
2016                                 <td style='$col'>
2017                                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2018                                         <input type='image' src='/images/utilities-system-monitor.png' alt="$Lang::tr{'status'}" title="$Lang::tr{'status'}" />
2019                                         <input type='hidden' name='ACTION' value='viewgraph'>
2020                                         <input type='hidden' name='host' value='$name'>
2021                                         <input type='hidden' name='month' value='$mon1'>
2022                                         <input type='hidden' name='year' value='$year1'>
2023                                         <input type='hidden' name='traffic' value="$Lang::tr{'acct sum'} $Lang::tr{'acct traffic'} $lineval $type">
2024                                         </form>
2025                                         
2026                                 </td>
2027                         </tr>
2028 END
2029                 }
2030         }else{
2031         print "<tr><td colspan='5'><center>$Lang::tr{'acct no data'}</td></tr>";
2032         }
2033         print "</table>";
2034         &Header::closebox();
2035         &ACCT::closedb;
2036 }
2037
2038 sub viewtablebillpos{
2039         my $grp=$_[0];
2040         #BOX for extra billpositions
2041         &Header::openbox('100%', 'left',"$Lang::tr{'acct fix billpos'} $grp" );
2042         #Table for optional billpositions
2043         print<<END;
2044         <center><table style='width:65%' cellspacing='0' class='tbl' border='0'>
2045         <tr>
2046                 <th align='left'>$Lang::tr{'acct amount'}</th>
2047                 <th align='left' style='padding-left:1.2em'>$Lang::tr{'acct name'}</th>
2048                 <th align='left'>$Lang::tr{'acct price pp'}</th>
2049                 <th></th>
2050         </tr>
2051 END
2052         #Fill Table for extra billpositions if any
2053         if ($cgiparams{'update'} eq 'on'){
2054                 my $res = &ACCT::getextrabillpos($cgiparams{'txt_billgroup'});
2055                 $count=0;
2056                 foreach my $line (@$res){
2057                         $count++;
2058                         if($count % 2){
2059                                 $col="style='background-color:$color{'color22'}'";
2060                         }else{
2061                                 $col="style='background-color:$color{'color20'}'";
2062                         }
2063                         my ($grp,$amnt,$pos,$price) = @$line;
2064                         setlocale(LC_NUMERIC,"$mainsettings{'LANGUAGE'}_$uplang");
2065                         my $locale_price=sprintf"%.2f",$price;
2066                         print "<tr><form method='post' action='$ENV{'SCRIPT_NAME'}'><td $col style='padding-right:1.2em' align='right'>$amnt</td><td $col style='padding-left:1.2em'>$pos</td><td $col style='padding-right:1.2em' align='right'>$locale_price $settings{'CURRENCY'}</td>";
2067                         print "<td $col><input type='image' src='/images/delete.gif' alt=$Lang::tr{'delete'} title=$Lang::tr{'delete'} >";
2068                         print "<input type='hidden' name='BILLPOS' value='delpos'>";
2069                         print "<input type='hidden' name='txt_billgroup' value='$grp'>";
2070                         print "<input type='hidden' name='txt_billpos' value='$pos'></form></tr>";
2071                 }
2072         }
2073         print<<END;
2074                 <tr>
2075                         
2076                         <td ><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='text' name='txt_amount' value='$cgiparams{'txt_amount'}' size='3'></td>
2077                         <td><input type='text' name='txt_name' value='$cgiparams{'txt_name'}' size='40'></td>
2078                         <td ><input type='text' name='txt_price' value='$cgiparams{'txt_price'}' size='6'></td>
2079                         <td></td>
2080                 </tr>
2081                 </table><br>
2082                 <table style='width:100%'>
2083                 <tr>
2084                         <td align='right'><input type='submit' name='BILLPOS' value='$Lang::tr{'save'}'></td>
2085                         <input type='hidden' name='txt_billgroup' value='$grp'>
2086                         </form>
2087                 </tr>
2088                 </table></form>
2089 END
2090
2091         &Header::closebox();
2092 }
2093
2094 sub billoverview{
2095         my $grp=shift;
2096         my $col;
2097         my $count=0;
2098         #Open site
2099         &Header::openpage($Lang::tr{'acct billoverview'}, 1, '');
2100         &Header::openbigbox('100%', 'center');
2101         &Header::openbox('100%', 'left', $grp);
2102         my $res=&ACCT::getbills($grp);
2103
2104         if (@$res > 0){
2105                 print<<END;
2106                 <table style='width:100%' cellspacing='0' class='tbl' border='0'>
2107                 <tr>
2108                         <th>$Lang::tr{'acct nr'}</th>
2109                         <th>$Lang::tr{'acct path'}</th>
2110                         <th>$Lang::tr{'name'}</th>
2111                         <th>$Lang::tr{'acct generated'}</th>
2112                         <th></th>
2113                 </tr>
2114         
2115 END
2116                 foreach my $row (@$res){
2117                         $count++;
2118                         if($count % 2){
2119                                 $col="style='background-color:$color{'color22'}'";
2120                         }else{
2121                                 $col="style='background-color:$color{'color20'}'";
2122                         }
2123                         my ($no,$path,$name,$date,$dbgrp) = @$row;
2124                         
2125                         print "<tr><td $col>$no</td><td $col>$path</td><td $col>$name</td><td $col>$date</td><td $col>";
2126                         print "<form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='image' src='/images/updbooster/updxl-src-adobe.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />";
2127                         print "<input type='hidden' name='BILLVIEW' value='show'>";
2128                         my $file="$path/$name";
2129                         print "<input type='hidden' name='file' value='$file'>";
2130                         print "<input type='hidden' name='name' value='$name'>";
2131                         print"</form></td></tr>";
2132                 }
2133                 print "</table><br>";
2134         }else{
2135                 print "<center>$Lang::tr{'acct no data'}";
2136         }
2137         &Header::closebox();
2138
2139         #BackButton
2140 print<<END;
2141         <table style='width:100%'>
2142                 <tr>
2143                         <form method='post' action='$ENV{'SCRIPT_NAME'}'>
2144                         <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'back'}'></td>
2145                         </form>
2146                 </tr>
2147         </table>
2148 END
2149         &Header::closebigbox();
2150         &Header::closepage();
2151         exit 0;
2152 }
2153
2154 sub checkmailsettings{
2155         #Check valid sender
2156         if(! $cgiparams{'txt_mailsender'}){
2157                 $errormessage.="$Lang::tr{'acct empty field'} $Lang::tr{'acct mailsender'}<br>";
2158         }else{
2159                 if (! &General::validemail($cgiparams{'txt_mailsender'})){
2160                         $errormessage.="<br>$Lang::tr{'acct invalid'} $Lang::tr{'acct mailsender'}<br>";
2161                 }
2162         }
2163         return $errormessage;
2164 }