本文整理汇总了PHP中zot_build_packet函数的典型用法代码示例。如果您正苦于以下问题:PHP zot_build_packet函数的具体用法?PHP zot_build_packet怎么用?PHP zot_build_packet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zot_build_packet函数的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: 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
示例4: zot_process_message_request
/**
* @brief Process a message request.
*
* If a site receives a comment to a post but finds they have no parent to attach it with, they
* may send a 'request' packet containing the message_id of the missing parent. This is the handler
* for that packet. We will create a message_list array of the entire conversation starting with
* the missing parent and invoke delivery to the sender of the packet.
*
* include/deliver.php (for local delivery) and mod/post.php (for web delivery) detect the existence of
* this 'message_list' at the destination and split it into individual messages which are
* processed/delivered in order.
*
* Called from mod/post.php
*
* @param array $data
* @return array
*/
function zot_process_message_request($data)
{
$ret = array('success' => false);
if (!$data['message_id']) {
$ret['message'] = 'no message_id';
logger('no message_id');
return $ret;
}
$sender = $data['sender'];
$sender_hash = make_xchan_hash($sender['guid'], $sender['guid_sig']);
/*
* Find the local channel in charge of this post (the first and only recipient of the request packet)
*/
$arr = $data['recipients'][0];
$recip_hash = make_xchan_hash($arr['guid'], $arr['guid_sig']);
$c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", dbesc($recip_hash));
if (!$c) {
logger('recipient channel not found.');
$ret['message'] .= 'recipient not found.' . EOL;
return $ret;
}
/*
* fetch the requested conversation
*/
$messages = zot_feed($c[0]['channel_id'], $sender_hash, array('message_id' => $data['message_id']));
if ($messages) {
$env_recips = null;
$r = q("select * from hubloc where hubloc_hash = '%s' and not hubloc_error and not hubloc_deleted \n\t\t\tgroup by hubloc_sitekey", dbesc($sender_hash));
if (!$r) {
logger('no hubs');
return $ret;
}
$hubs = $r;
$private = array_key_exists('flags', $messages[0]) && in_array('private', $messages[0]['flags']) ? true : false;
if ($private) {
$env_recips = array('guid' => $sender['guid'], 'guid_sig' => $sender['guid_sig'], 'hash' => $sender_hash);
}
$data_packet = json_encode(array('message_list' => $messages));
foreach ($hubs as $hub) {
$hash = random_string();
/*
* create a notify packet and drop the actual message packet in the queue for pickup
*/
$n = zot_build_packet($c[0], 'notify', $env_recips, $private ? $hub['hubloc_sitekey'] : null, $hash, array('message_id' => $data['message_id']));
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async,\n\t\t\t\toutq_created, outq_updated, outq_notify, outq_msg )\n\t\t\t\tvalues ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($c[0]['channel_account_id']), intval($c[0]['channel_id']), dbesc('zot'), dbesc($hub['hubloc_callback']), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($n), dbesc($data_packet));
/*
* invoke delivery to send out the notify packet
*/
proc_run('php', 'include/deliver.php', $hash);
}
}
$ret['success'] = true;
return $ret;
}
开发者ID:23n,项目名称:hubzilla,代码行数:71,代码来源:zot.php
示例5: ratenotif_run
function ratenotif_run($argv, $argc)
{
cli_startup();
$a = get_app();
require_once "session.php";
require_once "datetime.php";
require_once 'include/items.php';
require_once 'include/Contact.php';
if ($argc < 3) {
return;
}
logger('ratenotif: invoked: ' . print_r($argv, true), LOGGER_DEBUG);
$cmd = $argv[1];
$item_id = $argv[2];
if ($cmd === 'rating') {
$r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1", intval($item_id));
if (!$r) {
logger('rating not found');
return;
}
$encoded_item = array('type' => 'rating', 'encoding' => 'zot', 'target' => $r[0]['xlink_link'], 'rating' => intval($r[0]['xlink_rating']), 'rating_text' => $r[0]['xlink_rating_text'], 'signature' => $r[0]['xlink_sig'], 'edited' => $r[0]['xlink_updated']);
}
$channel = channelx_by_hash($r[0]['xlink_xchan']);
if (!$channel) {
logger('no channel');
return;
}
$primary = get_directory_primary();
if (!$primary) {
return;
}
$interval = get_config('system', 'delivery_interval') !== false ? intval(get_config('system', 'delivery_interval')) : 2;
$deliveries_per_process = intval(get_config('system', 'delivery_batch_count'));
if ($deliveries_per_process <= 0) {
$deliveries_per_process = 1;
}
$deliver = array();
$x = z_fetch_url($primary . '/regdir');
if ($x['success']) {
$j = json_decode($x['body'], true);
if ($j && $j['success'] && is_array($j['directories'])) {
foreach ($j['directories'] as $h) {
if ($h == z_root()) {
continue;
}
$hash = random_string();
$n = zot_build_packet($channel, 'notify', null, null, $hash);
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", dbesc($hash), intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc('zot'), dbesc($h . '/post'), intval(1), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($n), dbesc(json_encode($encoded_item)));
$deliver[] = $hash;
if (count($deliver) >= $deliveries_per_process) {
proc_run('php', 'include/deliver.php', $deliver);
$deliver = array();
if ($interval) {
@time_sleep_until(microtime(true) + (double) $interval);
}
}
}
// catch any stragglers
if (count($deliver)) {
proc_run('php', 'include/deliver.php', $deliver);
}
}
}
logger('ratenotif: complete.');
return;
}
开发者ID:msooon,项目名称:hubzilla,代码行数:66,代码来源:ratenotif.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: notifier_run
//.........这里部分代码省略.........
}
}
$narr = array('channel' => $channel, 'env_recips' => $env_recips, 'packet_recips' => $packet_recips, 'recipients' => $recipients, 'item' => $item, 'target_item' => $target_item, 'top_level_post' => $top_level_post, 'private' => $private, 'followup' => $followup, 'relay_to_owner' => $relay_to_owner, 'uplink' => $uplink, 'cmd' => $cmd, 'mail' => $mail, 'location' => $location, 'request' => $request, 'normal_mode' => $normal_mode, 'packet_type' => $packet_type, 'walltowall' => $walltowall, 'queued' => array());
call_hooks('notifier_process', $narr);
if ($narr['queued']) {
foreach ($narr['queued'] as $pq) {
$deliveries[] = $pq;
}
}
if ($private && !$env_recips) {
// shouldn't happen
logger('notifier: private message with no envelope recipients.' . print_r($argv, true), LOGGER_NORMAL, LOG_NOTICE);
}
logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list, true), LOGGER_DEBUG);
// Now we have collected recipients (except for external mentions, FIXME)
// Let's reduce this to a set of hubs.
$r = q("select * from hubloc where hubloc_hash in (" . implode(',', $recipients) . ") \n\t\tand hubloc_error = 0 and hubloc_deleted = 0");
if (!$r) {
logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE);
return;
}
$hubs = $r;
/**
* Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey, since it may have been
* a re-install which has not yet been detected and pruned.
* For other networks which don't have or require sitekeys, we'll have to use the URL
*/
$hublist = array();
// this provides an easily printable list for the logs
$dhubs = array();
// delivery hubs where we store our resulting unique array
$keys = array();
// array of keys to check uniquness for zot hubs
$urls = array();
// array of urls to check uniqueness of hubs from other networks
foreach ($hubs as $hub) {
if (in_array($hub['hubloc_url'], $dead_hubs)) {
logger('skipping dead hub: ' . $hub['hubloc_url'], LOGGER_DEBUG, LOG_INFO);
continue;
}
if ($hub['hubloc_network'] == 'zot') {
if (!in_array($hub['hubloc_sitekey'], $keys)) {
$hublist[] = $hub['hubloc_host'];
$dhubs[] = $hub;
$keys[] = $hub['hubloc_sitekey'];
}
} else {
if (!in_array($hub['hubloc_url'], $urls)) {
$hublist[] = $hub['hubloc_host'];
$dhubs[] = $hub;
$urls[] = $hub['hubloc_url'];
}
}
}
logger('notifier: will notify/deliver to these hubs: ' . print_r($hublist, true), LOGGER_DEBUG, LOG_DEBUG);
foreach ($dhubs as $hub) {
if ($hub['hubloc_network'] !== 'zot') {
$narr = array('channel' => $channel, 'env_recips' => $env_recips, 'packet_recips' => $packet_recips, 'recipients' => $recipients, 'item' => $item, 'target_item' => $target_item, 'hub' => $hub, 'top_level_post' => $top_level_post, 'private' => $private, 'followup' => $followup, 'relay_to_owner' => $relay_to_owner, 'uplink' => $uplink, 'cmd' => $cmd, 'mail' => $mail, 'location' => $location, 'request' => $request, 'normal_mode' => $normal_mode, 'packet_type' => $packet_type, 'walltowall' => $walltowall, 'queued' => array());
call_hooks('notifier_hub', $narr);
if ($narr['queued']) {
foreach ($narr['queued'] as $pq) {
$deliveries[] = $pq;
}
}
continue;
}
// default: zot protocol
$hash = random_string();
$packet = null;
if ($packet_type === 'refresh' || $packet_type === 'purge') {
$packet = zot_build_packet($channel, $packet_type, $packet_recips ? $packet_recips : null);
} elseif ($packet_type === 'request') {
$packet = zot_build_packet($channel, $packet_type, $env_recips, $hub['hubloc_sitekey'], $hash, array('message_id' => $request_message_id));
}
if ($packet) {
queue_insert(array('hash' => $hash, 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $hub['hubloc_callback'], 'notify' => $packet));
} else {
$packet = zot_build_packet($channel, 'notify', $env_recips, $private ? $hub['hubloc_sitekey'] : null, $hash);
queue_insert(array('hash' => $hash, 'account_id' => $target_item['aid'], 'channel_id' => $target_item['uid'], 'posturl' => $hub['hubloc_callback'], 'notify' => $packet, 'msg' => json_encode($encoded_item)));
// only create delivery reports for normal undeleted items
if (is_array($target_item) && array_key_exists('postopts', $target_item) && !$target_item['item_deleted'] && !get_config('system', 'disable_dreport')) {
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s','%s','%s','%s','%s','%s','%s' ) ", dbesc($target_item['mid']), dbesc($hub['hubloc_host']), dbesc($hub['hubloc_host']), dbesc('queued'), dbesc(datetime_convert()), dbesc($channel['channel_hash']), dbesc($hash));
}
}
$deliveries[] = $hash;
}
if ($normal_mode) {
$x = q("select * from hook where hook = 'notifier_normal'");
if ($x) {
proc_run('php', 'include/deliver_hooks.php', $target_item['id']);
}
}
if ($deliveries) {
do_delivery($deliveries);
}
logger('notifier: basic loop complete.', LOGGER_DEBUG);
call_hooks('notifier_end', $target_item);
logger('notifer: complete.');
return;
}
开发者ID:royalterra,项目名称:hubzilla,代码行数:101,代码来源:notifier.php
示例8: 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
示例9: zot_reply_message_request
/**
* @brief Process a message request.
*
* If a site receives a comment to a post but finds they have no parent to attach it with, they
* may send a 'request' packet containing the message_id of the missing parent. This is the handler
* for that packet. We will create a message_list array of the entire conversation starting with
* the missing parent and invoke delivery to the sender of the packet.
*
* include/deliver.php (for local delivery) and mod/post.php (for web delivery) detect the existence of
* this 'message_list' at the destination and split it into individual messages which are
* processed/delivered in order.
*
* Called from mod/post.php
*
* @param array $data
* @return array
*/
function zot_reply_message_request($data)
{
$ret = array('success' => false);
if (!$data['message_id']) {
$ret['message'] = 'no message_id';
logger('no message_id');
json_return_and_die($ret);
}
$sender = $data['sender'];
$sender_hash = make_xchan_hash($sender['guid'], $sender['guid_sig']);
/*
* Find the local channel in charge of this post (the first and only recipient of the request packet)
*/
$arr = $data['recipients'][0];
$recip_hash = make_xchan_hash($arr['guid'], $arr['guid_sig']);
$c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", dbesc($recip_hash));
if (!$c) {
logger('recipient channel not found.');
$ret['message'] .= 'recipient not found.' . EOL;
json_return_and_die($ret);
}
/*
* fetch the requested conversation
*/
$messages = zot_feed($c[0]['channel_id'], $sender_hash, array('message_id' => $data['message_id']));
if ($messages) {
$env_recips = null;
$r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0 and hubloc_deleted = 0 \n\t\t\tgroup by hubloc_sitekey", dbesc($sender_hash));
if (!$r) {
logger('no hubs');
json_return_and_die($ret);
}
$hubs = $r;
$private = array_key_exists('flags', $messages[0]) && in_array('private', $messages[0]['flags']) ? true : false;
if ($private) {
$env_recips = array('guid' => $sender['guid'], 'guid_sig' => $sender['guid_sig'], 'hash' => $sender_hash);
}
$data_packet = json_encode(array('message_list' => $messages));
foreach ($hubs as $hub) {
$hash = random_string();
/*
* create a notify packet and drop the actual message packet in the queue for pickup
*/
$n = zot_build_packet($c[0], 'notify', $env_recips, $private ? $hub['hubloc_sitekey'] : null, $hash, array('message_id' => $data['message_id']));
queue_insert(array('hash' => $hash, 'account_id' => $c[0]['channel_account_id'], 'channel_id' => $c[0]['channel_id'], 'posturl' => $hub['hubloc_callback'], 'notify' => $n, 'msg' => $data_packet));
/*
* invoke delivery to send out the notify packet
*/
Zotlabs\Daemon\Master::Summon(array('Deliver', $hash));
}
}
$ret['success'] = true;
json_return_and_die($ret);
}
开发者ID:einervonvielen,项目名称:hubzilla,代码行数:71,代码来源:zot.php
示例10: 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
示例11: post_init
//.........这里部分代码省略.........
if ($ret['success']) {
$j = json_decode($ret['body'], true);
if ($j) {
import_xchan($j);
}
$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);
开发者ID:Mauru,项目名称:red,代码行数:67,代码来源:post.php
示例12: 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
示例13: post_init
//.........这里部分代码省略.........
}
$x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc", 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);
}
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);
开发者ID:23n,项目名称:hubzilla,代码行数:67,代码来源:post.php
示例14: run
public static function run($argc, $argv)
{
require_once "datetime.php";
require_once 'include/items.php';
if ($argc < 3) {
return;
}
logger('ratenotif: invoked: ' . print_r($argv, true), LOGGER_DEBUG);
$cmd = $argv[1];
$item_id = $argv[2];
if ($cmd === 'rating') {
$r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1", intval($item_id));
if (!$r) {
logger('rating not found');
return;
}
$encoded_item = array('type' => 'rating', 'encoding' => 'zot', 'target' => $r[0]['xlink_link'], 'rating' => intval($r[0]['xlink_rating']), 'rating_text' => $r[0]['xlink_rating_text'], 'signature' => $r[0]['xlink_sig'], 'edited' => $r[0]['xlink_updated']);
}
$channel = channelx_by_hash($r[0]['xlink_xchan']);
if (!$channel) {
logger('no channel');
return;
}
$primary = get_directory_primary();
if (!$primary) {
return;
}
$interval = get_config('system', 'delivery_interval') !== false ? intval(get_config('system', 'delivery_interval')) : 2;
$deliveries_per_process = intval(get_config('system', 'delivery_batch_count'));
if ($deliveries_per_process <= 0) {
$deliveries_per_process = 1;
}
$deliver = array();
$x = z_fetch_url($primary . '/regdir');
if ($x['success']) {
$j = json_decode($x['body'], true);
if ($j && $j['success'] && is_array($j['directories'])) {
foreach ($j['directories'] as $h) {
if ($h == z_root()) {
continue;
}
$hash = random_string();
$n = zot_build_packet($channel, 'notify', null, null, $hash);
queue_insert(array('hash' => $hash, 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $h . '/post', 'notify' => $n, 'msg' => json_encode($encoded_item)));
$deliver[] = $hash;
if (count($deliver) >= $deliveries_per_process) {
Master::Summon(array('Deliver', $deliver));
$deliver = array();
if ($interval) {
@time_sleep_until(microtime(true) + (double) $interval);
}
}
}
// catch any stragglers
if (count($deliver)) {
Master::Summon(array('Deliver', $deliver));
}
}
}
logger('ratenotif: complete.');
return;
}
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:62,代码来源:Ratenotif.php
示例15: build_sync_packet
/**
* Send a zot packet to all hubs where this channel is duplicated, refreshing
* such things a
|
请发表评论