project "snakebite"
This commit is contained in:
parent
08b571c9d0
commit
b3ce1cd87b
@ -16,6 +16,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
$result = array('success' => false,'message' => '');
|
||||
|
||||
$a = get_app();
|
||||
$is_red = false;
|
||||
|
||||
|
||||
if(! allowed_url($url)) {
|
||||
$result['message'] = t('Channel is blocked on this site.');
|
||||
@ -37,81 +39,93 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
$ret = zot_finger($url,$channel);
|
||||
|
||||
if($ret['success']) {
|
||||
$is_red = true;
|
||||
$j = json_decode($ret['body'],true);
|
||||
}
|
||||
else {
|
||||
$result['message'] = t('Channel discovery failed. Website may be down or misconfigured.');
|
||||
logger('mod_follow: ' . $result['message']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
logger('follow: ' . $url . ' ' . print_r($j,true));
|
||||
if($is_red && $j) {
|
||||
|
||||
if(! $j) {
|
||||
$result['message'] = t('Response from remote channel was not understood.');
|
||||
logger('mod_follow: ' . $result['message']);
|
||||
return $result;
|
||||
}
|
||||
$my_perms = PERMS_W_STREAM|PERMS_W_MAIL;
|
||||
|
||||
logger('follow: ' . $url . ' ' . print_r($j,true), LOGGER_DEBUG);
|
||||
|
||||
|
||||
if(! ($j['success'] && $j['guid'])) {
|
||||
$result['message'] = t('Response from remote channel was incomplete.');
|
||||
logger('mod_follow: ' . $result['message']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Premium channel, set confirm before callback to avoid recursion
|
||||
|
||||
if(array_key_exists('connect_url',$j) && (! $confirm))
|
||||
goaway(zid($j['connect_url']));
|
||||
|
||||
|
||||
// check service class limits
|
||||
|
||||
$r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ",
|
||||
intval($uid),
|
||||
intval(ABOOK_FLAG_SELF)
|
||||
);
|
||||
if($r)
|
||||
$total_channels = $r[0]['total'];
|
||||
|
||||
if(! service_class_allows($uid,'total_channels',$total_channels)) {
|
||||
$result['message'] = upgrade_message();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// do we have an xchan and hubloc?
|
||||
// If not, create them.
|
||||
|
||||
$x = import_xchan($j);
|
||||
|
||||
if(! $x['success'])
|
||||
return $x;
|
||||
|
||||
$xchan_hash = $x['hash'];
|
||||
|
||||
|
||||
$their_perms = 0;
|
||||
|
||||
$global_perms = get_perms();
|
||||
|
||||
if( array_key_exists('permissions',$j) && array_key_exists('data',$j['permissions'])) {
|
||||
$permissions = crypto_unencapsulate(array(
|
||||
'data' => $j['permissions']['data'],
|
||||
'key' => $j['permissions']['key'],
|
||||
'iv' => $j['permissions']['iv']),
|
||||
$channel['channel_prvkey']);
|
||||
if($permissions)
|
||||
$permissions = json_decode($permissions,true);
|
||||
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
|
||||
}
|
||||
else
|
||||
$permissions = $j['permissions'];
|
||||
|
||||
foreach($permissions as $k => $v) {
|
||||
if($v) {
|
||||
$their_perms = $their_perms | intval($global_perms[$k][1]);
|
||||
if(! ($j['success'] && $j['guid'])) {
|
||||
$result['message'] = t('Response from remote channel was incomplete.');
|
||||
logger('mod_follow: ' . $result['message']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Premium channel, set confirm before callback to avoid recursion
|
||||
|
||||
if(array_key_exists('connect_url',$j) && (! $confirm))
|
||||
goaway(zid($j['connect_url']));
|
||||
|
||||
// check service class limits
|
||||
|
||||
$r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ",
|
||||
intval($uid),
|
||||
intval(ABOOK_FLAG_SELF)
|
||||
);
|
||||
if($r)
|
||||
$total_channels = $r[0]['total'];
|
||||
|
||||
if(! service_class_allows($uid,'total_channels',$total_channels)) {
|
||||
$result['message'] = upgrade_message();
|
||||
return $result;
|
||||
}
|
||||
|
||||
// do we have an xchan and hubloc?
|
||||
// If not, create them.
|
||||
|
||||
$x = import_xchan($j);
|
||||
|
||||
if(! $x['success'])
|
||||
return $x;
|
||||
|
||||
$xchan_hash = $x['hash'];
|
||||
|
||||
|
||||
$their_perms = 0;
|
||||
|
||||
$global_perms = get_perms();
|
||||
|
||||
if( array_key_exists('permissions',$j) && array_key_exists('data',$j['permissions'])) {
|
||||
$permissions = crypto_unencapsulate(array(
|
||||
'data' => $j['permissions']['data'],
|
||||
'key' => $j['permissions']['key'],
|
||||
'iv' => $j['permissions']['iv']),
|
||||
$channel['channel_prvkey']);
|
||||
if($permissions)
|
||||
$permissions = json_decode($permissions,true);
|
||||
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
|
||||
}
|
||||
else
|
||||
$permissions = $j['permissions'];
|
||||
|
||||
foreach($permissions as $k => $v) {
|
||||
if($v) {
|
||||
$their_perms = $their_perms | intval($global_perms[$k][1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// attempt network auto-discovery
|
||||
|
||||
$my_perms = 0;
|
||||
$their_perms = 0;
|
||||
$xchan_hash = '';
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(! $xchan_hash) {
|
||||
$result['message'] = t('Channel discovery failed.');
|
||||
logger('follow: ' . $result['message']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
if((local_user()) && $uid == local_user()) {
|
||||
@ -156,7 +170,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
intval($uid),
|
||||
dbesc($xchan_hash),
|
||||
intval($their_perms),
|
||||
intval(PERMS_W_STREAM|PERMS_W_MAIL),
|
||||
intval($my_perms),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
@ -172,7 +186,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
);
|
||||
if($r) {
|
||||
$result['abook'] = $r[0];
|
||||
proc_run('php', 'include/notifier.php', 'permission_update', $result['abook']['abook_id']);
|
||||
if($is_red)
|
||||
proc_run('php', 'include/notifier.php', 'permission_update', $result['abook']['abook_id']);
|
||||
}
|
||||
|
||||
$arr = array('channel_id' => $uid, 'abook' => $result['abook']);
|
||||
@ -188,12 +203,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
group_add_member($uid,'',$xchan_hash,$g['id']);
|
||||
}
|
||||
|
||||
// Then send a ping/message to the other side
|
||||
|
||||
|
||||
$result['success'] = true;
|
||||
return $result;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user