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