-
Notifications
You must be signed in to change notification settings - Fork 66
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
base: 1.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
/* | ||
/** | ||
* MailWatch for MailScanner | ||
* Copyright (C) 2003-2011 Steve Freegard (steve@freegard.name) | ||
* Copyright (C) 2011 Garrod Alwood (garrod.alwood@lorodoes.com) | ||
|
@@ -33,7 +33,7 @@ | |
|
||
html_start(__('geoipupdate15'), 0, false, false); | ||
|
||
if (!defined('MAXMIND_LICENSE_KEY') || !validateInput(MAXMIND_LICENSE_KEY, 'maxmind')) { | ||
if (!defined('MAXMIND_LICENSE_KEY') || !defined('MAXMIND_ACCOUNT_ID') || !validateInput(MAXMIND_LICENSE_KEY, 'maxmind')) { | ||
$error_message = __('geoipnokey15') . '<br>' . "\n"; | ||
exit($error_message); | ||
} elseif (!isset($_POST['run'])) { | ||
|
@@ -55,15 +55,13 @@ | |
</table> | ||
</form>' . "\n"; | ||
} else { | ||
require_once __DIR__ . '/lib/request/Requests.php'; | ||
Requests::register_autoloader(); | ||
|
||
ob_start(); | ||
echo __('downfile15') . '<br>' . "\n"; | ||
|
||
$files_base_url = 'https://download.maxmind.com'; | ||
$urlSchema = 'https://'; | ||
$downloadServer = 'download.maxmind.com'; | ||
$file['description'] = __('geoip15'); | ||
$file['path'] = '/app/geoip_download?edition_id=GeoLite2-Country&suffix=tar.gz&license_key=' . MAXMIND_LICENSE_KEY; | ||
$file['path'] = '/geoip/databases/GeoLite2-Country/download?suffix=tar.gz'; | ||
$file['destination'] = __DIR__ . '/temp/GeoLite2-Country.tar.gz'; | ||
$file['destinationFileName'] = 'GeoLite2-Country.mmdb'; | ||
|
||
|
@@ -80,44 +78,46 @@ | |
if (!file_exists($file['destination'])) { | ||
if (is_writable($extract_dir) && is_readable($extract_dir)) { | ||
if (function_exists('fsockopen') || extension_loaded('curl')) { | ||
$requestSession = new Requests_Session($files_base_url . '/'); | ||
$requestSession->options['useragent'] = 'MailWatch/' . mailwatch_version(); | ||
if (USE_PROXY === true) { | ||
$ch = curl_init($urlSchema . $downloadServer . $file['path']); | ||
Check notice on line 81 in mailscanner/geoip_update.php Codacy Production / Codacy Static Code Analysismailscanner/geoip_update.php#L81
|
||
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); | ||
Comment on lines
+81
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
if (PROXY_USER !== '') { | ||
$requestSession->options['proxy']['authentication'] = [ | ||
PROXY_SERVER . ':' . PROXY_PORT, | ||
PROXY_USER, | ||
PROXY_PASS, | ||
]; | ||
} else { | ||
$requestSession->options['proxy']['authentication'] = [ | ||
PROXY_SERVER . ':' . PROXY_PORT, | ||
]; | ||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USER . ':' . PROXY_PASS); | ||
} | ||
|
||
switch (PROXY_TYPE) { | ||
case 'HTTP': | ||
case 'CURLPROXY_HTTP': // BC for old constant name | ||
// $requestProxy = new Requests_Proxy_HTTP($requestProxyParams); | ||
$requestSession->options['proxy']['type'] = 'HTTP'; | ||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); | ||
break; | ||
case 'SOCKS5': | ||
case 'CURLPROXY_SOCKS5': // BC for old constant name | ||
$requestSession->options['proxy']['type'] = 'SOCKS5'; | ||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); | ||
break; | ||
default: | ||
exit(__('dieproxy15')); | ||
} | ||
} | ||
|
||
try { | ||
$requestSession->options['filename'] = $file['destination']; | ||
$result = $requestSession->get($file['path']); | ||
if (true === $result->success) { | ||
$fpDestinationFile = fopen($file['destination'], 'w'); | ||
curl_setopt($ch, CURLOPT_FILE, $fpDestinationFile); | ||
curl_exec($ch); | ||
if (empty(curl_error($ch))) { | ||
echo $file['description'] . ' ' . __('downok15') . '<br>' . "\n"; | ||
} else { | ||
echo __('downbad15') . ' ' . $file['description'] . __('colon99') . ' ' . curl_error($ch) . "<br>\n"; | ||
} | ||
} catch (Requests_Exception $e) { | ||
echo __('downbad15') . ' ' . $file['description'] . __('colon99') . ' ' . $e->getMessage() . "<br>\n"; | ||
} catch (Exception $e) { | ||
echo __('downbad15') . ' ' . $file['description'] . __('colon99') . ' ' . curl_error($ch) . "<br>\n"; | ||
} finally { | ||
fclose($fpDestinationFile); | ||
} | ||
|
||
ob_flush(); | ||
|
@@ -137,7 +137,7 @@ | |
} | ||
} | ||
|
||
$command = escapeshellcmd('wget ' . $proxyString . ' -N ' . $files_base_url . $file['path'] . ' -O ' . $file['destination']); | ||
$command = escapeshellcmd('wget ' . $proxyString . ' -N ' . $urlSchema . MAXMIND_ACCOUNT_ID . ':' . MAXMIND_LICENSE_KEY . '@' . $downloadServer . $file['path'] . ' -O ' . $file['destination']); | ||
$result = exec( | ||
$command, | ||
$output_wget, | ||
|
There was a problem hiding this comment.
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?