aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorMarcello Coutinho <marcellocoutinho@gmail.com>2014-12-01 00:27:45 -0200
committermarcelloc <marcellocoutinho@gmail.com>2014-12-01 00:27:45 -0200
commit013b19b7ab96847cffc6fdb9c6adb29f4da47323 (patch)
treef7024e1032fb25bb9f68bd1eb16e8467caf3a867 /config
parentbc7e20f0fac8c79d7c7e20371006c12944748b8d (diff)
downloadpfsense-packages-013b19b7ab96847cffc6fdb9c6adb29f4da47323.tar.gz
pfsense-packages-013b19b7ab96847cffc6fdb9c6adb29f4da47323.tar.bz2
pfsense-packages-013b19b7ab96847cffc6fdb9c6adb29f4da47323.zip
varnish3 - Add force ssl option to LB Directors, config check before reload and improve stats gui
Diffstat (limited to 'config')
-rw-r--r--config/varnish3/varnish.inc69
-rw-r--r--config/varnish3/varnish_backends.xml1
-rw-r--r--config/varnish3/varnish_custom_vcl.xml3
-rw-r--r--config/varnish3/varnish_lb_directors.xml12
-rw-r--r--config/varnish3/varnish_settings.xml4
-rw-r--r--config/varnish3/varnish_sync.xml1
-rw-r--r--config/varnish3/varnish_view_config.php9
-rw-r--r--config/varnish3/varnishstat.php47
8 files changed, 115 insertions, 31 deletions
diff --git a/config/varnish3/varnish.inc b/config/varnish3/varnish.inc
index bca02203..587d01bc 100644
--- a/config/varnish3/varnish.inc
+++ b/config/varnish3/varnish.inc
@@ -36,9 +36,6 @@ $shortcut_section = "varnish";
$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3);
if (is_dir('/usr/pbi/varnish-' . php_uname("m"))) {
- if ($pfs_version == 2.2)
- define('VARNISH_LOCALBASE', '/usr/pbi/varnish-' . php_uname("m")."/local");
- else
define('VARNISH_LOCALBASE', '/usr/pbi/varnish-' . php_uname("m"));
} else {
define('VARNISH_LOCALBASE','/usr/local');
@@ -122,11 +119,25 @@ function varnish_deinstall() {
function text_area_decode($text){
return preg_replace('/\r\n/', "\n",base64_decode($text));
}
+
+function varnish_check_config(){
+ global $savemsg;
+ exec(VARNISH_LOCALBASE."/bin/varnishd -C -f /var/etc/default.vcl 2>&1",$output,$return);
+ if ($return >0){
+ $savemsg.= implode("<br>",$output);
+ $savemsg.= "<br>Daemon will not be restarted.";
+ return 1;
+ }
+ return 0;
+}
+
+
function varnish_start() {
global $g, $config;
if ($config['installedpackages']['varnishsettings']['config'][0]['enablevarnish']){
exec("chmod +x /usr/local/etc/rc.d/varnish.sh");
- mwexec("/usr/local/etc/rc.d/varnish.sh");}
+ if (varnish_check_config() == 0)
+ mwexec("/usr/local/etc/rc.d/varnish.sh");}
else{
exec("chmod -x /usr/local/etc/rc.d/varnish.sh");
mwexec("/usr/bin/killall varnishd");}
@@ -165,6 +176,13 @@ function varnish_get_url_mappings_txt() {
$urlmappings .= "if (req.http.host $fieldtype ".'"'.$url['directorurl'].'"'." && req.url $fieldtype ".'"^'.$url['directorurl2'].'") {'."\n";
$urlbackend = "\t\t\tset req.backend = ".$url['directorname'].";";
+ // check force ssl option
+ if ($url['forcessl']){
+ $urlmappings .="\t\t#Force ssl for this host/director\n";
+ $urlmappings .="\t\tif((req.http.X-Forwarded-Proto !~ \"(?i)https\" ) && !(client.ip ~ SslOffloadServers)){\n";
+ $urlmappings .="\t\t\tset req.http.x-redir-url = \"https://\" + req.http.host + req.url;\n";
+ $urlmappings .="\t\t\terror 750 req.http.x-redir-url;\n\t\t\t}\n";
+ }
// check rewrite options
if ($url['rewritehost'])
$urlmappings .= "\t\t\tset req.http.host = regsub(req.http.host, ".'"'.$url['directorurl'].'",'.'"'.$url['rewritehost'].'")'.";\n";
@@ -425,11 +443,23 @@ function sync_package_varnish() {
$vcl_pipe_late = text_area_decode($vcl['vcl_pipe_late']);
}
}
- $vcl_recv_set_basic='#BASIC VCL RULES SETTING'."\n";
- $vcl_recv_action_basic='#BASIC VCL RULES ACTIONS'."\n";
- #$plataform=posix_uname();
- if (is_array($config['installedpackages']['varnishsettings']['config']))
- foreach($config['installedpackages']['varnishsettings']['config'] as $vcl) {
+
+ $vcl_recv_set_basic='#BASIC VCL RULES SETTING'."\n";
+ $vcl_recv_action_basic='#BASIC VCL RULES ACTIONS'."\n";
+ #$plataform=posix_uname();
+ if (is_array($config['installedpackages']['varnishsettings']['config']))
+ foreach($config['installedpackages']['varnishsettings']['config'] as $vcl) {
+ if ($vcl['ssloffload']){
+ $vcl_acls="acl SslOffloadServers {\n\t\"localhost\";";
+ $sslservers= split (" ",$vcl['ssloffload']);
+ foreach ($sslservers as $sslserver){
+ if (preg_match("/(\S+)\/(d+)/",$sslserver,$sslm))
+ $vcl_acls.="\n\t\"{$sslm[1]}\"/{$sslm[2]};";
+ else
+ $vcl_acls.="\n\t\"{$sslserver}\";";
+ }
+ $vcl_acls.="\n\t}\n";
+ }
if ($vcl['streaming'])
$vcl_fetch_stream="set beresp.do_stream = true;\n";
if ($vcl['fixgzip']) {
@@ -466,15 +496,6 @@ function sync_package_varnish() {
$vcl_recv_set_basic .= "\tset req.http.X-Forwarded-For = req.http.X-Forwarded-For + \",\" + client.ip;\n\n";
break;
case 'create':
- $vcl_acls="acl SslOffloadServers {\n\t\"localhost\";";
- $sslservers= split (" ",$vcl['ssloffload']);
- foreach ($sslservers as $sslserver){
- if (preg_match("/(\S+)\/(d+)/",$sslserver,$sslm))
- $vcl_acls.="\n\t\"{$sslm[1]}\"/{$sslm[2]};";
- else
- $vcl_acls.="\n\t\"{$sslserver}\";";
- }
- $vcl_acls.="}\n";
$vcl_recv_set_basic .= "\tif (req.http.X-Forwarded-For && client.ip ~ SslOffloadServers){\n\t\t";
$vcl_recv_set_basic .= "set req.http.X-Forwarded-Varnish = req.http.X-Forwarded-For;\n\t}";
$vcl_recv_set_basic .= "else{\n\t\tset req.http.X-Forwarded-Varnish = client.ip;\n\n\t}";
@@ -577,10 +598,16 @@ $varnish_config_file = <<<EOF
# This file is located in /var/etc/default.vcl
sub vcl_error {
- if (obj.status == 503 && req.restarts < {$vcl_restarts}) {
- return(restart);
+ if (obj.status == 503 && req.restarts < {$vcl_restarts}) {
+ return(restart);
}
+ if (obj.status == 750) {
+ set obj.http.Location = obj.response;
+ set obj.status = 301;
+ return(deliver);
+ }
+
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
@@ -669,7 +696,7 @@ sub vcl_fini {
EOF;
file_put_contents("/var/etc/default.vcl",$varnish_config_file,LOCK_EX);
- $cc_file="/usr/local/bin/cc";
+ $cc_file=VARNISH_LOCALBASE."/bin/cc";
foreach (glob(VARNISH_LOCALBASE."/bin/gcc*") as $bin_file) {
$gcc_file=$bin_file;
}
diff --git a/config/varnish3/varnish_backends.xml b/config/varnish3/varnish_backends.xml
index dd93eba5..2a2db35e 100644
--- a/config/varnish3/varnish_backends.xml
+++ b/config/varnish3/varnish_backends.xml
@@ -293,6 +293,7 @@
varnish_install();
</custom_php_install_command>
<custom_php_command_before_form>
+ varnish_check_config();
</custom_php_command_before_form>
<custom_delete_php_command>
sync_package_varnish();
diff --git a/config/varnish3/varnish_custom_vcl.xml b/config/varnish3/varnish_custom_vcl.xml
index 7c940f40..d0d9ff21 100644
--- a/config/varnish3/varnish_custom_vcl.xml
+++ b/config/varnish3/varnish_custom_vcl.xml
@@ -169,6 +169,9 @@
<encoding>base64</encoding>
</field>
</fields>
+ <custom_php_command_before_form>
+ varnish_check_config();
+ </custom_php_command_before_form>
<custom_php_validation_command>
</custom_php_validation_command>
<custom_php_resync_config_command>
diff --git a/config/varnish3/varnish_lb_directors.xml b/config/varnish3/varnish_lb_directors.xml
index e3cd8c04..313bf0d6 100644
--- a/config/varnish3/varnish_lb_directors.xml
+++ b/config/varnish3/varnish_lb_directors.xml
@@ -130,6 +130,10 @@
<fieldname>grace</fieldname>
</columnitem>
<columnitem>
+ <fielddescr>SSL</fielddescr>
+ <fieldname>forcessl</fieldname>
+ </columnitem>
+ <columnitem>
<fielddescr>Failover</fielddescr>
<fieldname>failover</fieldname>
</columnitem>
@@ -197,6 +201,13 @@
<type>input</type>
<size>5</size>
</field>
+ <field>
+ <fielddescr>Force SSL</fielddescr>
+ <fieldname>forcessl</fieldname>
+ <description><![CDATA[Redirect to ssl if request does not came from ssl offload servers.]]></description>
+ <type>checkbox</type>
+ <size>5</size>
+ </field>
<field>
<fielddescr>Additions options</fielddescr>
<fieldname>customapping</fieldname>
@@ -261,6 +272,7 @@
</field>
</fields>
<custom_php_command_before_form>
+ varnish_check_config();
</custom_php_command_before_form>
<custom_delete_php_command>
sync_package_varnish();
diff --git a/config/varnish3/varnish_settings.xml b/config/varnish3/varnish_settings.xml
index 99e29663..b80b7fcf 100644
--- a/config/varnish3/varnish_settings.xml
+++ b/config/varnish3/varnish_settings.xml
@@ -283,6 +283,10 @@
<encoding>base64</encoding>
</field>
</fields>
+ <custom_php_command_before_form>
+ varnish_check_config();
+ </custom_php_command_before_form>
+
<custom_php_resync_config_command>
sync_package_varnish();
create_varnish_rcd_file();
diff --git a/config/varnish3/varnish_sync.xml b/config/varnish3/varnish_sync.xml
index eb908afe..c5b4b69c 100644
--- a/config/varnish3/varnish_sync.xml
+++ b/config/varnish3/varnish_sync.xml
@@ -136,5 +136,6 @@
</custom_php_resync_config_command>
<custom_php_command_before_form>
unset($_POST['temp']);
+ varnish_check_config();
</custom_php_command_before_form>
</packagegui> \ No newline at end of file
diff --git a/config/varnish3/varnish_view_config.php b/config/varnish3/varnish_view_config.php
index b02e5c88..30765756 100644
--- a/config/varnish3/varnish_view_config.php
+++ b/config/varnish3/varnish_view_config.php
@@ -28,7 +28,7 @@
*/
require("guiconfig.inc");
-
+require("varnish.inc");
$pf_version=substr(trim(file_get_contents("/etc/version")),0,3);
if ($pf_version < 2.0)
$one_two = true;
@@ -44,7 +44,7 @@ include("head.inc");
<p class="pgtitle"><?=$pgtitle?></font></p>
<?php endif; ?>
-<?php if ($savemsg) print_info_box($savemsg); ?>
+<?php varnish_check_config();if ($savemsg) print_info_box($savemsg); ?>
<form action="varnishstat_view_config.php" method="post">
@@ -71,8 +71,9 @@ include("head.inc");
<td class="tabcont" >
<textarea id="varnishlogs" rows="50" cols="100%">
<?php
- $config_file = file_get_contents("/var/etc/default.vcl");
- echo $config_file;
+ $config_file = file("/var/etc/default.vcl");
+ foreach ($config_file as $l => $v)
+ echo ($l+1)." - {$v}";
?>
</textarea>
</td>
diff --git a/config/varnish3/varnishstat.php b/config/varnish3/varnishstat.php
index 9e4e2f3d..aa6827a8 100644
--- a/config/varnish3/varnishstat.php
+++ b/config/varnish3/varnishstat.php
@@ -1,8 +1,9 @@
<?php
/*
- varnishstat_view_logs.php
+ varnishstat.php
part of pfSense (https://www.pfsense.org/)
Copyright (C) 2006 Scott Ullrich <sullrich@gmail.com>
+ Copyright (C) 2014 Marcello Coutinho
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -28,11 +29,45 @@
*/
require("guiconfig.inc");
-
+require("varnish.inc");
+function open_table(){
+ echo "<table style=\"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
+ echo" <tr>";
+}
+function close_table(){
+ echo" </tr>";
+ echo"</table>";
+ echo "<br>";
+}
if($_REQUEST['getactivity']) {
- $varnishstatlogs = `varnishstat -1`;
+ //$varnishstatlogs = `varnishstat -1`;
+ $backends=exec("varnishstat -1",$debug);
echo "<h2>VarnishSTAT Server logs as of " . date("D M j G:i:s T Y") . "</h2>";
- echo $varnishstatlogs;
+ open_table();
+ print "<td class=\"vncellt\" width=30%><strong>Description</strong></td>";
+ print "<td class=\"vncellt\" width=15%><strong>Count</strong></td>";
+ print "<td class=\"vncellt\" width=15%><strong></strong></td>";
+ print "<td width=20%></td><td width=20%></td></tr>";
+ foreach ($debug as $line){
+ if (!preg_match("/^VBE/",$line,$lm) &&
+ preg_match("/(\S+)\s+(\S+)\s+(\S+)\s+(.*)/",$line,$lm))
+ $varnish_stats[]=$lm;
+ }
+ unset($debug);
+ if (is_array($varnish_stats)){
+ foreach ($varnish_stats as $v){
+ print "<td class=\"listlr\"> $v[4] ($v[1])</td>";
+ print "<td class=\"listlr\" align=\"Right\">". @number_format($v[2]) ."</td>";
+ print "<td class=\"listlr\" align=\"Right\">$v[3]</td>";
+ print "<td>&nbsp;</td><td>&nbsp;</td></tr>";
+ }
+ }
+ else{
+ print "<td class=\"listlr\">No traffic</td><td class=\"listlr\"></td><td class=\"listlr\"></td></tr>";
+ }
+
+close_table();
+ //echo $varnishstatlogs;
exit;
}
@@ -70,7 +105,7 @@ include("head.inc");
<p class="pgtitle"><?=$pgtitle?></font></p>
<?php endif; ?>
-<?php if ($savemsg) print_info_box($savemsg); ?>
+<?php varnish_check_config();if ($savemsg) print_info_box($savemsg); ?>
<div id="mainlevel">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
@@ -93,7 +128,7 @@ include("head.inc");
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tabcont" >
- <form action="varnishstat_view_logs.php" method="post">
+ <form action="varnishstat.php" method="post">
<div id="varnishstatlogs">
<pre>One moment please, loading VarnishSTAT...</pre>
</div>