Exemple #1
0
function diaspora_dispatch_public($msg)
{
    $enabled = intval(get_config('system', 'diaspora_enabled'));
    if (!$enabled) {
        logger('mod-diaspora: disabled');
        return;
    }
    $sys_disabled = true;
    if (!get_config('system', 'disable_discover_tab')) {
        $sys_disabled = get_config('system', 'disable_diaspora_discover_tab');
    }
    $sys = $sys_disabled ? null : get_sys_channel();
    // find everybody following or allowing this author
    $r = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network like '%%diaspora%%' and xchan_addr = '%s' )", dbesc($msg['author']));
    // also need to look for those following public streams
    if ($r) {
        foreach ($r as $rr) {
            logger('diaspora_public: delivering to: ' . $rr['channel_name'] . ' (' . $rr['channel_address'] . ') ');
            diaspora_dispatch($rr, $msg);
        }
    } else {
        if (!$sys) {
            logger('diaspora_public: no subscribers');
        }
    }
    if ($sys) {
        $sys['system'] = true;
        logger('diaspora_public: delivering to sys.');
        diaspora_dispatch($sys, $msg);
    }
}
function diaspora_dispatch_public($msg)
{
    $sys_disabled = true;
    if (!get_config('system', 'disable_discover_tab')) {
        $sys_disabled = get_config('system', 'disable_diaspora_discover_tab');
    }
    $sys = $sys_disabled ? null : get_sys_channel();
    // find everybody following or allowing this author
    $r = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network like '%%diaspora%%' and xchan_addr = '%s' ) and channel_removed = 0 ", dbesc($msg['author']));
    // look for those following tags - we'll check tag validity for each specific channel later
    $y = q("select * from channel where channel_id in ( SELECT uid from pconfig where cat = 'diaspora' and k = 'followed_tags' and v != '') and channel_removed = 0 ");
    if (is_array($y) && is_array($r)) {
        $r = array_merge($r, $y);
    }
    // @FIXME we should also enumerate channels that allow postings by anybody
    if ($r) {
        foreach ($r as $rr) {
            logger('diaspora_public: delivering to: ' . $rr['channel_name'] . ' (' . $rr['channel_address'] . ') ');
            diaspora_dispatch($rr, $msg);
        }
    } else {
        if (!$sys) {
            logger('diaspora_public: no subscribers');
        }
    }
    if ($sys) {
        $sys['system'] = true;
        logger('diaspora_public: delivering to sys.');
        diaspora_dispatch($sys, $msg);
    }
}
Exemple #3
0
function dsprphotoq_run($argv, $argc)
{
    global $a, $db;
    if (is_null($a)) {
        $a = new App();
    }
    if (is_null($db)) {
        @(include ".htconfig.php");
        require_once "include/dba.php";
        $db = new dba($db_host, $db_user, $db_pass, $db_data);
        unset($db_host, $db_user, $db_pass, $db_data);
    }
    logger("diaspora photo queue: running", LOGGER_DEBUG);
    $r = q("SELECT * FROM dsprphotoq");
    if (!$r) {
        return;
    }
    $dphotos = $r;
    logger("diaspora photo queue: processing " . count($dphotos) . " photos");
    foreach ($dphotos as $dphoto) {
        $r = q("SELECT * FROM user WHERE uid = %d", intval($dphoto['uid']));
        if (!$r) {
            logger("diaspora photo queue: user " . $dphoto['uid'] . " not found");
            return;
        }
        $ret = diaspora_dispatch($r[0], unserialize($dphoto['msg']), $dphoto['attempt']);
        q("DELETE FROM dsprphotoq WHERE id = %d", intval($dphoto['id']));
    }
}
Exemple #4
0
function diaspora_dispatch_public($msg)
{
    $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 ", dbesc(NETWORK_DIASPORA), dbesc($msg['author']));
    if (count($r)) {
        foreach ($r as $rr) {
            logger('diaspora_public: delivering to: ' . $rr['username']);
            diaspora_dispatch($rr, $msg);
        }
    } else {
        logger('diaspora_public: no subscribers');
    }
}
function receive_post(&$a)
{
    $public = false;
    logger('diaspora_receive: ' . print_r($a->argv, true), LOGGER_DEBUG);
    if (argc() == 2 && argv(1) === 'public') {
        $public = true;
    } else {
        if (argc() != 3 || argv(1) !== 'users') {
            http_status_exit(500);
        }
        $guid = argv(2);
        $hn = str_replace('.', '', $a->get_hostname());
        if (($x = strpos($guid, $hn)) > 0) {
            $guid = substr($guid, 0, $x);
        }
        // Diaspora sites *may* provide a truncated guid.
        $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_guid like '%s' AND channel_removed = 0 LIMIT 1", dbesc($guid . '%'));
        if (!$r) {
            http_status_exit(500);
        }
        $importer = $r[0];
    }
    // It is an application/x-www-form-urlencoded that has been urlencoded twice.
    logger('mod-diaspora: receiving post', LOGGER_DEBUG);
    $xml = urldecode($_POST['xml']);
    logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
    if (!$xml) {
        http_status_exit(500);
    }
    logger('mod-diaspora: message is okay', LOGGER_DEBUG);
    $msg = diaspora_decode($importer, $xml);
    logger('mod-diaspora: decoded', LOGGER_DEBUG);
    logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
    if (!is_array($msg)) {
        http_status_exit(500);
    }
    logger('mod-diaspora: dispatching', LOGGER_DEBUG);
    $ret = 0;
    if ($public) {
        diaspora_dispatch_public($msg);
    } else {
        $ret = diaspora_dispatch($importer, $msg);
    }
    http_status_exit($ret ? $ret : 200);
    // NOTREACHED
}
Exemple #6
0
function receive_post(&$a)
{
    $enabled = intval(get_config('system', 'diaspora_enabled'));
    if (!$enabled) {
        logger('mod-diaspora: disabled');
        http_status_exit(500);
    }
    $public = false;
    if (argc() == 2 && argv(1) === 'public') {
        $public = true;
    } else {
        if (argc() != 3 || argv(1) !== 'users') {
            http_status_exit(500);
        }
        $guid = argv(2);
        // Diaspora sites *may* provide a truncated guid.
        $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_guid like '%s' AND NOT (channel_pageflags & %d )>0 LIMIT 1", dbesc($guid . '%'), intval(PAGE_REMOVED));
        if (!$r) {
            http_status_exit(500);
        }
        $importer = $r[0];
    }
    // It is an application/x-www-form-urlencoded that has been urlencoded twice.
    logger('mod-diaspora: receiving post', LOGGER_DEBUG);
    $xml = urldecode($_POST['xml']);
    logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
    if (!$xml) {
        http_status_exit(500);
    }
    logger('mod-diaspora: message is okay', LOGGER_DEBUG);
    $msg = diaspora_decode($importer, $xml);
    logger('mod-diaspora: decoded', LOGGER_DEBUG);
    logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
    if (!is_array($msg)) {
        http_status_exit(500);
    }
    logger('mod-diaspora: dispatching', LOGGER_DEBUG);
    $ret = 0;
    if ($public) {
        diaspora_dispatch_public($msg);
    } else {
        $ret = diaspora_dispatch($importer, $msg);
    }
    http_status_exit($ret ? $ret : 200);
    // NOTREACHED
}
Exemple #7
0
function diaspora_dispatch_public($msg)
{
    $enabled = intval(get_config('system', 'diaspora_enabled'));
    if (!$enabled) {
        logger('mod-diaspora: disabled');
        return;
    }
    $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN\n\t        ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' )\n\t        AND `account_expired` = 0 AND `account_removed` = 0 ", dbesc(NETWORK_DIASPORA), dbesc($msg['author']));
    if (count($r)) {
        foreach ($r as $rr) {
            logger('diaspora_public: delivering to: ' . $rr['username']);
            diaspora_dispatch($rr, $msg);
        }
    } else {
        logger('diaspora_public: no subscribers');
    }
}
Exemple #8
0
function receive_post(&$a)
{
    $enabled = intval(get_config('system', 'diaspora_enabled'));
    if (!$enabled) {
        logger('mod-diaspora: disabled');
        http_status_exit(500);
    }
    $public = false;
    if ($a->argc == 2 && $a->argv[1] === 'public') {
        $public = true;
    } else {
        if ($a->argc != 3 || $a->argv[1] !== 'users') {
            http_status_exit(500);
        }
        $guid = $a->argv[2];
        $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($guid));
        if (!count($r)) {
            http_status_exit(500);
        }
        $importer = $r[0];
    }
    // It is an application/x-www-form-urlencoded
    logger('mod-diaspora: receiving post', LOGGER_DEBUG);
    $xml = urldecode($_POST['xml']);
    logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
    if (!$xml) {
        http_status_exit(500);
    }
    logger('mod-diaspora: message is okay', LOGGER_DEBUG);
    $msg = diaspora_decode($importer, $xml);
    logger('mod-diaspora: decoded', LOGGER_DEBUG);
    logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
    if (!is_array($msg)) {
        http_status_exit(500);
    }
    logger('mod-diaspora: dispatching', LOGGER_DEBUG);
    $ret = 0;
    if ($public) {
        diaspora_dispatch_public($msg);
    } else {
        $ret = diaspora_dispatch($importer, $msg);
    }
    http_status_exit($ret ? $ret : 200);
    // NOTREACHED
}
Exemple #9
0
function diaspora_dispatch_public($msg)
{
    $enabled = intval(get_config('system', 'diaspora_enabled'));
    if (!$enabled) {
        logger('mod-diaspora: disabled');
        return;
    }
    // Use a dummy importer to import the data for the public copy
    $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
    $result = diaspora_dispatch($importer, $msg);
    logger("Dispatcher reported " . $result, LOGGER_DEBUG);
    // Now distribute it to the followers
    $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN\n\t\t( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' )\n\t\tAND `account_expired` = 0 AND `account_removed` = 0 ", dbesc(NETWORK_DIASPORA), dbesc($msg['author']));
    if (count($r)) {
        foreach ($r as $rr) {
            logger('diaspora_public: delivering to: ' . $rr['username']);
            diaspora_dispatch($rr, $msg);
        }
    } else {
        logger('diaspora_public: no subscribers for ' . $msg["author"] . ' ' . print_r($msg, true));
    }
}
Exemple #10
0
function receive_post(&$a)
{
    $public = false;
    logger('diaspora_receive: ' . print_r(App::$argv, true), LOGGER_DEBUG, LOG_INFO);
    if (argc() == 2 && argv(1) === 'public') {
        $public = true;
    } else {
        if (argc() != 3 || argv(1) !== 'users') {
            http_status_exit(500);
        }
        $guid = argv(2);
        // So that the Diaspora GUID will work with nomadic identity, we append
        // the hostname but remove any periods so that it doesn't mess up URLs.
        // (This was an occasional issue with message_ids that include the hostname,
        // and we learned from that experience).
        // Without the hostname bit the Diaspora side would not be able to share
        // with two channels which have the same GUID (e.g. channel clones). In this step
        // we're stripping the hostname part which Diaspora thinks is our GUID so
        // that we can locate our channel by the channel_guid. On our network,
        // channel clones have the same GUID even if they are on different sites.
        $hn = str_replace('.', '', App::get_hostname());
        if (($x = strpos($guid, $hn)) > 0) {
            $guid = substr($guid, 0, $x);
        }
        // Sites running old code *may* provide a truncated guid, when GUIDs were 16 hex chars.
        // This might also be true for older Friendica sites that stored the guid separately.
        // We may not require this truncation check any more, but it probably does no harm to leave it.
        // Forgeries and mischief will be caught out by permission checks later.
        $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_guid like '%s' AND channel_removed = 0 LIMIT 1", dbesc($guid . '%'));
        if (!$r) {
            http_status_exit(500);
        }
        $importer = $r[0];
    }
    logger('mod-diaspora: receiving post', LOGGER_DEBUG, LOG_INFO);
    // Diaspora traditionally urlencodes or base64 encodes things a superfluous number of times.
    // The legacy format is double url-encoded for an unknown reason. At the time of this writing
    // the new formats have not yet been seen crossing the wire, so we're being proactive and decoding
    // until we see something reasonable. Once we know how many times we are expected to decode we can
    // refine this.
    if ($_POST['xml']) {
        $xml = ltrim($_POST['xml']);
        $format = 'legacy';
        // PHP performed the first decode when populating the $_POST variable.
        // Here we do the second - which has been required since 2010-2011.
        if (substr($xml, 0, 1) !== '<') {
            $xml = ltrim(urldecode($xml));
        }
    } else {
        $xml = ltrim(file_get_contents('php://input'));
        $format = 'bis';
        $decode_counter = 0;
        while ($decode_counter < 3) {
            if (substr($xml, 0, 1) === '{' || substr($xml, 0, 1) === '<') {
                break;
            }
            $decode_counter++;
            $xml = ltrim(urldecode($xml));
        }
        logger('decode_counter: ' . $decode_counter, LOGGER_DEBUG, LOG_INFO);
    }
    if ($format === 'bis') {
        switch (substr($xml, 0, 1)) {
            case '{':
                $format = 'json';
                break;
            case '<':
                $format = 'salmon';
                break;
            default:
                break;
        }
    }
    logger('diaspora salmon format: ' . $format, LOGGER_DEBUG, LOG_INFO);
    logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA);
    if (!$xml || $format === 'bis') {
        http_status_exit(500);
    }
    logger('mod-diaspora: message is okay', LOGGER_DEBUG);
    $msg = diaspora_decode($importer, $xml, $format);
    logger('mod-diaspora: decoded', LOGGER_DEBUG);
    logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
    if (!is_array($msg)) {
        http_status_exit(500);
    }
    logger('mod-diaspora: dispatching', LOGGER_DEBUG);
    $ret = 0;
    if ($public) {
        diaspora_dispatch_public($msg);
    } else {
        $ret = diaspora_dispatch($importer, $msg);
    }
    http_status_exit($ret ? $ret : 200);
    // NOTREACHED
}