X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fdistant.php;fp=www%2Fecrire%2Finc%2Fdistant.php;h=31b5e519db838b42c977d3aae56db76df526d27d;hb=d18fcb8f27a4016e3fa7b50a9b2255d529dca543;hp=e433095b801fbbae5a77cc83147ec4b9886d568a;hpb=e847eea4a82a7396dd0abf860f9b30d654f38629;p=ptitvelo%2Fweb%2Fwww.git diff --git a/www/ecrire/inc/distant.php b/www/ecrire/inc/distant.php index e433095..31b5e51 100644 --- a/www/ecrire/inc/distant.php +++ b/www/ecrire/inc/distant.php @@ -21,6 +21,7 @@ if (!defined('_INC_DISTANT_VERSION_HTTP')) define('_INC_DISTANT_VERSION_HTTP', " if (!defined('_INC_DISTANT_CONTENT_ENCODING')) define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); if (!defined('_INC_DISTANT_USER_AGENT')) define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); if (!defined('_INC_DISTANT_MAX_SIZE')) define('_INC_DISTANT_MAX_SIZE',2097152); +if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT',10); define('_REGEXP_COPIE_LOCALE', ',' . preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) @@ -661,8 +662,8 @@ function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "" $scheme = 'http'; $noproxy = ''; } elseif ($t['scheme']=='https') { - $scheme = 'ssl'; - $noproxy = 'ssl://'; + $scheme = 'tls'; + $noproxy = 'tls://'; if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; } else { @@ -680,7 +681,8 @@ function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = "" if (!$f){ // fallback : fopen if (!need_proxy($host) - AND !_request('tester_proxy')){ + AND !_request('tester_proxy') + AND (!isset($GLOBALS['inc_distant_allow_fopen']) OR $GLOBALS['inc_distant_allow_fopen'])){ $f = @fopen($url, "rb"); spip_log("connexion vers $url par simple fopen"); $fopen = true; @@ -702,14 +704,14 @@ function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $ $connect = ""; if ($http_proxy){ - if (defined('_PROXY_HTTPS_VIA_CONNECT') AND $scheme=="ssl"){ + if (defined('_PROXY_HTTPS_VIA_CONNECT') AND $scheme=="tls"){ $path_host = (!$user ? '' : "$user@") . $host . (($port!=80) ? ":$port" : ""); $connect = "CONNECT " .$path_host." $vers\r\n" ."Host: $path_host\r\n" ."Proxy-Connection: Keep-Alive\r\n"; } else { - $path = (($scheme=='ssl') ? 'https://' : "$scheme://") + $path = (($scheme=='tls') ? 'https://' : "$scheme://") . (!$user ? '' : "$user@") . "$host" . (($port!=80) ? ":$port" : "") . $path; } @@ -724,10 +726,10 @@ function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $ if ($connect){ $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); - $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, 10, STREAM_CLIENT_CONNECT, $streamContext); + $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); if (!$f) return false; - stream_set_timeout($f, 10); + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); fputs($f, $connect); fputs($f, "\r\n"); @@ -746,9 +748,13 @@ function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $ spip_log("OK CONNECT sur $first_host:$port","connect"); } else { - $f = @fsockopen($first_host, $port); + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); spip_log("Recuperer $path sur $first_host:$port par $f"); - if (!$f) return false; + if (!$f) { + spip_log("Erreur connexion $errno $errstr",_LOG_ERREUR); + return false; + } + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); } $site = $GLOBALS['meta']["adresse_site"];