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

Update GeoIP to support authentication by account id+license key #1302

Open
wants to merge 2 commits into
base: 1.2
Choose a base branch
from

Conversation

Skywalker-11
Copy link
Member

fixes #1301

Comment on lines +81 to +89
$ch = curl_init($urlSchema . $downloadServer . $file['path']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERNAME, MAXMIND_ACCOUNT_ID);
curl_setopt($ch, CURLOPT_PASSWORD, MAXMIND_LICENSE_KEY);
curl_setopt($ch, CURLOPT_USERAGENT, 'MailWatch/' . mailwatch_version());
if (defined('USE_PROXY') && USE_PROXY === true) {
curl_setopt($ch, CURLOPT_PROXY, PROXY_SERVER);
curl_setopt($ch, CURLOPT_PROXYPORT, PROXY_PORT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try Requests_Auth_Basic in $requestSession->options['auth']? I don't like very much removing Requests integration

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I

Did you try Requests_Auth_Basic in $requestSession->options['auth']? I don't like very much removing Requests integration

To be honest I thought it might be good to remove the Request library as it is big piece of code for just downloading a file and it was orignally introduced for geoip download (if the commit history is correct) and isn't used anywhere else right now. But I'm fine if you want to keep it.

I did try the auth option of the requestsession but it didn't work that time. But I also didn't invest a lot of time trying. So it might just have been me 🤷.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, Requests was introduced simplify the geoip file download in 2015, and it proved useful to manage automatically the redirection that MaxMind apply on the download link when they switched to CloudFlare R2 storage: with curl you have to check the first response for a 301/302 redirect location and then make a second request to download from the correct location. The actual library in mailscanner/lib/request has also been patched to support HTTP/2 calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CURLOPT_FOLLOWLOCATION options tells curl to follow such redirects and I'm pretty sure that HTTP/2 is supported out of the box. Corresponding feature flags are supported since PHP 7.0.7 (release 05/2016) and matching curl versions also since 2016.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it seems anachronistic, but the 1.2.x branch needs to support PHP 5, so PHP 7+ solutions are a no go in 1.2 :(

We should start a 1.3 branch with php 7.4 support or even better align with officially supported only PHP version

$file['description'] = __('geoip15');
$file['path'] = '/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=' . MAXMIND_LICENSE_KEY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still working for my legacy Maxmind key, should we fall back and attempt this download when MAXMIND_ACCOUNT_ID is not populated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot Update GeoIP Database
3 participants