Beispiel #1
0
    //syslog(LOG_NOTICE, "Meneame: Too old: $tb_url -> " . $link->get_permalink());
    die;
}
if (!empty($tb_url) && !empty($title) && !empty($excerpt)) {
    header('Content-Type: text/xml; charset=UTF-8');
    $title = clean_text($title);
    $excerpt = clean_text($excerpt);
    $blog_name = clean_text($blog_name);
    $title = mb_strlen($title) > 120 ? mb_substr($title, 0, 120) . '...' : $title;
    $excerpt = mb_strlen($excerpt) > 200 ? mb_substr($excerpt, 0, 200) . '...' : $excerpt;
    $trackres = new Trackback();
    $trackres->link_id = $tb_id;
    $trackres->type = 'in';
    $trackres->link = $tb_url;
    $trackres->url = $tb_url;
    if ($trackres->abuse()) {
        trackback_response(1, 'Dont abuse.');
    }
    $dupe = $trackres->read();
    if ($dupe) {
        syslog(LOG_NOTICE, "Meneame: We already have a ping from that URI for this post: {$tb_url} - {$permalink}");
        trackback_response(1, 'We already have a ping from that URI for this post.');
    }
    $response = get_url($tb_url);
    if (!$response || empty($result['content'])) {
        syslog(LOG_NOTICE, "Meneame: The provided URL does not seem to work: {$tb_url}");
        trackback_response(1, 'The provided URL does not seem to work.');
    }
    $permalink = $link->get_permalink();
    $permalink_q = preg_quote($permalink, '/');
    $pattern = "/<\\s*a.*href\\s*=[\"'\\s]*" . $permalink_q . "[#\\/0-9a-z\\-]*[\"'\\s]*.*>.*<\\s*\\/\\s*a\\s*>/i";
Beispiel #2
0
 function pingback_ping($args)
 {
     global $db, $globals;
     $pagelinkedfrom = clean_input_string($args[0]);
     //$pagelinkedfrom = str_replace('&amp;', '&', $pagelinkedfrom);
     $pagelinkedto = clean_input_string($args[1]);
     $title = '';
     $urlfrom = parse_url($pagelinkedfrom);
     $urltest = parse_url($pagelinkedto);
     if (!$urlfrom || !$urltest) {
         return new IXR_Error(0, 'Is there no link to us?');
     }
     if ($urltest['host'] != get_server_name()) {
         return new IXR_Error(0, 'Is there no link to us?');
     }
     $base_uri = preg_quote($globals['base_url'] . $globals['base_story_url'], '/');
     $uri = preg_replace("/^{$base_uri}/", '', $urltest[path]);
     if (check_ban($globals['user_ip'], 'ip')) {
         syslog(LOG_NOTICE, "Meneame: pingback, IP is banned ({$globals['user_ip']}): {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(33, 'IP is banned.');
     }
     // Antispam of sites like xxx.yyy-zzz.info/archives/xxx.php
     if (preg_match('/http:\\/\\/[a-z0-9]\\.[a-z0-9]+-[^\\/]+\\.info\\/archives\\/.+\\.php$/', $pagelinkedfrom)) {
         return new IXR_Error(33, 'Host not allowed.');
     }
     if (check_ban($urlfrom[host], 'hostname', false)) {
         syslog(LOG_NOTICE, "Meneame: pingback, site is banned: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(33, 'Site is banned.');
     }
     $link = new Link();
     $link->uri = preg_replace('/#[\\w\\-\\_]+$/', '', $uri);
     if (empty($uri) || !$link->read('uri')) {
         syslog(LOG_NOTICE, "Meneame: pingback, story does not exist: {$pagelinkedto}");
         return new IXR_Error(33, 'Story doesn\'t exist.');
     }
     if ($link->get_permalink() == $pagelinkedfrom) {
         syslog(LOG_NOTICE, "Meneame: pingback, points to the same post: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(48, 'The pingback points to the same post.');
     }
     if ($link->date < time() - 86400 * 15) {
         syslog(LOG_NOTICE, "Meneame: pingback, story is too old: {$pagelinkedto}");
         return new IXR_Error(33, 'Story is too old for pingbacks.');
     }
     $trackres = new Trackback();
     $trackres->link_id = $link->id;
     $trackres->type = 'in';
     $trackres->link = $pagelinkedfrom;
     $trackres->url = $pagelinkedfrom;
     if ($trackres->abuse()) {
         return new IXR_Error(33, 'Don\'t send so many pings.');
     }
     $dupe = $trackres->read();
     if ($dupe) {
         syslog(LOG_NOTICE, "Meneame: pingback, we already have a ping from that URI for this post: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(48, 'The pingback has already been registered.');
     }
     // very stupid, but gives time to the 'from' server to publish !
     sleep(1);
     // Let's check the remote site
     if (version_compare(phpversion(), '5.1.0') >= 0) {
         $contents = @file_get_contents($pagelinkedfrom, FALSE, NULL, 0, 100000);
     } else {
         $contents = @file_get_contents($pagelinkedfrom);
     }
     if (!$contents) {
         syslog(LOG_NOTICE, "Meneame: pingback, the provided URL does not seem to work: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(16, 'The source URL does not exist.');
     }
     if (preg_match('/charset=([a-zA-Z0-9-_]+)/i', $contents, $matches)) {
         $this->encoding = trim($matches[1]);
         if (strcasecmp($this->encoding, 'utf-8') != 0) {
             $contents = iconv($this->encoding, 'UTF-8//IGNORE', $contents);
         }
     }
     // Check is links back to us
     $permalink = $link->get_permalink();
     $permalink_q = preg_quote($permalink, '/');
     $pattern = "/<\\s*a[^>]+href=[\"']" . $permalink_q . "[#\\/0-9a-z\\-]*[\"'][^>]*>/i";
     if (!preg_match($pattern, $contents)) {
         syslog(LOG_NOTICE, "Meneame: pingback, the provided URL does not have a link back to us: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(17, 'The source URL does not contain a link to the target URL, and so cannot be used as a source.');
     }
     // Search Title
     if (preg_match('/<title[^<>]*>([^<>]*)<\\/title>/si', $contents, $matches)) {
         $url_title = clean_text($matches[1]);
         if (mb_strlen($url_title) > 3) {
             $title = $url_title;
         }
     }
     if (empty($title)) {
         syslog(LOG_NOTICE, "Meneame: pingback, cannot find a title on that page: {$pagelinkedfrom} - {$pagelinkedto}");
         return new IXR_Error(32, 'We cannot find a title on that page.');
     }
     $title = mb_strlen($title) > 120 ? mb_substr($title, 0, 120) . '...' : $title;
     $trackres->title = $title;
     $trackres->status = 'ok';
     $trackres->store();
     syslog(LOG_NOTICE, "Meneame: pingback ok: {$pagelinkedfrom} - {$pagelinkedto}");
     return "Pingback from registered. Keep the web talking! :-)";
 }