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