]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
captive-portal: Use template engine to render HTML template
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Apr 2017 16:34:59 +0000 (17:34 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Sep 2017 17:54:45 +0000 (18:54 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/rootfiles/common/web-user-interface
html/cgi-bin/captive/index.cgi
html/html/captive/template.html [new file with mode: 0644]

index dbf5a869f2f6ee318582cf77870b2e18b2fdab9a..b755e6e7bbc3df642dcdee7456f5188702f07cab 100644 (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/favicon.ico
 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/dial.cgi
 srv/web/ipfire/html/favicon.ico
index c3f9d035f40ad9c4eff32e0292b5fc39c0f669cb..71bff37a2912008161bb005268841721922dcece 100755 (executable)
@@ -23,6 +23,7 @@ use strict;
 use CGI ':standard';
 use URI::Escape;
 use HTML::Entities();
+use HTML::Template;
 
 # enable only the following on debugging purpose
 #use warnings;
@@ -134,107 +135,25 @@ if($redir == 1){
 }
 
 #Open HTML Page, load header and css
-&head();
-&error();
-&start();
+my $tmpl = HTML::Template->new(
+       filename => "/srv/web/ipfire/html/captive/template.html",
+       die_on_bad_params => 0
+);
 
-#Functions
-sub start(){
-       if ($settings{'AUTH'} eq 'VOUCHER'){
-               &voucher();
-       }else{
-               &agb();
-       }
-}
-
-sub error(){
-       if ($errormessage){
-               print "<center><div class='title'><br><font color='red'>$errormessage</font><br></div><br>";
-       }
-}
+$tmpl->param(REDIRECT_URL => $url);
 
-sub head(){
-print<<END
-Content-type: text/html\n\n
-<html> 
-       <head>
-               <meta charset="utf-8">
-               <title>$settings{'TITLE'}</title>
-               <link href="../assets/captive.css" type="text/css" rel="stylesheet">
-       </head>
-       <body>
-END
-;
-}
+$tmpl->param(AUTH  => $settings{'AUTH'});
+$tmpl->param(TITLE => $settings{'TITLE'});
+$tmpl->param(ERROR => $errormessage);
 
-sub agb(){
-print<<END
-       <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
-;
-}
+# Print header
+print "Pragma: no-cache\n";
+print "Cache-control: no-cache\n";
+print "Connection: close\n";
+print "Content-type: text/html\n\n";
 
-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
-;
-}
+# Print rendered template
+print $tmpl->output;
 
 sub getcgihash {
        my ($hash, $params) = @_;
diff --git a/html/html/captive/template.html b/html/html/captive/template.html
new file mode 100644 (file)
index 0000000..20b7919
--- /dev/null
@@ -0,0 +1 @@
+TEMPLATE GOES HERE