[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / prive / formulaires / configurer_relayeur.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
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 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14 include_spip('inc/presentation');
15 include_spip('inc/config');
16
17 function formulaires_configurer_relayeur_charger_dist(){
18 $valeurs = array(
19 'http_proxy' =>no_password_proxy_url(lire_config('http_proxy', '')),
20 'http_noproxy' => lire_config('http_noproxy', ''),
21 'test_proxy' => 'http://www.spip.net/',
22 );
23
24 return $valeurs;
25 }
26
27 function formulaires_configurer_relayeur_verifier_dist(){
28 $erreurs = array();
29 $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
30 $http_noproxy = _request('http_noproxy');
31
32 if ($http_proxy AND !preg_match(",https?://,", $http_proxy)){
33 $erreurs['http_proxy'] = _L('format_proxy_incorrect');
34 }
35
36 if (!isset($erreurs['http_proxy']) AND _request('tester_proxy')) {
37 if (!$http_proxy)
38 $erreurs['http_proxy'] = _T('info_obligatoire');
39 else {
40 include_spip('inc/distant');
41 $test_proxy = _request('test_proxy');
42 $t = parse_url($test_proxy);
43 if (!@$t['host']) {
44 $erreurs['test_proxy'] = _T('info_adresse_non_indiquee');
45 }
46 else {
47 include_spip('inc/texte'); // pour aide, couper, lang
48 $info = "";
49 if (!need_proxy($t['host'],$http_proxy,$http_noproxy))
50 $info = "<strong>"._T('page_pas_proxy')."</strong><br />";
51
52 // il faut fausser le proxy actuel pour faire le test !
53 $cur_http_proxy = $GLOBALS['meta']['http_proxy'];
54 $cur_http_noproxy = $GLOBALS['meta']['http_noproxy'];
55 $GLOBALS['meta']['http_proxy'] = $http_proxy;
56 $GLOBALS['meta']['http_noproxy'] = $http_noproxy;
57 $page = recuperer_page($test_proxy, true);
58 $GLOBALS['meta']['http_proxy'] = $cur_http_proxy;
59 $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy;
60 if ($page) {
61 $erreurs['message_ok'] = _T('info_proxy_ok')."<br />$info\n<tt>".couper(entites_html($page),300)."</tt>";
62 }
63 else {
64 $erreurs['message_erreur'] = $info._T('info_impossible_lire_page', array('test_proxy' => "<tt>$test_proxy</tt>"))
65 . " <b><tt>".no_password_proxy_url($http_proxy)."</tt></b>."
66 . aide('confhttpproxy');
67 }
68 }
69
70 }
71 }
72 return $erreurs;
73 }
74
75 function formulaires_configurer_relayeur_traiter_dist(){
76 $res = array('editable'=>true);
77
78 $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
79 $http_noproxy = _request('http_noproxy');
80 if ($http_proxy !== NULL)
81 ecrire_meta('http_proxy', $http_proxy);
82
83 if ($http_noproxy !== NULL)
84 ecrire_meta('http_noproxy', $http_noproxy);
85
86 $res['message_ok'] = _T('config_info_enregistree');
87 return $res;
88 }
89
90 function relayeur_saisie_ou_config($http_proxy, $default){
91 // http_proxy : ne pas prendre en compte la modif si le password est '****'
92 if (preg_match(',:\*\*\*\*@,', $http_proxy))
93 $http_proxy = $default;
94 return $http_proxy;
95 }
96
97 // Function glue_url : le pendant de parse_url
98 // http://doc.spip.org/@glue_url
99 function glue_url ($url){
100 if (!is_array($url)){
101 return false;
102 }
103 // scheme
104 $uri = (!empty($url['scheme'])) ? $url['scheme'].'://' : '';
105 // user & pass
106 if (!empty($url['user'])){
107 $uri .= $url['user'].':'.$url['pass'].'@';
108 }
109 // host
110 $uri .= $url['host'];
111 // port
112 $port = (!empty($url['port'])) ? ':'.$url['port'] : '';
113 $uri .= $port;
114 // path
115 $uri .= $url['path'];
116 // fragment or query
117 if (isset($url['fragment'])){
118 $uri .= '#'.$url['fragment'];
119 } elseif (isset($url['query'])){
120 $uri .= '?'.$url['query'];
121 }
122 return $uri;
123 }
124
125
126 // Ne pas afficher la partie 'password' du proxy
127 // http://doc.spip.org/@no_password_proxy_url
128 function no_password_proxy_url($http_proxy) {
129 if ($http_proxy
130 AND $p = @parse_url($http_proxy)
131 AND isset($p['pass'])
132 AND $p['pass']) {
133 $p['pass'] = '****';
134 $http_proxy = glue_url($p);
135 }
136 return $http_proxy;
137 }
138 ?>