mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #791 from paulgear/master
Add proxy support for callback stats
This commit is contained in:
10
callback.php
10
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());
|
||||
}
|
||||
|
||||
|
@@ -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";
|
||||
|
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user