function formulaires_configurer_relayeur_verifier_dist() { $erreurs = array(); $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', '')); $http_noproxy = _request('http_noproxy'); if ($http_proxy and !tester_url_absolue($http_proxy)) { $erreurs['http_proxy'] = _T('info_url_proxy_pas_conforme'); } if (!isset($erreurs['http_proxy']) and _request('tester_proxy')) { if (!$http_proxy) { $erreurs['http_proxy'] = _T('info_obligatoire'); } else { include_spip('inc/distant'); $test_proxy = _request('test_proxy'); $t = parse_url($test_proxy); if (!@$t['host']) { $erreurs['test_proxy'] = _T('info_adresse_non_indiquee'); } else { include_spip('inc/texte'); // pour aide, couper, lang $info = ""; if (!need_proxy($t['host'], $http_proxy, $http_noproxy)) { $info = "<strong>" . _T('page_pas_proxy') . "</strong><br />"; } // il faut fausser le proxy actuel pour faire le test ! $cur_http_proxy = $GLOBALS['meta']['http_proxy']; $cur_http_noproxy = $GLOBALS['meta']['http_noproxy']; $GLOBALS['meta']['http_proxy'] = $http_proxy; $GLOBALS['meta']['http_noproxy'] = $http_noproxy; $page = recuperer_page($test_proxy, true); $GLOBALS['meta']['http_proxy'] = $cur_http_proxy; $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy; if ($page) { $erreurs['message_ok'] = _T('info_proxy_ok') . "<br />{$info}\n<tt>" . couper(entites_html($page), 300) . "</tt>"; $erreurs['message_erreur'] = ''; } else { $erreurs['message_erreur'] = $info . _T('info_impossible_lire_page', array('test_proxy' => "<tt>{$test_proxy}</tt>")) . " <b><tt>" . no_password_proxy_url($http_proxy) . "</tt></b>." . aide('confhttpproxy'); } } } } return $erreurs; }
function configuration_relayeur_post ($http_proxy, $http_noproxy, $test_proxy, $tester_proxy) { // http_proxy : ne pas prendre en compte la modif si le password est '****' if (preg_match(',:\*\*\*\*@,', $http_proxy)) $http_proxy = $GLOBALS['meta']['http_proxy']; $retour = $page = ''; if ($tester_proxy AND preg_match(",https?://,", $http_proxy)) { include_spip('inc/distant'); $t = parse_url($test_proxy); if (!@$t['host']) { $retour = _T('info_adresse_non_indiquee'); } elseif (!need_proxy($t['host'])) { $retour = "<p>"._T('page_pas_proxy')."</p>\n"; } elseif ($page = recuperer_page($test_proxy, true)) { include_spip('inc/texte'); // pour aide, couper, lang $retour = "<p>"._T('info_proxy_ok')."</p>\n<tt>" . couper(entites_html($page),300)."</tt>"; } else $retour = _T('info_impossible_lire_page', array('test_proxy' => $test_proxy)) . " <tt>".no_password_proxy_url($http_proxy)."</tt>." . aide('confhttpproxy'); } if ($http_proxy !== NULL) { ecrire_meta('http_proxy', $http_proxy); } if ($http_noproxy !== NULL) { ecrire_meta('http_noproxy', $http_noproxy); } if ($page) { include_spip('install/etape_fin'); $retour .= install_verifier_htaccess(); } return $retour; }
function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = '') { $proxy_user = ''; $http_proxy = need_proxy($host); if ($user) { $user = urlencode($user[0]) . ":" . urlencode($user[1]); } if ($http_proxy) { $path = ($scheme == 'ssl' ? 'https://' : "{$scheme}://") . (!$user ? '' : "{$user}@") . "{$host}" . ($port != 80 ? ":{$port}" : "") . $path; $t2 = @parse_url($http_proxy); $first_host = $t2['host']; if (!($port = $t2['port'])) { $port = 80; } if ($t2['user']) { $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); } } else { $first_host = $noproxy . $host; } $f = @fsockopen($first_host, $port); spip_log("Recuperer {$path} sur {$first_host}:{$port} par {$f}"); if (!$f) { return false; } $site = $GLOBALS['meta']["adresse_site"]; $req = "{$method} {$path} {$vers}\r\n" . "Host: {$host}\r\n" . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" . ($refuse_gz ? '' : "Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n") . (!$site ? '' : "Referer: {$site}/{$referer}\r\n") . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) . " GMT\r\n")) . (!$user ? '' : "Authorization: Basic " . base64_encode($user) . "\r\n") . (!$proxy_user ? '' : "Proxy-Authorization: Basic {$proxy_user}\r\n") . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); # spip_log("Requete\n$req"); fputs($f, $req); fputs($f, $datas ? $datas : "\r\n"); return $f; }
/** * Lancer la requete proprement dite * * @param string $method * type de la requete (GET, HEAD, POST...) * @param string $scheme * protocole (http, tls, ftp...) * @param array $user * couple (utilisateur, mot de passe) en cas d'authentification http * @param string $host * nom de domaine * @param string $path * chemin de la page cherchee * @param string $port * port utilise pour la connexion * @param bool $noproxy * protocole utilise si requete sans proxy * @param bool $refuse_gz * refuser la compression GZ * @param string $referer * referer * @param string $datas * donnees postees * @param string $vers * version HTTP * @param int|string $date * timestamp pour entente If-Modified-Since * @return bool|resource * false|int si echec * resource socket vers l'url demandee */ function lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz = false, $referer = '', $datas = "", $vers = "HTTP/1.0", $date = '') { $proxy_user = ''; $http_proxy = need_proxy($host); if ($user) { $user = urlencode($user[0]) . ":" . urlencode($user[1]); } $connect = ""; if ($http_proxy) { 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 == 'tls' ? 'https://' : "{$scheme}://") . (!$user ? '' : "{$user}@") . "{$host}" . ($port != 80 ? ":{$port}" : "") . $path; } $t2 = @parse_url($http_proxy); $first_host = $t2['host']; if (!($port = $t2['port'])) { $port = 80; } if ($t2['user']) { $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); } } else { $first_host = $noproxy . $host; } if ($connect) { $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); $f = @stream_socket_client("tcp://{$first_host}:{$port}", $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); spip_log("Recuperer {$path} sur {$first_host}:{$port} par {$f} (via CONNECT)", "connect"); if (!$f) { spip_log("Erreur connexion {$errno} {$errstr}", _LOG_ERREUR); return $errno; } stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); fputs($f, $connect); fputs($f, "\r\n"); $res = fread($f, 1024); if (!$res or !count($res = explode(' ', $res)) or $res[1] !== '200') { spip_log("Echec CONNECT sur {$first_host}:{$port}", "connect" . _LOG_INFO_IMPORTANTE); fclose($f); return false; } // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo stream_set_blocking($f, true); // envoyer le handshake stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); spip_log("OK CONNECT sur {$first_host}:{$port}", "connect"); } else { $ntry = 3; do { $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); spip_log("Recuperer {$path} sur {$first_host}:{$port} par {$f}"); if (!$f) { spip_log("Erreur connexion {$errno} {$errstr}", _LOG_ERREUR); return $errno; } stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); } $site = isset($GLOBALS['meta']["adresse_site"]) ? $GLOBALS['meta']["adresse_site"] : ''; $req = "{$method} {$path} {$vers}\r\n" . "Host: {$host}\r\n" . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" . ($refuse_gz ? '' : "Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n") . (!$site ? '' : "Referer: {$site}/{$referer}\r\n") . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) . " GMT\r\n")) . (!$user ? '' : "Authorization: Basic " . base64_encode($user) . "\r\n") . (!$proxy_user ? '' : "Proxy-Authorization: Basic {$proxy_user}\r\n") . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); # spip_log("Requete\n$req"); fputs($f, $req); fputs($f, $datas ? $datas : "\r\n"); return $f; }
function migration_lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz=false, $referer = '', $datas="", $vers="HTTP/1.0", $date='') { $proxy_user = ''; $http_proxy = need_proxy($host); if ($user) $user = urlencode($user[0]).":".urlencode($user[1]); if ($http_proxy) { $path = "$scheme://" . (!$user ? '' : "$user@") . "$host" . (($port != 80) ? ":$port" : "") . $path; $t2 = @parse_url($http_proxy); $first_host = $t2['host']; if (!($port = $t2['port'])) $port = 80; if ($t2['user']) $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); } else $first_host = $noproxy.$host; $f = @fsockopen($first_host, $port); spip_log("Recuperer $path sur $first_host:$port par $f"); if (!$f) return false; $site = $GLOBALS['meta']["adresse_site"]; $req = "$method $path $vers\r\n" . "Host: $host\r\n" . "User-Agent: " . _INC_DISTANT_USER_AGENT . "\r\n" . ($refuse_gz ? '' : ("Accept-Encoding: " . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) . (!$site ? '' : "Referer: $site/$referer\r\n") . (!$date ? '' : "If-Modified-Since: " . (gmdate("D, d M Y H:i:s", $date) ." GMT\r\n")) . (!$user ? '' : ("Authorization: Basic " . base64_encode($user) ."\r\n")) . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); # spip_log("Requete\n$req"); fputs($f, $req); fputs($f, $datas ? $datas : "\r\n"); return $f; }