Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy settings\hook for plugins #2437

Open
jpobeda opened this issue Feb 21, 2019 · 5 comments
Open

Proxy settings\hook for plugins #2437

jpobeda opened this issue Feb 21, 2019 · 5 comments
Labels
enhancement General tag for an enhancement
Milestone

Comments

@jpobeda
Copy link
Contributor

jpobeda commented Feb 21, 2019

I've opened a Feature request for Mactrack and @cigamit mentioned that it would also be useful for other plugins.

I'd like an option to create proxy servers that could later on be used on different plugins such as WebSeer, Mactrack, etc. Some of these plugins need to reach URLs for one thing or another, either internally or at internet.

I couldn't find any practical alternative to replace the proxy's function.

Mactrack has an option to import or update MAC OUI Database from internet BUT, at least on my case, most of the servers allowed to go out to internet must use a proxy.

image

Let me know if you need further details.

@netniV
Copy link
Member

netniV commented Feb 21, 2019

It would depend on what is being used. For raw PHP we can use the following if all connections should be proxied:

stream_context_set_default([
    'http'=>[
        'proxy'=>'proxy-host:proxy-port', 
        'header'=>'Proxy-Authorization: Basic ' . 
           base64_encode('your-username:your-password')
    ]
]);

For curl:

function getUrl($url)
{
    $ch = curl_init(); 
    $timeout = 5; // set to zero for no timeout 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_PROXY, "http://proxy.example.com"); //your proxy url
    curl_setopt($ch, CURLOPT_PROXYPORT, "8080"); // your proxy port number 
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, "username:pass"); //username:pass 
    $file_contents = curl_exec($ch); 
    curl_close($ch); 
    return $file_contents;
}

An example of the first option is showing in this gist (which i've copied below in case it gets removed):
https://gist.github.com/ebuildy/381f116e9cd18216a69188ce0230708d

$proxy = getenv('http_proxy');
if (!empty($proxy)) {
    $proxy = str_replace('http://', 'tcp://', $proxy);
    echo "Found a proxy " . $proxy . PHP_EOL;
    $context = array(
        'http' => array(
            'proxy' => $proxy,
            'request_fulluri' => true,
            'verify_peer'      => false,
            'verify_peer_name' => false,
        ),
        "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false
        )
    );
    stream_context_set_default($context);
} else {
    echo "Proxy not found" . PHP_EOL;
}

This would not cover everything though, since we also call scripts which could be using SSH/SCP/SFTP or some other protocol. Currently, the poller uses the stream_context when connecting to a remote poller but i don't think that has proxy settings yet.

@cigamit cigamit added the enhancement General tag for an enhancement label Feb 23, 2019
@JorisFRST
Copy link

Hi,
I already have been adding the curl proxy manually to some of the plugins on my cacti install. For instance mactrack for the oui update and flowview for the arin lookups.

Having this as a cacti global setting or a per plugin setting would be very helpfull.

@netniV netniV added this to the v1.3.0 milestone Mar 4, 2020
@netniV
Copy link
Member

netniV commented Mar 4, 2020

We can look at introducing base settings, and then tackle those places that are missed via issue trackers later.

@TheWitness
Copy link
Member

Yea, that's what I'm thinking. Need a user/password/proxy/port. Add it to the 'Mail/Reporting/DNS' page.

netniV added a commit that referenced this issue May 4, 2020
@netniV
Copy link
Member

netniV commented May 4, 2020

The system options have been added to 1.3, but no functionality has been added yet.

@TheWitness TheWitness changed the title [Feature request] Proxy settings\hook for plugins Proxy settings\hook for plugins Mar 21, 2021
@netniV netniV modified the milestones: v1.3.0, v1.4.0 Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement General tag for an enhancement
Projects
None yet
Development

No branches or pull requests

5 participants