diff --git a/callback.php b/callback.php index bbfe57260b..2c82b3ef95 100644 --- a/callback.php +++ b/callback.php @@ -16,7 +16,7 @@ $enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'" if ($enabled == 1) { if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') { - dbInsert(array('name'=>'uuid','value'=>guidv4(openssl_random_pseudo_bytes(16))),'callback'); + dbInsert(array('name'=>'uuid','value'=>guidv4(openssl_random_pseudo_bytes(16))), 'callback'); } $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); @@ -72,12 +72,13 @@ if ($enabled == 1) { $submit = array('data'=>$data); $fields = ''; - foreach($submit as $key => $value) { - $fields .= $key . '=' . $value . '&'; + foreach ($submit as $key => $value) { + $fields .= $key . '=' . $value . '&'; } rtrim($fields, '&'); $post = curl_init(); + set_curl_proxy($post); curl_setopt($post, CURLOPT_URL, $config['callback_post']); curl_setopt($post, CURLOPT_POST, count($submit)); curl_setopt($post, CURLOPT_POSTFIELDS, $fields); @@ -89,12 +90,13 @@ if ($enabled == 1) { $fields = "uuid=$uuid"; $clear = curl_init(); + set_curl_proxy($clear); curl_setopt($clear, CURLOPT_URL, $config['callback_clear']); curl_setopt($clear, CURLOPT_POST, count($clear)); curl_setopt($clear, CURLOPT_POSTFIELDS, $fields); curl_setopt($clear, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($clear); - dbDelete('callback','`name`="uuid"',array()); + dbDelete('callback', '`name`="uuid"', array()); dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array()); } 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"; diff --git a/includes/functions.php b/includes/functions.php index 5865dc3a79..701229ecfa 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1140,4 +1140,17 @@ function guidv4($data) { return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } -?> +function set_curl_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; + echo "Setting proxy to ".$proxystr." (from https_proxy=".$_ENV['https_proxy'].")\n"; + } + if (isset($config['callback_proxy'])) { + echo "Using ".$config['callback_proxy']." as proxy\n"; + curl_setopt($post, CURLOPT_PROXY, $config['callback_proxy']); + } +}