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