@@ -147,7 +147,7 @@ |
||
| 147 | 147 | /** |
| 148 | 148 | * Verifier qu'une url est absolue et que son protocole est bien parmi une liste autorisee |
| 149 | 149 | * @param string $url_absolue |
| 150 | - * @param array $protocoles_autorises |
|
| 150 | + * @param string[] $protocoles_autorises |
|
| 151 | 151 | * @return bool |
| 152 | 152 | */ |
| 153 | 153 | function protocole_verifier($url_absolue, $protocoles_autorises = array('http','https')) { |
@@ -15,13 +15,25 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 18 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 19 | + return; |
|
| 20 | +} |
|
| 19 | 21 | |
| 20 | -if (!defined('_INC_DISTANT_VERSION_HTTP')) define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0"); |
|
| 21 | -if (!defined('_INC_DISTANT_CONTENT_ENCODING')) define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); |
|
| 22 | -if (!defined('_INC_DISTANT_USER_AGENT')) define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); |
|
| 23 | -if (!defined('_INC_DISTANT_MAX_SIZE')) define('_INC_DISTANT_MAX_SIZE',2097152); |
|
| 24 | -if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
|
| 22 | +if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0"); |
|
| 24 | +} |
|
| 25 | +if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', "gzip"); |
|
| 27 | +} |
|
| 28 | +if (!defined('_INC_DISTANT_USER_AGENT')) { |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . " (" . $GLOBALS['home_server'] . ")"); |
|
| 30 | +} |
|
| 31 | +if (!defined('_INC_DISTANT_MAX_SIZE')) { |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE',2097152); |
|
| 33 | +} |
|
| 34 | +if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT',10); |
|
| 36 | +} |
|
| 25 | 37 | |
| 26 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 27 | 39 | preg_replace('@^https?:@', 'https?:', $GLOBALS['meta']['adresse_site']) |
@@ -57,9 +69,9 @@ discard block |
||
| 57 | 69 | return @file_exists($source) ? $source : false; |
| 58 | 70 | } |
| 59 | 71 | |
| 60 | - if (is_null($local)) |
|
| 61 | - $local = fichier_copie_locale($source); |
|
| 62 | - else { |
|
| 72 | + if (is_null($local)) { |
|
| 73 | + $local = fichier_copie_locale($source); |
|
| 74 | + } else { |
|
| 63 | 75 | if (_DIR_RACINE AND strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE))==0) { |
| 64 | 76 | $local = substr($local, strlen(_DIR_RACINE)); |
| 65 | 77 | } |
@@ -68,27 +80,36 @@ discard block |
||
| 68 | 80 | // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
| 69 | 81 | // par exemple un fichier qui ne figure pas dans nos documents ; |
| 70 | 82 | // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
| 71 | - if (!$local) return false; |
|
| 83 | + if (!$local) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 72 | 86 | |
| 73 | 87 | $localrac = _DIR_RACINE.$local; |
| 74 | 88 | $t = ($mode=='force') ? false : @file_exists($localrac); |
| 75 | 89 | |
| 76 | 90 | // test d'existence du fichier |
| 77 | - if ($mode=='test') return $t ? $local : ''; |
|
| 91 | + if ($mode=='test') { |
|
| 92 | + return $t ? $local : ''; |
|
| 93 | + } |
|
| 78 | 94 | |
| 79 | 95 | // sinon voir si on doit/peut le telecharger |
| 80 | - if ($local==$source OR !preg_match(',^\w+://,', $source)) |
|
| 81 | - return $local; |
|
| 96 | + if ($local==$source OR !preg_match(',^\w+://,', $source)) { |
|
| 97 | + return $local; |
|
| 98 | + } |
|
| 82 | 99 | |
| 83 | 100 | if ($mode=='modif' OR !$t){ |
| 84 | 101 | // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
| 85 | 102 | // et des eventuelles recuperations concurantes |
| 86 | 103 | include_spip("inc/acces"); |
| 87 | - if (!$taille_max) $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 104 | + if (!$taille_max) { |
|
| 105 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 106 | + } |
|
| 88 | 107 | $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : ''); |
| 89 | 108 | if (!$res) { |
| 90 | - if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 109 | + if (!$t) { |
|
| 110 | + // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false |
|
| 91 | 111 | spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE); |
| 112 | + } |
|
| 92 | 113 | return $t ? $local : false; |
| 93 | 114 | } |
| 94 | 115 | spip_log("copie_locale : recuperation $source sur $localrac taille $res OK"); |
@@ -224,8 +245,7 @@ discard block |
||
| 224 | 245 | $donnees = substr($donnees, $p+2); |
| 225 | 246 | } |
| 226 | 247 | $chaine = str_replace("\n", "\r\n", $donnees); |
| 227 | - } |
|
| 228 | - else { |
|
| 248 | + } else { |
|
| 229 | 249 | /* boundary automatique */ |
| 230 | 250 | // Si on a plus de 500 octects de donnees, on "boundarise" |
| 231 | 251 | if ($boundary===''){ |
@@ -340,18 +360,22 @@ discard block |
||
| 340 | 360 | // $copy = copier le fichier ? |
| 341 | 361 | $copy = (is_string($trans) AND strlen($trans)>5); // eviter "false" :-) |
| 342 | 362 | |
| 343 | - if (is_null($taille_max)) |
|
| 344 | - $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 363 | + if (is_null($taille_max)) { |
|
| 364 | + $taille_max = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 365 | + } |
|
| 345 | 366 | |
| 346 | 367 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// |
| 347 | 368 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 348 | - if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url; |
|
| 369 | + if (!preg_match(',^[a-z]+://,i', $url)) { |
|
| 370 | + $url = 'http://' . $url; |
|
| 371 | + } |
|
| 349 | 372 | $url = url_to_ascii($url); |
| 350 | 373 | |
| 351 | - if ($taille_max==0) |
|
| 352 | - $get = 'HEAD'; |
|
| 353 | - else |
|
| 354 | - $get = 'GET'; |
|
| 374 | + if ($taille_max==0) { |
|
| 375 | + $get = 'HEAD'; |
|
| 376 | + } else { |
|
| 377 | + $get = 'GET'; |
|
| 378 | + } |
|
| 355 | 379 | |
| 356 | 380 | if (!empty($datas)) { |
| 357 | 381 | $get = 'POST'; |
@@ -362,11 +386,15 @@ discard block |
||
| 362 | 386 | // dix tentatives maximum en cas d'entetes 301... |
| 363 | 387 | for ($i = 0; $i<10; $i++){ |
| 364 | 388 | $url = recuperer_lapage($url, $trans, $get, $taille_max, $datas, $refuser_gz, $date_verif, $uri_referer); |
| 365 | - if (!$url) return false; |
|
| 389 | + if (!$url) { |
|
| 390 | + return false; |
|
| 391 | + } |
|
| 366 | 392 | if (is_array($url)){ |
| 367 | 393 | list($headers, $result) = $url; |
| 368 | 394 | return ($get_headers ? $headers . "\n" : '') . $result; |
| 369 | - } else spip_log("recuperer page recommence sur $url"); |
|
| 395 | + } else { |
|
| 396 | + spip_log("recuperer page recommence sur $url"); |
|
| 397 | + } |
|
| 370 | 398 | } |
| 371 | 399 | } |
| 372 | 400 | |
@@ -381,8 +409,9 @@ discard block |
||
| 381 | 409 | |
| 382 | 410 | // si on ecrit directement dans un fichier, pour ne pas manipuler |
| 383 | 411 | // en memoire refuser gz |
| 384 | - if ($copy) |
|
| 385 | - $refuser_gz = true; |
|
| 412 | + if ($copy) { |
|
| 413 | + $refuser_gz = true; |
|
| 414 | + } |
|
| 386 | 415 | |
| 387 | 416 | // ouvrir la connexion et envoyer la requete et ses en-tetes |
| 388 | 417 | list($f, $fopen) = init_http($get, $url, $refuser_gz, $uri_referer, $datas, _INC_DISTANT_VERSION_HTTP, $date_verif); |
@@ -394,9 +423,9 @@ discard block |
||
| 394 | 423 | $result = ''; |
| 395 | 424 | // Sauf en fopen, envoyer le flux d'entree |
| 396 | 425 | // et recuperer les en-tetes de reponses |
| 397 | - if ($fopen) |
|
| 398 | - $headers = ''; |
|
| 399 | - else { |
|
| 426 | + if ($fopen) { |
|
| 427 | + $headers = ''; |
|
| 428 | + } else { |
|
| 400 | 429 | $headers = recuperer_entetes($f, $date_verif); |
| 401 | 430 | if (is_numeric($headers)){ |
| 402 | 431 | fclose($f); |
@@ -412,9 +441,9 @@ discard block |
||
| 412 | 441 | AND $result = @file_get_contents($url)){ |
| 413 | 442 | // on peuple les headers de vide et on continue |
| 414 | 443 | $headers = array(''); |
| 444 | + } else { |
|
| 445 | + return false; |
|
| 415 | 446 | } |
| 416 | - else |
|
| 417 | - return false; |
|
| 418 | 447 | } |
| 419 | 448 | if (!is_array($headers)){ // cas Location |
| 420 | 449 | fclose($f); |
@@ -424,7 +453,9 @@ discard block |
||
| 424 | 453 | $headers = join('', $headers); |
| 425 | 454 | } |
| 426 | 455 | |
| 427 | - if ($trans===NULL) return array($headers, ''); |
|
| 456 | + if ($trans===NULL) { |
|
| 457 | + return array($headers, ''); |
|
| 458 | + } |
|
| 428 | 459 | |
| 429 | 460 | // s'il faut deballer, le faire via un fichier temporaire |
| 430 | 461 | // sinon la memoire explose pour les gros flux |
@@ -437,8 +468,9 @@ discard block |
||
| 437 | 468 | $result = recuperer_body($f, $taille_max, $gz ? $gz : ($copy ? $trans : '')); |
| 438 | 469 | fclose($f); |
| 439 | 470 | } |
| 440 | - if (!$result) |
|
| 441 | - return array($headers, $result); |
|
| 471 | + if (!$result) { |
|
| 472 | + return array($headers, $result); |
|
| 473 | + } |
|
| 442 | 474 | |
| 443 | 475 | // Decompresser au besoin |
| 444 | 476 | if ($gz){ |
@@ -466,8 +498,9 @@ discard block |
||
| 466 | 498 | if (!$fp AND file_exists($fichier)){ |
| 467 | 499 | return filesize($fichier); |
| 468 | 500 | } |
| 469 | - if (!$fp) |
|
| 470 | - return false; |
|
| 501 | + if (!$fp) { |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 471 | 504 | $result = 0; // on renvoie la taille du fichier |
| 472 | 505 | } |
| 473 | 506 | while (!feof($f) AND $taille<$taille_max){ |
@@ -476,16 +509,17 @@ discard block |
||
| 476 | 509 | if ($fp){ |
| 477 | 510 | fwrite($fp, $res); |
| 478 | 511 | $result = $taille; |
| 512 | + } else { |
|
| 513 | + $result .= $res; |
|
| 479 | 514 | } |
| 480 | - else |
|
| 481 | - $result .= $res; |
|
| 482 | 515 | } |
| 483 | 516 | if ($fp){ |
| 484 | 517 | spip_fclose_unlock($fp); |
| 485 | 518 | spip_unlink($fichier); |
| 486 | 519 | @rename($tmpfile, $fichier); |
| 487 | - if (!file_exists($fichier)) |
|
| 488 | - return false; |
|
| 520 | + if (!file_exists($fichier)) { |
|
| 521 | + return false; |
|
| 522 | + } |
|
| 489 | 523 | } |
| 490 | 524 | return $result; |
| 491 | 525 | } |
@@ -511,8 +545,7 @@ discard block |
||
| 511 | 545 | list(, $d, $v) = $r; |
| 512 | 546 | if (strtolower(trim($d))=='location' AND $status>=300 AND $status<400){ |
| 513 | 547 | $location = $v; |
| 514 | - } |
|
| 515 | - elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 548 | + } elseif ($date_verif AND ($d=='Last-Modified')) { |
|
| 516 | 549 | if ($date_verif>=strtotime($v)){ |
| 517 | 550 | //Cas ou la page distante n'a pas bouge depuis |
| 518 | 551 | //la derniere visite |
@@ -521,10 +554,12 @@ discard block |
||
| 521 | 554 | } |
| 522 | 555 | } |
| 523 | 556 | |
| 524 | - if ($location) |
|
| 525 | - return $location; |
|
| 526 | - if ($status!=200 or $not_modif) |
|
| 527 | - return $status; |
|
| 557 | + if ($location) { |
|
| 558 | + return $location; |
|
| 559 | + } |
|
| 560 | + if ($status!=200 or $not_modif) { |
|
| 561 | + return $status; |
|
| 562 | + } |
|
| 528 | 563 | return $headers; |
| 529 | 564 | } |
| 530 | 565 | |
@@ -540,8 +575,9 @@ discard block |
||
| 540 | 575 | $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
| 541 | 576 | |
| 542 | 577 | // on se place tout le temps comme si on etait a la racine |
| 543 | - if (_DIR_RACINE) |
|
| 544 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 578 | + if (_DIR_RACINE) { |
|
| 579 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 580 | + } |
|
| 545 | 581 | |
| 546 | 582 | $m = md5($source); |
| 547 | 583 | |
@@ -558,8 +594,9 @@ discard block |
||
| 558 | 594 | function fichier_copie_locale($source){ |
| 559 | 595 | // Si c'est deja local pas de souci |
| 560 | 596 | if (!preg_match(',^\w+://,', $source)){ |
| 561 | - if (_DIR_RACINE) |
|
| 562 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 597 | + if (_DIR_RACINE) { |
|
| 598 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 599 | + } |
|
| 563 | 600 | return $source; |
| 564 | 601 | } |
| 565 | 602 | |
@@ -572,8 +609,9 @@ discard block |
||
| 572 | 609 | AND preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 573 | 610 | AND $f = nom_fichier_copie_locale($source, $ext) |
| 574 | 611 | AND file_exists(_DIR_RACINE . $f) |
| 575 | - ) |
|
| 576 | - return $f; |
|
| 612 | + ) { |
|
| 613 | + return $f; |
|
| 614 | + } |
|
| 577 | 615 | |
| 578 | 616 | |
| 579 | 617 | // Si c'est deja dans la table des documents, |
@@ -582,7 +620,9 @@ discard block |
||
| 582 | 620 | $ext = sql_getfetsel("extension", "spip_documents", "fichier=" . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
| 583 | 621 | |
| 584 | 622 | |
| 585 | - if ($ext) return nom_fichier_copie_locale($source, $ext); |
|
| 623 | + if ($ext) { |
|
| 624 | + return nom_fichier_copie_locale($source, $ext); |
|
| 625 | + } |
|
| 586 | 626 | |
| 587 | 627 | // voir si l'extension indiquee dans le nom du fichier est ok |
| 588 | 628 | // et si il n'aurait pas deja ete rapatrie |
@@ -591,8 +631,9 @@ discard block |
||
| 591 | 631 | |
| 592 | 632 | if ($ext AND sql_getfetsel("extension", "spip_types_documents", "extension=" . sql_quote($ext))){ |
| 593 | 633 | $f = nom_fichier_copie_locale($source, $ext); |
| 594 | - if (file_exists(_DIR_RACINE . $f)) |
|
| 595 | - return $f; |
|
| 634 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 635 | + return $f; |
|
| 636 | + } |
|
| 596 | 637 | } |
| 597 | 638 | |
| 598 | 639 | // Ping pour voir si son extension est connue et autorisee |
@@ -645,14 +686,17 @@ discard block |
||
| 645 | 686 | if ($headers = recuperer_page($source, false, true, $max, '', '', true)){ |
| 646 | 687 | list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
| 647 | 688 | |
| 648 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) |
|
| 649 | - $mime_type = (trim($regs[1])); |
|
| 650 | - else |
|
| 651 | - $mime_type = ''; // inconnu |
|
| 689 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 690 | + $mime_type = (trim($regs[1])); |
|
| 691 | + } else { |
|
| 692 | + $mime_type = ''; |
|
| 693 | + } |
|
| 694 | + // inconnu |
|
| 652 | 695 | |
| 653 | 696 | // Appliquer les alias |
| 654 | - while (isset($mime_alias[$mime_type])) |
|
| 655 | - $mime_type = $mime_alias[$mime_type]; |
|
| 697 | + while (isset($mime_alias[$mime_type])) { |
|
| 698 | + $mime_type = $mime_alias[$mime_type]; |
|
| 699 | + } |
|
| 656 | 700 | |
| 657 | 701 | // Si on a un mime-type insignifiant |
| 658 | 702 | // text/plain,application/octet-stream ou vide |
@@ -675,8 +719,9 @@ discard block |
||
| 675 | 719 | } |
| 676 | 720 | |
| 677 | 721 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 678 | - if (!$t) |
|
| 679 | - $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 722 | + if (!$t) { |
|
| 723 | + $t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . sql_quote($mime_type)); |
|
| 724 | + } |
|
| 680 | 725 | |
| 681 | 726 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
| 682 | 727 | // On essaie de nouveau avec l'extension |
@@ -695,14 +740,17 @@ discard block |
||
| 695 | 740 | # par defaut on retombe sur '.bin' si c'est autorise |
| 696 | 741 | spip_log("mime-type $mime_type inconnu"); |
| 697 | 742 | $t = sql_fetsel("extension", "spip_types_documents", "extension='bin'"); |
| 698 | - if (!$t) return false; |
|
| 743 | + if (!$t) { |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 699 | 746 | $a['extension'] = $t['extension']; |
| 700 | 747 | } |
| 701 | 748 | |
| 702 | 749 | if (preg_match(",\nContent-Length: *([^[:space:]]*),i", |
| 703 | 750 | "\n$headers", $regs) |
| 704 | - ) |
|
| 705 | - $a['taille'] = intval($regs[1]); |
|
| 751 | + ) { |
|
| 752 | + $a['taille'] = intval($regs[1]); |
|
| 753 | + } |
|
| 706 | 754 | } |
| 707 | 755 | |
| 708 | 756 | // Echec avec HEAD, on tente avec GET |
@@ -725,8 +773,7 @@ discard block |
||
| 725 | 773 | AND $charger_si_petite_image |
| 726 | 774 | ){ |
| 727 | 775 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 728 | - } |
|
| 729 | - else if ($a['body']){ |
|
| 776 | + } else if ($a['body']){ |
|
| 730 | 777 | $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
| 731 | 778 | ecrire_fichier($a['fichier'], $a['body']); |
| 732 | 779 | $size_image = @getimagesize($a['fichier']); |
@@ -748,9 +795,13 @@ discard block |
||
| 748 | 795 | if ($mime_type=='text/html'){ |
| 749 | 796 | include_spip('inc/filtres'); |
| 750 | 797 | $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
| 751 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) |
|
| 752 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 753 | - if (!$a['taille']) $a['taille'] = strlen($page); # a peu pres |
|
| 798 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 799 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 800 | + } |
|
| 801 | + if (!$a['taille']) { |
|
| 802 | + $a['taille'] = strlen($page); |
|
| 803 | + } |
|
| 804 | + # a peu pres |
|
| 754 | 805 | } |
| 755 | 806 | $a['mime_type']=$mime_type; |
| 756 | 807 | |
@@ -769,10 +820,12 @@ discard block |
||
| 769 | 820 | * @return string |
| 770 | 821 | */ |
| 771 | 822 | function need_proxy($host, $http_proxy = null, $http_noproxy = null){ |
| 772 | - if (is_null($http_proxy)) |
|
| 773 | - $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 774 | - if (is_null($http_noproxy)) |
|
| 775 | - $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 823 | + if (is_null($http_proxy)) { |
|
| 824 | + $http_proxy = @$GLOBALS['meta']["http_proxy"]; |
|
| 825 | + } |
|
| 826 | + if (is_null($http_noproxy)) { |
|
| 827 | + $http_noproxy = @$GLOBALS['meta']["http_noproxy"]; |
|
| 828 | + } |
|
| 776 | 829 | |
| 777 | 830 | $domain = substr($host, strpos($host, '.')); |
| 778 | 831 | |
@@ -799,18 +852,26 @@ discard block |
||
| 799 | 852 | } elseif ($t['scheme']=='https') { |
| 800 | 853 | $scheme = 'ssl'; |
| 801 | 854 | $noproxy = 'ssl://'; |
| 802 | - if (!isset($t['port']) || !($port = $t['port'])) $t['port'] = 443; |
|
| 803 | - } |
|
| 804 | - else { |
|
| 855 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 856 | + $t['port'] = 443; |
|
| 857 | + } |
|
| 858 | + } else { |
|
| 805 | 859 | $scheme = $t['scheme']; |
| 806 | 860 | $noproxy = $scheme . '://'; |
| 807 | 861 | } |
| 808 | - if (isset($t['user'])) |
|
| 809 | - $user = array($t['user'], $t['pass']); |
|
| 862 | + if (isset($t['user'])) { |
|
| 863 | + $user = array($t['user'], $t['pass']); |
|
| 864 | + } |
|
| 810 | 865 | |
| 811 | - if (!isset($t['port']) || !($port = $t['port'])) $port = 80; |
|
| 812 | - if (!isset($t['path']) || !($path = $t['path'])) $path = "/"; |
|
| 813 | - if (@$t['query']) $path .= "?" . $t['query']; |
|
| 866 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 867 | + $port = 80; |
|
| 868 | + } |
|
| 869 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 870 | + $path = "/"; |
|
| 871 | + } |
|
| 872 | + if (@$t['query']) { |
|
| 873 | + $path .= "?" . $t['query']; |
|
| 874 | + } |
|
| 814 | 875 | |
| 815 | 876 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
| 816 | 877 | if (!$f){ |
@@ -821,9 +882,9 @@ discard block |
||
| 821 | 882 | $f = @fopen($url, "rb"); |
| 822 | 883 | spip_log("connexion vers $url par simple fopen"); |
| 823 | 884 | $fopen = true; |
| 885 | + } else { |
|
| 886 | + $f = false; |
|
| 824 | 887 | } |
| 825 | - else |
|
| 826 | - $f = false; |
|
| 827 | 888 | // echec total |
| 828 | 889 | } |
| 829 | 890 | |
@@ -835,7 +896,9 @@ discard block |
||
| 835 | 896 | |
| 836 | 897 | $proxy_user = ''; |
| 837 | 898 | $http_proxy = need_proxy($host); |
| 838 | - if ($user) $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 899 | + if ($user) { |
|
| 900 | + $user = urlencode($user[0]) . ":" . urlencode($user[1]); |
|
| 901 | + } |
|
| 839 | 902 | |
| 840 | 903 | $connect = ''; |
| 841 | 904 | if ($http_proxy) { |
@@ -851,18 +914,23 @@ discard block |
||
| 851 | 914 | } |
| 852 | 915 | $t2 = @parse_url($http_proxy); |
| 853 | 916 | $first_host = $t2['host']; |
| 854 | - if (!($port = $t2['port'])) $port = 80; |
|
| 855 | - if ($t2['user']) |
|
| 856 | - $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 917 | + if (!($port = $t2['port'])) { |
|
| 918 | + $port = 80; |
|
| 919 | + } |
|
| 920 | + if ($t2['user']) { |
|
| 921 | + $proxy_user = base64_encode($t2['user'] . ":" . $t2['pass']); |
|
| 922 | + } |
|
| 923 | + } else { |
|
| 924 | + $first_host = $noproxy . $host; |
|
| 857 | 925 | } |
| 858 | - else |
|
| 859 | - $first_host = $noproxy . $host; |
|
| 860 | 926 | |
| 861 | 927 | if ($connect){ |
| 862 | 928 | $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true))); |
| 863 | 929 | $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, _INC_DISTANT_CONNECT_TIMEOUT, STREAM_CLIENT_CONNECT, $streamContext); |
| 864 | 930 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect"); |
| 865 | - if (!$f) return false; |
|
| 931 | + if (!$f) { |
|
| 932 | + return false; |
|
| 933 | + } |
|
| 866 | 934 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
| 867 | 935 | |
| 868 | 936 | fputs($f, $connect); |
@@ -880,8 +948,7 @@ discard block |
||
| 880 | 948 | // envoyer le handshake |
| 881 | 949 | stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
| 882 | 950 | spip_log("OK CONNECT sur $first_host:$port","connect"); |
| 883 | - } |
|
| 884 | - else { |
|
| 951 | + } else { |
|
| 885 | 952 | $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
| 886 | 953 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 887 | 954 | if (!$f) { |