]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/captive.cgi
629acaee2be4420322eb750f836298fff1567408
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2016 IPFire Team <alexander.marx@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
27 use constant mm
=> 25.4 / 72 ;
29 # enable only the following on debugging purpose
31 #use CGI::Carp 'fatalsToBrowser';
33 require '/var/ipfire/general-functions.pl' ;
34 require "${General::swroot}/lang.pl" ;
35 require "${General::swroot}/header.pl" ;
39 my $coupons = "${General::swroot}/captive/coupons" ;
42 my $logo = "${General::swroot}/captive/logo.dat" ;
51 my $clients = "${General::swroot}/captive/clients" ;
53 my $settingsfile = "${General::swroot}/captive/settings" ;
54 unless (- e
$settingsfile ) { system ( "touch $settingsfile " ); }
56 & Header
:: getcgihash
( \
%cgiparams );
58 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
59 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
60 & General
:: readhash
( " $settingsfile " , \
%settings ) if (- f
$settingsfile );
61 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
63 if ( $cgiparams { 'ACTION' } eq "export-coupons" ) {
64 my $pdf = & generate_pdf
();
66 print "Content-Type: application/pdf \n " ;
67 print "Content-Disposition: attachment; filename=captive-portal-coupons.pdf \n " ;
68 print " \n " ; # end headers
77 & Header
:: showhttpheaders
();
79 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'save' }) {
80 my $file = $cgiparams { 'logo' };
82 # Check if the file extension is PNG/JPEG
85 my ( $name , $path , $ext ) = fileparse
( $file , qr/\.[^.]*$/ );
86 if ( $ext ne ".png" && $ext ne ".jpg" && $ext ne ".jpeg" ) {
87 $errormessage = $Lang :: tr
{ 'Captive wrong ext' };
91 $settings { 'ENABLE_GREEN' } = $cgiparams { 'ENABLE_GREEN' };
92 $settings { 'ENABLE_BLUE' } = $cgiparams { 'ENABLE_BLUE' };
93 $settings { 'AUTH' } = $cgiparams { 'AUTH' };
94 $settings { 'TITLE' } = $cgiparams { 'TITLE' };
95 $settings { 'COLOR' } = $cgiparams { 'COLOR' };
96 $settings { 'SESSION_TIME' } = $cgiparams { 'SESSION_TIME' };
99 #Check if we need to upload a new logo
102 my ( $filehandle ) = CGI
:: upload
( "logo" );
106 open ( FILE
, "> $logo " );
108 while (< $filehandle >) {
114 & General
:: writehash
( " $settingsfile " , \
%settings );
117 $cgiparams { 'TERMS' } = & Header
:: escape
( $cgiparams { 'TERMS' });
118 open ( FH
, ">:utf8" , "/var/ipfire/captive/terms.txt" ) or die ( "$!" );
119 print FH
$cgiparams { 'TERMS' };
121 $cgiparams { 'TERMS' } = "" ;
123 #execute binary to reload firewall rules
124 system ( "/usr/local/bin/captivectrl" );
126 if ( $cgiparams { 'ENABLE_BLUE' } eq 'on' ){
127 system ( "/usr/local/bin/wirelessctrl" );
132 if ( $cgiparams { 'ACTION' } eq " $Lang ::tr{'Captive generate coupon'}" ) {
134 if ( $cgiparams { 'EXP_HOUR' } + $cgiparams { 'EXP_DAY' } + $cgiparams { 'EXP_WEEK' } + $cgiparams { 'EXP_MONTH' } == 0 && $cgiparams { 'UNLIMITED' } == '' ) {
135 $errormessage = $Lang :: tr
{ 'Captive noexpiretime' };
139 if ( $cgiparams { 'REMARK' } ne '' && !& validremark
( $cgiparams { 'REMARK' })){
140 $errormessage = $Lang :: tr
{ 'fwhost err remark' };
143 if (! $errormessage ) {
144 # Remember selected values
145 foreach my $val (( "UNLIMITED" , "EXP_HOUR" , "EXP_DAY" , "EXP_WEEK" , "EXP_MONTH" )) {
146 $settings { $val } = $cgiparams { $val };
148 & General
:: writehash
( $settingsfile , \
%settings );
150 & General
:: readhasharray
( $coupons , \
%couponhash ) if (- e
$coupons );
153 # Calculate expiry time in seconds
156 if ( $settings { 'UNLIMITED' } ne 'on' ) {
157 $expires += $settings { 'EXP_HOUR' };
158 $expires += $settings { 'EXP_DAY' };
159 $expires += $settings { 'EXP_WEEK' };
160 $expires += $settings { 'EXP_MONTH' };
163 my $count = $cgiparams { 'COUNT' } || 1 ;
164 while ( $count -- > 0 ) {
165 # Generate a new code
166 my $code = & gencode
();
168 # Check if the coupon code already exists
169 foreach my $key ( keys %couponhash ) {
170 if ( $couponhash { $key }[ 1 ] eq $code ) {
171 # Code already exists, so try again
178 next if ( $code eq "" );
180 # Get a new key from hash
181 my $key = & General
:: findhasharraykey
( \
%couponhash );
183 # Initialize all fields
184 foreach my $i ( 0 .. 3 ) { $couponhash { $key }[ $i ] = "" ; }
186 $couponhash { $key }[ 0 ] = $now ;
187 $couponhash { $key }[ 1 ] = $code ;
188 $couponhash { $key }[ 2 ] = $expires ;
189 $couponhash { $key }[ 3 ] = $cgiparams { 'REMARK' };
192 # Save everything to disk
193 & General
:: writehasharray
( $coupons , \
%couponhash );
197 if ( $cgiparams { 'ACTION' } eq 'delete-coupon' ) {
198 #deletes an already generated but unused voucher
200 #read all generated vouchers
201 & General
:: readhasharray
( $coupons , \
%couponhash ) if (- e
$coupons );
202 foreach my $key ( keys %couponhash ) {
203 if ( $cgiparams { 'key' } eq $couponhash { $key }[ 0 ]){
204 #write logenty with decoded remark
205 my $rem = HTML
:: Entities
:: decode_entities
( $couponhash { $key }[ 4 ]);
206 & General
:: log ( "Captive" , "Delete unused coupon $couponhash { $key }[1] $couponhash { $key }[2] hours valid expires on $couponhash { $key }[3] remark $rem " );
207 #delete line from hash
208 delete $couponhash { $key };
213 & General
:: writehasharray
( $coupons , \
%couponhash );
216 if ( $cgiparams { 'ACTION' } eq 'delete-client' ) {
217 #delete voucher and connection in use
219 #read all active clients
220 & General
:: readhasharray
( $clients , \
%clientshash ) if (- e
$clients );
221 foreach my $key ( keys %clientshash ) {
222 if ( $cgiparams { 'key' } eq $clientshash { $key }[ 0 ]){
223 #prepare log entry with decoded remark
224 my $rem = HTML
:: Entities
:: decode_entities
( $clientshash { $key }[ 7 ]);
226 & 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" );
227 #delete line from hash
228 delete $clientshash { $key };
233 & General
:: writehasharray
( " $clients " , \
%clientshash );
234 #reload firewallrules to kill connection of client
235 system ( "/usr/local/bin/captivectrl" );
238 #open webpage, print header and open box
239 & Header
:: openpage
( $Lang :: tr
{ 'Captive menu' }, 1 , '' );
240 & Header
:: openbigbox
();
242 # If an error message exists, show a box with the error message
244 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'error messages' });
249 # Prints the config box on the website
250 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'Captive config' });
252 <form method='post' action=' $ENV {'SCRIPT_NAME'}' enctype="multipart/form-data"> \n
253 <table width='100%' border="0">
257 #check which parameters have to be enabled (from settings file)
258 $checked { 'ENABLE_GREEN' }{ 'off' } = '' ;
259 $checked { 'ENABLE_GREEN' }{ 'on' } = '' ;
260 $checked { 'ENABLE_GREEN' }{ $settings { 'ENABLE_GREEN' }} = "checked='checked'" ;
262 $checked { 'ENABLE_BLUE' }{ 'off' } = '' ;
263 $checked { 'ENABLE_BLUE' }{ 'on' } = '' ;
264 $checked { 'ENABLE_BLUE' }{ $settings { 'ENABLE_BLUE' }} = "checked='checked'" ;
266 $checked { 'UNLIMITED' }{ 'off' } = '' ;
267 $checked { 'UNLIMITED' }{ 'on' } = '' ;
268 $checked { 'UNLIMITED' }{ $settings { 'UNLIMITED' }} = "checked='checked'" ;
270 $selected { 'AUTH' } = ();
271 $selected { 'AUTH' }{ 'COUPON' } = "" ;
272 $selected { 'AUTH' }{ 'TERMS' } = "" ;
273 $selected { 'AUTH' }{ $settings { 'AUTH' }} = "selected" ;
275 if ( $netsettings { 'GREEN_DEV' }){
279 $Lang ::tr{'Captive active on'}
280 <font color=' $Header ::colourgreen'> $Lang ::tr{'green'}</font>
283 <input type='checkbox' name='ENABLE_GREEN' $checked {'ENABLE_GREEN'}{'on'} />
289 if ( $netsettings { 'BLUE_DEV' }){
293 $Lang ::tr{'Captive active on'}
294 <font color=' $Header ::colourblue'> $Lang ::tr{'blue'}</font>
297 <input type='checkbox' name='ENABLE_BLUE' $checked {'ENABLE_BLUE'}{'on'} />
306 $Lang ::tr{'Captive authentication'}
310 <option value="TERMS" $selected {'AUTH'}{'TERMS'} > $Lang ::tr{'Captive terms'}</option>
311 <option value="COUPON" $selected {'AUTH'}{'COUPON'}> $Lang ::tr{'Captive coupon'}</option>
318 if ( $settings { 'AUTH' } eq 'TERMS' ) {
319 $selected { 'SESSION_TIME' } = ();
320 $selected { 'SESSION_TIME' }{ '0' } = "" ;
321 $selected { 'SESSION_TIME' }{ '3600' } = "" ;
322 $selected { 'SESSION_TIME' }{ '28800' } = "" ;
323 $selected { 'SESSION_TIME' }{ '86400' } = "" ;
324 $selected { 'SESSION_TIME' }{ '604800' } = "" ;
325 $selected { 'SESSION_TIME' }{ '18144000' } = "" ;
326 $selected { 'SESSION_TIME' }{ $settings { 'SESSION_TIME' }} = "selected" ;
330 <td> $Lang ::tr{'Captive client session expiry time'}</td>
332 <select name="SESSION_TIME">
333 <option value="0" $selected {'SESSION_TIME'}{'0'}>- $Lang ::tr{'unlimited'} -</option>
334 <option value="3600" $selected {'SESSION_TIME'}{'3600'}> $Lang ::tr{'one hour'}</option>
335 <option value="28800" $selected {'SESSION_TIME'}{'28800'}> $Lang ::tr{'eight hours'}</option>
336 <option value="86400" $selected {'SESSION_TIME'}{'86400'}> $Lang ::tr{'24 hours'}</option>
337 <option value="604800" $selected {'SESSION_TIME'}{'604800'}> $Lang ::tr{'one week'}</option>
338 <option value="18144000" $selected {'SESSION_TIME'}{'18144000'}> $Lang ::tr{'one month'}</option>
349 <strong> $Lang ::tr{'Captive branding'}</strong>
354 $Lang ::tr{'Captive title'}
357 <input type='text' name='TITLE' value=" $settings {'TITLE'}" size='40'>
361 <td> $Lang ::tr{'Captive brand color'}</td>
363 <input type="color" name="COLOR" value=" $settings {'COLOR'}">
368 $Lang ::tr{'Captive upload logo'}
371 <input type="file" name="logo">
372 <br> $Lang ::tr{'Captive upload logo recommendations'}
380 <td> $Lang ::tr{'Captive logo uploaded'}</td>
381 <td> $Lang ::tr{'yes'}</td>
386 my $terms = & getterms
();
389 <td> $Lang ::tr{'Captive terms'}</td>
391 <textarea cols="50" rows="10" name="TERMS"> $terms </textarea>
397 <input type='submit' name='ACTION' value=" $Lang ::tr{'save'}"/>
405 #if settings is set to use coupons, the coupon part has to be displayed
406 if ( $settings { 'AUTH' } eq 'COUPON' ) {
410 # Show active clients
416 open ( FILE
, "<:utf8" , "/var/ipfire/captive/terms.txt" );
418 push ( @ret , HTML
:: Entities
:: decode_entities
( $_ ));
422 return join ( /\n/ , @ret );
426 #generate a random code only letters from A-Z except 'O' and 0-9
427 my @chars = ( "A" .. "N" , "P" .. "Z" , "0" .. "9" );
429 $randomstring .= $chars [ rand @chars ] for 1 . .8 ;
430 return $randomstring ;
434 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'Captive generate coupon' });
436 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
437 <table border='0' width='100%'>
440 $Lang ::tr{'Captive vouchervalid'}
443 <table class='tbl' border='0' width='100%'>
445 <th> $Lang ::tr{'hours'}</th>
446 <th> $Lang ::tr{'days'}</th>
447 <th> $Lang ::tr{'weeks'}</th>
448 <th> $Lang ::tr{'months'}</th>
453 #print hour-dropdownbox
455 print "<tr height='40px'><td><select name='EXP_HOUR' style='width:8em;'>" ;
456 print "<option value='0' " ;
457 print " selected='selected'" if ( $settings { 'EXP_HOUR' } eq '0' );
458 print ">--</option>" ;
459 for ( my $i = 1 ; $i < 25 ; $i ++){
460 my $exp_sec = $i * $hrs ;
461 print "<option value=' $exp_sec ' " ;
462 print " selected='selected'" if ( $settings { 'EXP_HOUR' } eq $exp_sec );
463 print "> $i </option>" ;
467 #print day-dropdownbox
469 print "<select name='EXP_DAY' style='width:8em;'>" ;
470 print "<option value='0' " ;
471 print " selected='selected'" if ( $settings { 'EXP_DAY' } eq '0' );
472 print ">--</option>" ;
473 for ( my $i = 1 ; $i < 8 ; $i ++){
474 my $exp_sec = $i * $days ;
475 print "<option value=' $exp_sec ' " ;
476 print " selected='selected'" if ( $settings { 'EXP_DAY' } eq $exp_sec );
477 print "> $i </option>" ;
481 #print week-dropdownbox
483 print "<select name='EXP_WEEK' style='width:8em;'>" ;
484 print "<option value='0' " ;
485 print " selected='selected'" if ( $settings { 'EXP_WEEK' } eq '0' );
486 print ">--</option>" ;
487 for ( my $i = 1 ; $i < 5 ; $i ++){
488 my $exp_sec = $i * $week ;
489 print "<option value=' $exp_sec ' " ;
490 print " selected='selected'" if ( $settings { 'EXP_WEEK' } eq $exp_sec );
491 print "> $i </option>" ;
495 #print month-dropdownbox
496 my $month = 3600 * 24 * 30 ;
497 print "<select name='EXP_MONTH' style='width:8em;'>" ;
498 print "<option value='0' " ;
499 print " selected='selected'" if ( $settings { 'EXP_MONTH' } eq '0' );
500 print ">--</option>" ;
501 for ( my $i = 1 ; $i < 13 ; $i ++){
502 my $exp_sec = $i * $month ;
503 print "<option value=' $exp_sec ' " ;
504 print " selected='selected'" if ( $settings { 'EXP_MONTH' } eq $exp_sec );
505 print "> $i </option>" ;
511 <input type='checkbox' name='UNLIMITED' $checked {'UNLIMITED'}{'on'} />
512 $Lang ::tr{'Captive nolimit'}
520 <td> $Lang ::tr{'remark'}</td>
522 <input type='text' style='width: 98%;' name='REMARK' align='left'>
528 <select name="COUNT">
529 <option value="1">1</option>
530 <option value="2">2</option>
531 <option value="3">3</option>
532 <option value="4">4</option>
533 <option value="5">5</option>
534 <option value="6">6</option>
535 <option value="7">7</option>
536 <option value="8">8</option>
537 <option value="9">9</option>
538 <option value="10">10</option>
539 <option value="20">20</option>
540 <option value="50">50</option>
541 <option value="100">100</option>
544 <input type="submit" name="ACTION" value=" $Lang ::tr{'Captive generate coupon'}">
551 # Show all coupons if exist
558 & General
:: readhasharray
( $coupons , \
%couponhash ) if (- e
$coupons );
560 #if there are already generated but unsused coupons, print a table
561 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'Captive issued coupons' });
564 <table class='tbl' border='0'>
566 <th align='center' width='15%'>
567 $Lang ::tr{'Captive coupon'}
569 <th align='center' width='15%'> $Lang ::tr{'Captive expiry time'}</th>
570 <th align='center' width='65%'> $Lang ::tr{'remark'}</th>
571 <th align='center' width='5%'> $Lang ::tr{'delete'}</th>
575 foreach my $key ( keys %couponhash ) {
576 my $expirytime = $Lang :: tr
{ 'Captive nolimit' };
577 if ( $couponhash { $key }[ 2 ] > 0 ) {
578 $expirytime = & General
:: format_time
( $couponhash { $key }[ 2 ]);
582 $col = "bgcolor=' $color {'color20'}'" ;
584 $col = "bgcolor=' $color {'color22'}'" ;
589 <td $col align="center">
590 <b> $couponhash { $key }[1]</b>
592 <td $col align="center">
595 <td $col align="center">
598 <td $col align="center">
600 <input type='image' src='/images/delete.gif' align='middle' alt=' $Lang ::tr{'delete'}' title=' $Lang ::tr{'delete'}' />
601 <input type='hidden' name='ACTION' value='delete-coupon' />
602 <input type='hidden' name='key' value=' $couponhash { $key }[0]' />
615 <input type="hidden" name="ACTION" value="export-coupons">
616 <input type="submit" value=" $Lang ::tr{'Captive export coupons'}">
625 # if there are active clients which use coupons show table
626 return if ( - z
$clients || ! - f
$clients );
631 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'Captive clients' });
634 <table class='tbl' width='100%'>
636 <th align='center' width='15%'> $Lang ::tr{'Captive coupon'}</th>
637 <th align='center' width='15%'> $Lang ::tr{'Captive activated'}</th>
638 <th align='center' width='15%'> $Lang ::tr{'Captive expiry time'}</th>
639 <th align='center' width='10%'> $Lang ::tr{'Captive mac'}</th>
640 <th align='center' width='43%'> $Lang ::tr{'remark'}</th>
641 <th align='center' width='5%'> $Lang ::tr{'delete'}</th>
645 & General
:: readhasharray
( $clients , \
%clientshash ) if (- e
$clients );
646 foreach my $key ( keys %clientshash ) {
647 #calculate time from clientshash (starttime)
648 my $starttime = sub { sprintf ' %02d . %02d . %04d %02d : %02d ' , $_ [ 3 ], $_ [ 4 ]+ 1 , $_ [ 5 ]+ 1900 , $_ [ 2 ], $_ [ 1 ] }->( localtime ( $clientshash { $key }[ 2 ]));
650 #calculate endtime from clientshash
652 if ( $clientshash { $key }[ 3 ] eq '0' ){
653 $endtime = $Lang :: tr
{ 'Captive nolimit' };
655 $endtime = sub { sprintf ' %02d . %02d . %04d %02d : %02d ' , $_ [ 3 ], $_ [ 4 ]+ 1 , $_ [ 5 ]+ 1900 , $_ [ 2 ], $_ [ 1 ] }->( localtime ( $clientshash { $key }[ 2 ]+ $clientshash { $key }[ 3 ]));
659 $col = "bgcolor=' $color {'color20'}'" ;
661 $col = "bgcolor=' $color {'color22'}'" ;
664 my $coupon = ( $clientshash { $key }[ 4 ] eq "LICENSE" ) ?
$Lang :: tr
{ 'Captive terms short' } : $clientshash { $key }[ 4 ];
668 <td $col align="center"><b> $coupon </b></td>
669 <td $col align="center"> $starttime </td>
670 <td $col align="center"> $endtime </td>
671 <td $col align="center"> $clientshash { $key }[0]</td>
672 <td $col align="center"> $clientshash { $key }[5]</td>
673 <td $col align="center">
675 <input type='image' src='/images/delete.gif' align='middle' alt=' $Lang ::tr{'delete'}' title=' $Lang ::tr{'delete'}' />
676 <input type='hidden' name='ACTION' value='delete-client' />
677 <input type='hidden' name='key' value=' $clientshash { $key }[0]' />
691 # Checks a hostname against RFC1035
693 # Each part should be at least two characters in length
694 # but no more than 63 characters
695 if ( length ( $remark ) < 1 || length ( $remark ) > 255 ) {
697 # Only valid characters are a-z, A-Z, 0-9 and -
698 if ( $remark !~ /^[a-zäöüA-ZÖÄÜ0-9-.:;\|_()\/ \s
]*$/) {
700 # First character can only be a letter or a digit
701 if ( substr ( $remark , 0 , 1 ) !~ /^[a-zäöüA-ZÖÄÜ0-9]*$/ ) {
703 # Last character can only be a letter or a digit
704 if ( substr ( $remark , - 1 , 1 ) !~ /^[a-zöäüA-ZÖÄÜ0-9.:;_)]*$/ ) {
710 my $pdf = PDF
:: API2
-> new ();
712 my ( $sec , $min , $hour , $mday , $mon , $year , $wday , $yday , $isdst ) = gmtime ( time );
713 my $timestamp = sprintf ( "D: %04d %02d %02d %02d %02d %02d +00;00" , $year + 1900 , $mon + 1 , $mday , $hour , $min , $sec );
716 "Creator" => $Lang :: tr
{ 'Captive portal' },
717 "Title" => $Lang :: tr
{ 'Captive portal coupons' },
718 "CreationDate" => $timestamp ,
719 "ModDate" => $timestamp ,
723 $pdf -> mediabox ( "A4" );
724 $pdf -> trimbox ( 28 /mm, 27/mm , 182 /mm, 270/mm );
727 my $font = $pdf -> ttfont ( "/usr/share/fonts/Ubuntu-R.ttf" );
729 my $page_h_margin = 27 / mm
;
730 my $page_v_margin = 28 / mm
;
737 my $tux_image = $pdf -> image_png ( "/srv/web/ipfire/html/captive/assets/ipfire.png" );
738 my $logo_height = 12 / mm
;
739 my $logo_width = 12 / mm
;
742 my %coupon_expiry_times = ();
745 & General
:: readhasharray
( $coupons , \
%couponhash ) if (- e
$coupons );
746 foreach my $key ( keys %couponhash ) {
747 $coupon_expiry_times { $couponhash { $key }[ 1 ]} = $couponhash { $key }[ 2 ];
748 push @coupons , $couponhash { $key }[ 1 ];
753 my $page = $pdf -> page ();
759 my $f_headline = $page -> text ();
760 $f_headline -> font ( $font , 20 );
763 my $f_subheadline = $page -> text ();
764 $f_subheadline -> font ( $font , 14 );
767 my $f_coupon = $page -> text ();
768 $f_coupon -> font ( $font , 36 );
771 my $f_lifetime = $page -> text ();
772 $f_lifetime -> font ( $font , 14 );
775 my $f_watermark = $page -> text ();
776 $f_watermark -> fillcolor ( "#666666" );
777 $f_watermark -> font ( $font , 10 );
780 while ( @coupons && $i < 8 ) {
781 my $coupon = shift @coupons ;
784 my $x = ( $page_v_margin / 2 ) + (( $i % 2 ) ?
$width : 0 );
785 my $y = ( $page_h_margin / 2) + (int($i / 2 ) * $height );
787 # Weidth and height of the box
788 my $w = $width - $margin ;
789 my $h = $height - $margin ;
792 my $cx = $x + ( $w / 2 );
793 my $cy = $y + ( $h / 2 );
796 $gfx -> strokecolor ( "#333333" );
797 $gfx -> linedash ( 1 /mm, 1/mm );
798 $gfx -> rect ( $x , $y , $w , $h );
803 $f_headline -> translate ( $cx , ( $y + $h - $cy ) / 1.7 + $cy );
804 $f_subheadline -> translate ( $cx , ( $y + $h - $cy ) / 2.4 + $cy );
806 if ( $settings { 'TITLE' }) {
807 $f_headline -> text_center ( $settings { 'TITLE' });
808 $f_subheadline -> text_center ( decode
( "utf8" , $Lang :: tr
{ 'Captive WiFi coupon' }));
810 $f_headline -> text_center ( decode
( "utf8" , $Lang :: tr
{ 'Captive WiFi coupon' }));
814 $f_coupon -> translate ( $cx , $cy );
815 $f_coupon -> text_center ( decode
( "utf8" , $coupon ));
818 my $expiry_time = $coupon_expiry_times { $coupon };
819 $f_lifetime -> translate ( $cx , $cy - ( $y + $h - $cy ) / 4 );
820 if ( $expiry_time > 0 ) {
821 my $lifetime = & General
:: format_time
( $expiry_time );
822 $f_lifetime -> text_center ( decode
( "utf8" , $Lang :: tr
{ 'Captive valid for' } . " " . $lifetime ));
824 $f_lifetime -> text_center ( decode
( "utf8" , $Lang :: tr
{ 'Captive nolimit' }));
828 $gfx -> image ( $tux_image , $x + $w - $logo_width - $margin , $y + $margin , $logo_width , $logo_height );
829 $f_watermark -> translate ( $x + $w - ( $margin * 2 ) - $logo_width , $y + ( $logo_height / 2 ));
830 $f_watermark -> text_right ( "Powered by IPFire" );
836 # Write out the PDF document
837 return $pdf -> stringify ();
840 & Header
:: closebigbox
();
841 & Header
:: closepage
();