captive-portal: Use template engine to render HTML template

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2017-04-21 17:34:59 +01:00
parent 0a02d9bb0c
commit a2c26388db
3 changed files with 18 additions and 97 deletions

View File

@@ -96,6 +96,7 @@ srv/web/ipfire/html/blob.gif
srv/web/ipfire/html/captive/assets/captive.css srv/web/ipfire/html/captive/assets/captive.css
srv/web/ipfire/html/captive/assets/favicon.ico srv/web/ipfire/html/captive/assets/favicon.ico
srv/web/ipfire/html/captive/assets/internet.png srv/web/ipfire/html/captive/assets/internet.png
srv/web/ipfire/html/captive/template.html
srv/web/ipfire/html/clwarn.cgi srv/web/ipfire/html/clwarn.cgi
srv/web/ipfire/html/dial.cgi srv/web/ipfire/html/dial.cgi
srv/web/ipfire/html/favicon.ico srv/web/ipfire/html/favicon.ico

View File

@@ -23,6 +23,7 @@ use strict;
use CGI ':standard'; use CGI ':standard';
use URI::Escape; use URI::Escape;
use HTML::Entities(); use HTML::Entities();
use HTML::Template;
# enable only the following on debugging purpose # enable only the following on debugging purpose
#use warnings; #use warnings;
@@ -134,107 +135,25 @@ if($redir == 1){
} }
#Open HTML Page, load header and css #Open HTML Page, load header and css
&head(); my $tmpl = HTML::Template->new(
&error(); filename => "/srv/web/ipfire/html/captive/template.html",
&start(); die_on_bad_params => 0
);
#Functions $tmpl->param(REDIRECT_URL => $url);
sub start(){
if ($settings{'AUTH'} eq 'VOUCHER'){
&voucher();
}else{
&agb();
}
}
sub error(){ $tmpl->param(AUTH => $settings{'AUTH'});
if ($errormessage){ $tmpl->param(TITLE => $settings{'TITLE'});
print "<center><div class='title'><br><font color='red'>$errormessage</font><br></div><br>"; $tmpl->param(ERROR => $errormessage);
}
}
sub head(){ # Print header
print<<END print "Pragma: no-cache\n";
Content-type: text/html\n\n print "Cache-control: no-cache\n";
<html> print "Connection: close\n";
<head> print "Content-type: text/html\n\n";
<meta charset="utf-8">
<title>$settings{'TITLE'}</title>
<link href="../assets/captive.css" type="text/css" rel="stylesheet">
</head>
<body>
END
;
}
sub agb(){ # Print rendered template
print<<END print $tmpl->output;
<center>
<div class="title">
<h1>$settings{'TITLE'}</h1>
</div>
<br>
<div class="agb">
<textarea style="width:100%;" rows='40'>
END
;
&getagb();
print<<END
</textarea>
<center>
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
<br><input type='hidden' name='redirect' value ='$url'><input type='submit' name='ACTION' value="$Lang::tr{'gpl i accept these terms and conditions'}"/>
</form>
</center>
</div>
</center>
</body>
</html>
END
;
}
sub voucher(){
print<<END
<center>
<div class="title">
<h1>$settings{'TITLE'}</h1>
</div>
<br>
<div class="login">
END
;
print<<END
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
<center>
<table>
<tr>
<td>
<b>$Lang::tr{'Captive voucher'}</b>&nbsp<input type='text' maxlength="8" size='10' style="font-size: 24px;font-weight: bold;" name='VOUCHER'>
</td>
<td>
<input type='hidden' name='redirect' value ='$url'><input type='submit' name='ACTION' value="$Lang::tr{'Captive activate'}"/>
</td>
</tr>
</table>
</form>
</div>
<br>
<div class="agb">
<textarea style="width:100%;" rows='40'>
END
;
&getagb();
print<<END
</textarea>
<br><br>
</div>
</body>
</html>
END
;
}
sub getcgihash { sub getcgihash {
my ($hash, $params) = @_; my ($hash, $params) = @_;

View File

@@ -0,0 +1 @@
TEMPLATE GOES HERE