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