diff --git a/callback.php b/callback.php index 038b6b077d..2f3871e43d 100644 --- a/callback.php +++ b/callback.php @@ -12,6 +12,21 @@ * the source code distribution for details. */ +function set_proxy($post) +{ + global $config; + if (isset($_ENV['https_proxy'])) { + $tmp = rtrim($_ENV['https_proxy'], "/"); + $proxystr = str_replace(array("http://", "https://"), "", $tmp); + $config['callback_proxy'] = $proxystr; + printf("Setting proxy to %s (from https_proxy=%s)\n", $proxystr, $_ENV['https_proxy']); + } + if (isset($config['callback_proxy'])) { + printf("Using %s as proxy\n", $config['callback_proxy']); + curl_setopt($post, CURLOPT_PROXY, $config['callback_proxy']); + } +} + $enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'"); if ($enabled == 1) { @@ -78,7 +93,9 @@ if ($enabled == 1) { rtrim($fields, '&'); $post = curl_init(); + set_proxy($post); curl_setopt($post, CURLOPT_URL, $config['callback_post']); + curl_setopt($post, CURLOPT_PROXY, count($submit)); curl_setopt($post, CURLOPT_POST, count($submit)); curl_setopt($post, CURLOPT_POSTFIELDS, $fields); curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); @@ -89,6 +106,7 @@ if ($enabled == 1) { $fields = "uuid=$uuid"; $clear = curl_init(); + set_proxy($post); curl_setopt($clear, CURLOPT_URL, $config['callback_clear']); curl_setopt($clear, CURLOPT_POST, count($clear)); curl_setopt($clear, CURLOPT_POSTFIELDS, $fields); diff --git a/config.php.default b/config.php.default index c98b8677ba..479482113b 100755 --- a/config.php.default +++ b/config.php.default @@ -41,3 +41,6 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth $config['poller-wrapper']['alerter'] = FALSE; # Uncomment the next line to disable daily updates #$config['update'] = 0; + +# Uncomment to submit callback stats via proxy +#$config['callback_proxy'] = "hostname:port";