one could say we've sort of got zot - at least there are two-way communications for channel meta info, don't yet know if it's working
This commit is contained in:
parent
f4ac91a8bc
commit
b4c603cdac
@ -69,11 +69,13 @@ function zot_notify($channel,$url,$type = 'notify',$recipients = null, $remote_k
|
|||||||
'hub' => z_root(),
|
'hub' => z_root(),
|
||||||
'hub_sig' => base64url_encode(z_root,$channel['prvkey'])
|
'hub_sig' => base64url_encode(z_root,$channel['prvkey'])
|
||||||
)),
|
)),
|
||||||
'recipients' => json_encode($recipients),
|
|
||||||
'callback' => '/post',
|
'callback' => '/post',
|
||||||
'version' => ZOT_REVISION
|
'version' => ZOT_REVISION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if($recipients)
|
||||||
|
$params['recipients'] = json_encode($recipients);
|
||||||
|
|
||||||
// Hush-hush ultra top-secret mode
|
// Hush-hush ultra top-secret mode
|
||||||
|
|
||||||
if($remote_key) {
|
if($remote_key) {
|
||||||
@ -137,7 +139,7 @@ function zot_finger($webbie,$channel) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function zot_refresh($them,$channel) {
|
function zot_refresh($them,$channel = null) {
|
||||||
|
|
||||||
if($them['hubloc_url'])
|
if($them['hubloc_url'])
|
||||||
$url = $them['hubloc_url'];
|
$url = $them['hubloc_url'];
|
||||||
@ -152,20 +154,26 @@ function zot_refresh($them,$channel) {
|
|||||||
if(! $url)
|
if(! $url)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if($them['xchan_hash'])
|
$postvars = array();
|
||||||
$guid_hash = $them['xchan_hash'];
|
|
||||||
|
|
||||||
if(! $guid_hash)
|
if($channel) {
|
||||||
return;
|
$postvars['target'] = $channel['channel_guid'];
|
||||||
|
$postvars['target_sig'] = $channel['channel_guid_sig'];
|
||||||
|
$postvars['key'] = $channel['channel_pubkey'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(array_key_exists('xchan_addr',$them) && $them['xchan_addr'])
|
||||||
|
$postvars['address'] = $them['xchan_addr'];
|
||||||
|
if(array_key_exists('xchan_hash',$them) && $them['xchan_hash'])
|
||||||
|
$postvars['guid_hash'] = $them['xchan_hash'];
|
||||||
|
if(array_key_exists('xchan_guid',$them) && $them['xchan_guid']
|
||||||
|
&& array_key_exists('xchan_guid_sig',$them) && $them['xchan_guid_sig']) {
|
||||||
|
$postvars['guid'] = $them['xchan_guid'];
|
||||||
|
$postvars['guid_sig'] = $them['xchan_guid_sig'];
|
||||||
|
}
|
||||||
|
|
||||||
$rhs = '/.well-known/zot-info';
|
$rhs = '/.well-known/zot-info';
|
||||||
|
|
||||||
$postvars = array(
|
|
||||||
'guid_hash' => $guid_hash,
|
|
||||||
'target' => $channel['channel_guid'],
|
|
||||||
'target_sig' => $channel['channel_guid_sig'],
|
|
||||||
'key' => $channel['channel_pubkey']
|
|
||||||
);
|
|
||||||
$result = z_post_url($url . $rhs,$postvars);
|
$result = z_post_url($url . $rhs,$postvars);
|
||||||
|
|
||||||
if($result['success']) {
|
if($result['success']) {
|
||||||
@ -181,37 +189,39 @@ function zot_refresh($them,$channel) {
|
|||||||
|
|
||||||
$their_perms = 0;
|
$their_perms = 0;
|
||||||
|
|
||||||
$global_perms = get_perms();
|
|
||||||
|
|
||||||
if($j->permissions->data) {
|
if($channel) {
|
||||||
$permissions = aes_unencapsulate(array(
|
$global_perms = get_perms();
|
||||||
'data' => $j->permissions->data,
|
if($j->permissions->data) {
|
||||||
'key' => $j->permissions->key,
|
$permissions = aes_unencapsulate(array(
|
||||||
'iv' => $j->permissions->iv),
|
'data' => $j->permissions->data,
|
||||||
$channel['channel_prvkey']);
|
'key' => $j->permissions->key,
|
||||||
if($permissions)
|
'iv' => $j->permissions->iv),
|
||||||
$permissions = json_decode($permissions);
|
$channel['channel_prvkey']);
|
||||||
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
|
if($permissions)
|
||||||
}
|
$permissions = json_decode($permissions);
|
||||||
else
|
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
|
||||||
$permissions = $j->permissions;
|
|
||||||
|
|
||||||
foreach($permissions as $k => $v) {
|
|
||||||
if($v) {
|
|
||||||
$their_perms = $their_perms | intval($global_perms[$k][1]);
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
$permissions = $j->permissions;
|
||||||
|
|
||||||
$r = q("update abook set their_perms = %d where abook_xchan = '%s' and abook_channel = %d limit 1",
|
foreach($permissions as $k => $v) {
|
||||||
intval($their_perms),
|
if($v) {
|
||||||
dbesc($channel['channel_hash']),
|
$their_perms = $their_perms | intval($global_perms[$k][1]);
|
||||||
intval($channel['channel_id'])
|
}
|
||||||
);
|
}
|
||||||
if(! $r)
|
|
||||||
logger('abook update failed');
|
$r = q("update abook set their_perms = %d
|
||||||
|
where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||||
|
intval($their_perms),
|
||||||
|
dbesc($channel['channel_hash']),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if(! $r)
|
||||||
|
logger('abook update failed');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
58
mod/post.php
58
mod/post.php
@ -9,16 +9,25 @@ require_once('include/zot.php');
|
|||||||
|
|
||||||
function post_post(&$a) {
|
function post_post(&$a) {
|
||||||
|
|
||||||
$ret = array('result' => false, 'message' => '');
|
$ret = array('result' => false);
|
||||||
|
|
||||||
$msgtype = ((array_key_exists('type',$_REQUEST)) ? $_REQUEST['type'] : '');
|
if(array_key_exists('iv',$_REQUEST)) {
|
||||||
|
// hush-hush ultra top secret mode
|
||||||
|
$data = aes_unencapsulate($_REQUEST,get_config('system','site_prvkey'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$data = $_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
if(array_key_exists('sender',$_REQUEST)) {
|
$msgtype = ((array_key_exists('type',$data)) ? $data['type'] : '');
|
||||||
$j_sender = json_decode($_REQUEST['sender']);
|
|
||||||
|
if(array_key_exists('sender',$data)) {
|
||||||
|
$j_sender = json_decode($data['sender']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hub = zot_gethub($j_sender);
|
$hub = zot_gethub($j_sender);
|
||||||
if(! $hub) {
|
if(! $hub) {
|
||||||
|
// (!!) this will validate the sender
|
||||||
$result = zot_register_hub($j_sender);
|
$result = zot_register_hub($j_sender);
|
||||||
if((! $result['success']) || (! zot_gethub($j_sender))) {
|
if((! $result['success']) || (! zot_gethub($j_sender))) {
|
||||||
$ret['message'] = 'Hub not available.';
|
$ret['message'] = 'Hub not available.';
|
||||||
@ -26,27 +35,54 @@ function post_post(&$a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check which hub is primary and take action if mismatched
|
// TODO: check which hub is primary and take action if mismatched
|
||||||
|
|
||||||
|
if(array_key_exists('recipients',$data))
|
||||||
|
$j_recipients = json_decode($data['recipients']);
|
||||||
|
|
||||||
if($msgtype === 'refresh') {
|
if($msgtype === 'refresh') {
|
||||||
|
|
||||||
// Need to pass the recipient in the message
|
// remote channel info (such as permissions or photo or something)
|
||||||
|
// has been updated. Grab a fresh copy and sync it.
|
||||||
|
|
||||||
// look up recipient
|
if($j_recipients) {
|
||||||
|
|
||||||
// format args
|
// This would be a permissions update, typically for one connection
|
||||||
// $r = zot_refresh($them,$channel);
|
|
||||||
|
|
||||||
return;
|
foreach($j_recipients as $recip) {
|
||||||
|
$r = q("select channel.*,xchan.* from channel
|
||||||
|
left join xchan on channel_hash = xchan_hash
|
||||||
|
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
|
||||||
|
dbesc($recip->guid),
|
||||||
|
dbesc($recip->guid_sig)
|
||||||
|
);
|
||||||
|
|
||||||
|
$x = zot_refresh(array(
|
||||||
|
'xchan_guid' => $j_sender->guid,
|
||||||
|
'xchan_guid_sig' => $j_sender->guid_sig,
|
||||||
|
'hubloc_url' => $j_sender->url
|
||||||
|
),$r[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
// system wide refresh
|
||||||
|
|
||||||
|
$x = zot_refresh(array(
|
||||||
|
'xchan_guid' => $j_sender->guid,
|
||||||
|
'xchan_guid_sig' => $j_sender->guid_sig,
|
||||||
|
'hubloc_url' => $j_sender->url
|
||||||
|
),null);
|
||||||
|
}
|
||||||
|
$ret['result'] = true;
|
||||||
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($msgtype === 'notify') {
|
if($msgtype === 'notify') {
|
||||||
|
|
||||||
|
|
||||||
// add to receive queue
|
// add to receive queue
|
||||||
// qreceive_add($_REQUEST);
|
// qreceive_add($data);
|
||||||
|
|
||||||
$ret['result'] = true;
|
$ret['result'] = true;
|
||||||
json_return_and_die($ret);
|
json_return_and_die($ret);
|
||||||
|
@ -7,11 +7,13 @@ function zfinger_init(&$a) {
|
|||||||
|
|
||||||
$ret = array('success' => false);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
$zhash = ((x($_REQUEST,'guid_hash')) ? $_REQUEST['guid_hash'] : '');
|
$zhash = ((x($_REQUEST,'guid_hash')) ? $_REQUEST['guid_hash'] : '');
|
||||||
$zaddr = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : '');
|
$zguid = ((x($_REQUEST,'guid')) ? $_REQUEST['guid'] : '');
|
||||||
$ztarget = ((x($_REQUEST,'target')) ? $_REQUEST['target'] : '');
|
$zguid_sig = ((x($_REQUEST,'guid_sig')) ? $_REQUEST['guid_sig'] : '');
|
||||||
$zsig = ((x($_REQUEST,'target_sig')) ? $_REQUEST['target_sig'] : '');
|
$zaddr = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : '');
|
||||||
$zkey = ((x($_REQUEST,'key')) ? $_REQUEST['key'] : '');
|
$ztarget = ((x($_REQUEST,'target')) ? $_REQUEST['target'] : '');
|
||||||
|
$zsig = ((x($_REQUEST,'target_sig')) ? $_REQUEST['target_sig'] : '');
|
||||||
|
$zkey = ((x($_REQUEST,'key')) ? $_REQUEST['key'] : '');
|
||||||
|
|
||||||
if($ztarget) {
|
if($ztarget) {
|
||||||
if((! $zkey) || (! $zsig) || (! rsa_verify($ztarget,base64url_decode($zsig),$zkey))) {
|
if((! $zkey) || (! $zsig) || (! rsa_verify($ztarget,base64url_decode($zsig),$zkey))) {
|
||||||
@ -23,12 +25,19 @@ function zfinger_init(&$a) {
|
|||||||
|
|
||||||
$r = null;
|
$r = null;
|
||||||
|
|
||||||
if(strlen($zguid)) {
|
if(strlen($zhash)) {
|
||||||
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
||||||
where channel_hash = '%s' limit 1",
|
where channel_hash = '%s' limit 1",
|
||||||
dbesc($zhash)
|
dbesc($zhash)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if(strlen($zguid) && strlen($zguid_sig)) {
|
||||||
|
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
||||||
|
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
|
||||||
|
dbesc($zguid),
|
||||||
|
dbesc($zguid_sig)
|
||||||
|
);
|
||||||
|
}
|
||||||
elseif(strlen($zaddr)) {
|
elseif(strlen($zaddr)) {
|
||||||
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
||||||
where channel_address = '%s' limit 1",
|
where channel_address = '%s' limit 1",
|
||||||
@ -40,7 +49,7 @@ function zfinger_init(&$a) {
|
|||||||
json_return_and_die($ret);
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! ($r && count($r))) {
|
if(! $r) {
|
||||||
$ret['message'] = 'Item not found.';
|
$ret['message'] = 'Item not found.';
|
||||||
json_return_and_die($ret);
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
@ -48,6 +57,8 @@ function zfinger_init(&$a) {
|
|||||||
$e = $r[0];
|
$e = $r[0];
|
||||||
|
|
||||||
$id = $e['channel_id'];
|
$id = $e['channel_id'];
|
||||||
|
|
||||||
|
// This is for birthdays and keywords, but must check access permissions
|
||||||
// $r = q("select contact.*, profile.*
|
// $r = q("select contact.*, profile.*
|
||||||
// from contact left join profile on contact.uid = profile.uid
|
// from contact left join profile on contact.uid = profile.uid
|
||||||
// where contact.uid = %d && contact.self = 1 and profile.is_default = 1 limit 1",
|
// where contact.uid = %d && contact.self = 1 and profile.is_default = 1 limit 1",
|
||||||
|
@ -1 +1 @@
|
|||||||
2012-11-11.135
|
2012-11-12.136
|
||||||
|
Reference in New Issue
Block a user