플러그인 46: 간단한 웹 프록시 서버
<?php // Plug-in 46: Simple Web Proxy
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$url = $_GET['u'];
// Change webproxy.php below to the name of your PHP proxy
$result = PIPHP_SimpleWebProxy(urldecode($_GET['u']), "webproxy.php");
switch(strtolower(substr($url, -4)))
{
case ".jpg":
header("Content-type: image/jpeg"); die($result);
case ".gif":
header("Content-type: image/gif"); die($result);
case ".png":
header("Content-type: image/png"); die($result);
case ".ico":
header("Content-type: image/x-icon"); die($result);
case ".css":
header("Content-type: text/css"); die($result);
case ".xml":
header("Content-type: text/xml"); die($result);
case ".htm": case "html": case ".php":
header("Content-type: text/html"); die($result);
default:
if (strtolower(substr($url, -3)) == ".js")
header("Content-type: application/x-javascript");
die($result);
}
function PIPHP_SimpleWebProxy($url, $redirect)
{
// Plug-in 46: Simple Web Proxy
//
// This plug-in takes a URL as an argument which it then
// passes back to the web browser with all links changed
// to keep the proxy working. The arguments required are:
//
// $url: URL of a page to display
// $redirect: Location of the PHP proxy program
$contents = @file_get_contents($url);
if (!$contents) return NULL;
switch(strtolower(substr($url, -4)))
{
case ".jpg": case ".gif": case ".png": case ".ico":
case ".css": case ".js": case ".xml":
return $contents;
}
$contents = str_replace('&', '&', $contents);
$contents = str_replace('&', '!!**1**!!', $contents);
$dom = new domdocument();
@$dom ->loadhtml($contents);
$xpath = new domxpath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
$sources = $xpath->evaluate("/html/body//img");
$iframes = $xpath->evaluate("/html/body//iframe");
$scripts = $xpath->evaluate("/html//script");
$css = $xpath->evaluate("/html/head/link");
$links = array();
for ($j = 0 ; $j < $hrefs->length ; ++$j)
$links[] = $hrefs->item($j)->getAttribute('href');
for ($j = 0 ; $j < $sources->length ; ++$j)
$links[] = $sources->item($j)->getAttribute('src');
for ($j = 0 ; $j < $iframes->length ; ++$j)
$links[] = $iframes->item($j)->getAttribute('src');
for ($j = 0 ; $j < $scripts->length ; ++$j)
$links[] = $scripts->item($j)->getAttribute('src');
for ($j = 0 ; $j < $css->length ; ++$j)
$links[] = $css->item($j)->getAttribute('href');
$links = array_unique($links);
$to = array();
$count = 0;
sort($links);
foreach ($links as $link)
{
if ($link != "")
{
$temp = str_replace('!!**1**!!', '&', $link);
$to[$count] = "/$redirect?u=" .
urlencode(PIPHP_RelToAbsURL($url, $temp));
$contents = str_replace("href=\"$link\"",
"href=\"!!$count!!\"", $contents);
$contents = str_replace("href='$link'",
"href='!!$count!!'", $contents);
$contents = str_replace("href=$link",
"href=!!$count!!", $contents);
$contents = str_replace("src=\"$link\"",
"src=\"!!$count!!\"", $contents);
$contents = str_replace("src='$link'",
"src='!!$count!!'", $contents);
$contents = str_replace("src=$link",
"src=!!$count!!", $contents);
++$count;
}
}
for ($j = 0 ; $j < $count ; ++$j)
$contents = str_replace("!!$j!!", $to[$j],
$contents);
return str_replace('!!**1**!!', '&', $contents);
}
// The below function is repeated here to ensure that it's
// available to the main function which relies on it
function PIPHP_RelToAbsURL($page, $url)
{
// Plug-in 21: Relative To Absolute URL
//
// This plug-in accepts the absolute URL of a web page
// and a link featured within that page. The link is then
// turned into an absolute URL which can be independently
// accessed. Only applies to http:// URLs. Arguments are:
//
// $page: The web page containing the URL
// $url: The URL to convert to absolute
if (substr($page, 0, 7) != "http://") return $url;
$parse = parse_url($page);
$root = $parse['scheme'] . "://" . $parse['host'];
$p = strrpos(substr($page, 7), '/');
if ($p) $base = substr($page, 0, $p + 8);
else $base = "$page/";
if (substr($url, 0, 1) == '/') $url = $root . $url;
elseif (substr($url, 0, 7) != "http://") $url = $base . $url;
return $url;
}
?>
플러그인 설명:
플러그인은 URL 주소를 받아들여 모든 링크를 프록시를 통해 접근하는 것으로 바꾸고 수정된 URL 주소를 되돌려줍니다. 다음 인자를 받아들여야 합니다.
$url 변환할 URL
$redirect에서 웹 프록시를 제공하는 PHP 프로그램의 파일 이름
webproxy.php 내용은 다음과 같습니다.
<?php // Plug-in 46: Simple Web Proxy
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$url = $_GET['u'];
// Change webproxy.php below to the name of your PHP proxy
$result = PIPHP_SimpleWebProxy(urldecode($_GET['u']), "webproxy.php");
switch(strtolower(substr($url, -4)))
{
case ".jpg":
header("Content-type: image/jpeg"); die($result);
case ".gif":
header("Content-type: image/gif"); die($result);
case ".png":
header("Content-type: image/png"); die($result);
case ".ico":
header("Content-type: image/x-icon"); die($result);
case ".css":
header("Content-type: text/css"); die($result);
case ".xml":
header("Content-type: text/xml"); die($result);
case ".htm": case "html": case ".php":
header("Content-type: text/html"); die($result);
default:
if (strtolower(substr($url, -3)) == ".js")
header("Content-type: application/x-javascript");
die($result);
}
function PIPHP_SimpleWebProxy($url, $redirect)
{
// Plug-in 46: Simple Web Proxy
//
// This plug-in takes a URL as an argument which it then
// passes back to the web browser with all links changed
// to keep the proxy working. The arguments required are:
//
// $url: URL of a page to display
// $redirect: Location of the PHP proxy program
$contents = @file_get_contents($url);
if (!$contents) return NULL;
switch(strtolower(substr($url, -4)))
{
case ".jpg": case ".gif": case ".png": case ".ico":
case ".css": case ".js": case ".xml":
return $contents;
}
$contents = str_replace('&', '&', $contents);
$contents = str_replace('&', '!!**1**!!', $contents);
$dom = new domdocument();
@$dom ->loadhtml($contents);
$xpath = new domxpath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
$sources = $xpath->evaluate("/html/body//img");
$iframes = $xpath->evaluate("/html/body//iframe");
$scripts = $xpath->evaluate("/html//script");
$css = $xpath->evaluate("/html/head/link");
$links = array();
for ($j = 0 ; $j < $hrefs->length ; ++$j)
$links[] = $hrefs->item($j)->getAttribute('href');
for ($j = 0 ; $j < $sources->length ; ++$j)
$links[] = $sources->item($j)->getAttribute('src');
for ($j = 0 ; $j < $iframes->length ; ++$j)
$links[] = $iframes->item($j)->getAttribute('src');
for ($j = 0 ; $j < $scripts->length ; ++$j)
$links[] = $scripts->item($j)->getAttribute('src');
for ($j = 0 ; $j < $css->length ; ++$j)
$links[] = $css->item($j)->getAttribute('href');
$links = array_unique($links);
$to = array();
$count = 0;
sort($links);
foreach ($links as $link)
{
if ($link != "")
{
$temp = str_replace('!!**1**!!', '&', $link);
$to[$count] = "/$redirect?u=" .
urlencode(PIPHP_RelToAbsURL($url, $temp));
$contents = str_replace("href=\"$link\"",
"href=\"!!$count!!\"", $contents);
$contents = str_replace("href='$link'",
"href='!!$count!!'", $contents);
$contents = str_replace("href=$link",
"href=!!$count!!", $contents);
$contents = str_replace("src=\"$link\"",
"src=\"!!$count!!\"", $contents);
$contents = str_replace("src='$link'",
"src='!!$count!!'", $contents);
$contents = str_replace("src=$link",
"src=!!$count!!", $contents);
++$count;
}
}
for ($j = 0 ; $j < $count ; ++$j)
$contents = str_replace("!!$j!!", $to[$j],
$contents);
return str_replace('!!**1**!!', '&', $contents);
}
// The below function is repeated here to ensure that it's
// available to the main function which relies on it
function PIPHP_RelToAbsURL($page, $url)
{
// Plug-in 21: Relative To Absolute URL
//
// This plug-in accepts the absolute URL of a web page
// and a link featured within that page. The link is then
// turned into an absolute URL which can be independently
// accessed. Only applies to http:// URLs. Arguments are:
//
// $page: The web page containing the URL
// $url: The URL to convert to absolute
if (substr($page, 0, 7) != "http://") return $url;
$parse = parse_url($page);
$root = $parse['scheme'] . "://" . $parse['host'];
$p = strrpos(substr($page, 7), '/');
if ($p) $base = substr($page, 0, $p + 8);
else $base = "$page/";
if (substr($url, 0, 1) == '/') $url = $root . $url;
elseif (substr($url, 0, 7) != "http://") $url = $base . $url;
return $url;
}
?>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fortinet FortiWeb Web Application Firewall Policy BypassFrom: Geffrey Velasquez Date: Wed, 2 May 2012 20:33:23 -0500...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.