]>
Commit | Line | Data |
---|---|---|
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 | 23 | use HTML::Entities(); |
b32d9e92 AM |
24 | use File::Basename; |
25 | ||
8b920789 AM |
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"; | |
e14adf75 | 33 | |
278309b9 MT |
34 | my %selected = (); |
35 | ||
97b91e8a MT |
36 | my $coupons = "${General::swroot}/captive/coupons"; |
37 | my %couponhash = (); | |
38 | ||
e2752bfe MT |
39 | my $logo = "${General::swroot}/captive/logo.dat"; |
40 | ||
8b920789 AM |
41 | my %settings=(); |
42 | my %mainsettings; | |
43 | my %color; | |
44 | my %cgiparams=(); | |
45 | my %netsettings=(); | |
46 | my %checked=(); | |
47 | my $errormessage=''; | |
8b920789 | 48 | my $clients="${General::swroot}/captive/clients"; |
8b920789 AM |
49 | my %clientshash=(); |
50 | my $settingsfile="${General::swroot}/captive/settings"; | |
e14adf75 | 51 | unless (-e $settingsfile) { system("touch $settingsfile"); } |
8b920789 AM |
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 | ||
b7a126d9 | 62 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
e2752bfe | 63 | my $file = $cgiparams{'logo'}; |
b7a126d9 MT |
64 | if ($file) { |
65 | # Check if the file extension is PNG/JPEG | |
b32d9e92 | 66 | chomp $file; |
b7a126d9 | 67 | |
b32d9e92 | 68 | my ($name, $path, $ext) = fileparse($file, qr/\.[^.]*$/); |
b7a126d9 MT |
69 | if ($ext ne ".png" && $ext ne ".jpg" && $ext ne ".jpeg") { |
70 | $errormessage = $Lang::tr{'Captive wrong ext'}; | |
b32d9e92 | 71 | } |
c7e78cc6 | 72 | } |
6945954c AM |
73 | |
74 | $settings{'ENABLE_GREEN'} = $cgiparams{'ENABLE_GREEN'}; | |
75 | $settings{'ENABLE_BLUE'} = $cgiparams{'ENABLE_BLUE'}; | |
76 | $settings{'AUTH'} = $cgiparams{'AUTH'}; | |
6945954c | 77 | $settings{'TITLE'} = $cgiparams{'TITLE'}; |
f8d35875 | 78 | $settings{'COLOR'} = $cgiparams{'COLOR'}; |
278309b9 | 79 | $settings{'SESSION_TIME'} = $cgiparams{'SESSION_TIME'}; |
6945954c | 80 | |
b32d9e92 AM |
81 | if (!$errormessage){ |
82 | #Check if we need to upload a new logo | |
e2752bfe MT |
83 | if ($file) { |
84 | # Save logo | |
85 | my ($filehandle) = CGI::upload("logo"); | |
86 | ||
87 | # XXX check filesize | |
88 | ||
89 | open(FILE, ">$logo"); | |
b32d9e92 | 90 | binmode $filehandle; |
e2752bfe MT |
91 | while (<$filehandle>) { |
92 | print FILE; | |
b32d9e92 | 93 | } |
e2752bfe | 94 | close(FILE); |
b32d9e92 | 95 | } |
c7e78cc6 | 96 | |
b32d9e92 AM |
97 | &General::writehash("$settingsfile", \%settings); |
98 | ||
9735e167 MT |
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'} = ""; | |
b32d9e92 | 106 | } |
9735e167 | 107 | |
b32d9e92 AM |
108 | #execute binary to reload firewall rules |
109 | system("/usr/local/bin/captivectrl"); | |
45129439 AM |
110 | |
111 | if ($cgiparams{'ENABLE_BLUE'} eq 'on'){ | |
112 | system("/usr/local/bin/wirelessctrl"); | |
113 | } | |
8b920789 | 114 | } |
8b920789 AM |
115 | } |
116 | ||
5cd9e28b | 117 | if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive generate coupon'}") { |
08061703 AM |
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 | } | |
8b920789 | 131 | |
e01c5ab7 AM |
132 | #check valid remark |
133 | if ($cgiparams{'REMARK'} ne '' && !&validremark($cgiparams{'REMARK'})){ | |
134 | $errormessage=$Lang::tr{'fwhost err remark'}; | |
135 | } | |
136 | ||
5cd9e28b | 137 | if (!$errormessage) { |
9cba29f1 MT |
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 | ||
5cd9e28b MT |
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] = ""; } | |
8b920789 | 169 | |
5cd9e28b MT |
170 | $couponhash{$key}[0] = $now; |
171 | $couponhash{$key}[1] = $code; | |
172 | $couponhash{$key}[2] = $expires; | |
173 | $couponhash{$key}[3] = $cgiparams{'REMARK'}; | |
174 | } | |
8b920789 | 175 | |
5cd9e28b MT |
176 | # Save everything to disk |
177 | &General::writehasharray($coupons, \%couponhash); | |
8b920789 AM |
178 | } |
179 | } | |
180 | ||
97b91e8a | 181 | if ($cgiparams{'ACTION'} eq 'delete-coupon') { |
8b920789 AM |
182 | #deletes an already generated but unused voucher |
183 | ||
184 | #read all generated vouchers | |
97b91e8a MT |
185 | &General::readhasharray($coupons, \%couponhash) if (-e $coupons); |
186 | foreach my $key (keys %couponhash) { | |
187 | if($cgiparams{'key'} eq $couponhash{$key}[0]){ | |
8b920789 | 188 | #write logenty with decoded remark |
97b91e8a MT |
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"); | |
8b920789 | 191 | #delete line from hash |
97b91e8a | 192 | delete $couponhash{$key}; |
8b920789 AM |
193 | last; |
194 | } | |
195 | } | |
196 | #write back hash | |
97b91e8a | 197 | &General::writehasharray($coupons, \%couponhash); |
8b920789 AM |
198 | } |
199 | ||
97b91e8a | 200 | if ($cgiparams{'ACTION'} eq 'delete-client') { |
8b920789 AM |
201 | #delete voucher and connection in use |
202 | ||
203 | #read all active clients | |
97b91e8a | 204 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 AM |
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 | |
97b91e8a | 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"); |
8b920789 AM |
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 | ||
a41fe924 MT |
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(); | |
8b920789 AM |
231 | } |
232 | ||
a41fe924 MT |
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 | |
8b920789 AM |
237 | <table width='100%' border="0"> |
238 | <tr> | |
239 | END | |
240 | ; | |
e01c5ab7 | 241 | |
a41fe924 MT |
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'"; | |
8b920789 | 246 | |
a41fe924 MT |
247 | $checked{'ENABLE_BLUE'}{'off'} = ''; |
248 | $checked{'ENABLE_BLUE'}{'on'} = ''; | |
249 | $checked{'ENABLE_BLUE'}{$settings{'ENABLE_BLUE'}} = "checked='checked'"; | |
c7e78cc6 | 250 | |
a41fe924 MT |
251 | $checked{'UNLIMITED'}{'off'} = ''; |
252 | $checked{'UNLIMITED'}{'on'} = ''; | |
253 | $checked{'UNLIMITED'}{$settings{'UNLIMITED'}} = "checked='checked'"; | |
254 | ||
e7d16ea5 MT |
255 | $selected{'AUTH'} = (); |
256 | $selected{'AUTH'}{'COUPON'} = ""; | |
257 | $selected{'AUTH'}{'TERMS'} = ""; | |
258 | $selected{'AUTH'}{$settings{'AUTH'}} = "selected"; | |
259 | ||
a41fe924 MT |
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 | } | |
e01c5ab7 | 266 | |
e01c5ab7 | 267 | print<<END |
a41fe924 MT |
268 | </tr> |
269 | <tr> | |
270 | <td> | |
271 | $Lang::tr{'Captive authentication'} | |
272 | </td> | |
273 | <td> | |
274 | <select name='AUTH'> | |
e7d16ea5 MT |
275 | <option value="TERMS" $selected{'AUTH'}{'TERMS'} >$Lang::tr{'Captive terms'}</option> |
276 | <option value="COUPON" $selected{'AUTH'}{'COUPON'}>$Lang::tr{'Captive coupon'}</option> | |
a41fe924 MT |
277 | </select> |
278 | </td> | |
279 | </tr> | |
8b920789 AM |
280 | END |
281 | ; | |
8b920789 | 282 | |
a41fe924 MT |
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; | |
297ebdd4 | 294 | <tr> |
a41fe924 | 295 | <td></td> |
297ebdd4 | 296 | <td> |
a41fe924 | 297 | <textarea cols="50" rows="10" name="TERMS">$terms</textarea> |
297ebdd4 MT |
298 | </td> |
299 | </tr> | |
a41fe924 | 300 | |
297ebdd4 | 301 | <tr> |
a41fe924 | 302 | <td>$Lang::tr{'Captive client session expiry time'}</td> |
297ebdd4 | 303 | <td> |
a41fe924 MT |
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> | |
297ebdd4 MT |
311 | </td> |
312 | </tr> | |
313 | END | |
a41fe924 | 314 | } |
297ebdd4 | 315 | |
a41fe924 MT |
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> | |
a41fe924 MT |
337 | <tr> |
338 | <td> | |
81019811 | 339 | $Lang::tr{'Captive upload logo'} |
a41fe924 MT |
340 | </td> |
341 | <td> | |
342 | <input type="file" name="logo"> | |
81019811 | 343 | <br>$Lang::tr{'Captive upload logo recommendations'} |
a41fe924 MT |
344 | </td> |
345 | </tr> | |
e2752bfe | 346 | END |
827d3f61 | 347 | |
a41fe924 | 348 | if (-e $logo) { |
297ebdd4 | 349 | print <<END; |
8b920789 | 350 | <tr> |
a41fe924 MT |
351 | <td>$Lang::tr{'Captive logo uploaded'}</td> |
352 | <td>$Lang::tr{'yes'}</td> | |
8b920789 | 353 | </tr> |
a41fe924 MT |
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> | |
297ebdd4 | 364 | </table></form> |
8b920789 | 365 | END |
297ebdd4 | 366 | |
a41fe924 | 367 | &Header::closebox(); |
8b920789 | 368 | |
a41fe924 MT |
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($_)); | |
8b920789 | 383 | } |
a41fe924 MT |
384 | close(FILE); |
385 | ||
386 | return join(/\n/, @ret); | |
8b920789 AM |
387 | } |
388 | ||
8b920789 AM |
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 | ||
97b91e8a MT |
397 | sub coupons() { |
398 | &Header::openbox('100%', 'left', $Lang::tr{'Captive generate coupon'}); | |
4f75fbfe MT |
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 | |
08061703 AM |
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 | } | |
4f75fbfe MT |
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"> | |
5cd9e28b MT |
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 | ||
4f75fbfe MT |
508 | <input type="submit" name="ACTION" value="$Lang::tr{'Captive generate coupon'}"> |
509 | </div> | |
510 | </form> | |
511 | END | |
08061703 | 512 | |
8b920789 | 513 | &Header::closebox(); |
97b91e8a MT |
514 | |
515 | # Show all coupons if exist | |
516 | if (! -z $coupons) { | |
517 | &show_coupons(); | |
518 | } | |
519 | ||
520 | if (! -z $clients) { | |
521 | &show_clients(); | |
522 | } | |
8b920789 AM |
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> | |
97b91e8a | 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> |
8b920789 AM |
535 | END |
536 | ; | |
537 | #read all clients from hash and show table | |
97b91e8a | 538 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 | 539 | foreach my $key (keys %clientshash){ |
c7e78cc6 AM |
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 | ||
8b920789 AM |
548 | if ($count % 2){ |
549 | print" <tr>"; | |
550 | $col="bgcolor='$color{'color20'}'"; | |
551 | }else{ | |
552 | $col="bgcolor='$color{'color22'}'"; | |
553 | print" <tr>"; | |
554 | } | |
c7e78cc6 AM |
555 | print "<td $col><center>$clientshash{$key}[4]</td><td $col><center>$starttime "; |
556 | print "</center></td><td $col><center>$endtime "; | |
97b91e8a | 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>"; |
8b920789 AM |
558 | $count++; |
559 | } | |
560 | ||
561 | print "</table>"; | |
562 | &Header::closebox(); | |
563 | } | |
564 | ||
97b91e8a MT |
565 | sub show_coupons() { |
566 | #if there are already generated but unsused coupons, print a table | |
8b920789 AM |
567 | my $count=0; |
568 | my $col; | |
569 | &Header::openbox('100%', 'left', $Lang::tr{'Captive vout'}); | |
570 | print<<END | |
e01c5ab7 | 571 | <center><table class='tbl' border='0'> |
8b920789 | 572 | <tr> |
97b91e8a | 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> |
8b920789 AM |
574 | END |
575 | ; | |
97b91e8a MT |
576 | &General::readhasharray($coupons, \%couponhash) if (-e $coupons); |
577 | foreach my $key (keys %couponhash) | |
8b920789 | 578 | { |
97b91e8a | 579 | my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($couponhash{$key}[0])); |
c7e78cc6 | 580 | my $endtime; |
97b91e8a | 581 | if ($couponhash{$key}[2] eq '0'){ |
c7e78cc6 AM |
582 | $endtime=$Lang::tr{'Captive nolimit'}; |
583 | }else{ | |
97b91e8a | 584 | $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$couponhash{$key}[2])); |
c7e78cc6 AM |
585 | } |
586 | ||
8b920789 AM |
587 | if ($count % 2){ |
588 | print" <tr>"; | |
589 | $col="bgcolor='$color{'color20'}'"; | |
590 | }else{ | |
591 | $col="bgcolor='$color{'color22'}'"; | |
592 | print" <tr>"; | |
593 | } | |
c7e78cc6 | 594 | |
97b91e8a | 595 | print "<td $col><center><b>$couponhash{$key}[1]</b></td>"; |
c7e78cc6 | 596 | print "<td $col><center>$starttime</td>"; |
e01c5ab7 | 597 | print "<td $col><center>$endtime</td>"; |
97b91e8a MT |
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>"; | |
8b920789 AM |
600 | $count++; |
601 | } | |
c7e78cc6 | 602 | |
8b920789 AM |
603 | print "</table>"; |
604 | &Header::closebox(); | |
605 | } | |
606 | ||
97b91e8a MT |
607 | sub show_clients() { |
608 | #if there are active clients which use coupons show table | |
8b920789 AM |
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 | |
c7e78cc6 | 614 | <center><table class='tbl' width='100%'> |
8b920789 | 615 | <tr> |
97b91e8a | 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> |
8b920789 AM |
617 | END |
618 | ; | |
97b91e8a | 619 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 AM |
620 | foreach my $key (keys %clientshash) |
621 | { | |
c7e78cc6 AM |
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 | } | |
e01c5ab7 | 631 | |
8b920789 AM |
632 | if ($count % 2){ |
633 | print" <tr>"; | |
634 | $col="bgcolor='$color{'color20'}'"; | |
635 | }else{ | |
636 | $col="bgcolor='$color{'color22'}'"; | |
637 | print" <tr>"; | |
638 | } | |
e01c5ab7 | 639 | |
c7e78cc6 AM |
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>"; | |
97b91e8a | 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>"; |
8b920789 AM |
643 | $count++; |
644 | } | |
c7e78cc6 | 645 | |
8b920789 AM |
646 | print "</table>"; |
647 | &Header::closebox(); | |
648 | } | |
649 | ||
e01c5ab7 AM |
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 | ||
8b920789 AM |
670 | &Header::closebigbox(); |
671 | &Header::closepage(); |