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