From 2d29bd39e4188a4f7e8315a12a50b70df1c48716 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 9 Nov 2020 11:20:23 +0100 Subject: [PATCH] Fix SSF by replacing curl with getURLContent() --- .../class/multicurrency.class.php | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index ec4b55f39dc..bb4df7060e9 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -628,46 +628,48 @@ class MultiCurrency extends CommonObject { global $conf, $db, $langs; + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + $urlendpoint = 'http://apilayer.net/api/live?access_key='.$key; //$urlendpoint.='&format=1'; $urlendpoint .= (empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '' : '&source='.$conf->global->MULTICURRENCY_APP_SOURCE); dol_syslog("Call url endpoint ".$urlendpoint); - // FIXME Use getURLContent() function instead. - $ch = curl_init($urlendpoint); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($ch); - curl_close($ch); - $response = json_decode($response); + $resget = getURLContent($urlendpoint, 'GET', '', 1, array(), array('http', 'https'), 1); - if ($response->success) - { - $TRate = $response->quotes; - $timestamp = $response->timestamp; + if ($resget['content']) { + $response = $resget['content']; + $response = json_decode($response); - if (self::recalculRates($TRate) >= 0) + if ($response->success) { - foreach ($TRate as $currency_code => $rate) + $TRate = $response->quotes; + $timestamp = $response->timestamp; + + if (self::recalculRates($TRate) >= 0) { - $code = substr($currency_code, 3, 3); - $obj = new MultiCurrency($db); - if ($obj->fetch(null, $code) > 0) + foreach ($TRate as $currency_code => $rate) { - $obj->updateRate($rate); - } elseif ($addifnotfound) - { - self::addRateFromDolibarr($code, $rate); + $code = substr($currency_code, 3, 3); + $obj = new MultiCurrency($db); + if ($obj->fetch(null, $code) > 0) + { + $obj->updateRate($rate); + } elseif ($addifnotfound) + { + self::addRateFromDolibarr($code, $rate); + } } } + + return 1; + } else { + dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING); + setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors'); + + return -1; } - - return 1; - } else { - dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING); - setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors'); - - return -1; } }