Skip to content

Commit

Permalink
Merge pull request #26 from rtp-cgs/feature/curl-proxy-option
Browse files Browse the repository at this point in the history
Feature/curl proxy option
  • Loading branch information
Benjamin-K authored Jan 9, 2024
2 parents ad05dc7 + ba2156e commit 41542f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Classes/RequestMethod/CurlPostWithProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ public function injectSettings(array $settings)
throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option has to be a string.");
}

$httpProxyParts = explode(':', $settings['httpProxy']);
if(count($httpProxyParts) !== 2 || (int)$httpProxyParts[1] === 0){
$httpProxy = $settings['httpProxy'];
$this->emitHttpProxyRetrieved($httpProxy);

$formatIsValid = preg_match('@^(.*):(\d{1,5})$@', $httpProxy, $httpProxyParts);
$this->proxyHost = $httpProxyParts[1];
$this->proxyPort = (int)$httpProxyParts[2];

if(!$formatIsValid || !$this->proxyHost || !$this->proxyPort){
throw new \Exception("Invalid configuration, the Wegmeister.Recaptcha.httpProxy option should have the following format: 'http://yourproxy.com:1234'");
}

$this->proxyHost = $httpProxyParts[0];
$this->proxyPort = $httpProxyParts[1];

$this->settings = $settings;
}

Expand Down Expand Up @@ -110,9 +113,6 @@ public function submit(RequestParameters $params)
CURLOPT_SSL_VERIFYPEER => true,
];

$httpProxy = $this->settings['httpProxy'];
$this->emitHttpProxyRetrieved($httpProxy);

$options[CURLOPT_RETURNTRANSFER] = 1;
$options[CURLOPT_PROXY] = $this->proxyHost;
$options[CURLOPT_PROXYPORT] = $this->proxyPort;
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ composer require wegmeister/recaptcha

Afterwards, go to [http://www.google.com/recaptcha](http://www.google.com/recaptcha) and create a key for your website. Select the API version you wish to use based on the list above.

## Configuration

### HTTP Proxy
If you are using a http proxy on your server you need to add this configuration:
```
Wegmeister:
Recaptcha:
requestMethod: 'Wegmeister\Recaptcha\RequestMethod\CurlPostWithProxy'
httpProxy: 'http://yourproxy.com:1234'
```

## Usage with [Neos.Form](https://github.com/neos/form)

Simply add the new form element to your form definition renderables:
Expand Down

0 comments on commit 41542f1

Please sign in to comment.