[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / configuration / relayeur.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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
15 include_spip('inc/presentation');
16
17 /// A PASSER DANS LES FICHIERS DE LANGUE
18
19 function configuration_relayeur_dist($retour_proxy='')
20 {
21 global $spip_lang_left;
22
23 $res = $submit = '';
24
25 $http_proxy = $GLOBALS['meta']["http_proxy"];
26 $http_noproxy = $GLOBALS['meta']["http_noproxy"];
27
28 if ($http_proxy) {
29 include_spip('inc/distant');
30 // Masquer un eventuel password authentifiant
31 $http_proxy=entites_html(no_password_proxy_url($http_proxy));
32 if ($http_proxy) {
33 $res = "\n<p style='text-align: $spip_lang_left;' class='verdana1 spip_small'>"
34 . "<label for='test_proxy'>"
35 . _T('texte_test_proxy')
36 . "</label>"
37 . "</p>"
38 . "\n<p>"
39 . "<input type='text' name='test_proxy' id='test_proxy' value='http://www.spip.net/' size='40' class='forml' />"
40 . "</p>";
41
42 if($retour_proxy) {
43 $res .= debut_boite_info(true)
44 . $retour_proxy
45 . fin_boite_info(true);
46 }
47 $submit = array('valider_proxy' => _T('bouton_valider'),
48 'tester_proxy' => _T('bouton_test_proxy'));
49 }
50 }
51
52 $encours = "<label for='http_proxy'>" . ($http_proxy ? $http_proxy : "http://proxy:8080") . '</label>' ;
53 $exemple = "<label for='http_noproxy'>" . ($http_noproxy ? $http_noproxy : "127.0.0.1 .mondomaine.net") . "</label>";
54 $res = "\n<div class='verdana2'>"
55 . propre(_T('texte_proxy', array('proxy_en_cours' => "<b><tt><html>$encours</html></tt></b>")))
56 . "</div>"
57 . "\n<div class='verdana2'>"
58 . "<input type='text' name='http_proxy' id='http_proxy' size='40' class='forml' value='$http_proxy' />"
59 . "<br />"
60 . propre(_T('pas_de_proxy_pour', array('exemple' => "<b><tt><html>$exemple</html></tt></b>")))
61 . "<input type='text' name='http_noproxy' id='http_noproxy' size='40' class='forml' value='$http_noproxy' />"
62 . $res
63 . "</div>";
64
65 $res = debut_cadre_trait_couleur("base-24.gif", true, "", _T('info_sites_proxy').aide ("confhttpproxy"))
66 . ajax_action_post('configurer_relayeur', 0, 'config_fonctions', '', $res, $submit)
67 . fin_cadre_trait_couleur(true);
68
69 return ajax_action_greffe("configurer_relayeur", 0, $res);
70 }
71
72 function configuration_relayeur_post ($http_proxy, $http_noproxy, $test_proxy, $tester_proxy)
73 {
74 // http_proxy : ne pas prendre en compte la modif si le password est '****'
75 if (preg_match(',:\*\*\*\*@,', $http_proxy))
76 $http_proxy = $GLOBALS['meta']['http_proxy'];
77
78 $retour = $page = '';
79
80 if ($tester_proxy AND preg_match(",https?://,", $http_proxy)) {
81 include_spip('inc/distant');
82 $t = parse_url($test_proxy);
83
84 if (!@$t['host']) {
85 $retour = _T('info_adresse_non_indiquee');
86 } elseif (!need_proxy($t['host'])) {
87
88 $retour = "<p>"._T('page_pas_proxy')."</p>\n";
89 } elseif ($page = recuperer_page($test_proxy, true)) {
90 include_spip('inc/texte'); // pour aide, couper, lang
91 $retour = "<p>"._T('info_proxy_ok')."</p>\n<tt>"
92 . couper(entites_html($page),300)."</tt>";
93 } else $retour = _T('info_impossible_lire_page',
94 array('test_proxy' => $test_proxy))
95 . " <tt>".no_password_proxy_url($http_proxy)."</tt>."
96 . aide('confhttpproxy');
97 }
98
99 if ($http_proxy !== NULL) {
100 ecrire_meta('http_proxy', $http_proxy);
101 }
102 if ($http_noproxy !== NULL) {
103 ecrire_meta('http_noproxy', $http_noproxy);
104 }
105 if ($page) {
106 include_spip('install/etape_fin');
107 $retour .= install_verifier_htaccess();
108 }
109 return $retour;
110 }
111
112 // Function glue_url : le pendant de parse_url
113 // http://doc.spip.org/@glue_url
114 function glue_url ($url){
115 if (!is_array($url)){
116 return false;
117 }
118 // scheme
119 $uri = (!empty($url['scheme'])) ? $url['scheme'].'://' : '';
120 // user & pass
121 if (!empty($url['user'])){
122 $uri .= $url['user'].':'.$url['pass'].'@';
123 }
124 // host
125 $uri .= $url['host'];
126 // port
127 $port = (!empty($url['port'])) ? ':'.$url['port'] : '';
128 $uri .= $port;
129 // path
130 $uri .= $url['path'];
131 // fragment or query
132 if (isset($url['fragment'])){
133 $uri .= '#'.$url['fragment'];
134 } elseif (isset($url['query'])){
135 $uri .= '?'.$url['query'];
136 }
137 return $uri;
138 }
139
140
141 // Ne pas afficher la partie 'password' du proxy
142 // http://doc.spip.org/@no_password_proxy_url
143 function no_password_proxy_url($http_proxy) {
144 if ($p = @parse_url($http_proxy)
145 AND $p['pass']) {
146 $p['pass'] = '****';
147 $http_proxy = glue_url($p);
148 }
149 return $http_proxy;
150 }
151 ?>