| [ Index ] |
|
Code source de Zelune 2.1 |
1 <?php 2 class proxied { 3 4 var $url; 5 var $url_first; 6 var $ch; 7 var $info; 8 var $data; 9 var $to_unlink; 10 11 function proxied ($url) { 12 session_start(); 13 $this->url = $url; 14 $this->handle_actions(); 15 $this->ch = curl_init($url); 16 $this->set_options(); 17 $s = array(); 18 $r = array(); 19 if ($_SESSION['__no_javascript'] == 'yes') { 20 $s[] = '#<\s*script[^>]*?>.*?<\s*/\s*script\s*>#si'; 21 $r[] = ''; 22 $s[] = '#(\bon[a-z]+)\s*=\s*(?:"([^"]*)"?|\'([^\']*)\'?|([^\'"\s>]*))?#si'; 23 $r[] = ''; 24 $s[] = '#<noscript>(.*?)</noscript>#si'; 25 $r[] = '\\1'; 26 } 27 if ($_SESSION['__no_images'] == 'yes') { 28 $s[] = '#<(img|image)[^>]*?>#si'; 29 $r[] = ''; 30 } 31 if ($_SESSION['__no_title'] == 'yes') { 32 $s[] = '#<\s*title[^>]*?>.*?<\s*/\s*title\s*>#si'; 33 $r[] = ''; 34 } 35 if ($_SESSION['__no_meta'] == 'yes') { 36 $s[] = '#<(meta)[^>]*?>#si'; 37 $r[] = ''; 38 } 39 $this->data = preg_replace($s, $r, curl_exec($this->ch)); 40 $this->info = curl_getinfo($this->ch); 41 $this->url = parse_url($this->info['url']); 42 $this->url['full'] = $this->info['url']; 43 $this->url_first = $this->info['url']; 44 header("Content-Type: {$this->info[content_type]}"); 45 if (eregi('css', $this->info['content_type'])) { 46 $this->data = $this->parse_css($this->data); 47 } elseif (eregi('html|xml', $this->info['content_type'])) { 48 $this->data = $this->parse_html($this->data); 49 } 50 echo $this->data; 51 curl_close($this->ch); 52 if ($this->to_unlink) { 53 foreach ($this->to_unlink as $file) { 54 @unlink($file); 55 } 56 } 57 } 58 59 function set_options () { 60 if (!array_key_exists('__no_javascript', $_SESSION)) { 61 $_SESSION['__no_javascript'] = 'yes'; 62 $_SESSION['__no_images'] = 'no'; 63 $_SESSION['__no_title'] = 'no'; 64 $_SESSION['__no_meta'] = 'no'; 65 } 66 $options = array( 67 CURLOPT_RETURNTRANSFER => true, 68 CURLOPT_FOLLOWLOCATION => true, 69 CURLOPT_AUTOREFERER => true, 70 CURLOPT_COOKIEFILE => 'cookies/' . session_id() . '.txt', 71 CURLOPT_COOKIEJAR => 'cookies/' . session_id() . '.txt' 72 ); 73 if (count($_POST)) { 74 $post = array(); 75 foreach ($_POST as $key => $value) { 76 $post[$key] = $value; 77 } 78 } 79 if (count($_FILES)) { 80 $post = $post ? $post : array(); 81 foreach ($_FILES as $name => $file) { 82 $this->to_unlink[] = "uploads/$file[name]"; 83 move_uploaded_file($file['tmp_name'], "uploads/$file[name]"); 84 $post[$name] = "@uploads/$file[name]"; 85 } 86 } 87 if ($post) { 88 $options[CURLOPT_POST] = true; 89 $options[CURLOPT_POSTFIELDS] = $post; 90 } 91 if (ereg('__new_url=', $_SERVER['HTTP_REFERER'])) { 92 preg_match('#__new_url=([^&]+)#', $_SERVER['HTTP_REFERER'], $referer); 93 $referer = base64_decode($referer[1]); 94 $options[CURLOPT_REFERER] = $referer; 95 } 96 if (!eregi('google\.com', $this->url)) { 97 $options[CURLOPT_USERAGENT] = $_SERVER['HTTP_USER_AGENT']; 98 } else { 99 $options[CURLOPT_USERAGENT] = 'None'; 100 } 101 foreach ($options as $option => $value) { 102 @curl_setopt($this->ch, $option, $value); 103 } 104 } 105 106 function parse_html ($string) { 107 $parse = array( 108 'a' => array('href'), 109 'img' => array('src', 'longdesc'), 110 'image' => array('src', 'longdesc'), 111 'body' => array('background'), 112 'frame' => array('src', 'longdesc'), 113 'iframe' => array('src', 'longdesc'), 114 'head' => array('profile'), 115 'layer' => array('src'), 116 'input' => array('src', 'usemap'), 117 'form' => array('action'), 118 'area' => array('href'), 119 'link' => array('href', 'src', 'urn'), 120 'meta' => array('content'), 121 'param' => array('value'), 122 'applet' => array('codebase', 'code', 'object', 'archive'), 123 'object' => array('usermap', 'codebase', 'classid', 'archive', 'data'), 124 'script' => array('src'), 125 'select' => array('src'), 126 'hr' => array('src'), 127 'table' => array('background'), 128 'tr' => array('background'), 129 'th' => array('background'), 130 'td' => array('background'), 131 'bgsound' => array('src'), 132 'blockquote' => array('cite'), 133 'del' => array('cite'), 134 'embed' => array('src'), 135 'fig' => array('src', 'imagemap'), 136 'ilayer' => array('src'), 137 'ins' => array('cite'), 138 'note' => array('src'), 139 'overlay' => array('src', 'imagemap'), 140 'q' => array('cite'), 141 'ul' => array('src') 142 ); 143 $tags = $this->get_tags($string); 144 $to_replace = array(); 145 foreach ($tags as $tag) { 146 $tag_name = $this->get_tag_name($tag); 147 $attributes = $this->get_attributes($tag); 148 if ($tag_name == 'base' && $attributes['href']) { 149 $this->url = parse_url($attributes['href']); 150 $this->url['full'] = $attributes['href']; 151 $to_replace[] = array( 152 'string' => $tag, 153 'value' => '' 154 ); 155 } 156 if ($attributes['style']) { 157 $attributes['style'] = $this->parse_css($attributes['style']); 158 } 159 if ($parse[$tag_name]) { 160 $extra_html = ''; 161 $relink = true; 162 $new_tag = "<$tag_name"; 163 switch ($tag_name) { 164 case 'form': 165 if (strtolower($attributes['method']) == 'get' || !$attributes['method']) { 166 $url = $attributes['action'] ? $this->encode_url($attributes['action'], false, true) : $this->encode_url($this->url['full'], false, true); 167 $extra_html = "<input type=\"hidden\" name=\"__new_url\" value=\"$url\" /><input type=\"hidden\" name=\"__proxy_action\" value=\"redirect_get\" />"; 168 $attributes['action'] = './'; 169 $attributes['method'] = 'post'; 170 $relink = false; 171 } 172 break; 173 case 'head': 174 if ($_GET['__proxy_form'] != '0') { 175 $extra_html = "<script language=\"javascript\" type=\"text/javascript\">\n"; 176 $extra_html .= "var __new_url = '{$this->url_first}';\n"; 177 $no_javascript = $_SESSION['__no_javascript'] == 'yes' ? 'true' : 'false'; 178 $extra_html .= "var __no_javascript = $no_javascript;\n"; 179 $no_images = $_SESSION['__no_images'] == 'yes' ? 'true' : 'false'; 180 $extra_html .= "var __no_images = $no_images;\n"; 181 $no_title = $_SESSION['__no_title'] == 'yes' ? 'true' : 'false'; 182 $extra_html .= "var __no_title = $no_title;\n"; 183 $no_meta = $_SESSION['__no_meta'] == 'yes' ? 'true' : 'false'; 184 $extra_html .= "var __no_meta = $no_meta;\n"; 185 $extra_html .= "</script>\n"; 186 $extra_html .= '<script language="javascript" type="text/javascript" src="./js/main.js"></script>'; 187 } 188 break; 189 } 190 if ($attributes) { 191 foreach ($attributes as $attribute_name => $attribute_value) { 192 if (in_array($attribute_name, $parse[$tag_name])) { 193 switch ($tag_name) { 194 default: 195 if ($relink) { 196 if ($attribute_name == 'src') { 197 $extra = '&__proxy_form=0'; 198 } else { 199 $extra = ''; 200 } 201 $attribute_value = $this->encode_url($attribute_value) . $extra; 202 } 203 break; 204 case 'meta': 205 if (eregi('refresh', $attributes['http-equiv']) && $tag_name == 'meta' && $attribute_name == 'content' && preg_match('#^(\s*[0-9]*\s*;\s*url=)(.*)#i', $attribute_value, $content)) { 206 $attribute_value = $content[1] . $this->encode_url($content[2]); 207 } 208 break; 209 } 210 } 211 $new_tag .= " $attribute_name=\"$attribute_value\""; 212 } 213 } 214 $new_tag .= ">$extra_html"; 215 $to_replace[] = array( 216 'string' => $tag, 217 'value' => $new_tag 218 ); 219 } 220 } 221 $string = $this->mass_replace($to_replace, $string); 222 return $string; 223 } 224 225 function parse_css ($string) { 226 $to_replace = array(); 227 preg_match_all('#url[\s]*\([\s]*("[^"]+"|\'[^\']+\'|[^\s>]+)[\s]*\)#si', $string, $urls); 228 for ($i = 0; $i < count($urls[0]); $i++) { 229 $url = $this->encode_url(preg_replace('#^("([^"]+)"|\'([^\']+)\')$#', '\\2\\3', $urls[1][$i])); 230 $to_replace[] = array( 231 'string' => $urls[0][$i], 232 'value' => "url('$url')" 233 ); 234 } 235 preg_match_all('#@import[\s]*("[^"]+"|\'[^\']+\'|[^\s>]+)#si', $string, $urls); 236 for ($i = 0; $i < count($urls[0]); $i++) { 237 $url = $this->encode_url(preg_replace('#^("([^"]+)"|\'([^\']+)\')$#', '\\2\\3', $urls[1][$i])); 238 $to_replace[] = array( 239 'string' => $urls[0][$i], 240 'value' => "@import '$url'" 241 ); 242 } 243 $string = $this->mass_replace($to_replace, $string); 244 return $string; 245 } 246 247 function get_tags ($string) { 248 preg_match_all('#<([a-z-]+)([^>]+)>#si', $string, $tags); 249 return $tags[0]; 250 } 251 252 function get_tag_name ($string) { 253 preg_match('#^<([a-z0-9-]+)#i', $string, $matches); 254 return strtolower($matches[1]); 255 } 256 257 function get_attributes ($string) { 258 $attributes = array(); 259 $string = preg_replace('#^<[a-z-]+|>$#i', '', $string); 260 if ($string) { 261 preg_match_all('#([a-z-]+)=?("[^">]*"|\'[^\'>]*\'|[^\s>]*)#si', $string, $matches); 262 for ($i = 0; $i < count($matches[0]); $i++) { 263 $attributes[strtolower($matches[1][$i])] = $this->strip_quotes($matches[2][$i]); 264 } 265 return $attributes; 266 } else { 267 return false; 268 } 269 } 270 271 function strip_quotes ($string) { 272 return ereg_replace('^("([^"]*)"|^\'([^\']*)\')$', '\\2\\3', $string); 273 } 274 275 function mass_replace ($array, $string) { 276 foreach ($array as $replacement) { 277 $string = str_replace($replacement['string'], $replacement['value'], $string); 278 } 279 return $string; 280 } 281 282 function encode_url ($string, $raw = false, $plain = false) { 283 $string = $this->strip_quotes(html_entity_decode($string)); 284 if (eregi('^[a-z]{2,}:', $string)) { 285 286 } elseif (ereg('^/', $string)) { 287 $string = "{$this->url[scheme]}://{$this->url[host]}$string"; 288 } elseif (ereg('^#', $string)) { 289 $raw = true; 290 } elseif (eregi('^mailto:', $string)) { 291 $raw = true; 292 } elseif (ereg('^\.\./', $string)) { 293 preg_match_all('#\.\./#', $string, $matches); 294 $path = ereg_replace('/([^/]*)$', '/', $this->url['path']); 295 for ($i = 0; $i < count($matches[0]); $i++) { 296 $path = ereg_replace('([^/]*)/$', '', $path); 297 } 298 $path = ereg_replace('/$', '', $path) . '/'; 299 $string = ereg_replace('\.\./', '', $string); 300 $string = "{$this->url[scheme]}://{$this->url[host]}$path$string"; 301 } else { 302 $string = ereg_replace('^\./', '', $string); 303 $path = ereg_replace('/([^/]*)$', '/', $this->url['path']); 304 $path = ereg_replace('/$', '', $path) . '/'; 305 $string = "{$this->url[scheme]}://{$this->url[host]}$path$string"; 306 } 307 return $raw ? $string : (!$plain ? './?__new_url=' : '') . base64_encode($string); 308 } 309 310 function handle_actions () { 311 if ($_POST['__proxy_action'] == 'redirect_get') { 312 $url = base64_decode($_POST['__new_url']); 313 unset($_POST['__proxy_action'], $_POST['__new_url']); 314 $get = ''; 315 foreach ($_POST as $key => $value) { 316 $value = urlencode($value); 317 $get .= "&$key=$value"; 318 } 319 $get = ereg('\?', $url) ? $get : ereg_replace('^&', '?', $get); 320 $url = base64_encode($url . $get); 321 header("Location: ./?__new_url=$url"); 322 exit; 323 } elseif ($_POST['__proxy_action'] == 'redirect_browse') { 324 $_SESSION['__no_javascript'] = (bool) $_POST['__no_javascript'] ? 'yes' : 'no'; 325 $_SESSION['__no_images'] = (bool) $_POST['__no_images'] ? 'yes' : 'no'; 326 $_SESSION['__no_title'] = (bool) $_POST['__no_title'] ? 'yes' : 'no'; 327 $_SESSION['__no_meta'] = (bool) $_POST['__no_meta'] ? 'yes' : 'no'; 328 header('Location: ./?__new_url=' . base64_encode($_POST['__new_url'])); 329 exit; 330 } 331 } 332 333 } 334 $url = @parse_url($_GET['__new_url']) && strlen($_GET['__new_url']) ? base64_decode($_GET['__new_url']) : false; 335 if (!$url && !$_POST['__proxy_action']) { 336 include 'home.php'; 337 exit; 338 } 339 $proxied = new proxied($url); 340 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Tue Nov 20 19:41:18 2007 | par Balluche grâce à PHPXref 0.7 |
|