From def68e846a9a8af2ffb72ae2cd4fec38ca39f03d Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 27 Apr 2010 20:41:15 -0400 Subject: Major code cleanups. Split a number of items out into their own functions. Only define a director or backend if it is actively being used. --- config/varnish64/varnish.inc | 222 ++++++++++++++++++++++++++----------------- 1 file changed, 133 insertions(+), 89 deletions(-) (limited to 'config/varnish64') diff --git a/config/varnish64/varnish.inc b/config/varnish64/varnish.inc index dc343a44..4a2bac07 100644 --- a/config/varnish64/varnish.inc +++ b/config/varnish64/varnish.inc @@ -31,24 +31,69 @@ */ /* ========================================================================== */ -function sync_package_varnish() { - global $config, $g; - if($config['installedpackages']['varnishcustomvcl']['config'] != "") { - foreach($config['installedpackages']['varnishcustomvcl']['config'] as $vcl) { - if($vcl['vcl_recv_early']) - $vcl_recv_early = $vcl['vcl_recv_early']; - if($vcl['vcl_recv_late']) - $vcl_recv_late = $vcl['vcl_recv_late']; - if($vcl['vcl_fetch_early']) - $vcl_fetch_early = $vcl['vcl_fetch_early']; - if($vcl['vcl_fetch_late']) - $vcl_fetch_late = $vcl['vcl_fetch_late']; - if($vcl['vcl_pipe_early']) - $vcl_pipe_early = $vcl['vcl_pipe_early']; - if($vcl['vcl_pipe_late']) - $vcl_pipe_late = $vcl['vcl_pipe_late']; +function is_varnish_backend_in_use($backendname) { + global $g, $config; + if($config['installedpackages']['varnishlbdirectors']['config'] != "") + foreach($config['installedpackages']['varnishlbdirectors']['config'] as $url) + foreach($url['row'] as $urlmapping) + if($urlmapping['backendname'] == $backendname) + return true; + if($config['installedpackages']['varnishbackends']['config'] != "") + foreach($config['installedpackages']['varnishbackends']['config'] as $backend) + if($backend['backendname'] == $backendname) + if($backend['row']) + foreach($backend['row'] as $row) + if($row['urlmapping']) + return true; + return false; +} + +function varnish_get_url_mappings_txt() { + global $g, $config, $urlmappings; + $backends = ""; + + if($config['installedpackages']['varnishbackends']['config'] != "") { + foreach($config['installedpackages']['varnishbackends']['config'] as $backend) { + $isfirst = true; + if($config['installedpackages']['varnishlbdirectors']['config'] != "") { + foreach($config['installedpackages']['varnishlbdirectors']['config'] as $url) { + foreach($url['row'] as $urlmapping) + if(!$isfirst) + $urlmappings .= "else "; + $urlmappings .= <</dev/null @@ -86,78 +132,15 @@ sleep 1 -w {$minworkers},{$maxworkers},{$timeoutworkers} EOF; - fwrite($fd, $rc_file); - fclose($fd); - exec("chmod a+rx /usr/local/etc/rc.d/varnish.sh"); - } - - if(!$errorvcl) - $errorvcl = << - - - -"} obj.status " " obj.response {" - - - -

We are very sorry but an error occurred during this request.

-
-

Please press refresh in your browser to try again.

-

Varnish Error "} obj.status " " obj.response {"

-

"} obj.response {"

-

Guru Meditation:

-

XID: "} req.xid {"

- - - -"}; -return(deliver); - -EOF; + fwrite($fd, $rc_file); + fclose($fd); + exec("chmod a+rx /usr/local/etc/rc.d/varnish.sh"); +} - $backends = ""; - $urlmappings = ""; - +function get_backend_config_txt() { + global $config, $g; if($config['installedpackages']['varnishbackends']['config'] != "") { foreach($config['installedpackages']['varnishbackends']['config'] as $backend) { - $isfirst = true; - if($config['installedpackages']['varnishlbdirectors']['config'] != "") { - foreach($config['installedpackages']['varnishlbdirectors']['config'] as $url) { - foreach($url['row'] as $urlmapping) { - if(!$isfirst) - $urlmappings .= "else "; - $urlmappings .= << + + + +"} obj.status " " obj.response {" + + + +

We are very sorry but an error occurred during this request.

+
+

Please press refresh in your browser to try again.

+

Varnish Error "} obj.status " " obj.response {"

+

"} obj.response {"

+

Guru Meditation:

+

XID: "} req.xid {"

+ + + +"}; +return(deliver); + +EOF; if($vcl_fetch_early or $vcl_fetch_late) { $vcl_fetch = <<