Per Browser über einen Weberver auf einen anderen blockierten Server zugreifen?

Paula

Erfahrenes Mitglied
Hallo zusammen,

mich beschäftigt gerade folgende Problematik:

Ich habe zwei Server gegeben. Der erste Server hat Tomcat installiert und ich kann per Browser auf diesen Webserver zugreifen. Jedoch läuft auf diesem Server als dynamische Scriptsprache nur Perl.

Der zweite Server hat LAMPP installiert. Dort laufen auch meine relevanten Sripte. Ich kann auf diesen Server jedoch nicht per Browser zugreifen, da eine Firewall dies blockiert.

Ich kann jedoch mit dem ersten Server auf den zweiten Server zugreifen.


Nun zu meiner Frage:
Ist es möglich, dass ich auf den ersten Server irgendein Script aufrufe, wodurch ein Request auf den zweiten Server gesendet wird und dort wird eine dynamische Seite erzeugt und wieder an den ersten Server gesendet und im Browser dargestellt wird. Sprich wie ein Spiegel oder so ähnlich.
 
Ich hab mal in PHP eine Art Proxy-Server geschrieben. Diesem Script wurde halt die aufzurufende Seite uebergeben und diese wurde dann vom Script abgeholt und an den Browser weitergeleitet. Ich koennte mir durchaus vorstellen, dass sowas auch mit Perl machbar ist.
 
Ist dein geschriebenes PHP-Script zufällig frei verfügbar, damit ich mir ein paar Ideen aufschnappen kann? :rolleyes:
 
Ja, das ist es.
Die Klasse die dort eingebunden wird kannst Du hier finden.
PHP:
<?php
error_reporting(E_ALL);
require_once("httpconnection.class.php");
function spliturl($url)
{
		$url_array=explode("://",$url);
		if (count($url_array)>1)
			{
				$protocol=$url_array[0];
				$url=$url_array[1];
			}
		else
			{
				$protocol="http";
				$url=$url_array[0];
			}
		$url_array=explode("?",$url);
		if (count($url_array)>1)
			{
				$parameters=$url_array[1];
			}
		else
			{
				$parameters="";
			}
		$url=$url_array[0];
		$url_array=explode("/",$url);
		if (count($url_array)>1)
			{
				$url=$url_array[0];
				unset($url_array[0]);
				$path=implode("/",$url_array);
			}
		else
			{
				$url=$url_array[0];
				$path="";
			}
		$url_array=explode(":",$url);
		if (count($url_array)>1)
			{
				$port=$url_array[1];
			}
		else
			{
				if ($protocol=="http")
					{
						$port=80;
					}
				elseif ($protocol=="https")
					{
						$port=443;
					}
			}
		$host=$url_array[0];
		$url=array("protocol"=>$protocol,"host"=>$host,"port"=>$port,"path"=>$path,"parameters"=>$parameters);
		return $url;
}

function preparedata($data,$url)
{
	//href
	$data_array=array();
	$replacements=array();
	preg_match_all("/href=([\"]|['])[\S]*([\"]|['])/",$data,$data_array);
	for ($x=0;$x<count($data_array[0]);$x++)
		{
			$extracted=substr($data_array[0][$x],6,strlen($data_array[0][$x])-7);
			$replacement="href=\"http://localhost:8080/proxy/phpproxy.php?url=";
			if (strpos($data_array[0][$x],$url['protocol'])==false)
				{
					$replacement.=$url['protocol']."://";
					if (strpos($data_array[0][$x],$url['host'])==false)
						{
							$replacement.=$url['host'].":".$url['port'];
							if (substr($extracted,0,1)!="/")
								{
									$replacement.="/";
								}
						}
				}
			$replacement.=$extracted."\"";
			$replacements[]=$replacement;
		}
	$data=str_replace($data_array[0],$replacements,$data);
	//src
	$data_array=array();
	$replacements=array();
	preg_match_all("/src=([\"]|['])[\S]*([\"]|['])/",$data,$data_array);
	for ($x=0;$x<count($data_array[0]);$x++)
		{
			$extracted=substr($data_array[0][$x],5,strlen($data_array[0][$x])-6);
			$replacement="src=\"http://localhost:8080/proxy/phpproxy.php?url=";
			if (strpos($data_array[0][$x],$url['protocol'])==false)
				{
					$replacement.=$url['protocol']."://";
					if (strpos($data_array[0][$x],$url['host'])==false)
						{
							$replacement.=$url['host'].":".$url['port'];
							if (substr($extracted,0,1)!="/")
								{
									$replacement.="/";
								}
						}
				}
			$replacement.=$extracted."\"";
			$replacements[]=$replacement;
		}
	$data=str_replace($data_array[0],$replacements,$data);
	//action
	$data_array=array();
	$replacements=array();
	preg_match_all("/action=([\"]|['])[\S]*([\"]|['])/",$data,$data_array);
	for ($x=0;$x<count($data_array[0]);$x++)
		{
			$extracted=substr($data_array[0][$x],8,strlen($data_array[0][$x])-9);
			$replacement="action=\"http://localhost:8080/proxy/phpproxy.php?url=";
			if (strpos($data_array[0][$x],$url['protocol'])==false)
				{
					$replacement.=$url['protocol']."://";
					if (strpos($data_array[0][$x],$url['host'])==false)
						{
							$replacement.=$url['host'].":".$url['port'];
							if (substr($extracted,0,1)!="/")
								{
									$replacement.="/";
								}
						}
				}
			$replacement.=$extracted."\"";
			$replacements[]=$replacement;
		}
	$data=str_replace($data_array[0],$replacements,$data);
	//for forms currently just post works, but not perfect
	//url (css)
	$data_array=array();
	$replacements=array();
	preg_match_all("/url\(([\"]|['])[\S]*([\"]|['])/",$data,$data_array);
	for ($x=0;$x<count($data_array[0]);$x++)
		{
			$extracted=substr($data_array[0][$x],5,strlen($data_array[0][$x])-6);
			$replacement="url(\"http://localhost:8080/proxy/phpproxy.php?url=";
			if (strpos($data_array[0][$x],$url['protocol'])==false)
				{
					$replacement.=$url['protocol']."://";
					if (strpos($data_array[0][$x],$url['host'])==false)
						{
							$replacement.=$url['host'].":".$url['port'];
							if (substr($extracted,0,1)!="/")
								{
									$replacement.="/";
								}
						}
				}
			$replacement.=$extracted."\"";
			$replacements[]=$replacement;
		}
	$data=str_replace($data_array[0],$replacements,$data);
	return $data;
}

if (!empty($_GET['url']))
	{
		$url=spliturl($_GET['url']);
		//echo $url['protocol'].' '.$url['host'].' '.$url['port'].' '.$url['path'].' '.$url['parameters'];
		if ($url['protocol']=="https")
			{
				$http=new httpconnection($url['host'],$url['port'],true,$_SERVER['HTTP_USER_AGENT']);
			}
		else
			{
				$http=new httpconnection($url['host'],$url['port'],false,$_SERVER['HTTP_USER_AGENT']);
			}
		if (empty($_POST))
			{
				$data=$http->get($url['path'],$url['parameters']);
			}
		else
			{
				$filestring=false;
				$mimestring=false;
				if (!empty($_FILES))
					{
						$dir=md5(uniqid());
						mkdir($dir);
						$filekeys=array_keys($_FILES);
						$fileitems=array();
						$mimetypes=array();
						for ($x=0;$x<count($filekeys);$x++)
							{
								if ($_FILES[$filekeys[$x]]['size']>0)
									{
										move_uploaded_file($_FILES[$filekeys[$x]]['tmp_name'],$dir."/".$_FILES[$filekeys[$x]]['name']);
										$fileitems[]=$filekeys[$x]."=".$dir."/".$_FILES[$filekeys[$x]]['name'];
										$mimetypes[]=$_FILES[$filekeys[$x]]['type'];
									}
							}
						$filestring=implode("&",$fileitems);
						$mimestring=implode(",",$mimetypes);
					}
				$postkeys=array_keys($_POST);
				$postitems=array();
				for ($x=0;$x<count($postkeys);$x++)
					{
						$postitems[]=$postkeys[$x]."=".$_POST[$postkeys[$x]];
					}
				$poststring=implode("&",$postitems);
				if ($filestring!=false)
					{
						$data=$http->post($url['path']."?".$url['parameters'],$poststring,false,$filestring,$mimestring);
					}
				else
					{
						$data=$http->post($url['path']."?".$url['parameters'],$poststring);
					}
				if (!empty($_FILES))
					{
						for ($x=0;$x<count($filekeys);$x++)
							{
								unlink($dir."/".$_FILES[$filekeys[$x]]['name']);
							}
						rmdir($dir);
					}
			}
		while (isset($data['head']['location']))
			{
				if (isset($data['head']['location']['parameters']))
					{
						$data=$http->get($data['head']['location']['uri'],$data['head']['location']['parameters']);
					}
				else
					{
						$data=$http->get($data['head']['location']['uri']);
					}
			}
		if (isset($data['head']['contenttype']))
			{
				header("Content-Type:".$data['head']['contenttype']);
			}
		unset($data['head']['contenttype']);
		if ((!isset($data['head']['contenttype'])) || (substr($data['head']['contenttype'],0,4)=="text"))
		//if ((isset($data['head']['contenttype'])) && (substr($data['head']['contenttype'],0,4)=="text"))
			{
				$output=preparedata($data['body'],$url);
			}
		else
			{
				$output=$data['body'];
			}
		//echo nl2br(print_r($data['head'],true));
		echo $output;
		unset($http);
	}
?>
 
Hey Dennis... gibts es irgendetwas, dass du noch nicht irgendwann mal programmiert hast?! :)
 
Zurück