오징어를 사용하여 웹 페이지 요청의 페이지 내용을 수정하려고합니다. 나는 upside-down-ternet 자습서를 따라 가며 페이지에 이미지를 뒤집는 방법에 대한 지침을 보여주었습니다.오징어 프록시가 수정 된 html 콘텐츠를 제공하지 않습니다.
페이지의 실제 html을 변경해야합니다. 튜토리얼에서와 같은 작업을 시도했지만 이미지 편집 대신 html 페이지를 편집하려고합니다. 아래는 내가 그것을하려고하는 데 사용하고 PHP 스크립트입니다.
모든 jpg 이미지가 뒤집 혔지만 페이지의 콘텐츠는 편집되지 않습니다. 작성된 편집 된 index.html 파일에는 편집 된 콘텐츠가 포함되어 있지만 사용자가받은 페이지에는 편집 된 콘텐츠가 포함되어 있지 않습니다.
#!/usr/bin/php
<?php
$temp = array();
while ($input = fgets(STDIN)) {
$micro_time = microtime();
// Split the output (space delimited) from squid into an array.
$temp = split(' ', $input);
//Flip jpg images, this works correctly
if (preg_match("/.*\.jpg/i", $temp[0])) {
system("/usr/bin/wget -q -O /var/www/cache/$micro_time.jpg ". $temp[0]);
system("/usr/bin/mogrify -flip /var/www/cache/$micro_time.jpg");
echo "http://127.0.0.1/cache/$micro_time.jpg\n";
}
//Don't edit files that are obviously not html. $temp[0] contains url of file to get
elseif (preg_match("/(jpg|png|gif|css|js|\(|\))/i", $temp[0], $matches)) {
echo $input;
}
//Otherwise, could be html (e.g. `wget http://www.google.com` downloads index.html)
else{
$time = time() . microtime(); //For unique directory names
$time = preg_replace("/ /", "", $time); //Simplify things by removing the spaces
mkdir("/var/www/cache/". $time); //Create unique folder
system("/usr/bin/wget -q --directory-prefix=\"/var/www/cache/$time/\" ". $temp[0]);
$filename = system("ls /var/www/cache/$time/"); //Get filename of downloaded file
//File is html, edit the content (this does not work)
if(preg_match("/.*\.html/", $filename)){
//Get the html file contents
$contentfh = fopen("/var/www/cache/$time/". $filename, 'r');
$content = fread($contentfh, filesize("/var/www/cache/$time/". $filename));
fclose($contentfh);
//Edit the html file contents
$content = preg_replace("/<\/body>/i", "<!-- content served by proxy --></body>", $content);
//Write the edited file
$contentfh = fopen("/var/www/cache/$time/". $filename, 'w');
fwrite($contentfh, $content);
fclose($contentfh);
//Return the edited page
echo "http://127.0.0.1/cache/$time/$filename\n";
}
//Otherwise file is not html, don't edit
else{
echo $input;
}
}
}
?>