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