]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - html/cgi-bin/captive.cgi
Captive-Portal: Add logo upload feature
[people/mfischer/ipfire-2.x.git] / html / cgi-bin / captive.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2016 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 #use strict;
23 use HTML::Entities();
24 use File::Basename;
25
26 # enable only the following on debugging purpose
27 #use warnings;
28 #use CGI::Carp 'fatalsToBrowser';
29
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33
34 my %settings=();
35 my %mainsettings;
36 my %color;
37 my %cgiparams=();
38 my %netsettings=();
39 my %checked=();
40 my $errormessage='';
41 my $voucherout="${General::swroot}/captive/voucher_out";
42 my $clients="${General::swroot}/captive/clients";
43 my %voucherhash=();
44 my %clientshash=();
45 my $settingsfile="${General::swroot}/captive/settings";
46 my $logopath = "/srv/web/ipfire/html/captive/logo";
47 unless (-e $settingsfile) { system("touch $settingsfile"); }
48 unless (-e $voucherout) { system("touch $voucherout"); }
49
50 &Header::getcgihash(\%cgiparams);
51
52 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
53 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
54 &General::readhash("$settingsfile", \%settings) if(-f $settingsfile);
55 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
56
57 &Header::showhttpheaders();
58
59 #actions
60 if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){
61 my $file = $cgiparams{'uploaded_file'};
62 if ($file){
63 #Check if extension is png
64 chomp $file;
65 my ($name, $path, $ext) = fileparse($file, qr/\.[^.]*$/);
66 if ($ext ne ".png"){
67 $errormessage=$Lang::tr{'Captive wrong ext'};
68 }
69 }
70 if (!$errormessage){
71 #Check if we need to upload a new logo
72 if($file){
73 #Save File
74 my ($filehandle) = CGI::upload('uploaded_file');
75 open (UPLOADFILE, ">$logopath/logo.png");
76 binmode $filehandle;
77 while ( <$filehandle> ) {
78 print UPLOADFILE;
79 }
80 close (UPLOADFILE);
81
82 #Open file to check if dimensions are within rang
83 open (PNG , "<$logopath/logo.png");
84 local $/;
85 my $PNG1=<PNG>;
86 close(PNG);
87 my ($width,$height)=&pngsize($PNG1);
88 if($width > 1920 || $height > 800 || $width < 1280 || $height < 4000){
89 $errormessage.="$Lang::tr{'Captive invalid logosize'} <br>Filedimensions width: $width height: $height<br>";
90 unlink("$logopath/logo.png");
91 }
92 }
93
94 #saves the Captiveportal settings to disk
95 if ($cgiparams{'UNLIMITED'} eq 'on'){
96 $cgiparams{'EXP_HOUR'} = '0';
97 $cgiparams{'EXP_DAY'} = '0';
98 $cgiparams{'EXP_WEEK'} = '0';
99 $cgiparams{'EXP_MONTH'} = '0';
100 }
101
102 $settings{'ENABLE_GREEN'} = $cgiparams{'ENABLE_GREEN'};
103 $settings{'ENABLE_BLUE'} = $cgiparams{'ENABLE_BLUE'};
104 $settings{'AUTH'} = $cgiparams{'AUTH'};
105 $settings{'EXPIRE'} = $cgiparams{'EXP_HOUR'}+$cgiparams{'EXP_DAY'}+$cgiparams{'EXP_WEEK'}+$cgiparams{'EXP_MONTH'};
106 $settings{'EXP_HOUR'} = $cgiparams{'EXP_HOUR'};
107 $settings{'EXP_DAY'} = $cgiparams{'EXP_DAY'};
108 $settings{'EXP_WEEK'} = $cgiparams{'EXP_WEEK'};
109 $settings{'EXP_MONTH'} = $cgiparams{'EXP_MONTH'};
110 $settings{'TITLE'} = $cgiparams{'TITLE'};
111 $settings{'UNLIMITED'} = $cgiparams{'UNLIMITED'};
112 &General::writehash("$settingsfile", \%settings);
113
114 #write Licensetext if defined
115 if ($cgiparams{'AGB'}){
116 $cgiparams{'AGB'} = &Header::escape($cgiparams{'AGB'});
117 open( FH, ">:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!");
118 print FH $cgiparams{'AGB'};
119 close( FH );
120 $cgiparams{'AGB'}="";
121 }
122 #execute binary to reload firewall rules
123 system("/usr/local/bin/captivectrl");
124 }
125 }
126
127 if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive voucherout'}"){
128 #generates a voucher and writes it to /var/ipfire/voucher_out
129
130 #check if we already have a voucher with same code
131 &General::readhasharray("$voucherout", \%voucherhash);
132 foreach my $key (keys %voucherhash) {
133 if($voucherhash{$key}[1] eq $cgiparams{'CODE'}){
134 $errormessage=$Lang::tr{'Captive err doublevoucher'};
135 last;
136 }
137 }
138
139 #check valid remark
140 if ($cgiparams{'REMARK'} ne '' && !&validremark($cgiparams{'REMARK'})){
141 $errormessage=$Lang::tr{'fwhost err remark'};
142 }
143
144 #if no error detected, write to disk
145 if (!$errormessage){
146 my $date=time(); #seconds in utc
147
148 #first get new key from hash
149 my $key=&General::findhasharraykey (\%voucherhash);
150 #initialize all fields with ''
151 foreach my $i (0 .. 3) { $voucherhash{$key}[$i] = "";}
152 #define fields
153 $voucherhash{$key}[0] = $date;
154 $voucherhash{$key}[1] = $cgiparams{'CODE'};
155 $voucherhash{$key}[2] = $settings{'EXPIRE'};
156 $voucherhash{$key}[3] = $cgiparams{'REMARK'};
157 #write values to disk
158 &General::writehasharray("$voucherout", \%voucherhash);
159
160 #now prepare log entry, get expiring date for voucher and decode remark for logfile
161 my $expdate=localtime(time()+$voucherhash{$key}[3]);
162 my $rem=HTML::Entities::decode_entities($voucherhash{$key}[4]);
163
164 #write logfile entry
165 &General::log("Captive", "Generated new voucher $voucherhash{$key}[1] $voucherhash{$key}[2] hours valid expires on $expdate remark $rem");
166 }
167 }
168
169 if ($cgiparams{'ACTION'} eq 'delvoucherout'){
170 #deletes an already generated but unused voucher
171
172 #read all generated vouchers
173 &General::readhasharray("$voucherout", \%voucherhash);
174 foreach my $key (keys %voucherhash) {
175 if($cgiparams{'key'} eq $voucherhash{$key}[0]){
176 #write logenty with decoded remark
177 my $rem=HTML::Entities::decode_entities($voucherhash{$key}[4]);
178 &General::log("Captive", "Delete unused voucher $voucherhash{$key}[1] $voucherhash{$key}[2] hours valid expires on $voucherhash{$key}[3] remark $rem");
179 #delete line from hash
180 delete $voucherhash{$key};
181 last;
182 }
183 }
184 #write back hash
185 &General::writehasharray("$voucherout", \%voucherhash);
186 }
187
188 if ($cgiparams{'ACTION'} eq 'delvoucherinuse'){
189 #delete voucher and connection in use
190
191 #read all active clients
192 &General::readhasharray("$clients", \%clientshash);
193 foreach my $key (keys %clientshash) {
194 if($cgiparams{'key'} eq $clientshash{$key}[0]){
195 #prepare log entry with decoded remark
196 my $rem=HTML::Entities::decode_entities($clientshash{$key}[7]);
197 #write logentry
198 &General::log("Captive", "Delete voucher in use $clientshash{$key}[1] $clientshash{$key}[2] hours valid expires on $clientshash{$key}[3] remark $rem - Connection will be terminated");
199 #delete line from hash
200 delete $clientshash{$key};
201 last;
202 }
203 }
204 #write back hash
205 &General::writehasharray("$clients", \%clientshash);
206 #reload firewallrules to kill connection of client
207 system("/usr/local/bin/captivectrl");
208 }
209
210 #open webpage, print header and open box
211 &Header::openpage($Lang::tr{'Captive menu'}, 1, '');
212 &Header::openbigbox();
213
214 #call error() to see if we have to print an errormessage on website
215 &error();
216
217 #call config() to display the configuration box
218 &config();
219
220 sub getagb(){
221 #open textfile from /var/ipfire/captive/agb.txt
222 open( my $handle, "<:utf8", "/var/ipfire/captive/agb.txt" ) or die("$!");
223 while(<$handle>){
224 #read line by line and print on screen
225 $cgiparams{'AGB'}.= HTML::Entities::decode_entities($_);
226 }
227 close( $handle );
228 }
229
230 sub config(){
231 #prints the config box on the website
232 &Header::openbox('100%', 'left', $Lang::tr{'Captive config'});
233 print <<END
234 <form method='post' action='$ENV{'SCRIPT_NAME'}' enctype="multipart/form-data">\n
235 <table width='100%' border="0">
236 <tr>
237 END
238 ;
239 #check which parameters have to be enabled (from settings file)
240 $checked{'ENABLE_GREEN'}{'off'} = '';
241 $checked{'ENABLE_GREEN'}{'on'} = '';
242 $checked{'ENABLE_GREEN'}{$settings{'ENABLE_GREEN'}} = "checked='checked'";
243
244 $checked{'ENABLE_BLUE'}{'off'} = '';
245 $checked{'ENABLE_BLUE'}{'on'} = '';
246 $checked{'ENABLE_BLUE'}{$settings{'ENABLE_BLUE'}} = "checked='checked'";
247
248 $checked{'UNLIMITED'}{'off'} = '';
249 $checked{'UNLIMITED'}{'on'} = '';
250 $checked{'UNLIMITED'}{$settings{'UNLIMITED'}} = "checked='checked'";
251
252 if ($netsettings{'GREEN_DEV'}){
253 print "<td width='30%'>$Lang::tr{'Captive active on'} <font color='$Header::colourgreen'>Green</font></td><td><input type='checkbox' name='ENABLE_GREEN' $checked{'ENABLE_GREEN'}{'on'} /></td></tr>";
254 }
255 if ($netsettings{'BLUE_DEV'}){
256 print "<td width='30%'>$Lang::tr{'Captive active on'} <font color='$Header::colourblue'>Blue</font></td><td><input type='checkbox' name='ENABLE_BLUE' $checked{'ENABLE_BLUE'}{'on'} /></td></tr>";
257 }
258
259 print<<END
260 </tr>
261 <tr>
262 <td><br>
263 $Lang::tr{'Captive title'}
264 </td>
265 <td><br>
266 <input type='text' name='TITLE' value="$settings{'TITLE'}" size='40'>
267 </td>
268 </tr>
269 END
270 ;
271
272 print<<END
273 <tr>
274 <td>
275 $Lang::tr{'Captive authentication'}
276 </td>
277 <td>
278 <select name='AUTH' style='width:8em;'>
279 END
280 ;
281 print "<option value='LICENSE' ";
282 print " selected='selected'" if ($settings{'AUTH'} eq 'LICENSE');
283 print ">$Lang::tr{'Captive auth_lic'}</option>";
284
285 print "<option value='VOUCHER' ";
286 print " selected='selected'" if ($settings{'AUTH'} eq 'VOUCHER');
287 print ">$Lang::tr{'Captive auth_vou'}</option>";
288
289 print<<END
290 </select>
291 </td>
292 </tr>
293 END
294 ;
295
296 &agbbox();
297
298 #Logo Upload
299 print "<tr><td>$Lang::tr{'Captive logo_upload'}</td><td><INPUT TYPE='file' NAME='uploaded_file' SIZE=30 MAXLENGTH=80></td></tr><tr>";
300 #Show Logo in webinterface with 1/2 size if set
301 if (-f "$logopath/logo.png"){
302 print"<td>$Lang::tr{'Captive logo_set'}</td>";
303 print"<td><img src='/captive/logo/logo.png' alt='$logopath/logo.png' width='25%' height='25%' /></td></tr>";
304 }else{
305 print"<td>$Lang::tr{'Captive logo_set'}</td>";
306 print"<td><br>$Lang::tr{'no'}</td></tr>";
307 }
308 print"<tr><td>$Lang::tr{'Captive vouchervalid'}</td><td>";
309 print "<br><table border='0' with=100%>";
310 print "<th>$Lang::tr{'hours'}</th><th>$Lang::tr{'days'}</th><th>$Lang::tr{'weeks'}</th><th>$Lang::tr{'months'}</th>";
311
312 #print hour-dropdownbox
313 my $hrs=3600;
314 print "<tr><td><select name='EXP_HOUR' style='width:8em;'>";
315 print "<option value='0' ";
316 print " selected='selected'" if ($settings{'EXP_HOUR'} eq '0');
317 print ">--</option>";
318 for (my $i = 1; $i<25; $i++){
319 my $exp_sec = $i * $hrs;
320 print "<option value='$exp_sec' ";
321 print " selected='selected'" if ($settings{'EXP_HOUR'} eq $exp_sec);
322 print ">$i</option>";
323 }
324 print "</td><td>";
325
326 #print day-dropdownbox
327 my $days=3600*24;
328 print "<select name='EXP_DAY' style='width:8em;'>";
329 print "<option value='0' ";
330 print " selected='selected'" if ($settings{'EXP_DAY'} eq '0');
331 print ">--</option>";
332 for (my $i = 1; $i<8; $i++){
333 my $exp_sec = $i * $days;
334 print "<option value='$exp_sec' ";
335 print " selected='selected'" if ($settings{'EXP_DAY'} eq $exp_sec);
336 print ">$i</option>";
337 }
338 print "</td><td>";
339
340 #print week-dropdownbox
341 my $week=3600*24*7;
342 print "<select name='EXP_WEEK' style='width:8em;'>";
343 print "<option value='0' ";
344 print " selected='selected'" if ($settings{'EXP_WEEK'} eq '0');
345 print ">--</option>";
346 for (my $i = 1; $i<5; $i++){
347 my $exp_sec = $i * $week;
348 print "<option value='$exp_sec' ";
349 print " selected='selected'" if ($settings{'EXP_WEEK'} eq $exp_sec);
350 print ">$i</option>";
351 }
352 print "</td><td>";
353
354 #print month-dropdownbox
355 my $month=3600*24*30;
356 print "<select name='EXP_MONTH' style='width:8em;'>";
357 print "<option value='0' ";
358 print " selected='selected'" if ($settings{'EXP_MONTH'} eq '0');
359 print ">--</option>";
360 for (my $i = 1; $i<13; $i++){
361 my $exp_sec = $i * $month;
362 print "<option value='$exp_sec' ";
363 print " selected='selected'" if ($settings{'EXP_MONTH'} eq $exp_sec);
364 print ">$i</option>";
365 }
366 print "</td>";
367
368 print "<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' name='UNLIMITED' $checked{'UNLIMITED'}{'on'} /></td><td>&nbsp;<b>$Lang::tr{'Captive nolimit'}</b></td>";
369
370 print "</tr></table>";
371
372 print<<END
373 <tr>
374 <td>
375 </td>
376 <td align='right'>
377 <input type='submit' name='ACTION' value="$Lang::tr{'save'}"/>
378 </td>
379 </tr>
380 </table>
381 <br><br>
382 END
383 ;
384 print "</form>";
385
386 &Header::closebox();
387
388 #if settings is set to use vouchers, the voucher part has to be displayed
389 if ($settings{'AUTH'} eq 'VOUCHER'){
390 &voucher();
391 }else{
392 #otherwise we show the licensepart
393 &show_license_connections();
394 }
395 }
396
397 sub agbbox(){
398 &getagb();
399 print<<END
400 <tr>
401 <td>
402 License agreement
403 </td>
404 <td>
405 <br>
406 <textarea cols="50" rows="10" name="AGB">$cgiparams{'AGB'}</textarea>
407 </td>
408 </tr>
409 END
410 ;
411 }
412
413 sub gencode(){
414 #generate a random code only letters from A-Z except 'O' and 0-9
415 my @chars = ("A".."N", "P".."Z", "0".."9");
416 my $randomstring;
417 $randomstring .= $chars[rand @chars] for 1..8;
418 return $randomstring;
419 }
420
421 sub voucher(){
422 #show voucher part
423 #calculate expiredate
424 my $expire;
425 if ($settings{'UNLIMITED'} eq 'on'){
426 $expire = $Lang::tr{'Captive nolimit'};
427 }else{
428 $expire = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$settings{'EXPIRE'}));
429 }
430
431 &Header::openbox('100%', 'left', $Lang::tr{'Captive voucher'});
432 print<<END
433 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
434 <table class='tbl'>
435 <tr>
436 <th align='center' width='20%'>$Lang::tr{'Captive voucher'}</th><th th align='center' width='25%'>$Lang::tr{'Captive expire'}</th><th align='center' width='55%'>$Lang::tr{'remark'}</th></tr>
437 END
438 ;
439
440 $cgiparams{'CODE'} = &gencode();
441 print "<tr><td><center><b><font size='5'>$cgiparams{'CODE'}</font></b></center></td><td><center><font size='3'>$expire</font></center></td><td><input type='text' name='REMARK' align='left' size='80'></td></tr>";
442 print "</table><br>";
443 print "<center><input type='submit' name='ACTION' value='$Lang::tr{'Captive voucherout'}'><input type='hidden' name='CODE' value='$cgiparams{'CODE'}'</center></form>";
444 &Header::closebox();
445 if (! -z $voucherout) { &show_voucher_out();}
446 if (! -z $clients) { &show_voucher_in_use();}
447 }
448
449 sub show_license_connections(){
450 #if there are active clients, show the box with active connections
451 return if ( -z $clients || ! -f $clients );
452 my $count=0;
453 my $col;
454 &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'});
455 print<<END
456 <center><table class='tbl'>
457 <tr>
458 <th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th th align='center' width='15%'>$Lang::tr{'Captive activated'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th align='center' width='50%'><font size='1'>$Lang::tr{'Captive mac'}</th><th th align='center' width='5%'>$Lang::tr{'delete'}</th></tr>
459 END
460 ;
461 #read all clients from hash and show table
462 &General::readhasharray("$clients", \%clientshash);
463 foreach my $key (keys %clientshash){
464 my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]));
465 my $endtime;
466 if ($clientshash{$key}[3] eq '0'){
467 $endtime=$Lang::tr{'Captive nolimit'};
468 }else{
469 $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3]));
470 }
471
472 if ($count % 2){
473 print" <tr>";
474 $col="bgcolor='$color{'color20'}'";
475 }else{
476 $col="bgcolor='$color{'color22'}'";
477 print" <tr>";
478 }
479 print "<td $col><center>$clientshash{$key}[4]</td><td $col><center>$starttime ";
480 print "</center></td><td $col><center>$endtime ";
481 print "</td><td $col><center>$clientshash{$key}[0]</td><td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherinuse' /><input type='hidden' name='key' value='$clientshash{$key}[0]' /></form></tr>";
482 $count++;
483 }
484
485 print "</table>";
486 &Header::closebox();
487 }
488
489 sub show_voucher_out(){
490 #if there are already generated but unsused vouchers, print a table
491 return if ( -z $voucherout);
492 my $count=0;
493 my $col;
494 &Header::openbox('100%', 'left', $Lang::tr{'Captive vout'});
495 print<<END
496 <center><table class='tbl' border='0'>
497 <tr>
498 <th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th align='center' width='15%'>$Lang::tr{'date'}</th><th th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th align='center' width='60%'>$Lang::tr{'remark'}</th><th align='center' width='5%'>$Lang::tr{'delete'}</th></tr>
499 END
500 ;
501 &General::readhasharray("$voucherout", \%voucherhash);
502 foreach my $key (keys %voucherhash)
503 {
504 my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($voucherhash{$key}[0]));
505 my $endtime;
506 if ($voucherhash{$key}[2] eq '0'){
507 $endtime=$Lang::tr{'Captive nolimit'};
508 }else{
509 $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$voucherhash{$key}[2]));
510 }
511
512 if ($count % 2){
513 print" <tr>";
514 $col="bgcolor='$color{'color20'}'";
515 }else{
516 $col="bgcolor='$color{'color22'}'";
517 print" <tr>";
518 }
519
520 print "<td $col><center><b>$voucherhash{$key}[1]</b></td>";
521 print "<td $col><center>$starttime</td>";
522 print "<td $col><center>$endtime</td>";
523 print "<td $col align='center'>$voucherhash{$key}[3]</td>";
524 print "<td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherout' /><input type='hidden' name='key' value='$voucherhash{$key}[0]' /></form></tr>";
525 $count++;
526 }
527
528 print "</table>";
529 &Header::closebox();
530 }
531
532 sub show_voucher_in_use(){
533 #if there are active clients which use vouchers show table
534 return if ( -z $clients || ! -f $clients );
535 my $count=0;
536 my $col;
537 &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'});
538 print<<END
539 <center><table class='tbl' width='100%'>
540 <tr>
541 <th align='center' width='15%'>$Lang::tr{'Captive voucher'}</th><th th align='center' width='15%'>$Lang::tr{'Captive activated'}</th><th align='center' width='15%'>$Lang::tr{'Captive expire'}</th><th align='center' width='10%'>$Lang::tr{'Captive mac'}</th><th align='center' width='43%'>$Lang::tr{'remark'}</th><th th align='center' width='5%'>$Lang::tr{'delete'}</th></tr>
542 END
543 ;
544 &General::readhasharray("$clients", \%clientshash);
545 foreach my $key (keys %clientshash)
546 {
547 #calculate time from clientshash (starttime)
548 my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]));
549 #calculate endtime from clientshash
550 my $endtime;
551 if ($clientshash{$key}[3] eq '0'){
552 $endtime=$Lang::tr{'Captive nolimit'};
553 }else{
554 $endtime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3]));
555 }
556
557 if ($count % 2){
558 print" <tr>";
559 $col="bgcolor='$color{'color20'}'";
560 }else{
561 $col="bgcolor='$color{'color22'}'";
562 print" <tr>";
563 }
564
565 print "<td $col><center><b>$clientshash{$key}[4]</b></td><td $col><center>$starttime ";
566 print "</center></td><td $col><center>$endtime</center></td><td $col><center>$clientshash{$key}[0]</td><td $col><center>$clientshash{$key}[5]</center>";
567 print "</td><td $col><form method='post'><center><input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' /><form method='post'><input type='hidden' name='ACTION' value='delvoucherinuse' /><input type='hidden' name='key' value='$clientshash{$key}[0]' /></form></tr>";
568 $count++;
569 }
570
571 print "</table>";
572 &Header::closebox();
573 }
574
575 sub validremark
576 {
577 # Checks a hostname against RFC1035
578 my $remark = $_[0];
579 # Each part should be at least two characters in length
580 # but no more than 63 characters
581 if (length ($remark) < 1 || length ($remark) > 255) {
582 return 0;}
583 # Only valid characters are a-z, A-Z, 0-9 and -
584 if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) {
585 return 0;}
586 # First character can only be a letter or a digit
587 if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) {
588 return 0;}
589 # Last character can only be a letter or a digit
590 if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) {
591 return 0;}
592 return 1;
593 }
594
595 sub pngsize {
596 my $Buffer = shift;
597 my ($width,$height) = ( undef, undef );
598
599 if ($Buffer =~ /IHDR(.{8})/) {
600 my $PNG = $1;
601 ($width,$height) = unpack( "NN", $PNG );
602 } else {
603 $width=$Lang::tr{'acct invalid png'};
604 };
605 return ($width,$height);
606 }
607
608 sub error{
609 #if an errormessage exits, show a box with errormessage
610 if ($errormessage) {
611 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
612 print "<class name='base'>$errormessage\n";
613 print "&nbsp;</class>\n";
614 &Header::closebox();
615 }
616 }
617
618 &Header::closebigbox();
619 &Header::closepage();