From ae89c2175b688b1877064eae1ad5112d5b3c5fc2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 3 Apr 2011 18:02:18 +0000 Subject: [PATCH] New: Add global parameter connect timeout and response timeout for all external access. --- htdocs/admin/proxy.php | 2 +- htdocs/langs/en_US/admin.lang | 2 +- htdocs/langs/fr_FR/admin.lang | 2 +- htdocs/lib/functions2.lib.php | 50 +++++++++++++++++++++-- htdocs/societe/checkvat/checkVatPopup.php | 6 ++- 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/proxy.php b/htdocs/admin/proxy.php index ea47060b5a0..419f8454152 100755 --- a/htdocs/admin/proxy.php +++ b/htdocs/admin/proxy.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index b46f7471d62..556aac1911e 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -823,7 +823,7 @@ MAIN_DISABLE_METEO=Disable meteo view TestLoginToAPI=Test login to API ProxyDesc=Some features of Dolibarr need to have an Internet access to work. Define here parameters for this. If the Dolibarr server is behind a Proxy server, those parameters tells Dolibarr how to access Internet through it. ExternalAccess=External access -MAIN_PROXY_USE=Use a proxy server +MAIN_PROXY_USE=Use a proxy server (otherwise direct access to internet) MAIN_PROXY_HOST=Name/Address of proxy server MAIN_PROXY_PORT=Port of proxy server MAIN_PROXY_USER=Login to use the proxy server diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 8d07a3c1593..7e0842d7ad0 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -834,7 +834,7 @@ MAIN_DISABLE_METEO=Désactiver la vue météo TestLoginToAPI=Tester connexion à l'API ProxyDesc=Certaines fonctions de Dolibarr nécessitent que le serveur ait accès à internet. Définissez ici les paramètres de ces accès. Si le serveur Dolibarr est derrière un proxy, ces paramètres indiquent à Dolibarr comment le traverser. ExternalAccess=Accès externes -MAIN_PROXY_USE=Utiliser un serveur proxy mandataire +MAIN_PROXY_USE=Utiliser un serveur proxy mandataire (sinon accès direct à internet) MAIN_PROXY_HOST=Nom/Adresse du serveur proxy mandataire MAIN_PROXY_PORT=Port du serveur proxy mandataire MAIN_PROXY_USER=Login pour passer le serveur proxy mandataire diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index 0ad45864139..f0fefed5b96 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -430,10 +430,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; } elseif (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; } if (dol_strlen($reg[$posy]) < 2) return 'ErrorCantUseRazWithYearOnOneDigit'; - } + } else { - if (! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazIfNoYearInMask'; + if (! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazIfNoYearInMask'; if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; } } //print "x".$maskwithonlyymcode." ".$maskraz." ".$posy." ".$posm; @@ -1113,4 +1113,48 @@ function dol_buildlogin($lastname,$firstname) $login.=strtolower(dol_string_unaccent($lastname)); $login=dol_string_nospecial($login,''); // For special names return $login; -} \ No newline at end of file +} + + + +/** + * Return array to use for SoapClient constructor + * @return param + */ +function getSoapParams() +{ + global $conf; + + $params=array(); + $proxyuse=($conf->global->MAIN_PROXY_USE?true:false); + $proxyhost=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_HOST:false); + $proxyport=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_PORT:false); + $proxyuser=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_USER:false); + $proxypass=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_PASS:false); + $timeout=(empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?10:$conf->global->MAIN_USE_CONNECT_TIMEOUT); // Connection timeout + $response_timeout=(empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT); // Response timeout + //print extension_loaded('soap'); + if ($proxyuse) + { + $params=array('connection_timeout'=>$timeout, + 'response_timeout'=>$response_timeout, + 'proxy_use' => 1, + 'proxy_host' => $proxyhost, + 'proxy_port' => $proxyport, + 'proxy_login' => $proxyuser, + 'proxy_password' => $proxypass + ); + } + else + { + $params=array('connection_timeout'=>$timeout, + 'response_timeout'=>$response_timeout, + 'proxy_use' => 0, + 'proxy_host' => false, + 'proxy_port' => false, + 'proxy_login' => false, + 'proxy_password' => false + ); + } + return $params; +} diff --git a/htdocs/societe/checkvat/checkVatPopup.php b/htdocs/societe/checkvat/checkVatPopup.php index 3232406474b..1280775e1b7 100644 --- a/htdocs/societe/checkvat/checkVatPopup.php +++ b/htdocs/societe/checkvat/checkVatPopup.php @@ -63,7 +63,11 @@ else // Set the WebService URL dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL); - $soapclient = new nusoap_client($WS_DOL_URL_WSDL,true); + require_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); + $params=getSoapParams(); + //ini_set('default_socket_timeout', $params['response_timeout']); + //$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params); + $soapclient = new nusoap_client($WS_DOL_URL_WSDL,true,$params['proxy_host'],$params['proxy_port'],$params['proxy_login'],$params['proxy_password'],$params['connection_timeout'],$params['response_timeout']); // Check for an error $err = $soapclient->getError();