2

I have a Craft application in an intranet behind a proxy. I'm struggling to find a way of configuring the application so it can access the internet via the proxy, in particular for the auto updating and license check.

I tried using PHP's stream_context_set_default() but cannot get it to work in the admin section. Here's what i did so far:

I created a connect.php file in my public folder just to check if my script works. It does as i can get the headers for any site.

$PROXY_HOST = "url.to.my.proxy";
$PROXY_PORT = "8080";
$PROXY_USER = "username";
$PROXY_PASS = "password";

$auth = base64_encode("$PROXY_USER:$PROXY_PASS");
stream_context_set_default(
  array(
    'http' => array(
      'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
      'request_fulluri' => true,
      'header' => "Proxy-Authorization: Basic $auth"
    )
  )
);

$url = "https://elliott.buildwithcraft.com/actions/elliott/app/ping";

print_r( get_headers($url) );

From there, i'm stuck. I have no idea what to do next to try and inject that into the auto updating part of Craft. I know it's bad to mess with the core, and don't want to, but i have no idea where to go from here.

Anyone been in a similar situation ?
Am i missing something obvious where all of this wouldn't be needed ? (hope so)


Following @BradBell answer i searched for Guzzle information and found this in the documentation for Guzzle 3.x:

Requests options can be specified when creating a request or in the request.options parameter of a client. These options can control various aspects of a request including: headers to send, query string data, where the response should be downloaded, proxies, auth, etc.

$request = $client->get($url, $headers, array('proxy' => 'http://proxy.com'));

Maybe this can be put to some use in the current Craft install?
If so, some guidance will be greatly appreciated.

1

I'm not sure I've got a good answer for you here.

Craft 2.x uses Guzzle 3.x for all of its outbound communications, so I'm not sure if it would be respecting stream_context_set_default at all.

If I recall, the last time someone brought this up, we looked into it and decided we needed to update to the latest Guzzle (5.x) to properly support it (they release quickly).

Unfortunately both Guzzle 4.x and 5.x introduced breaking changes to Craft. So it'll have to be Craft 3.x before we add outbound proxy connection configuration options to Craft.

The only workarounds I can think of until then are to whitelist the IP address(es) of the Craft install to allow direct outbound access if that's possible. If you can't do that, then maybe you can just get away with manual updates and let license checking silently fail.

  • I updated my question following your answer. Looks like proxy is doable in Guzzle 3.x. I guess that would require editing the core, but until Craft 3 is released maybe that's the best option. If it is doable at all. What do you think ? – SierraRomeo Jan 16 '15 at 19:32
  • Just keep in mind that an auto-update could and a manual update would overwrite any core file changes. Also, Craft has dependencies (SimplePie for feeds, S3, Rackspace, etc.) that make their own external calls that don't go through our Guzzle dependency. – Brad Bell Jan 16 '15 at 19:41
  • Yes i am well aware of that. I will run some tests on Monday to see which files may be impacted in relation with an auto-update. I take note that proxy configuration is on your todo list for Craft 3. – SierraRomeo Jan 16 '15 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.