3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) {
16 include_spip('inc/presentation');
17 include_spip('inc/config');
19 function formulaires_configurer_relayeur_charger_dist() {
21 'http_proxy' => no_password_proxy_url(lire_config('http_proxy', '')),
22 'http_noproxy' => lire_config('http_noproxy', ''),
23 'test_proxy' => 'http://www.spip.net/',
29 function formulaires_configurer_relayeur_verifier_dist() {
31 $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
32 $http_noproxy = _request('http_noproxy');
34 if ($http_proxy and !tester_url_absolue($http_proxy)) {
35 $erreurs['http_proxy'] = _T('info_url_proxy_pas_conforme');
38 if (!isset($erreurs['http_proxy']) and _request('tester_proxy')) {
40 $erreurs['http_proxy'] = _T('info_obligatoire');
42 include_spip('inc/distant');
43 $test_proxy = _request('test_proxy');
44 $t = parse_url($test_proxy);
46 $erreurs['test_proxy'] = _T('info_adresse_non_indiquee');
48 include_spip('inc/texte'); // pour aide, couper, lang
50 if (!need_proxy($t['host'], $http_proxy, $http_noproxy)) {
51 $info = '<strong>' . _T('page_pas_proxy') . '</strong><br />';
54 // il faut fausser le proxy actuel pour faire le test !
55 $cur_http_proxy = $GLOBALS['meta']['http_proxy'];
56 $cur_http_noproxy = $GLOBALS['meta']['http_noproxy'];
57 $GLOBALS['meta']['http_proxy'] = $http_proxy;
58 $GLOBALS['meta']['http_noproxy'] = $http_noproxy;
59 $page = recuperer_page($test_proxy, true);
60 $GLOBALS['meta']['http_proxy'] = $cur_http_proxy;
61 $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy;
63 $erreurs['message_ok'] = _T('info_proxy_ok') . "<br />$info\n<tt>" . couper(entites_html($page), 300) . '</tt>';
64 $erreurs['message_erreur'] = '';
66 $erreurs['message_erreur'] = $info . _T(
67 'info_impossible_lire_page',
68 array('test_proxy' => "<tt>$test_proxy</tt>")
70 . ' <b><tt>' . no_password_proxy_url($http_proxy) . '</tt></b>.'
71 . aider('confhttpproxy');
80 function formulaires_configurer_relayeur_traiter_dist() {
81 $res = array('editable' => true);
83 $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
84 $http_noproxy = _request('http_noproxy');
85 if ($http_proxy !== null) {
86 ecrire_meta('http_proxy', $http_proxy);
89 if ($http_noproxy !== null) {
90 ecrire_meta('http_noproxy', $http_noproxy);
93 $res['message_ok'] = _T('config_info_enregistree');
98 function relayeur_saisie_ou_config($http_proxy, $default) {
99 // http_proxy : ne pas prendre en compte la modif si le password est '****'
100 if (preg_match(',:\*\*\*\*@,', $http_proxy)) {
101 $http_proxy = $default;
107 // Function glue_url : le pendant de parse_url
108 // http://code.spip.net/@glue_url
109 function glue_url($url) {
110 if (!is_array($url)) {
114 $uri = (!empty($url['scheme'])) ?
$url['scheme'] . '://' : '';
116 if (!empty($url['user'])) {
117 $uri .= $url['user'] . ':' . $url['pass'] . '@';
120 $uri .= $url['host'];
122 $port = (!empty($url['port'])) ?
':' . $url['port'] : '';
125 $uri .= $url['path'];
127 if (isset($url['fragment'])) {
128 $uri .= '#' . $url['fragment'];
129 } elseif (isset($url['query'])) {
130 $uri .= '?' . $url['query'];
137 // Ne pas afficher la partie 'password' du proxy
138 // http://code.spip.net/@no_password_proxy_url
139 function no_password_proxy_url($http_proxy) {
141 and $p = @parse_url
($http_proxy)
142 and isset($p['pass'])
146 $http_proxy = glue_url($p);