From 6a5acf4a9bdfd1e1f9a3382f96ceea9270a410a8 Mon Sep 17 00:00:00 2001 From: marcelloc Date: Fri, 12 Aug 2011 02:42:45 -0300 Subject: gui improvements and bug fixes --- config/varnish64/varnish.inc | 214 +++++++++++++++++++++++++++++-------------- 1 file changed, 144 insertions(+), 70 deletions(-) (limited to 'config/varnish64') diff --git a/config/varnish64/varnish.inc b/config/varnish64/varnish.inc index 3e1aa81e..bf41245d 100644 --- a/config/varnish64/varnish.inc +++ b/config/varnish64/varnish.inc @@ -42,6 +42,13 @@ function varnish_settings_post_validate($post, $input_errors) { $input_errors[] = "A valid number is required for the field 'Maximum worker threads'"; if($post['timeoutworkers'] && !is_numeric($post['timeoutworkers'])) $input_errors[] = "A valid number is required for the field 'Worker thread timeout'"; + if($post['managment'] && !preg_match("/^\w+:\d+$/",$post['managment'])) + $input_errors[] = "A valid host/ip:port is required for the field 'managment'"; + if($post['grace'] && ! preg_match("/^\d+(h|m|s)$/",$post['grace'])) + $input_errors[] = "A valid number with a time reference is required for the field 'Fetch grace'"; + if($post['saint'] && ! preg_match("/^\d+(h|m|s)$/",$post['saint'])) + $input_errors[] = "A valid number with a time reference is required for the field 'Saint mode'"; + } function varnish_lb_directors_post_validate($post, $input_errors) { @@ -49,10 +56,12 @@ function varnish_lb_directors_post_validate($post, $input_errors) { $input_errors[] = "The directorname name must only contain the characters a-Z or 0-9"; if(stristr($post['directorurl'], 'http')) $input_errors[] = "You do not need to include the http:// string in the director URL"; + if($post['grace'] && ! preg_match("/^\d+(h|m|s)$/",$post['grace'])) + $input_errors[] = "A valid number with a time reference is required for the field 'Req grace'"; } function varnish_backends_post_validate($post, $input_errors) { - if (preg_match("/[^a-zA-Z0-9]/", $post['backendname'])) + if (!$post['backendname'] || preg_match("/[^a-zA-Z0-9]/", $post['backendname'])) $input_errors[] = "The backend name must only contain the characters a-Z or 0-9"; if(!is_ipaddr($post['ipaddress'])) $input_errors[] = "A valid IP address is required for the field 'IPAddress'"; @@ -70,6 +79,15 @@ function varnish_backends_post_validate($post, $input_errors) { $input_errors[] = "A valid number is required for the field 'probe window'"; if($post['probe_threshold'] && !is_numeric($post['probe_threshold'])) $input_errors[] = "A valid number is required for the field 'probe threshold'"; + $x=0; + while ($post['maptype'.$x] != ""){ + if($post['grace'.$x] && ! preg_match("/^\d+(h|m|s)$/",$post['grace'.$x])){ + $input_errors[] = "A valid number with a time reference is required for the field 'grace' in map ".($x +1); + } + $x++; + +} + } function varnish_install() { @@ -80,53 +98,79 @@ function varnish_deinstall() { create_varnish_rcd_file(); } +function text_area_decode($text){ + return preg_replace('/\r\n/', "\n",base64_decode($text)); +} function varnish_start() { global $g, $config; - if ($config['installedpackages']['varnishsettings']['config'][0]['enablevarnish']) - mwexec("/usr/local/etc/rc.d/varnish.sh"); - else - mwexec("/usr/bin/killall varnishd"); + if ($config['installedpackages']['varnishsettings']['config'][0]['enablevarnish']){ + mwexec("/usr/local/etc/rc.d/varnish.sh");} + else{ + mwexec("/usr/bin/killall varnishd");} } /* Build the URL mappings logic VCL config txt */ function varnish_get_url_mappings_txt() { - global $g, $config, $urlmappings; - $backends = ""; + global $g, $config, $urlmappings,$backends_in_use; + $catch_all= "unset"; $isfirst = true; if($config['installedpackages']['varnishlbdirectors']['config'] != "") { foreach($config['installedpackages']['varnishlbdirectors']['config'] as $url) { + #check options + $directo_grace_time=($url['grace']?"\n\t\tset req.grace=".$url['grace'].";":""); + $fieldtype = ($url['fieldtype']?$url['fieldtype']:"=="); + $req=($url['directorurl2']?"url":"http.host"); + $director_prefix=($url['directorurl'] && $url['directorurl2']?"^http://":""); + if ( $url['directorurl'] || $url['directorurl2'] || $catch_all == "unset"){ + if($url['directorurl']== "" && $url['directorurl2']== ""){ + #director with no host or url, so director for catch all traffic not specified in config + $lasturlmappings = "\n\telse{\n\t\tset req.backend = ".$url['directorname'].";\n\t\t}\n"; + $catch_all = "set"; + } + else{ if(!$isfirst) - $urlmappings .= "else "; + $urlmappings .= "\telse "; $urlmappings .= << - "} obj.status " " obj.response {" @@ -397,29 +462,18 @@ synthetic {"

"} obj.response {"

Guru Meditation:

XID: "} req.xid {"

- -"}; -return(deliver); - EOF; -if($vcl_fetch_early or $vcl_fetch_late) { - $vcl_fetch = << + +{$errorvcl}"}; + return(deliver); + } - + {$backends} sub vcl_recv { {$vcl_recv_early} - {$vcl_recv_basic} {$urlmappings} {$vcl_recv_late} - if (req.request != "GET" && req.request != "HEAD") { - return(pipe); - } + {$vcl_recv_basic} return(lookup); } @@ -457,8 +518,21 @@ sub vcl_pipe { {$vcl_pipe_late} } -{$vcl_fetch} - +sub vcl_fetch { + {$vcl_fetch_early} + ## If the request to the backend returns a code other than 200, restart the loop + ## If the number of restarts reaches the value of the parameter max_restarts, + ## the request will be error'ed. max_restarts defaults to 4. This prevents + ## an eternal loop in the event that, e.g., the object does not exist at all. + if (beresp.status != 200 && beresp.status != 403 && beresp.status != 404 && beresp.status != 302 && beresp.status != 301) { + {$vcl_saint_mode} + restart; + } + {$vcl_fetch_late} + {$vcl_grace_time} + return(deliver); +} + EOF; $fd = fopen("/var/etc/default.vcl", "w"); @@ -586,4 +660,4 @@ function varnish_do_xmlrpc_sync($sync_to_ip, $password) { } -?> \ No newline at end of file +?> -- cgit v1.2.3