Visualizzazione risultati 1 fino 6 di 6

Discussione: Can't do transparent proxying without a Host: header.

  1. #1
    Data registrazione
    05-02-2013
    Messaggi
    27

    Predefinito Can't do transparent proxying without a Host: header.

    Salve, ho uno script così composto:

    class Padre
    |- function s ($var) [espleta richieste server 2 server tramite fsockopen($var) ]

    class Figlia extends Padre
    |- function a { parent::s(x) }
    |- function b { parent::s(y) }

    $A = Figlia->a()
    $B = Figlia->b()

    in risposta ho che la richiesta eseguita per la variabile $A va a buon fine, mentre con la richiesta eseguita per la variabile $B ritorna la dicitura "Can't do transparent proxying without a Host: header."

    Ho provato ad invertire l'ordine delle richieste ( $B, $A ) ma è sempre la seconda richiesta a fallire, come se si sovrapponesse alla prima.

    La mia domanda è: come faccio a fare in modo che entrambe le richieste vadano a buon fine?
    Ultima modifica di ravimatsolutions : 13-12-2016 alle ore 00.42.28

  2. #2
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Riporta il codice in questione, altrimenti è difficile aiutarti.

  3. #3
    Data registrazione
    05-02-2013
    Messaggi
    27

    Predefinito

    Codice PHP:
    class HTTP_Request
    {
    public function
    __construct()
    {
    }

    public function
    Request( $host, $data )
    {
    if( !
    filter_var($host, FILTER_VALIDATE_URL) === false ){
    $this->PostData = 'url='.$host.'&'.$data;
    if(
    $this->Initialize() ) return $this->Send();
    }else return
    $host.' is not a valid URL';
    }

    private function
    Initialize()
    {
    $this->Method = "POST";
    if (empty(
    $this->PostData))
    {
    $this->Method = "GET";}
    $this->Port = 80;
    if (
    strtolower(substr($this->Host, 0, 5)) == "https")
    {
    $this->Port = 443;}
    $this->Host = explode("//", $this->Host, 2);
    if (
    count($this->Host) < 2)
    {
    $this->Host[1] = $this->Host[0];}
    $this->Host = explode("/", $this->Host[1], 2);
    if (
    $this->Port == 443)
    {
    $this->SSLAdd = "ssl://";}
    $this->Host[0] = explode(":", $this->Host[0]);
    if (
    count($this->Host[0]) > 1)
    {
    $this->Port = $this->Host[0][1];
    $this->Host[0] = $this->Host[0][0];
    }
    else
    {
    $this->Host[0] = $this->Host[0][0];}
    return
    true;
    }

    private function
    Send()
    {
    $this->attempt++;
    $Socket = fsockopen($this->SSLAdd.$this->Host[0], $this->Port, $errno, $errstr, 4.9);
    if (
    $Socket)
    {
    fputs($Socket, $this->Method." /".$this->Host[1]." HTTP/1.1\r\n".
    "Host: ".$this->Host[0]."\r\n".
    "Content-type: application/x-www-form-urlencoded\r\n".
    "User-Agent: Opera/9.01 (Windows NT 5.1; U; en)\r\n".
    "Accept-Language: de-DE,de;q=0.9,en;q=0.8\r\n".
    "Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\n".
    "Content-length: ".strlen($this->PostData)."\r\n".
    "Connection: close\r\n".
    "\r\n".
    $this->PostData);
    $Tme = time();
    while(!
    feof($Socket) && $Tme + 30 > time())
    {
    $Res = $Res.fgets($Socket, 256);}
    fclose($Socket);
    }
    if (
    $errno == 0 )
    {
    $Res = explode("\r\n\r\n", $Res, 2);
    return
    $Res[1];
    }
    else
    {
    if (
    $this->attempt < 3 )
    {
    sleep(3);
    $this->Send();
    }
    else return
    '{"errno":"'.$errno.'","errstr":"'.$errstr.'"}';
    }
    }
    }
    Codice PHP:
    class User extends HTTP_Request
    {
    private
    $user;
    public function
    __construct($value)
    {
    ...
    }
    public function
    online()
    {
    $myfile = fopen("file.txt", "r");
    $Host = base64_decode( fgets($myfile) );
    fclose($myfile);
    $json = base64_encode('{"request":["agent","'.$this->user['uuid'].'","online"]}');
    $response = json_decode(parent::Request($Host, 'data='.$json), true);
    return (
    $response['response']['agent']['online'] == 1) ? true : false ;
    }
    public function
    onlineMonitoring($value)
    {
    $myfile = fopen("file.txt", "r");
    $Host = base64_decode( fgets($myfile) );
    fclose($myfile);
    if( !empty(
    $value) ){
    $value = ($value==1)?'add':'remove';
    $json = base64_encode('{"request":["agent","'.$this->user['uuid'].'","list","'.$value.'"],"details":["'.$this->user['name'].'"]}');
    }else{
    $value = 'check';
    $json = base64_encode('{"request":["agent","'.$this->user['uuid'].'","list","check"]}');
    }
    $response = json_decode(parent::Request($Host, 'data='.$json), true);
    return (
    $response['response']['agent']['list'][$value] == 1) ? true : false ;
    }
    }
    Codice PHP:
    $user = new User($x);
    $response['online'] = $user->online(); // OK
    $response['monitoring'] = $user->onlineMonitoring(); // Can't do transparent proxying without a Host: header.
    Ultima modifica di ravimatsolutions : 13-12-2016 alle ore 20.17.47

  4. #4
    Data registrazione
    05-02-2013
    Messaggi
    27

    Predefinito

    up

  5. #5
    karl94 non è connesso Staff AV
    Data registrazione
    03-10-2005
    Messaggi
    17,744

    Predefinito

    Controlla bene il codice. Anzitutto la proprietà Host non la inizializzi da nessuna parte, ma sopratutto ad ogni richiesta viene eseguito il metodo Initialize, che effettua un explode sulla proprietà Host. Prima dell'esecuzione di questo metodo quindi ipotizzo che Hostcontenga una stringa, ma dopo l'esecuzione conterrà necessariamente un array. Alla seconda esecuzione (causata dalla seconda chiamata a Request) verrà quindi chiamata di nuovo la funzione explode, ma su un array. Correggi.

  6. #6
    Data registrazione
    05-02-2013
    Messaggi
    27

    Predefinito

    Host viene inizializzata, ma fuori dalla funzione e dal costruttore. Di conseguenza andavo a sovrascrivere il valore iniziale con un array e nella seconda chiamata non trovava più l'url di riferimento. Adesso in Initialize() ho incluso anche Host, in modo che venga riconfigurata ad ogni chiamata, e funziona correttamente.
    Ti ringrazio per l'aiuto.

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •