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