Jump to content

Settings for using SOCKS proxy for all CURL requests


phpony

Recommended Posts

Hi fellow developers and members of community. I'm here with a small quality of life suggestion that can slightly improve the usability of forum software in some cases.

The forum software I'm supporting is installed on server without direct internet access. Yes, that's weird, I know. And there's nothing I can do about. But there's a proxy server on internal network that may and should be used for all external connections. As for now I'm bound to implement a hardcode fix after each system's upgrade. All I do is editing the file system\Http\Request\Curl.php around lines 139-145 from this:

			curl_setopt_array( $this->curl, array(			
				CURLOPT_HEADER			=> TRUE,								// Specifies that we want the headers
				CURLOPT_HTTP_VERSION	=> $httpVersion,						// Sets the HTTP version
				CURLOPT_RETURNTRANSFER	=> TRUE,								// Specifies that we want the response
...

To this:

			curl_setopt_array( $this->curl, array(			
				CURLOPT_PROXY => "10.0.0.33",
				CURLOPT_PROXYPORT => "1080",
				CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
				CURLOPT_PROXYUSERPWD => "forum:password",			
				CURLOPT_HEADER			=> TRUE,								// Specifies that we want the headers
				CURLOPT_HTTP_VERSION	=> $httpVersion,						// Sets the HTTP version
				CURLOPT_RETURNTRANSFER	=> TRUE,								// Specifies that we want the response
...

After this change everything works as intended - oembed codes, updates check, marketplace, etc.

So I'm here with a suggestion - I understand that I may be a single one user with such a problem, but maybe developers would find it useful to make their system a bit better by creating a group of system settings named "Proxy" with "Use a proxy for external connections" checkbox and "Proxy IP", "Proxy port", "Proxy type", "Proxy login", "Proxy password" strings, that could be passed into curl settings right there? That wouldn't break anything for existing customers but will provide additional opportunities for others in cost of few additional code lines and one `if` check.

Thanks in advance!

Link to comment
Share on other sites

Rather than make the change every new version, you might want to take a look at writing a plugin. This guide has a complete walkthrough but you can skip everything except steps 1, 6 and 8, because all you'll need is a code hook on that class with something like:

public function __construct( $url, $timeout=5, $httpVersion=NULL, $followRedirects=TRUE, $allowedProtocols=NULL )
{
	parent::__construct( $url, $timeout, $httpVersion, $followRedirects, $allowedProtocols );
	
	curl_setopt_array( $this->curl, [		
		CURLOPT_PROXY			=> "10.0.0.33",
		CURLOPT_PROXYPORT		=> "1080",
		CURLOPT_PROXYTYPE		=> CURLPROXY_SOCKS5,
		CURLOPT_PROXYUSERPWD	=> "forum:password"
	] );
}

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...