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