当前位置: 首页>>代码示例>>PHP>>正文


PHP zot_zot函数代码示例

本文整理汇总了PHP中zot_zot函数的典型用法代码示例。如果您正苦于以下问题:PHP zot_zot函数的具体用法?PHP zot_zot怎么用?PHP zot_zot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zot_zot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: directory_run

/**
 * @brief
 *
 * @param array $argv
 * @param array $argc
 */
function directory_run($argv, $argc)
{
    cli_startup();
    if ($argc < 2) {
        return;
    }
    $force = false;
    $pushall = true;
    if ($argc > 2) {
        if ($argv[2] === 'force') {
            $force = true;
        }
        if ($argv[2] === 'nopush') {
            $pushall = false;
        }
    }
    logger('directory update', LOGGER_DEBUG);
    $dirmode = get_config('system', 'directory_mode');
    if ($dirmode === false) {
        $dirmode = DIRECTORY_MODE_NORMAL;
    }
    $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]));
    if (!$x) {
        return;
    }
    $channel = $x[0];
    if ($dirmode != DIRECTORY_MODE_NORMAL) {
        // this is an in-memory update and we don't need to send a network packet.
        local_dir_update($argv[1], $force);
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
        // Now update all the connections
        if ($pushall) {
            proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
        }
        return;
    }
    // otherwise send the changes upstream
    $directory = find_upstream_directory($dirmode);
    $url = $directory['url'] . '/post';
    // ensure the upstream directory is updated
    $packet = zot_build_packet($channel, $force ? 'force_refresh' : 'refresh');
    $z = zot_zot($url, $packet);
    // re-queue if unsuccessful
    if (!$z['success']) {
        /** @FIXME we aren't updating channel_dirdate if we have to queue
         * the directory packet. That means we'll try again on the next poll run.
         */
        $hash = random_string();
        q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) \n\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc('zot'), dbesc($url), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($packet), dbesc(''));
    } else {
        q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
    }
    // Now update all the connections
    if ($pushall) {
        proc_run('php', 'include/notifier.php', 'refresh_all', $channel['channel_id']);
    }
}
开发者ID:msooon,项目名称:hubzilla,代码行数:63,代码来源:directory.php

示例2: run

 public static function run($argc, $argv)
 {
     if ($argc < 2) {
         return;
     }
     $force = false;
     $pushall = true;
     if ($argc > 2) {
         if ($argv[2] === 'force') {
             $force = true;
         }
         if ($argv[2] === 'nopush') {
             $pushall = false;
         }
     }
     logger('directory update', LOGGER_DEBUG);
     $dirmode = get_config('system', 'directory_mode');
     if ($dirmode === false) {
         $dirmode = DIRECTORY_MODE_NORMAL;
     }
     $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]));
     if (!$x) {
         return;
     }
     $channel = $x[0];
     if ($dirmode != DIRECTORY_MODE_NORMAL) {
         // this is an in-memory update and we don't need to send a network packet.
         local_dir_update($argv[1], $force);
         q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
         // Now update all the connections
         if ($pushall) {
             Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
         }
         return;
     }
     // otherwise send the changes upstream
     $directory = find_upstream_directory($dirmode);
     $url = $directory['url'] . '/post';
     // ensure the upstream directory is updated
     $packet = zot_build_packet($channel, $force ? 'force_refresh' : 'refresh');
     $z = zot_zot($url, $packet);
     // re-queue if unsuccessful
     if (!$z['success']) {
         /** @FIXME we aren't updating channel_dirdate if we have to queue
          * the directory packet. That means we'll try again on the next poll run.
          */
         $hash = random_string();
         queue_insert(array('hash' => $hash, 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $url, 'notify' => $packet));
     } else {
         q("update channel set channel_dirdate = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($channel['channel_id']));
     }
     // Now update all the connections
     if ($pushall) {
         Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id']));
     }
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:56,代码来源:Directory.php

示例3: queue_run

function queue_run($argv, $argc)
{
    cli_startup();
    global $a;
    require_once 'include/items.php';
    require_once 'include/bbcode.php';
    if (argc() > 1) {
        $queue_id = argv(1);
    } else {
        $queue_id = 0;
    }
    $deadguys = array();
    logger('queue: start');
    $r = q("DELETE FROM outq WHERE outq_created < UTC_TIMESTAMP() - INTERVAL 3 DAY");
    if ($queue_id) {
        $r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1", dbesc($queue_id));
    } else {
        // For the first 12 hours we'll try to deliver every 15 minutes
        // After that, we'll only attempt delivery once per hour.
        // This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
        // so that we don't start off a thousand deliveries for a couple of dead hubs.
        // The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
        // Other drivers will have to do something different here and may need their own query.
        $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) group by outq_posturl");
    }
    if (!$r) {
        return;
    }
    foreach ($r as $rr) {
        if (in_array($rr['outq_posturl'], $deadguys)) {
            continue;
        }
        if ($rr['outq_driver'] === 'post') {
            $result = z_post_url($rr['outq_posturl'], $rr['outq_msg']);
            if ($result['success'] && $result['return_code'] < 300) {
                logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG);
                $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($rr['ouq_hash']));
            } else {
                logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'], LOGGER_DEBUG);
                $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($rr['outq_hash']));
            }
            continue;
        }
        $result = zot_zot($rr['outq_posturl'], $rr['outq_notify']);
        if ($result['success']) {
            zot_process_response($rr['outq_posturl'], $result, $rr);
        } else {
            $deadguys[] = $rr['outq_posturl'];
            $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($rr['outq_hash']));
        }
    }
}
开发者ID:Mauru,项目名称:red,代码行数:52,代码来源:queue.php

示例4: get

 function get()
 {
     // This is just a test utility function and may go away once we build these tools into
     // the address book and directory to do dead site discovery.
     // The response packet include the current URL and key so we can discover if the server
     // has been re-installed and clean up (e.g. get rid of) any old hublocs and xchans.
     // Remember to add '/post' to the url
     if (!local_channel()) {
         return;
     }
     $url = $_REQUEST['url'];
     if (!$url) {
         return;
     }
     $m = zot_build_packet(\App::get_channel(), 'ping');
     $r = zot_zot($url, $m);
     return print_r($r, true);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:18,代码来源:Zping.php

示例5: deliver_run

function deliver_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
    for ($x = 1; $x < $argc; $x++) {
        $r = q("select * from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
        if ($r) {
            if ($r[0]['outq_driver'] === 'post') {
                $result = z_post_url($r[0]['outq_posturl'], $r[0]['outq_msg']);
                if ($result['success'] && $result['return_code'] < 300) {
                    logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
                } else {
                    logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post') {
                logger('deliver: local delivery', LOGGER_DEBUG);
                // local delivery
                // we should probably batch these and save a few delivery processes
                // If there is no outq_msg, this is a refresh_all message which does not require local handling
                if ($r[0]['outq_msg']) {
                    $msg = array('body' => json_encode(array('pickup' => array(array('notify' => json_decode($r[0]['outq_notify'], true), 'message' => json_decode($r[0]['outq_msg'], true))))));
                    zot_import($msg, z_root());
                    $r = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
                }
            } else {
                logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                $result = zot_zot($r[0]['outq_posturl'], $r[0]['outq_notify']);
                if ($result['success']) {
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
}
开发者ID:Mauru,项目名称:red,代码行数:44,代码来源:deliver.php

示例6: admin_page_hubloc_post

 function admin_page_hubloc_post(&$a)
 {
     check_form_security_token_redirectOnErr('/admin/hubloc', 'admin_hubloc');
     require_once 'include/zot.php';
     //prepare for ping
     if ($_POST['hublocid']) {
         $hublocid = $_POST['hublocid'];
         $arrhublocurl = q("SELECT hubloc_url FROM hubloc WHERE hubloc_id = %d ", intval($hublocid));
         $hublocurl = $arrhublocurl[0]['hubloc_url'] . '/post';
         //perform ping
         $m = zot_build_packet(\App::get_channel(), 'ping');
         $r = zot_zot($hublocurl, $m);
         //handle results and set the hubloc flags in db to make results visible
         $r2 = $r['body'];
         $r3 = $r2['success'];
         if ($r3['success'] == True) {
             //set HUBLOC_OFFLINE to 0
             logger(' success = true ', LOGGER_DEBUG);
         } else {
             //set HUBLOC_OFFLINE to 1
             logger(' success = false ', LOGGER_DEBUG);
         }
         //unfotunatly zping wont work, I guess return format is not correct
         //require_once('mod/zping.php');
         //$r = zping_content($hublocurl);
         //logger('zping answer: ' . $r, LOGGER_DEBUG);
         //in case of repair store new pub key for tested hubloc (all channel with this hubloc) in db
         //after repair set hubloc flags to 0
     }
     goaway(z_root() . '/admin/hubloc');
 }
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:31,代码来源:Admin.php

示例7: Verify

 function Verify($channel, $hubloc)
 {
     logger('auth request received from ' . $hubloc['hubloc_addr']);
     $this->remote = remote_channel();
     $this->remote_service_class = '';
     $this->remote_level = 0;
     $this->remote_hub = $hubloc['hubloc_url'];
     $this->dnt = 0;
     // check credentials and access
     // If they are already authenticated and haven't changed credentials,
     // we can save an expensive network round trip and improve performance.
     // Also check that they are coming from the same site as they authenticated with originally.
     $already_authed = remote_channel() && $hubloc['hubloc_hash'] == remote_channel() && $hubloc['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
     if ($this->delegate && $this->delegate !== $_SESSION['delegate_channel']) {
         $already_authed = false;
     }
     if ($already_authed) {
         return true;
     }
     if (local_channel()) {
         // tell them to logout if they're logged in locally as anything but the target remote account
         // in which case just shut up because they don't need to be doing this at all.
         if (\App::$channel['channel_hash'] == $hubloc['xchan_hash']) {
             return true;
         } else {
             logger('already authenticated locally as somebody else.');
             notice(t('Remote authentication blocked. You are logged into this site locally. Please logout and retry.') . EOL);
             if ($this->test) {
                 $this->Debug('already logged in locally with a conflicting identity.');
                 return false;
             }
         }
         return false;
     }
     // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the
     // site private key
     // The actual channel sending the packet ($c[0]) is not important, but this provides a
     // generic zot packet with a sender which can be verified
     $p = zot_build_packet($channel, $type = 'auth_check', array(array('guid' => $hubloc['hubloc_guid'], 'guid_sig' => $hubloc['hubloc_guid_sig'])), $hubloc['hubloc_sitekey'], $this->sec);
     $this->Debug('auth check packet created using sitekey ' . $hubloc['hubloc_sitekey']);
     $this->Debug('packet contents: ' . $p);
     $result = zot_zot($hubloc['hubloc_callback'], $p);
     if (!$result['success']) {
         logger('auth_check callback failed.');
         if ($this->test) {
             $this->Debug('auth check request to your site returned .' . print_r($result, true));
         }
         return false;
     }
     $j = json_decode($result['body'], true);
     if (!$j) {
         logger('auth_check json data malformed.');
         if ($this->test) {
             $this->Debug('json malformed: ' . $result['body']);
         }
         return false;
     }
     $this->Debug('auth check request returned .' . print_r($j, true));
     if (!$j['success']) {
         return false;
     }
     // legit response, but we do need to check that this wasn't answered by a man-in-middle
     if (!rsa_verify($this->sec . $hubloc['xchan_hash'], base64url_decode($j['confirm']), $hubloc['xchan_pubkey'])) {
         logger('final confirmation failed.');
         if ($this->test) {
             $this->Debug('final confirmation failed. ' . $sec . print_r($j, true) . print_r($hubloc, true));
         }
         return false;
     }
     if (array_key_exists('service_class', $j)) {
         $this->remote_service_class = $j['service_class'];
     }
     if (array_key_exists('level', $j)) {
         $this->remote_level = $j['level'];
     }
     if (array_key_exists('DNT', $j)) {
         $this->dnt = $j['DNT'];
     }
     // log them in
     if ($this->test) {
         // testing only - return the success result
         $this->test_results['success'] = true;
         $this->Debug('Authentication Success!');
         $this->Finalise();
     }
     $_SESSION['authenticated'] = 1;
     // check for delegation and if all is well, log them in locally with delegation restrictions
     $this->delegate_success = false;
     if ($this->delegate) {
         $r = q("select * from channel left join xchan on channel_hash = xchan_hash where xchan_addr = '%s' limit 1", dbesc($this->delegate));
         if ($r && intval($r[0]['channel_id'])) {
             $allowed = perm_is_allowed($r[0]['channel_id'], $hubloc['xchan_hash'], 'delegate');
             if ($allowed) {
                 $_SESSION['delegate_channel'] = $r[0]['channel_id'];
                 $_SESSION['delegate'] = $hubloc['xchan_hash'];
                 $_SESSION['account_id'] = intval($r[0]['channel_account_id']);
                 require_once 'include/security.php';
                 // this will set the local_channel authentication in the session
                 change_channel($r[0]['channel_id']);
                 $this->delegate_success = true;
//.........这里部分代码省略.........
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:101,代码来源:Auth.php

示例8: queue_deliver

function queue_deliver($outq, $immediate = false)
{
    $base = null;
    $h = parse_url($outq['outq_posturl']);
    if ($h) {
        $base = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
    }
    if ($base && $base !== z_root() && $immediate) {
        $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base));
        if ($y) {
            if (intval($y[0]['site_dead'])) {
                remove_queue_by_posturl($outq['outq_posturl']);
                logger('dead site ignored ' . $base);
                return;
            }
            if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
                update_queue_item($outq['outq_hash'], 10);
                logger('immediate delivery deferred for site ' . $base);
                return;
            }
        } else {
            // zot sites should all have a site record, unless they've been dead for as long as
            // your site has existed. Since we don't know for sure what these sites are,
            // call them unknown
            q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", dbesc($base), dbesc(datetime_convert()), intval($outq['outq_driver'] === 'post' ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN));
        }
    }
    $arr = array('outq' => $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate);
    call_hooks('queue_deliver', $arr);
    if ($arr['handled']) {
        return;
    }
    // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
    if ($outq['outq_driver'] === 'post') {
        $result = z_post_url($outq['outq_posturl'], $outq['outq_msg']);
        if ($result['success'] && $result['return_code'] < 300) {
            logger('deliver: queue post success to ' . $outq['outq_posturl'], LOGGER_DEBUG);
            if ($base) {
                q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", dbesc(datetime_convert()), dbesc($base));
            }
            q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", dbesc('accepted for delivery'), dbesc(datetime_convert()), dbesc($outq['outq_hash']));
            remove_queue_item($outq['outq_hash']);
            // server is responding - see if anything else is going to this destination and is piled up
            // and try to send some more. We're relying on the fact that delivery_loop() results in an
            // immediate delivery otherwise we could get into a queue loop.
            if (!$immediate) {
                $x = q("select outq_hash from outq where outq_posturl = '%s' and outq_delivered = 0", dbesc($outq['outq_posturl']));
                $piled_up = array();
                if ($x) {
                    foreach ($x as $xx) {
                        $piled_up[] = $xx['outq_hash'];
                    }
                }
                if ($piled_up) {
                    delivery_loop($piled_up);
                }
            }
        } else {
            logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $outq['outq_posturl'], LOGGER_DEBUG);
            update_queue_item($outq['outq_posturl']);
        }
        return;
    }
    // normal zot delivery
    logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG);
    $result = zot_zot($outq['outq_posturl'], $outq['outq_notify']);
    if ($result['success']) {
        logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']);
        zot_process_response($outq['outq_posturl'], $result, $outq);
    } else {
        logger('deliver: remote zot delivery failed to ' . $outq['outq_posturl']);
        logger('deliver: remote zot delivery fail data: ' . print_r($result, true), LOGGER_DATA);
        update_queue_item($outq['outq_hash'], 10);
    }
    return;
}
开发者ID:royalterra,项目名称:hubzilla,代码行数:76,代码来源:queue_fn.php

示例9: notifier_run

function notifier_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    require_once "session.php";
    require_once "datetime.php";
    require_once 'include/items.php';
    require_once 'include/bbcode.php';
    if ($argc < 3) {
        return;
    }
    logger('notifier: invoked: ' . print_r($argv, true), LOGGER_DEBUG);
    $cmd = $argv[1];
    $item_id = $argv[2];
    $extra = $argc > 3 ? $argv[3] : null;
    if (!$item_id) {
        return;
    }
    require_once 'include/identity.php';
    $sys = get_sys_channel();
    if ($cmd == 'permission_update') {
        // Get the recipient
        $r = q("select abook.*, hubloc.* from abook \n\t\t\tleft join hubloc on hubloc_hash = abook_xchan\n\t\t\twhere abook_id = %d and not ( abook_flags & %d ) > 0 \n\t\t\tand not (hubloc_flags & %d) > 0  and not (hubloc_status & %d) > 0 limit 1", intval($item_id), intval(ABOOK_FLAG_SELF), intval(HUBLOC_FLAGS_DELETED), intval(HUBLOC_OFFLINE));
        if ($r) {
            // Get the sender
            $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", intval($r[0]['abook_channel']));
            if ($s) {
                if ($r[0]['hubloc_network'] === 'diaspora' || $r[0]['hubloc_network'] === 'friendica-over-diaspora') {
                    require_once 'include/diaspora.php';
                    diaspora_share($s[0], $r[0]);
                } else {
                    // send a refresh message to each hub they have registered here
                    $h = q("select * from hubloc where hubloc_hash = '%s' \n\t\t\t\t\t\tand not (hubloc_flags & %d) > 0  and not (hubloc_status & %d) > 0", dbesc($r[0]['hubloc_hash']), intval(HUBLOC_FLAGS_DELETED), intval(HUBLOC_OFFLINE));
                    if ($h) {
                        foreach ($h as $hh) {
                            $data = zot_build_packet($s[0], 'refresh', array(array('guid' => $hh['hubloc_guid'], 'guid_sig' => $hh['hubloc_guid_sig'], 'url' => $hh['hubloc_url'])));
                            if ($data) {
                                $result = zot_zot($hh['hubloc_callback'], $data);
                                // if immediate delivery failed, stick it in the queue to try again later.
                                if (!$result['success']) {
                                    $hash = random_string();
                                    q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) \n\t\t\t\t\t\t\t\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($s[0]['channel_account_id']), intval($s[0]['channel_id']), dbesc('zot'), dbesc($hh['hubloc_callback']), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($data), dbesc(''));
                                }
                            }
                        }
                    }
                }
            }
        }
        return;
    }
    $expire = false;
    $request = false;
    $mail = false;
    $fsuggest = false;
    $top_level = false;
    $location = false;
    $recipients = array();
    $url_recipients = array();
    $normal_mode = true;
    $packet_type = 'undefined';
    if ($cmd === 'mail') {
        $normal_mode = false;
        $mail = true;
        $private = true;
        $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1", intval($item_id));
        if (!$message) {
            return;
        }
        xchan_mail_query($message[0]);
        $uid = $message[0]['channel_id'];
        $recipients[] = $message[0]['from_xchan'];
        // include clones
        $recipients[] = $message[0]['to_xchan'];
        $item = $message[0];
        $encoded_item = encode_mail($item);
        $s = q("select * from channel where channel_id = %d limit 1", intval($item['channel_id']));
        if ($s) {
            $channel = $s[0];
        }
    } elseif ($cmd === 'request') {
        $channel_id = $item_id;
        $xchan = $argv[3];
        $request_message_id = $argv[4];
        $s = q("select * from channel where channel_id = %d limit 1", intval($channel_id));
        if ($s) {
            $channel = $s[0];
        }
        $private = true;
        $recipients[] = $xchan;
        $packet_type = 'request';
        $normal_mode = false;
    } elseif ($cmd === 'expire') {
        // FIXME
        // This will require a special zot packet containing a list of item message_id's to be expired.
        // This packet will be public, since we cannot selectively deliver here.
        // We need the handling on this end to create the array, and the handling on the remote end
        // to verify permissions (for each item) and process it. Until this is complete, the expire feature will be disabled.
        return;
        $normal_mode = false;
//.........这里部分代码省略.........
开发者ID:redmatrix,项目名称:red,代码行数:101,代码来源:notifier.php

示例10: post_init


//.........这里部分代码省略.........
                $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc limit 1", dbesc($address));
            }
        }
        if (!$x) {
            logger('mod_zot: auth: unable to finger ' . $address);
            if ($test) {
                $ret['message'] .= 'no hubloc found for ' . $address . ' and probing failed.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        logger('mod_zot: auth request received from ' . $x[0]['hubloc_addr']);
        // check credentials and access
        // If they are already authenticated and haven't changed credentials,
        // we can save an expensive network round trip and improve performance.
        $remote = remote_user();
        $result = null;
        $remote_service_class = '';
        $remote_level = 0;
        $remote_hub = $x[0]['hubloc_url'];
        $DNT = 0;
        // Also check that they are coming from the same site as they authenticated with originally.
        $already_authed = $remote && $x[0]['hubloc_hash'] == $remote && $x[0]['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
        $j = array();
        if (!$already_authed) {
            // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the site private key
            // The actual channel sending the packet ($c[0]) is not important, but this provides a generic zot packet with a sender
            // which can be verified
            $p = zot_build_packet($c[0], $type = 'auth_check', array(array('guid' => $x[0]['hubloc_guid'], 'guid_sig' => $x[0]['hubloc_guid_sig'])), $x[0]['hubloc_sitekey'], $sec);
            if ($test) {
                $ret['message'] .= 'auth check packet created using sitekey ' . $x[0]['hubloc_sitekey'] . EOL;
                $ret['message'] .= 'packet contents: ' . $p . EOL;
            }
            $result = zot_zot($x[0]['hubloc_callback'], $p);
            if (!$result['success']) {
                logger('mod_zot: auth_check callback failed.');
                if ($test) {
                    $ret['message'] .= 'auth check request to your site returned .' . print_r($result, true) . EOL;
                    json_return_and_die($ret);
                }
                goaway($desturl);
            }
            $j = json_decode($result['body'], true);
            if (!$j) {
                logger('mod_zot: auth_check json data malformed.');
                if ($test) {
                    $ret['message'] .= 'json malformed: ' . $result['body'] . EOL;
                    json_return_and_die($ret);
                }
            }
        }
        if ($test) {
            $ret['message'] .= 'auth check request returned .' . print_r($j, true) . EOL;
        }
        if ($already_authed || $j['success']) {
            if ($j['success']) {
                // legit response, but we do need to check that this wasn't answered by a man-in-middle
                if (!rsa_verify($sec . $x[0]['xchan_hash'], base64url_decode($j['confirm']), $x[0]['xchan_pubkey'])) {
                    logger('mod_zot: auth: final confirmation failed.');
                    if ($test) {
                        $ret['message'] .= 'final confirmation failed. ' . $sec . print_r($j, true) . print_r($x[0], true);
                        json_return_and_die($ret);
                    }
                    goaway($desturl);
                }
                if (array_key_exists('service_class', $j)) {
开发者ID:Mauru,项目名称:red,代码行数:67,代码来源:post.php

示例11: post_init


//.........这里部分代码省略.........
            logger('mod_zot: auth: unable to finger ' . $address);
            if ($test) {
                $ret['message'] .= 'no hubloc found for ' . $address . ' and probing failed.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        foreach ($x as $xx) {
            logger('mod_zot: auth request received from ' . $xx['hubloc_addr']);
            // check credentials and access
            // If they are already authenticated and haven't changed credentials,
            // we can save an expensive network round trip and improve performance.
            $remote = remote_channel();
            $result = null;
            $remote_service_class = '';
            $remote_level = 0;
            $remote_hub = $xx['hubloc_url'];
            $DNT = 0;
            // Also check that they are coming from the same site as they authenticated with originally.
            $already_authed = $remote && $xx['hubloc_hash'] == $remote && $xx['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
            if ($delegate && $delegate !== $_SESSION['delegate_channel']) {
                $already_authed = false;
            }
            $j = array();
            if (!$already_authed) {
                // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the site private key
                // The actual channel sending the packet ($c[0]) is not important, but this provides a generic zot packet with a sender
                // which can be verified
                $p = zot_build_packet($c[0], $type = 'auth_check', array(array('guid' => $xx['hubloc_guid'], 'guid_sig' => $xx['hubloc_guid_sig'])), $xx['hubloc_sitekey'], $sec);
                if ($test) {
                    $ret['message'] .= 'auth check packet created using sitekey ' . $xx['hubloc_sitekey'] . EOL;
                    $ret['message'] .= 'packet contents: ' . $p . EOL;
                }
                $result = zot_zot($xx['hubloc_callback'], $p);
                if (!$result['success']) {
                    logger('mod_zot: auth_check callback failed.');
                    if ($test) {
                        $ret['message'] .= 'auth check request to your site returned .' . print_r($result, true) . EOL;
                        continue;
                    }
                    continue;
                }
                $j = json_decode($result['body'], true);
                if (!$j) {
                    logger('mod_zot: auth_check json data malformed.');
                    if ($test) {
                        $ret['message'] .= 'json malformed: ' . $result['body'] . EOL;
                        continue;
                    }
                }
            }
            if ($test) {
                $ret['message'] .= 'auth check request returned .' . print_r($j, true) . EOL;
            }
            if ($already_authed || $j['success']) {
                if ($j['success']) {
                    // legit response, but we do need to check that this wasn't answered by a man-in-middle
                    if (!rsa_verify($sec . $xx['xchan_hash'], base64url_decode($j['confirm']), $xx['xchan_pubkey'])) {
                        logger('mod_zot: auth: final confirmation failed.');
                        if ($test) {
                            $ret['message'] .= 'final confirmation failed. ' . $sec . print_r($j, true) . print_r($xx, true);
                            continue;
                        }
                        continue;
                    }
                    if (array_key_exists('service_class', $j)) {
开发者ID:23n,项目名称:hubzilla,代码行数:67,代码来源:post.php

示例12: notifier_run

function notifier_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    require_once "session.php";
    require_once "datetime.php";
    require_once 'include/items.php';
    require_once 'include/bbcode.php';
    if ($argc < 3) {
        return;
    }
    logger('notifier: invoked: ' . print_r($argv, true), LOGGER_DEBUG);
    $cmd = $argv[1];
    $item_id = $argv[2];
    $extra = $argc > 3 ? $argv[3] : null;
    if (!$item_id) {
        return;
    }
    require_once 'include/identity.php';
    $sys = get_sys_channel();
    if ($cmd == 'permission_update') {
        // Get the recipient
        $r = q("select abook.*, hubloc.* from abook \n\t\t\tleft join hubloc on hubloc_hash = abook_xchan\n\t\t\twhere abook_id = %d and abook_self = 0\n\t\t\tand not (hubloc_flags & %d) > 0  and not (hubloc_status & %d) > 0 limit 1", intval($item_id), intval(HUBLOC_FLAGS_DELETED), intval(HUBLOC_OFFLINE));
        if ($r) {
            // Get the sender
            $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", intval($r[0]['abook_channel']));
            if ($s) {
                $perm_update = array('sender' => $s[0], 'recipient' => $r[0], 'success' => false);
                call_hooks('permissions_update', $perm_update);
                if (!$perm_update['success']) {
                    // send a refresh message to each hub they have registered here
                    $h = q("select * from hubloc where hubloc_hash = '%s' \n\t\t\t\t\t\tand not (hubloc_flags & %d) > 0  and not (hubloc_status & %d) > 0", dbesc($r[0]['hubloc_hash']), intval(HUBLOC_FLAGS_DELETED), intval(HUBLOC_OFFLINE));
                    if ($h) {
                        foreach ($h as $hh) {
                            $data = zot_build_packet($s[0], 'refresh', array(array('guid' => $hh['hubloc_guid'], 'guid_sig' => $hh['hubloc_guid_sig'], 'url' => $hh['hubloc_url'])));
                            if ($data) {
                                $result = zot_zot($hh['hubloc_callback'], $data);
                                // if immediate delivery failed, stick it in the queue to try again later.
                                if (!$result['success']) {
                                    $hash = random_string();
                                    q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) \n\t\t\t\t\t\t\t\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($s[0]['channel_account_id']), intval($s[0]['channel_id']), dbesc('zot'), dbesc($hh['hubloc_callback']), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($data), dbesc(''));
                                }
                            }
                        }
                    }
                }
            }
        }
        return;
    }
    $expire = false;
    $request = false;
    $mail = false;
    $fsuggest = false;
    $top_level = false;
    $location = false;
    $recipients = array();
    $url_recipients = array();
    $normal_mode = true;
    $packet_type = 'undefined';
    if ($cmd === 'mail') {
        $normal_mode = false;
        $mail = true;
        $private = true;
        $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1", intval($item_id));
        if (!$message) {
            return;
        }
        xchan_mail_query($message[0]);
        $uid = $message[0]['channel_id'];
        $recipients[] = $message[0]['from_xchan'];
        // include clones
        $recipients[] = $message[0]['to_xchan'];
        $item = $message[0];
        $encoded_item = encode_mail($item);
        $s = q("select * from channel where channel_id = %d limit 1", intval($item['channel_id']));
        if ($s) {
            $channel = $s[0];
        }
    } elseif ($cmd === 'request') {
        $channel_id = $item_id;
        $xchan = $argv[3];
        $request_message_id = $argv[4];
        $s = q("select * from channel where channel_id = %d limit 1", intval($channel_id));
        if ($s) {
            $channel = $s[0];
        }
        $private = true;
        $recipients[] = $xchan;
        $packet_type = 'request';
        $normal_mode = false;
    } elseif ($cmd === 'expire') {
        // FIXME
        // This will require a special zot packet containing a list of item message_id's to be expired.
        // This packet will be public, since we cannot selectively deliver here.
        // We need the handling on this end to create the array, and the handling on the remote end
        // to verify permissions (for each item) and process it. Until this is complete, the expire feature will be disabled.
        return;
        $normal_mode = false;
        $expire = true;
//.........这里部分代码省略.........
开发者ID:kenrestivo,项目名称:hubzilla,代码行数:101,代码来源:notifier.php

示例13: ping_site

function ping_site($url)
{
    $ret = array('success' => false);
    $sys = get_sys_channel();
    $m = zot_build_packet($sys, 'ping');
    $r = zot_zot($url . '/post', $m);
    if (!$r['success']) {
        $ret['message'] = 'no answer from ' . $url;
        return $ret;
    }
    $packet_result = json_decode($r['body'], true);
    if (!$packet_result['success']) {
        $ret['message'] = 'packet failure from ' . $url;
        return $ret;
    }
    if ($packet_result['success']) {
        $ret['success'] = true;
    } else {
        $ret['message'] = 'unknown error from ' . $url;
    }
    return $ret;
}
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:22,代码来源:hubloc.php

示例14: deliver_run

function deliver_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
    for ($x = 1; $x < $argc; $x++) {
        $r = q("select * from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
        if ($r) {
            /**
             * Check to see if we have any recent communications with this hub (in the last month).
             * If not, reduce the outq_priority.
             */
            $h = parse_url($r[0]['outq_posturl']);
            if ($h) {
                $base = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
                if ($base !== z_root()) {
                    $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base));
                    if ($y) {
                        if (intval($y[0]['site_dead'])) {
                            q("delete from outq where outq_posturl = '%s'", dbesc($r[0]['outq_posturl']));
                            logger('dead site ignored ' . $base);
                            continue;
                        }
                        if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
                            q("update outq set outq_priority = %d where outq_hash = '%s'", intval($r[0]['outq_priority'] + 10), dbesc($r[0]['outq_hash']));
                            logger('immediate delivery deferred for site ' . $base);
                            continue;
                        }
                    }
                }
            }
            // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
            if ($r[0]['outq_driver'] === 'post') {
                $result = z_post_url($r[0]['outq_posturl'], $r[0]['outq_msg']);
                if ($result['success'] && $result['return_code'] < 300) {
                    logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]));
                } else {
                    logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            $notify = json_decode($r[0]['outq_notify'], true);
            // Check if this is a conversation request packet. It won't have outq_msg
            // but will be an encrypted packet - so will need to be handed off to
            // web delivery rather than processed inline.
            $sendtoweb = false;
            if (array_key_exists('iv', $notify) && !$r[0]['outq_msg']) {
                $sendtoweb = true;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post' && !$sendtoweb) {
                logger('deliver: local delivery', LOGGER_DEBUG);
                // local delivery
                // we should probably batch these and save a few delivery processes
                if ($r[0]['outq_msg']) {
                    $m = json_decode($r[0]['outq_msg'], true);
                    if (array_key_exists('message_list', $m)) {
                        foreach ($m['message_list'] as $mm) {
                            $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $mm)))));
                            zot_import($msg, z_root());
                        }
                    } else {
                        $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $m)))));
                        zot_import($msg, z_root());
                    }
                    $r = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]));
                }
            } else {
                logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                $result = zot_zot($r[0]['outq_posturl'], $r[0]['outq_notify']);
                if ($result['success']) {
                    logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']);
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
}
开发者ID:HaakonME,项目名称:redmatrix,代码行数:85,代码来源:deliver.php

示例15: deliver_run

function deliver_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc < 2) {
        return;
    }
    logger('deliver: invoked: ' . print_r($argv, true), LOGGER_DATA);
    for ($x = 1; $x < $argc; $x++) {
        $dresult = null;
        $r = q("select * from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]));
        if ($r) {
            /**
             * Check to see if we have any recent communications with this hub (in the last month).
             * If not, reduce the outq_priority.
             */
            $h = parse_url($r[0]['outq_posturl']);
            if ($h) {
                $base = $h['scheme'] . '://' . $h['host'] . ($h['port'] ? ':' . $h['port'] : '');
                if ($base !== z_root()) {
                    $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base));
                    if ($y) {
                        if (intval($y[0]['site_dead'])) {
                            q("delete from outq where outq_posturl = '%s'", dbesc($r[0]['outq_posturl']));
                            logger('dead site ignored ' . $base);
                            continue;
                        }
                        if ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) {
                            q("update outq set outq_priority = %d where outq_hash = '%s'", intval($r[0]['outq_priority'] + 10), dbesc($r[0]['outq_hash']));
                            logger('immediate delivery deferred for site ' . $base);
                            continue;
                        }
                    } else {
                        // zot sites should all have a site record, unless they've been dead for as long as
                        // your site has existed. Since we don't know for sure what these sites are,
                        // call them unknown
                        q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", dbesc($base), dbesc(datetime_convert()), intval($r[0]['outq_driver'] === 'post' ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN));
                    }
                }
            }
            // "post" queue driver - used for diaspora and friendica-over-diaspora communications.
            if ($r[0]['outq_driver'] === 'post') {
                $result = z_post_url($r[0]['outq_posturl'], $r[0]['outq_msg']);
                if ($result['success'] && $result['return_code'] < 300) {
                    logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", dbesc(datetime_convert()), dbesc($site_url));
                    q("update dreport set status = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", dbesc('accepted for delivery'), dbesc(datetime_convert()), dbesc($argv[$x]));
                    $y = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]));
                } else {
                    logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
                continue;
            }
            $notify = json_decode($r[0]['outq_notify'], true);
            // Check if this is a conversation request packet. It won't have outq_msg
            // but will be an encrypted packet - so will need to be handed off to
            // web delivery rather than processed inline.
            $sendtoweb = false;
            if (array_key_exists('iv', $notify) && !$r[0]['outq_msg']) {
                $sendtoweb = true;
            }
            if ($r[0]['outq_posturl'] === z_root() . '/post' && !$sendtoweb) {
                logger('deliver: local delivery', LOGGER_DEBUG);
                // local delivery
                // we should probably batch these and save a few delivery processes
                if ($r[0]['outq_msg']) {
                    $m = json_decode($r[0]['outq_msg'], true);
                    if (array_key_exists('message_list', $m)) {
                        foreach ($m['message_list'] as $mm) {
                            $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $mm)))));
                            zot_import($msg, z_root());
                        }
                    } else {
                        $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify, 'message' => $m)))));
                        $dresult = zot_import($msg, z_root());
                    }
                    $r = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]));
                    if ($dresult && is_array($dresult)) {
                        foreach ($dresult as $xx) {
                            if (is_array($xx) && array_key_exists('message_id', $xx)) {
                                q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", dbesc($xx['message_id']), dbesc($xx['location']), dbesc($xx['recipient']), dbesc($xx['status']), dbesc(datetime_convert($xx['date'])), dbesc($xx['sender']));
                            }
                        }
                    }
                    q("delete from dreport where dreport_queue = '%s' limit 1", dbesc($argv[$x]));
                }
            } else {
                logger('deliver: dest: ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
                $result = zot_zot($r[0]['outq_posturl'], $r[0]['outq_notify']);
                if ($result['success']) {
                    logger('deliver: remote zot delivery succeeded to ' . $r[0]['outq_posturl']);
                    zot_process_response($r[0]['outq_posturl'], $result, $r[0]);
                } else {
                    logger('deliver: remote zot delivery failed to ' . $r[0]['outq_posturl']);
                    $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($argv[$x]));
                }
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:kenrestivo,项目名称:hubzilla,代码行数:101,代码来源:deliver.php


注:本文中的zot_zot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。