2009-01-24 17:38:12 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-25 23:14:12 +01:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-25 23:12:20 +01:00
|
|
|
* Copyright (C) 2009, StatusNet, Inc.
|
2009-01-24 17:38:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-08-26 15:41:36 +01:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
2009-01-24 17:38:12 +00:00
|
|
|
|
|
|
|
function ping_broadcast_notice($notice) {
|
2010-10-30 12:47:19 +01:00
|
|
|
if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-19 13:21:50 +00:00
|
|
|
|
2011-03-22 15:54:23 +00:00
|
|
|
// Array of servers, URL => type
|
2010-10-30 12:47:19 +01:00
|
|
|
$notify = common_config('ping', 'notify');
|
2010-10-28 20:58:30 +01:00
|
|
|
try {
|
|
|
|
$profile = $notice->getProfile();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// @todo: distinguish the 'broken notice/profile' case from more general
|
|
|
|
// transitory errors.
|
|
|
|
common_log(LOG_ERR, "Exception getting notice profile: " . $e->getMessage());
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-30 12:47:19 +01:00
|
|
|
$tags = ping_notice_tags($notice);
|
2009-03-19 13:21:50 +00:00
|
|
|
|
2010-10-30 12:47:19 +01:00
|
|
|
foreach ($notify as $notify_url => $type) {
|
|
|
|
switch ($type) {
|
|
|
|
case 'xmlrpc':
|
|
|
|
case 'extended':
|
|
|
|
$req = xmlrpc_encode_request('weblogUpdates.ping',
|
|
|
|
array($profile->nickname, # site name
|
|
|
|
common_local_url('showstream',
|
|
|
|
array('nickname' => $profile->nickname)),
|
|
|
|
common_local_url('shownotice',
|
|
|
|
array('notice' => $notice->id)),
|
|
|
|
common_local_url('userrss',
|
|
|
|
array('nickname' => $profile->nickname)),
|
|
|
|
$tags));
|
2009-01-24 17:38:12 +00:00
|
|
|
|
2009-10-28 19:29:20 +00:00
|
|
|
$request = HTTPClient::start();
|
2010-05-05 02:43:32 +01:00
|
|
|
$request->setConfig('connect_timeout', common_config('ping', 'timeout'));
|
|
|
|
$request->setConfig('timeout', common_config('ping', 'timeout'));
|
|
|
|
try {
|
|
|
|
$httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
common_log(LOG_ERR,
|
|
|
|
"Exception pinging $notify_url: " . $e->getMessage());
|
2019-05-05 14:03:55 +01:00
|
|
|
break;
|
2010-05-05 02:43:32 +01:00
|
|
|
}
|
2009-03-22 19:34:09 +00:00
|
|
|
|
2009-10-28 19:29:20 +00:00
|
|
|
if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) {
|
2009-03-22 19:34:09 +00:00
|
|
|
common_log(LOG_WARNING,
|
|
|
|
"XML-RPC empty results for ping ($notify_url, $notice->id) ");
|
2019-05-05 14:03:55 +01:00
|
|
|
break;
|
2009-03-22 19:34:09 +00:00
|
|
|
}
|
|
|
|
|
2009-10-28 19:29:20 +00:00
|
|
|
$response = xmlrpc_decode($httpResponse->getBody());
|
2009-03-22 19:34:09 +00:00
|
|
|
|
2009-07-08 02:15:39 +01:00
|
|
|
if (is_array($response) && xmlrpc_is_fault($response)) {
|
2009-03-19 13:21:50 +00:00
|
|
|
common_log(LOG_WARNING,
|
|
|
|
"XML-RPC error for ping ($notify_url, $notice->id) ".
|
|
|
|
"$response[faultString] ($response[faultCode])");
|
|
|
|
} else {
|
|
|
|
common_log(LOG_INFO,
|
|
|
|
"Ping success for $notify_url $notice->id");
|
|
|
|
}
|
|
|
|
break;
|
2010-10-30 12:47:19 +01:00
|
|
|
case 'get':
|
|
|
|
case 'post':
|
2009-03-19 13:21:50 +00:00
|
|
|
$args = array('name' => $profile->nickname,
|
|
|
|
'url' => common_local_url('showstream',
|
|
|
|
array('nickname' => $profile->nickname)),
|
|
|
|
'changesURL' => common_local_url('userrss',
|
|
|
|
array('nickname' => $profile->nickname)));
|
|
|
|
|
|
|
|
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
|
|
|
|
|
|
|
if ($type === 'get') {
|
|
|
|
$result = $fetcher->get($notify_url . '?' . http_build_query($args),
|
2013-11-01 12:28:52 +00:00
|
|
|
array('User-Agent: ' . HTTPClient::userAgent()));
|
2009-03-19 13:21:50 +00:00
|
|
|
} else {
|
|
|
|
$result = $fetcher->post($notify_url,
|
|
|
|
http_build_query($args),
|
2013-11-01 12:28:52 +00:00
|
|
|
array('User-Agent: ' . HTTPClient::userAgent()));
|
2009-03-19 13:21:50 +00:00
|
|
|
}
|
|
|
|
if ($result->status != '200') {
|
|
|
|
common_log(LOG_WARNING,
|
|
|
|
"Ping error for '$notify_url' ($notice->id): ".
|
|
|
|
"$result->body");
|
|
|
|
} else {
|
|
|
|
common_log(LOG_INFO,
|
|
|
|
"Ping success for '$notify_url' ($notice->id): ".
|
|
|
|
"'$result->body'");
|
|
|
|
}
|
|
|
|
break;
|
2010-10-30 12:47:19 +01:00
|
|
|
default:
|
|
|
|
common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
|
2009-03-19 13:21:50 +00:00
|
|
|
}
|
2010-10-30 12:47:19 +01:00
|
|
|
}
|
2009-03-19 13:21:50 +00:00
|
|
|
|
|
|
|
return true;
|
2009-01-24 17:38:12 +00:00
|
|
|
}
|
2009-03-19 13:21:50 +00:00
|
|
|
|
2009-01-24 17:38:12 +00:00
|
|
|
function ping_notice_tags($notice) {
|
2010-10-30 12:47:19 +01:00
|
|
|
$tag = new Notice_tag();
|
|
|
|
$tag->notice_id = $notice->id;
|
|
|
|
$tags = array();
|
|
|
|
if ($tag->find()) {
|
|
|
|
while ($tag->fetch()) {
|
|
|
|
$tags[] = $tag->tag;
|
|
|
|
}
|
|
|
|
$tag->free();
|
|
|
|
unset($tag);
|
|
|
|
return implode('|', $tags);
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-01-07 20:59:31 +00:00
|
|
|
}
|