]>
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 | |
97b91e8a MT |
34 | my $coupons = "${General::swroot}/captive/coupons"; |
35 | my %couponhash = (); | |
36 | ||
8b920789 AM |
37 | my %settings=(); |
38 | my %mainsettings; | |
39 | my %color; | |
40 | my %cgiparams=(); | |
41 | my %netsettings=(); | |
42 | my %checked=(); | |
43 | my $errormessage=''; | |
8b920789 | 44 | my $clients="${General::swroot}/captive/clients"; |
8b920789 AM |
45 | my %clientshash=(); |
46 | my $settingsfile="${General::swroot}/captive/settings"; | |
b32d9e92 | 47 | my $logopath = "/srv/web/ipfire/html/captive/logo"; |
e14adf75 | 48 | unless (-e $settingsfile) { system("touch $settingsfile"); } |
8b920789 AM |
49 | |
50 | &Header::getcgihash(\%cgiparams); | |
51 | ||
52 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
53 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
54 | &General::readhash("$settingsfile", \%settings) if(-f $settingsfile); | |
55 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
56 | ||
57 | &Header::showhttpheaders(); | |
58 | ||
59 | #actions | |
60 | if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}"){ | |
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 | ||
97b91e8a MT |
122 | if ($cgiparams{'ACTION'} eq "$Lang::tr{'Captive generate coupon'}"){ |
123 | # Generates a new coupon | |
8b920789 | 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 | } | |
97b91e8a MT |
138 | #check if we already have a coupon with same code |
139 | &General::readhasharray($coupons, \%couponhash) if (-e $coupons); | |
140 | foreach my $key (keys %couponhash) { | |
141 | if($couponhash{$key}[1] eq $cgiparams{'CODE'}){ | |
8b920789 AM |
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 | |
97b91e8a | 157 | my $key=&General::findhasharraykey (\%couponhash); |
8b920789 | 158 | #initialize all fields with '' |
97b91e8a | 159 | foreach my $i (0 .. 3) { $couponhash{$key}[$i] = "";} |
8b920789 | 160 | #define fields |
97b91e8a MT |
161 | $couponhash{$key}[0] = $date; |
162 | $couponhash{$key}[1] = $cgiparams{'CODE'}; | |
163 | $couponhash{$key}[2] = $settings{'EXPIRE'}; | |
164 | $couponhash{$key}[3] = $cgiparams{'REMARK'}; | |
8b920789 | 165 | #write values to disk |
97b91e8a | 166 | &General::writehasharray($coupons, \%couponhash); |
8b920789 AM |
167 | |
168 | #now prepare log entry, get expiring date for voucher and decode remark for logfile | |
97b91e8a MT |
169 | my $expdate=localtime(time()+$couponhash{$key}[3]); |
170 | my $rem=HTML::Entities::decode_entities($couponhash{$key}[4]); | |
8b920789 AM |
171 | |
172 | #write logfile entry | |
97b91e8a | 173 | &General::log("Captive", "Generated new coupon $couponhash{$key}[1] $couponhash{$key}[2] hours valid expires on $expdate remark $rem"); |
8b920789 AM |
174 | } |
175 | } | |
176 | ||
97b91e8a | 177 | if ($cgiparams{'ACTION'} eq 'delete-coupon') { |
8b920789 AM |
178 | #deletes an already generated but unused voucher |
179 | ||
180 | #read all generated vouchers | |
97b91e8a MT |
181 | &General::readhasharray($coupons, \%couponhash) if (-e $coupons); |
182 | foreach my $key (keys %couponhash) { | |
183 | if($cgiparams{'key'} eq $couponhash{$key}[0]){ | |
8b920789 | 184 | #write logenty with decoded remark |
97b91e8a MT |
185 | my $rem=HTML::Entities::decode_entities($couponhash{$key}[4]); |
186 | &General::log("Captive", "Delete unused coupon $couponhash{$key}[1] $couponhash{$key}[2] hours valid expires on $couponhash{$key}[3] remark $rem"); | |
8b920789 | 187 | #delete line from hash |
97b91e8a | 188 | delete $couponhash{$key}; |
8b920789 AM |
189 | last; |
190 | } | |
191 | } | |
192 | #write back hash | |
97b91e8a | 193 | &General::writehasharray($coupons, \%couponhash); |
8b920789 AM |
194 | } |
195 | ||
97b91e8a | 196 | if ($cgiparams{'ACTION'} eq 'delete-client') { |
8b920789 AM |
197 | #delete voucher and connection in use |
198 | ||
199 | #read all active clients | |
97b91e8a | 200 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 AM |
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 | |
97b91e8a | 206 | &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 |
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 |
228 | sub 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 | ||
240 | sub 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> | |
247 | END | |
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 | |
e01c5ab7 | 269 | print<<END |
297ebdd4 | 270 | </tr> |
8b920789 | 271 | <tr> |
827d3f61 | 272 | <td> |
8b920789 AM |
273 | $Lang::tr{'Captive authentication'} |
274 | </td> | |
827d3f61 | 275 | <td> |
9735e167 | 276 | <select name='AUTH'> |
8b920789 AM |
277 | END |
278 | ; | |
9735e167 MT |
279 | print "<option value='TERMS' "; |
280 | print " selected='selected'" if ($settings{'AUTH'} eq 'TERMS'); | |
281 | print ">$Lang::tr{'Captive terms'}</option>"; | |
e01c5ab7 | 282 | |
97b91e8a MT |
283 | print "<option value='COUPON' "; |
284 | print " selected='selected'" if ($settings{'AUTH'} eq 'COUPON'); | |
285 | print ">$Lang::tr{'Captive coupon'}</option>"; | |
e01c5ab7 | 286 | |
8b920789 AM |
287 | print<<END |
288 | </select> | |
289 | </td> | |
290 | </tr> | |
8b920789 AM |
291 | END |
292 | ; | |
9735e167 MT |
293 | if ($settings{'AUTH'} eq 'TERMS') { |
294 | my $terms = &getterms(); | |
295 | print <<END; | |
296 | <tr> | |
297 | <td></td> | |
298 | <td> | |
299 | <textarea cols="50" rows="10" name="TERMS">$terms</textarea> | |
300 | </td> | |
301 | </tr> | |
302 | END | |
303 | } | |
8b920789 | 304 | |
297ebdd4 MT |
305 | print<<END; |
306 | <tr> | |
307 | <td colspan="2"> | |
308 | <br> | |
309 | <strong>$Lang::tr{'Captive branding'}</strong> | |
310 | </td> | |
311 | </tr> | |
312 | <tr> | |
313 | <td> | |
314 | $Lang::tr{'Captive title'} | |
315 | </td> | |
316 | <td> | |
317 | <input type='text' name='TITLE' value="$settings{'TITLE'}" size='40'> | |
318 | </td> | |
319 | </tr> | |
320 | <tr> | |
321 | <td>$Lang::tr{'Captive brand color'}</td> | |
322 | <td> | |
323 | <input type="color" name="COLOR" value="$settings{'COLOR'}"> | |
324 | </td> | |
325 | </tr> | |
326 | END | |
327 | ||
b32d9e92 | 328 | #Logo Upload |
827d3f61 MT |
329 | print <<END; |
330 | <tr> | |
331 | <td> | |
332 | $Lang::tr{'Captive logo_upload'} | |
333 | <br> | |
334 | $Lang::tr{'Captive logo_upload1'} | |
335 | </td> | |
336 | <td> | |
337 | <INPUT TYPE='file' NAME='uploaded_file' SIZE=30 MAXLENGTH=80> | |
338 | </td> | |
339 | </tr> | |
340 | END | |
341 | ||
b32d9e92 AM |
342 | #Show Logo in webinterface with 1/2 size if set |
343 | if (-f "$logopath/logo.png"){ | |
827d3f61 | 344 | print"<tr><td>$Lang::tr{'Captive logo_set'}</td>"; |
b32d9e92 AM |
345 | print"<td><img src='/captive/logo/logo.png' alt='$logopath/logo.png' width='25%' height='25%' /></td></tr>"; |
346 | }else{ | |
827d3f61 | 347 | print"<tr><td>$Lang::tr{'Captive logo_set'}</td>"; |
b32d9e92 AM |
348 | print"<td><br>$Lang::tr{'no'}</td></tr>"; |
349 | } | |
827d3f61 | 350 | |
297ebdd4 | 351 | print <<END; |
8b920789 | 352 | <tr> |
827d3f61 | 353 | <td></td> |
8b920789 | 354 | <td align='right'> |
827d3f61 | 355 | <input type='submit' name='ACTION' value="$Lang::tr{'save'}"/> |
8b920789 AM |
356 | </td> |
357 | </tr> | |
297ebdd4 | 358 | </table></form> |
8b920789 | 359 | END |
297ebdd4 | 360 | |
8b920789 AM |
361 | &Header::closebox(); |
362 | ||
97b91e8a MT |
363 | #if settings is set to use coupons, the coupon part has to be displayed |
364 | if ($settings{'AUTH'} eq 'COUPON'){ | |
365 | &coupons(); | |
8b920789 AM |
366 | }else{ |
367 | #otherwise we show the licensepart | |
368 | &show_license_connections(); | |
369 | } | |
370 | } | |
371 | ||
8b920789 AM |
372 | sub gencode(){ |
373 | #generate a random code only letters from A-Z except 'O' and 0-9 | |
374 | my @chars = ("A".."N", "P".."Z", "0".."9"); | |
375 | my $randomstring; | |
376 | $randomstring .= $chars[rand @chars] for 1..8; | |
377 | return $randomstring; | |
378 | } | |
379 | ||
97b91e8a MT |
380 | sub coupons() { |
381 | &Header::openbox('100%', 'left', $Lang::tr{'Captive generate coupon'}); | |
08061703 AM |
382 | print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>"; |
383 | print "<table border='0' width='100%'>"; | |
384 | print "<tr><td width='30%'><br>$Lang::tr{'Captive vouchervalid'}</td><td width='70%'><br>"; | |
385 | ||
386 | print "<table class='tbl' border='0' width='100%'>"; | |
387 | 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>"; | |
388 | ||
389 | #print hour-dropdownbox | |
390 | my $hrs=3600; | |
391 | print "<tr height='40px'><td><select name='EXP_HOUR' style='width:8em;'>"; | |
392 | print "<option value='0' "; | |
393 | print " selected='selected'" if ($settings{'EXP_HOUR'} eq '0'); | |
394 | print ">--</option>"; | |
395 | for (my $i = 1; $i<25; $i++){ | |
396 | my $exp_sec = $i * $hrs; | |
397 | print "<option value='$exp_sec' "; | |
398 | print " selected='selected'" if ($settings{'EXP_HOUR'} eq $exp_sec); | |
399 | print ">$i</option>"; | |
400 | } | |
401 | print "</td><td>"; | |
402 | ||
403 | #print day-dropdownbox | |
404 | my $days=3600*24; | |
405 | print "<select name='EXP_DAY' style='width:8em;'>"; | |
406 | print "<option value='0' "; | |
407 | print " selected='selected'" if ($settings{'EXP_DAY'} eq '0'); | |
408 | print ">--</option>"; | |
409 | for (my $i = 1; $i<8; $i++){ | |
410 | my $exp_sec = $i * $days; | |
411 | print "<option value='$exp_sec' "; | |
412 | print " selected='selected'" if ($settings{'EXP_DAY'} eq $exp_sec); | |
413 | print ">$i</option>"; | |
414 | } | |
415 | print "</td><td>"; | |
416 | ||
417 | #print week-dropdownbox | |
418 | my $week=3600*24*7; | |
419 | print "<select name='EXP_WEEK' style='width:8em;'>"; | |
420 | print "<option value='0' "; | |
421 | print " selected='selected'" if ($settings{'EXP_WEEK'} eq '0'); | |
422 | print ">--</option>"; | |
423 | for (my $i = 1; $i<5; $i++){ | |
424 | my $exp_sec = $i * $week; | |
425 | print "<option value='$exp_sec' "; | |
426 | print " selected='selected'" if ($settings{'EXP_WEEK'} eq $exp_sec); | |
427 | print ">$i</option>"; | |
428 | } | |
429 | print "</td><td>"; | |
430 | ||
431 | #print month-dropdownbox | |
432 | my $month=3600*24*30; | |
433 | print "<select name='EXP_MONTH' style='width:8em;'>"; | |
434 | print "<option value='0' "; | |
435 | print " selected='selected'" if ($settings{'EXP_MONTH'} eq '0'); | |
436 | print ">--</option>"; | |
437 | for (my $i = 1; $i<13; $i++){ | |
438 | my $exp_sec = $i * $month; | |
439 | print "<option value='$exp_sec' "; | |
440 | print " selected='selected'" if ($settings{'EXP_MONTH'} eq $exp_sec); | |
441 | print ">$i</option>"; | |
442 | } | |
443 | print "</td>"; | |
444 | print "<td> <input type='checkbox' name='UNLIMITED' $checked{'UNLIMITED'}{'on'} /></td><td> <b>$Lang::tr{'Captive nolimit'}</b></td>"; | |
445 | print "</tr></table>"; | |
446 | print "</td></tr>"; | |
447 | print "<tr><td><br>$Lang::tr{'remark'}</td><td><br><input type='text' style='width: 98%;' name='REMARK' align='left'></td></tr>"; | |
448 | print "<tr><td> </td><td></td></tr></table><br><br>"; | |
8b920789 | 449 | $cgiparams{'CODE'} = &gencode(); |
97b91e8a | 450 | 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>"; |
08061703 | 451 | |
8b920789 | 452 | &Header::closebox(); |
97b91e8a MT |
453 | |
454 | # Show all coupons if exist | |
455 | if (! -z $coupons) { | |
456 | &show_coupons(); | |
457 | } | |
458 | ||
459 | if (! -z $clients) { | |
460 | &show_clients(); | |
461 | } | |
8b920789 AM |
462 | } |
463 | ||
464 | sub show_license_connections(){ | |
465 | #if there are active clients, show the box with active connections | |
466 | return if ( -z $clients || ! -f $clients ); | |
467 | my $count=0; | |
468 | my $col; | |
469 | &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'}); | |
470 | print<<END | |
471 | <center><table class='tbl'> | |
472 | <tr> | |
97b91e8a | 473 | <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 |
474 | END |
475 | ; | |
476 | #read all clients from hash and show table | |
97b91e8a | 477 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 | 478 | foreach my $key (keys %clientshash){ |
c7e78cc6 AM |
479 | my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2])); |
480 | my $endtime; | |
481 | if ($clientshash{$key}[3] eq '0'){ | |
482 | $endtime=$Lang::tr{'Captive nolimit'}; | |
483 | }else{ | |
484 | $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3])); | |
485 | } | |
486 | ||
8b920789 AM |
487 | if ($count % 2){ |
488 | print" <tr>"; | |
489 | $col="bgcolor='$color{'color20'}'"; | |
490 | }else{ | |
491 | $col="bgcolor='$color{'color22'}'"; | |
492 | print" <tr>"; | |
493 | } | |
c7e78cc6 AM |
494 | print "<td $col><center>$clientshash{$key}[4]</td><td $col><center>$starttime "; |
495 | print "</center></td><td $col><center>$endtime "; | |
97b91e8a | 496 | 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 |
497 | $count++; |
498 | } | |
499 | ||
500 | print "</table>"; | |
501 | &Header::closebox(); | |
502 | } | |
503 | ||
97b91e8a MT |
504 | sub show_coupons() { |
505 | #if there are already generated but unsused coupons, print a table | |
8b920789 AM |
506 | my $count=0; |
507 | my $col; | |
508 | &Header::openbox('100%', 'left', $Lang::tr{'Captive vout'}); | |
509 | print<<END | |
e01c5ab7 | 510 | <center><table class='tbl' border='0'> |
8b920789 | 511 | <tr> |
97b91e8a | 512 | <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 |
513 | END |
514 | ; | |
97b91e8a MT |
515 | &General::readhasharray($coupons, \%couponhash) if (-e $coupons); |
516 | foreach my $key (keys %couponhash) | |
8b920789 | 517 | { |
97b91e8a | 518 | my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($couponhash{$key}[0])); |
c7e78cc6 | 519 | my $endtime; |
97b91e8a | 520 | if ($couponhash{$key}[2] eq '0'){ |
c7e78cc6 AM |
521 | $endtime=$Lang::tr{'Captive nolimit'}; |
522 | }else{ | |
97b91e8a | 523 | $endtime=sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime(time()+$couponhash{$key}[2])); |
c7e78cc6 AM |
524 | } |
525 | ||
8b920789 AM |
526 | if ($count % 2){ |
527 | print" <tr>"; | |
528 | $col="bgcolor='$color{'color20'}'"; | |
529 | }else{ | |
530 | $col="bgcolor='$color{'color22'}'"; | |
531 | print" <tr>"; | |
532 | } | |
c7e78cc6 | 533 | |
97b91e8a | 534 | print "<td $col><center><b>$couponhash{$key}[1]</b></td>"; |
c7e78cc6 | 535 | print "<td $col><center>$starttime</td>"; |
e01c5ab7 | 536 | print "<td $col><center>$endtime</td>"; |
97b91e8a MT |
537 | print "<td $col align='center'>$couponhash{$key}[3]</td>"; |
538 | 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 |
539 | $count++; |
540 | } | |
c7e78cc6 | 541 | |
8b920789 AM |
542 | print "</table>"; |
543 | &Header::closebox(); | |
544 | } | |
545 | ||
97b91e8a MT |
546 | sub show_clients() { |
547 | #if there are active clients which use coupons show table | |
8b920789 AM |
548 | return if ( -z $clients || ! -f $clients ); |
549 | my $count=0; | |
550 | my $col; | |
551 | &Header::openbox('100%', 'left', $Lang::tr{'Captive voactive'}); | |
552 | print<<END | |
c7e78cc6 | 553 | <center><table class='tbl' width='100%'> |
8b920789 | 554 | <tr> |
97b91e8a | 555 | <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 |
556 | END |
557 | ; | |
97b91e8a | 558 | &General::readhasharray($clients, \%clientshash) if (-e $clients); |
8b920789 AM |
559 | foreach my $key (keys %clientshash) |
560 | { | |
c7e78cc6 AM |
561 | #calculate time from clientshash (starttime) |
562 | my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2])); | |
563 | #calculate endtime from clientshash | |
564 | my $endtime; | |
565 | if ($clientshash{$key}[3] eq '0'){ | |
566 | $endtime=$Lang::tr{'Captive nolimit'}; | |
567 | }else{ | |
568 | $endtime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]+$clientshash{$key}[3])); | |
569 | } | |
e01c5ab7 | 570 | |
8b920789 AM |
571 | if ($count % 2){ |
572 | print" <tr>"; | |
573 | $col="bgcolor='$color{'color20'}'"; | |
574 | }else{ | |
575 | $col="bgcolor='$color{'color22'}'"; | |
576 | print" <tr>"; | |
577 | } | |
e01c5ab7 | 578 | |
c7e78cc6 AM |
579 | print "<td $col><center><b>$clientshash{$key}[4]</b></td><td $col><center>$starttime "; |
580 | print "</center></td><td $col><center>$endtime</center></td><td $col><center>$clientshash{$key}[0]</td><td $col><center>$clientshash{$key}[5]</center>"; | |
97b91e8a | 581 | 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 |
582 | $count++; |
583 | } | |
c7e78cc6 | 584 | |
8b920789 AM |
585 | print "</table>"; |
586 | &Header::closebox(); | |
587 | } | |
588 | ||
e01c5ab7 AM |
589 | sub validremark |
590 | { | |
591 | # Checks a hostname against RFC1035 | |
592 | my $remark = $_[0]; | |
593 | # Each part should be at least two characters in length | |
594 | # but no more than 63 characters | |
595 | if (length ($remark) < 1 || length ($remark) > 255) { | |
596 | return 0;} | |
597 | # Only valid characters are a-z, A-Z, 0-9 and - | |
598 | if ($remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/\s]*$/) { | |
599 | return 0;} | |
600 | # First character can only be a letter or a digit | |
601 | if (substr ($remark, 0, 1) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/) { | |
602 | return 0;} | |
603 | # Last character can only be a letter or a digit | |
604 | if (substr ($remark, -1, 1) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/) { | |
605 | return 0;} | |
606 | return 1; | |
607 | } | |
608 | ||
b32d9e92 AM |
609 | sub pngsize { |
610 | my $Buffer = shift; | |
611 | my ($width,$height) = ( undef, undef ); | |
612 | ||
613 | if ($Buffer =~ /IHDR(.{8})/) { | |
614 | my $PNG = $1; | |
615 | ($width,$height) = unpack( "NN", $PNG ); | |
616 | } else { | |
52383f58 AM |
617 | $width="invalid"; |
618 | $height= "invalid"; | |
b32d9e92 AM |
619 | }; |
620 | return ($width,$height); | |
621 | } | |
622 | ||
8b920789 AM |
623 | sub error{ |
624 | #if an errormessage exits, show a box with errormessage | |
625 | if ($errormessage) { | |
626 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
627 | print "<class name='base'>$errormessage\n"; | |
628 | print " </class>\n"; | |
629 | &Header::closebox(); | |
630 | } | |
631 | } | |
632 | ||
633 | &Header::closebigbox(); | |
634 | &Header::closepage(); |