Page 2 of 3

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Wed Aug 14, 2013 3:41 pm
by bernd_d
Liefert mir die Seite als HTML zurück, sowohl bei Aufruf über https://.../test.php als auch http://.../test.php

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 12:11 pm
by garvinhicking
Hi!

OK, dann bitte mal folgendes probieren:

Code: Select all

<?php

include 'serendipity_config.inc.php';

$loc = 'https://bernd.distler.ws/archives/1385-Probleme-mit-Serendipity-und-https-URLs.html';

$u = parse_url($loc);

if ($u['scheme'] != 'http' && $u['scheme'] != 'https') {
	echo "SCHEME != http(s)<br />\n";
    return;
} elseif ($u['scheme'] == 'https' && !extension_loaded('openssl')) {
	echo "HTTPS not supported!<br />\n";
    return; // Trackbacks to HTTPS URLs can only be performed with openssl activated
}

if (empty($u['port'])) {
    $u['port'] = 80;
    $port      = '';
} else {
    $port      = ':' . $u['port'];
}

if (!empty($u['query'])) {
    $u['path'] .= '?' . $u['query'];
}

$parsed_loc = $u['scheme'] . '://' . $u['host'] . $port . $u['path'];

echo "Checking: " . $parsed_loc . "<br />\n";

require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'GET');
serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_detect');
serendipity_request_start();
$req = new HTTP_Request($url, $options);
$res = $req->sendRequest();

if (PEAR::isError($res)) {
    echo '<div>&#8226; ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'</div>';
    serendipity_request_end();
    return;
}

$fContent = $req->getResponseBody();
serendipity_request_end();
echo $fContent . "<br />\n";
Ich vermute, dass im oberen Teil (extension_loaded('openssl')) der Code abbricht. Was komisch wäre, denn openssl scheint bei Dir aktiviert zu sein. Naja, erstmal schauen was mit obigem test.php code bei dir passiert.

GRüße
Garvin

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 12:27 pm
by onli
Das war noch nicht im Forum: Ich hab gestern per IM mit Bernd ein paar Debugausgaben eingefügt und getestet. Demnach wird die Anfrage gestellt, der Code bricht also nicht ab, aber es kommt keine Antwort zurück. Ab da wusste ich nicht wirklich weiter und der Thread hier belebte sich.

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 1:00 pm
by bernd_d
garvinhicking wrote:Ich vermute, dass im oberen Teil (extension_loaded('openssl')) der Code abbricht. Was komisch wäre, denn openssl scheint bei Dir aktiviert zu sein. Naja, erstmal schauen was mit obigem test.php code bei dir passiert.
http://bernd.distler.ws/test2.php liefert

Code: Select all

Checking: https://bernd.distler.ws/archives/1385-Probleme-mit-Serendipity-und-https-URLs.html
• Kein Trackback: Konnte Verbindung zu bernd.distler.ws auf Port 80 nicht herstellen.

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 1:56 pm
by garvinhicking
Hi!

OK, dann kommt er zumindest bis zum Request, aber krieg da (wie onli gerade schrieb) wohl keine Daten herein.

Füg bitte nochmal folgende Zeilen ein nach der Zeile "$res= $req->sendRequest()"::

Code: Select all

echo 'Ziehe HTTP-Request aus: ' . S9Y_PEAR_PATH . '<br />';
echo 'LOC: ' . $parsed_loc . '<br />';
echo '<pre>' . print_r($options, true) . '</pre>';
echo '<pre>' . print_r($res, true) . '</pre>';
echo '<pre>' . print_r($req, true) . '</pre>';
Die Debuggingangaben sollten Details zum fehlgeschlagenen Request enthalten.

Nutzt Du evtl eines der Proxy-Eventplugins, diese könnten einen HTTP-Request beeinflussen.

Grüße,
Garvin

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 2:09 pm
by bernd_d
Hab den Code eingebaut, kannst du dir auf http://bernd.distler.ws/test2.php ansehen. Von Proxy-Plugins weiß ich nix :oops:

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 2:14 pm
by onli
$url exisitiert nicht, oder?
Sollte das

Code: Select all

$req = new HTTP_Request($loc, $options);
statt

Code: Select all

$req = new HTTP_Request($url, $options);
heißen?

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 2:16 pm
by garvinhicking
onli wrote:$url exisitiert nicht, oder?
Sollte das

Code: Select all

$req = new HTTP_Request($loc, $options);
statt

Code: Select all

$req = new HTTP_Request($url, $options);
heißen?
Argl. Ja. Danke dafür. Hier nochmal der angepasst komplette Code:

Code: Select all

<?php

include 'serendipity_config.inc.php';

$loc = 'https://bernd.distler.ws/archives/1385-Probleme-mit-Serendipity-und-https-URLs.html';

$u = parse_url($loc);

if ($u['scheme'] != 'http' && $u['scheme'] != 'https') {
   echo "SCHEME != http(s)<br />\n";
    return;
} elseif ($u['scheme'] == 'https' && !extension_loaded('openssl')) {
   echo "HTTPS not supported!<br />\n";
    return; // Trackbacks to HTTPS URLs can only be performed with openssl activated
}

if (empty($u['port'])) {
    $u['port'] = 80;
    $port      = '';
} else {
    $port      = ':' . $u['port'];
}

if (!empty($u['query'])) {
    $u['path'] .= '?' . $u['query'];
}

$parsed_loc = $u['scheme'] . '://' . $u['host'] . $port . $u['path'];

echo "Checking: " . $parsed_loc . "<br />\n";

require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'GET');
serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_detect');
serendipity_request_start();
$req = new HTTP_Request($loc, $options);
$res = $req->sendRequest();

echo 'Ziehe HTTP-Request aus: ' . S9Y_PEAR_PATH . '<br />';
echo 'LOC: ' . $parsed_loc . '<br />';
echo '<pre>' . print_r($options, true) . '</pre>';
echo '<pre>' . print_r($res, true) . '</pre>';
echo '<pre>' . print_r($req, true) . '</pre>';

if (PEAR::isError($res)) {
    echo '<div>&#8226; ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'</div>';
    serendipity_request_end();
    return;
}

$fContent = $req->getResponseBody();
serendipity_request_end();
echo $fContent . "<br />\n";

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 2:33 pm
by bernd_d
OK, hab die test2.php aktualisiert.

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 3:06 pm
by garvinhicking
Hi!

Interessant. Der SSL-Request geht eigentlich durch um die URL zu holen. Als nächster Schritt würde s9y den HTML-Content auswerten um die Trackback-URL festzustellen.

Anbei ein neuer PHP-Code der diee Schritte weiter debugged:

Code: Select all

<?php
include 'serendipity_config.inc.php';

function test_serendipity_send($loc, $data, $contenttype = null) {
    global $serendipity;

    $target = parse_url($loc);
    if ($target['query'] != '') {
        $target['query'] = '?' . str_replace('&', '&', $target['query']);
    }

    if (!is_numeric($target['port'])) {
       $target['port'] = 80;
    }

    $uri = $target['scheme'] . '://' . $target['host'] . ':' . $target['port'] . $target['path'] . $target['query'];

    echo "Sending TB to: " . $uri . "<br />\n";
    require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
    $options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'POST');
    serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_send');
    serendipity_request_start();

    $req = new HTTP_Request($uri, $options);
    if (isset($contenttype)){
       $req->addHeader('Content-Type', $contenttype);
    }

    $req->addRawPostData($data, true);
    $res = $req->sendRequest();

    echo 'Sent to: ' . print_r($res, true) . "<br />\n";

    if (PEAR::isError($res)) {
        echo "PEAR FAILRUE!<br />\n";
        serendipity_request_end();
        return false;
    }

    $fContent = $req->getResponseBody();
    serendipity_request_end();

    echo "Returned " . strlen($fContent) . " Bytes.<br />\n";
    print_r($fContent);

    return $fContent;
}

function test_serendipity_trackback_autodiscover($res, $loc, $url, $author, $title, $text, $loc2 = '') {
    $is_wp    = false;
    $wp_check = false;

    if (preg_match('@((' . preg_quote($loc, '@') . '|' . preg_quote($loc2, '@') . ')/?trackback/)@i', $res, $wp_loc)) {
        // We found a WP-blog that may not advertise RDF-Tags!
        $is_wp = true;
    }

    if (!preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*["\'](https?:[^"\']+)["\']@i', $res, $matches)) {
        echo "RDF-XML not found!<br />\n";
        $matches = array();
        serendipity_plugin_api::hook_event('backend_trackback_check', $matches, $loc);

        // Plugins may say that a URI is valid, in situations where a blog has no valid RDF metadata
        if (empty($matches[2])) {
            if ($is_wp) {
                $wp_check = true;
            } else {
                echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '</div>';
                return false;
            }
        }
    }

    $trackURI = trim($matches[2]);
    echo "TB-URI resolved to " . $trackURI . "<br />\n";

    if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) {
        if ($loc != $test[1] && $loc2 != $test[1]) {
            if ($is_wp) {
                $wp_check = true;
            } else {
                echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '</div>';
                return false;
            }
        }
    }

    // If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url.
    if ($wp_check) {
        $trackURI = $wp_loc[0];
    }

    $data = 'url='        . rawurlencode($url)
          . '&title='     . rawurlencode($title)
          . '&blog_name=' . rawurlencode($author)
          . '&excerpt='   . rawurlencode(strip_tags($text));

    printf(TRACKBACK_SENDING, htmlspecialchars($trackURI));

    $sent = test_serendipity_send($trackURI, $data);
    $response = serendipity_trackback_is_success($sent);

    if ($response === true) {
        echo '<div>&#8226; ' . TRACKBACK_SENT .'</div>';
    } else {
        echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, $response) . '</div>';
    }

    return $response;
}

$loc = 'https://bernd.distler.ws/archives/1385-Probleme-mit-Serendipity-und-https-URLs.html';

$u = parse_url($loc);

if ($u['scheme'] != 'http' && $u['scheme'] != 'https') {
   echo "SCHEME != http(s)<br />\n";
    return;
} elseif ($u['scheme'] == 'https' && !extension_loaded('openssl')) {
   echo "HTTPS not supported!<br />\n";
    return; // Trackbacks to HTTPS URLs can only be performed with openssl activated
}

if (empty($u['port'])) {
    $u['port'] = 80;
    $port      = '';
} else {
    $port      = ':' . $u['port'];
}

if (!empty($u['query'])) {
    $u['path'] .= '?' . $u['query'];
}

$parsed_loc = $u['scheme'] . '://' . $u['host'] . $port . $u['path'];

echo "Checking: " . $parsed_loc . "<br />\n";

require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'GET');
serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_detect');
serendipity_request_start();
$req = new HTTP_Request($loc, $options);
$res = $req->sendRequest();

echo 'Ziehe HTTP-Request aus: ' . S9Y_PEAR_PATH . '<br />';
echo 'LOC: ' . $parsed_loc . '<br />';
echo '<pre>' . print_r($options, true) . '</pre>';
#echo '<pre>' . print_r($res, true) . '</pre>';
#echo '<pre>' . print_r($req, true) . '</pre>';

if (PEAR::isError($res)) {
    echo '<div>&#8226; ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'</div>';
    serendipity_request_end();
    return;
}

$fContent = $req->getResponseBody();
serendipity_request_end();
echo strlen($fContent) . " Bytes erhalten.<br />\n";

$tb = test_serendipity_trackback_autodiscover($fContent, $parsed_loc, $parsed_loc, 'Author', 'Title', 'Text');
echo '<pre>' . print_r($tb, true) . '</pre>';
Grüße,
Garvin

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 3:19 pm
by bernd_d
test2 ist up-to-date.

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 3:31 pm
by garvinhicking
Hi!

OK. Fehler gefunden. Der Code setzt ein ":80" als Defaultport dran, was bei https natürlich falsch ist.

Folgneder Bugfix im s9y core behebt das:

https://github.com/s9y/Serendipity/comm ... 6701e3bcbf

Alternativ kannst Du das Trackback an https://bernd.distler.ws:443/URL...html verschicken, also 443 als Port mitgeben, dann müsste es auch ankommen.

Grüße,
Garvin

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 3:34 pm
by Timbalu
TB-URI resolved to https: //bernd.distler.ws/comment.php?type=trackback&entry_id=1385<br />
Sende Trackback zu URI https: //bernd.distler.ws/comment.php?type=trackback&amp;entry_id=1385 ...Sending TB to: https: //bernd.distler.ws:80/comment.php?type=trackback&entry_id=1385<br />
Wo kommt das zweite "amp;" ohne "&" und überhaupt das "Sende Trackback zu URI " her?

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 4:04 pm
by garvinhicking
Wo kommt das zweite "amp;" ohne "&" und überhaupt das "Sende Trackback zu URI " her?
Wg. htmlspecialchars() in der URL-Ausgabe zur Sicherheit um da kein XSS zu haben.

Grüße,
Garvin

Re: Trackbacks und https (keine Eingangserkennung)

Posted: Thu Aug 15, 2013 4:04 pm
by bernd_d
garvinhicking wrote:OK. Fehler gefunden. Der Code setzt ein ":80" als Defaultport dran, was bei https natürlich falsch ist.

Folgneder Bugfix im s9y core behebt das:

https://github.com/s9y/Serendipity/comm ... 6701e3bcbf

Alternativ kannst Du das Trackback an https://bernd.distler.ws:443/URL...html verschicken, also 443 als Port mitgeben, dann müsste es auch ankommen.
Ich habe den Patch eingebaut, aber beide Varianten funktionieren nicht. Es kommt leider kein Trackback an.