From 7ac743723db1276c178579c071a82cce57e0926d Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 13 Apr 2015 19:35:25 +1000 Subject: [PATCH 1/5] Keep syntax checker happy --- callback.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/callback.php b/callback.php index bbfe57260..038b6b077 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,8 +72,8 @@ 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, '&'); @@ -94,7 +94,7 @@ if ($enabled == 1) { 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()); } From 93eab16e5a20d1afa69919690ec023cbdf87c17f Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 13 Apr 2015 19:37:12 +1000 Subject: [PATCH 2/5] Add proxy support to callback function --- callback.php | 18 ++++++++++++++++++ config.php.default | 3 +++ 2 files changed, 21 insertions(+) diff --git a/callback.php b/callback.php index 038b6b077..2f3871e43 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 c98b8677b..479482113 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"; From 2cbe6ea4649f0f22c83b09ee6a8a455a2447b0f0 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 13 Apr 2015 19:45:41 +1000 Subject: [PATCH 3/5] Try to remember which language I'm coding in... --- callback.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/callback.php b/callback.php index 2f3871e43..62a3d85dc 100644 --- a/callback.php +++ b/callback.php @@ -19,10 +19,10 @@ function set_proxy($post) $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']); + echo "Setting proxy to ".$proxystr." (from https_proxy=".$_ENV['https_proxy'].")\n"; } if (isset($config['callback_proxy'])) { - printf("Using %s as proxy\n", $config['callback_proxy']); + echo "Using ".$config['callback_proxy']." as proxy\n"; curl_setopt($post, CURLOPT_PROXY, $config['callback_proxy']); } } From 26564c6b195d3d6416fad6b8d6da5829b1259c2e Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 13 Apr 2015 19:51:16 +1000 Subject: [PATCH 4/5] Move & rename curl proxy function --- callback.php | 19 ++----------------- includes/functions.php | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/callback.php b/callback.php index 62a3d85dc..b9bc592d7 100644 --- a/callback.php +++ b/callback.php @@ -12,21 +12,6 @@ * 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; - 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']); - } -} - $enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'"); if ($enabled == 1) { @@ -93,7 +78,7 @@ if ($enabled == 1) { rtrim($fields, '&'); $post = curl_init(); - set_proxy($post); + set_curl_proxy($post); curl_setopt($post, CURLOPT_URL, $config['callback_post']); curl_setopt($post, CURLOPT_PROXY, count($submit)); curl_setopt($post, CURLOPT_POST, count($submit)); @@ -106,7 +91,7 @@ if ($enabled == 1) { $fields = "uuid=$uuid"; $clear = curl_init(); - set_proxy($post); + set_curl_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/includes/functions.php b/includes/functions.php index 5865dc3a7..701229ecf 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']); + } +} From cd70aecc97974ec97848ed2afeac109ced2ef966 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 13 Apr 2015 20:04:41 +1000 Subject: [PATCH 5/5] Fix cut & paste errors --- callback.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/callback.php b/callback.php index b9bc592d7..2c82b3ef9 100644 --- a/callback.php +++ b/callback.php @@ -80,7 +80,6 @@ if ($enabled == 1) { $post = curl_init(); set_curl_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); @@ -91,7 +90,7 @@ if ($enabled == 1) { $fields = "uuid=$uuid"; $clear = curl_init(); - set_curl_proxy($post); + 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);