Diaspora Relay: Only accept postings from anyone when the relay is configured
This commit is contained in:
parent
8d2c74eb3c
commit
40390cc5ec
3 changed files with 90 additions and 72 deletions
11
boot.php
11
boot.php
|
@ -430,6 +430,17 @@ define('PRIORITY_LOW', 40);
|
||||||
define('PRIORITY_NEGLIGIBLE',50);
|
define('PRIORITY_NEGLIGIBLE',50);
|
||||||
/* @}*/
|
/* @}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Social Relay settings
|
||||||
|
*
|
||||||
|
* See here: https://github.com/jaywink/social-relay
|
||||||
|
* and here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
define('SR_SCOPE_NONE', '');
|
||||||
|
define('SR_SCOPE_ALL', 'all');
|
||||||
|
define('SR_SCOPE_TAGS', 'tags');
|
||||||
|
/* @}*/
|
||||||
|
|
||||||
// Normally this constant is defined - but not if "pcntl" isn't installed
|
// Normally this constant is defined - but not if "pcntl" isn't installed
|
||||||
if (!defined("SIGTERM"))
|
if (!defined("SIGTERM"))
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
* This will change in the future.
|
* This will change in the future.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use \Friendica\Core\Config;
|
||||||
|
|
||||||
require_once("include/items.php");
|
require_once("include/items.php");
|
||||||
require_once("include/bb2diaspora.php");
|
require_once("include/bb2diaspora.php");
|
||||||
require_once("include/Scrape.php");
|
require_once("include/Scrape.php");
|
||||||
|
@ -309,10 +311,6 @@ class Diaspora {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a dummy importer to import the data for the public copy
|
|
||||||
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
|
|
||||||
$message_id = self::dispatch($importer,$msg);
|
|
||||||
|
|
||||||
// Now distribute it to the followers
|
// Now distribute it to the followers
|
||||||
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
|
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
|
||||||
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
|
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
|
||||||
|
@ -320,7 +318,7 @@ class Diaspora {
|
||||||
dbesc(NETWORK_DIASPORA),
|
dbesc(NETWORK_DIASPORA),
|
||||||
dbesc($msg["author"])
|
dbesc($msg["author"])
|
||||||
);
|
);
|
||||||
if ($r) {
|
if (dbm::is_result($r)) {
|
||||||
foreach ($r as $rr) {
|
foreach ($r as $rr) {
|
||||||
logger("delivering to: ".$rr["username"]);
|
logger("delivering to: ".$rr["username"]);
|
||||||
self::dispatch($rr,$msg);
|
self::dispatch($rr,$msg);
|
||||||
|
@ -329,6 +327,14 @@ class Diaspora {
|
||||||
logger("No subscribers for ".$msg["author"]." ".print_r($msg, true), LOGGER_DEBUG);
|
logger("No subscribers for ".$msg["author"]." ".print_r($msg, true), LOGGER_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$social_relay = (bool)Config::get('system', 'relay_subscribe', false);
|
||||||
|
|
||||||
|
// Use a dummy importer to import the data for the public copy
|
||||||
|
if (dbm::is_result($r) OR $social_relay) {
|
||||||
|
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
|
||||||
|
$message_id = self::dispatch($importer,$msg);
|
||||||
|
}
|
||||||
|
|
||||||
return $message_id;
|
return $message_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,67 +1,68 @@
|
||||||
<?php
|
<?php
|
||||||
/// @TODO This file has DOS line endings!
|
|
||||||
require_once("mod/hostxrd.php");
|
use \Friendica\Core\Config;
|
||||||
require_once("mod/nodeinfo.php");
|
|
||||||
|
require_once("mod/hostxrd.php");
|
||||||
function _well_known_init(App $a) {
|
require_once("mod/nodeinfo.php");
|
||||||
if ($a->argc > 1) {
|
|
||||||
switch($a->argv[1]) {
|
function _well_known_init(App $a) {
|
||||||
case "host-meta":
|
if ($a->argc > 1) {
|
||||||
hostxrd_init($a);
|
switch($a->argv[1]) {
|
||||||
break;
|
case "host-meta":
|
||||||
case "x-social-relay":
|
hostxrd_init($a);
|
||||||
wk_social_relay($a);
|
break;
|
||||||
break;
|
case "x-social-relay":
|
||||||
case "nodeinfo":
|
wk_social_relay($a);
|
||||||
nodeinfo_wellknown($a);
|
break;
|
||||||
break;
|
case "nodeinfo":
|
||||||
}
|
nodeinfo_wellknown($a);
|
||||||
}
|
break;
|
||||||
http_status_exit(404);
|
}
|
||||||
killme();
|
}
|
||||||
}
|
http_status_exit(404);
|
||||||
|
killme();
|
||||||
function wk_social_relay(App $a) {
|
}
|
||||||
|
|
||||||
define('SR_SCOPE_ALL', 'all');
|
function wk_social_relay(App $a) {
|
||||||
define('SR_SCOPE_TAGS', 'tags');
|
|
||||||
|
$subscribe = (bool)Config::get('system', 'relay_subscribe', false);
|
||||||
$subscribe = (bool)get_config('system', 'relay_subscribe');
|
|
||||||
|
if ($subscribe) {
|
||||||
if ($subscribe)
|
$scope = Config::get('system', 'relay_scope', SR_SCOPE_ALL);
|
||||||
$scope = get_config('system', 'relay_scope');
|
} else {
|
||||||
else
|
$scope = SR_SCOPE_NONE;
|
||||||
$scope = "";
|
}
|
||||||
|
|
||||||
$tags = array();
|
$tags = array();
|
||||||
|
|
||||||
if ($scope == SR_SCOPE_TAGS) {
|
if ($scope == SR_SCOPE_TAGS) {
|
||||||
|
$server_tags = Config::get('system', 'relay_server_tags');
|
||||||
$server_tags = get_config('system', 'relay_server_tags');
|
$tagitems = explode(",", $server_tags);
|
||||||
$tagitems = explode(",", $server_tags);
|
|
||||||
|
foreach($tagitems AS $tag) {
|
||||||
foreach($tagitems AS $tag)
|
$tags[trim($tag, "# ")] = trim($tag, "# ");
|
||||||
$tags[trim($tag, "# ")] = trim($tag, "# ");
|
}
|
||||||
|
|
||||||
if (get_config('system', 'relay_user_tags')) {
|
if (Config::get('system', 'relay_user_tags')) {
|
||||||
$terms = q("SELECT DISTINCT(`term`) FROM `search`");
|
$terms = q("SELECT DISTINCT(`term`) FROM `search`");
|
||||||
|
|
||||||
foreach($terms AS $term) {
|
foreach($terms AS $term) {
|
||||||
$tag = trim($term["term"], "#");
|
$tag = trim($term["term"], "#");
|
||||||
$tags[$tag] = $tag;
|
$tags[$tag] = $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$taglist = array();
|
$taglist = array();
|
||||||
foreach($tags AS $tag)
|
foreach($tags AS $tag) {
|
||||||
$taglist[] = $tag;
|
$taglist[] = $tag;
|
||||||
|
}
|
||||||
$relay = array("subscribe" => $subscribe,
|
|
||||||
"scope" => $scope,
|
$relay = array("subscribe" => $subscribe,
|
||||||
"tags" => $taglist);
|
"scope" => $scope,
|
||||||
|
"tags" => $taglist);
|
||||||
header('Content-type: application/json; charset=utf-8');
|
|
||||||
echo json_encode($relay, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
header('Content-type: application/json; charset=utf-8');
|
||||||
exit;
|
echo json_encode($relay, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||||
}
|
exit;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue