Trackbacks und https (keine Eingangserkennung)

Hier können Probleme und alles andere in Deutscher Sprache gelöst werden.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by garvinhicking »

Hi!

Dann mal hier der code der meinen Patch enthält, evtl ist da immer noch etwas mit falschem Port.

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']);
    }

    echo "Parts: " . print_r($target, true) . "<br />\n";
    if ($target['scheme'] == 'https' && empty($target['port'])) {
        $target['port'] = 443;
        echo "FIXED port to 443<br />\n";
    }
    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);
    echo "RAW POST DATA: <pre>" . print_r($data, true) . "</pre><br />\n";
    $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>';
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
bernd_d
Regular
Posts: 468
Joined: Thu Jun 03, 2010 9:28 am
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by bernd_d »

Update ist eingespielt. Rest können wir morgen testen, jetzt muss ich erstmal aufs Weinfest :D
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by garvinhicking »

Hi!

PROST!

Jetzt wirds allerdings interessant. Er schickt den Request nun korrekt zu:

Code: Select all

https://bernd.distler.ws:443/comment.php?type=trackback&entry_id=1385
aber da kommt eine Fehlermeldung. Möglich dass hier irgendein Filter irgendwas abfängt. Füg am ende der test2.php mal ein:

Code: Select all

echo "Trying plain: " . file_get_contents('https://bernd.distler.ws:443/comment.php?type=trackback&entry_id=1385') . "<br />\n";

echo "TRYING GET...<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_send');
    serendipity_request_start();

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

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

echo "TRYING POST without DATA...<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);
    }

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

Grüße,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
bernd_d
Regular
Posts: 468
Joined: Thu Jun 03, 2010 9:28 am
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by bernd_d »

Ich musste

Code: Select all

    // $tb = test_serendipity_trackback_autodiscover($fContent, $parsed_loc, $parsed_loc, 'Author', 'Title', 'Text');
    // echo '<pre>' . print_r($tb, true) . '</pre>';
auskommentieren, sonst hätte die Datei immer abgebrochen, siehe test3.php Den restlichen Code hab ich danach eingefügt.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by garvinhicking »

Hi!

Debugging so wie hier macht keinen Spaß, ggf. kannst Du mir FTP/SSH Zugriff geben?

Im Code hatte ich mal wieder $uri vercheckt, es müsste heißen:

Code: Select all

$uri = 'https://bernd.distler.ws:443/comment.php?type=trackback&entry_id=1385';
echo "Trying plain: " . file_get_contents($uri) . "<br />\n";
echo "TRYING GET...<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_send');
    serendipity_request_start();

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

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

echo "TRYING POST without DATA...<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);
    }

    $res = $req->sendRequest();
    echo $req->getResponseBody() . "<br />\n";
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
sws
Regular
Posts: 23
Joined: Wed Oct 08, 2008 9:47 am

Re: Trackbacks und https (keine Eingangserkennung)

Post by sws »

Hi,

hat sich an dem Problem etwas getan? Ich kann ebenfalls keine trackbacks zu https-Seiten erstellen. Und dabei handelt es sich um dieselbe URI wie das Blog selbst. Ein soeben erfolgreich durchgeführtes Update auf 1.7.3 brachte keine Verbesserung.

Bislang sucht sich s9y einen Wolf unter Port 80. Aber auch ein manueller Zusatz in der URL mit :443 bringt kein Glück.

Hat sich an dem Problem etwas getan?

Grüße,
Sebastian
bernd_d
Regular
Posts: 468
Joined: Thu Jun 03, 2010 9:28 am
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by bernd_d »

Ich habe es eben mal versucht und bei mir funktionieren Trackbacks an den eigenen Weblog. Wie es aussieht, wenn eine fremde Seite einen Track-/Pingback sendet, kann ich leider nicht sagen. Falls du eine Blog-URL angibst, könnten wir höchstens mal hin und her pingen um zu testen.

Prinzipiell ist der Code aber noch problematisch bzw. in einigen Fällen nicht funktional. Garvin hatte sich damals aber nicht mehr weiter damit beschäftigt, da andere Dinge wichtiger sind/waren.
sws
Regular
Posts: 23
Joined: Wed Oct 08, 2008 9:47 am

Re: Trackbacks und https (keine Eingangserkennung)

Post by sws »

Hin- und herpingen geht schlecht. Mein Blog ist rein privat und nichtöffentlich.

Wie muss ich denn die URI angeben, um intern einen trackback hinzubekommen? https://www.blog.privat
oder https://www.blog.privat:443 ?
bernd_d
Regular
Posts: 468
Joined: Thu Jun 03, 2010 9:28 am
Contact:

Re: Trackbacks und https (keine Eingangserkennung)

Post by bernd_d »

Ich habe es bei mir nur ohne Port-Angabe versucht, also die reine URL sowie wie sie der Besucher auch im Browser hat. Alles andere wäre ja auch doof und sehr nutzerunfreundlich.


Edit: Hast du auch mal die Spam-Plugins geprüft, wie am Anfang des Themas beschrieben?
sws
Regular
Posts: 23
Joined: Wed Oct 08, 2008 9:47 am

Re: Trackbacks und https (keine Eingangserkennung)

Post by sws »

Na gut, dann eben nicht. Wenn es bei mir nicht funktioniert, ist das auch kein Beinbruch. Es geht auch ohne.

Vielen Dank trotzdem für die prompte Rückmeldung,
frohes Fest und guten Rutsch,
Sebastian
sws
Regular
Posts: 23
Joined: Wed Oct 08, 2008 9:47 am

Re: Trackbacks und https (keine Eingangserkennung)

Post by sws »

bernd_d wrote:Edit: Hast du auch mal die Spam-Plugins geprüft, wie am Anfang des Themas beschrieben?
Daran habe ich nie geschraubt. Sind alle noch in der Standardeinstellung.

EDIT: Habe testhalber den Spamschutz entfernt --> keine Verbesserung: bei "normaler" URI findet er port 80 nicht, bei URI mit :443 ebenfalls negativ.
Post Reply