tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
5
ZUGRIFFE
828
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Paula Paula ist offline Mitglied Gold
    Registriert seit
    Aug 2003
    Beiträge
    124
    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.
     

  2. #2
    Avatar von Dennis Wronka
    Dennis Wronka Dennis Wronka ist offline Soulcollector
    Registriert seit
    Apr 2002
    Ort
    Hong Kong
    Beiträge
    12.296
    Blog-Einträge
    231
    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.
     
    PHP Class Collection - PHP-Klassen fuer PHP 5 (und Teilweise auch fuer PHP 4)
    Updates: Catcher 1.1, FTPConnection 1.2, MultiSQL 1.1, RSS2 1.1, SMTPConnection 1.4
    __________________
    EasyLFS - Hintergrundinformationen, Installationsanleitung, Softwareliste und Download
    EasyLFS Projektthread - Informationen, Status und Diskussion zu meiner Linux-Distribution
    __________________
    Ich bin die Schildkroete, mein Sohn. Ich habe das Universum erschaffen, aber bitte mach mir daraus keinen Vorwurf; ich hatte Bauchschmerzen.
    __________________
    Zitat Zitat von Friedrich Nietzsche
    Man muss noch Chaos in sich haben, um einen tanzenden Stern gebaeren zu koennen.

  3. #3
    Paula Paula ist offline Mitglied Gold
    Registriert seit
    Aug 2003
    Beiträge
    124
    Ist dein geschriebenes PHP-Script zufällig frei verfügbar, damit ich mir ein paar Ideen aufschnappen kann?
     

  4. #4
    Avatar von Dennis Wronka
    Dennis Wronka Dennis Wronka ist offline Soulcollector
    Registriert seit
    Apr 2002
    Ort
    Hong Kong
    Beiträge
    12.296
    Blog-Einträge
    231
    Ja, das ist es.
    Die Klasse die dort eingebunden wird kannst Du hier finden.
    Code php:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    
    <?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);
        }
    ?>
     
    PHP Class Collection - PHP-Klassen fuer PHP 5 (und Teilweise auch fuer PHP 4)
    Updates: Catcher 1.1, FTPConnection 1.2, MultiSQL 1.1, RSS2 1.1, SMTPConnection 1.4
    __________________
    EasyLFS - Hintergrundinformationen, Installationsanleitung, Softwareliste und Download
    EasyLFS Projektthread - Informationen, Status und Diskussion zu meiner Linux-Distribution
    __________________
    Ich bin die Schildkroete, mein Sohn. Ich habe das Universum erschaffen, aber bitte mach mir daraus keinen Vorwurf; ich hatte Bauchschmerzen.
    __________________
    Zitat Zitat von Friedrich Nietzsche
    Man muss noch Chaos in sich haben, um einen tanzenden Stern gebaeren zu koennen.

  5. #5
    Registriert seit
    Jan 2002
    Ort
    Hamburg
    Beiträge
    2.852
    Hey Dennis... gibts es irgendetwas, dass du noch nicht irgendwann mal programmiert hast?!
     
    Wenn euch mein Beitrag gefällt, meldet euch als Referal bei Dropbox an: http://db.tt/4tKC8O5

  6. #6
    Avatar von Dennis Wronka
    Dennis Wronka Dennis Wronka ist offline Soulcollector
    Registriert seit
    Apr 2002
    Ort
    Hong Kong
    Beiträge
    12.296
    Blog-Einträge
    231
    Ja, da gibt es schon noch ein paar Sachen.
    Aber es ist mittlerweile schon einiges an interessanten Sachen zusammengekommen.
     
    PHP Class Collection - PHP-Klassen fuer PHP 5 (und Teilweise auch fuer PHP 4)
    Updates: Catcher 1.1, FTPConnection 1.2, MultiSQL 1.1, RSS2 1.1, SMTPConnection 1.4
    __________________
    EasyLFS - Hintergrundinformationen, Installationsanleitung, Softwareliste und Download
    EasyLFS Projektthread - Informationen, Status und Diskussion zu meiner Linux-Distribution
    __________________
    Ich bin die Schildkroete, mein Sohn. Ich habe das Universum erschaffen, aber bitte mach mir daraus keinen Vorwurf; ich hatte Bauchschmerzen.
    __________________
    Zitat Zitat von Friedrich Nietzsche
    Man muss noch Chaos in sich haben, um einen tanzenden Stern gebaeren zu koennen.

Ähnliche Themen

  1. Antworten: 2
    Letzter Beitrag: 29.03.09, 10:49
  2. Antworten: 1
    Letzter Beitrag: 29.02.08, 10:59
  3. Auf einen anderen PC via Internet zugreifen
    Von Hattrix im Forum Netzwerke
    Antworten: 2
    Letzter Beitrag: 25.01.08, 14:46
  4. Antworten: 4
    Letzter Beitrag: 16.09.05, 07:29
  5. Von einem Frame auf einen anderen zugreifen
    Von JanRei im Forum Javascript & Ajax
    Antworten: 2
    Letzter Beitrag: 19.11.04, 13:12