project "snakebite"

This commit is contained in:
friendica 2014-02-17 16:00:17 -08:00
parent 08b571c9d0
commit b3ce1cd87b

View File

@ -16,6 +16,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$result = array('success' => false,'message' => ''); $result = array('success' => false,'message' => '');
$a = get_app(); $a = get_app();
$is_red = false;
if(! allowed_url($url)) { if(! allowed_url($url)) {
$result['message'] = t('Channel is blocked on this site.'); $result['message'] = t('Channel is blocked on this site.');
@ -37,21 +39,15 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$ret = zot_finger($url,$channel); $ret = zot_finger($url,$channel);
if($ret['success']) { if($ret['success']) {
$is_red = true;
$j = json_decode($ret['body'],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) { $my_perms = PERMS_W_STREAM|PERMS_W_MAIL;
$result['message'] = t('Response from remote channel was not understood.');
logger('mod_follow: ' . $result['message']); logger('follow: ' . $url . ' ' . print_r($j,true), LOGGER_DEBUG);
return $result;
}
if(! ($j['success'] && $j['guid'])) { if(! ($j['success'] && $j['guid'])) {
@ -65,7 +61,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
if(array_key_exists('connect_url',$j) && (! $confirm)) if(array_key_exists('connect_url',$j) && (! $confirm))
goaway(zid($j['connect_url'])); goaway(zid($j['connect_url']));
// check service class limits // check service class limits
$r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ", $r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ",
@ -113,6 +108,25 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$their_perms = $their_perms | intval($global_perms[$k][1]); $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()) { if((local_user()) && $uid == local_user()) {
$aid = get_account_id(); $aid = get_account_id();
@ -156,7 +170,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
intval($uid), intval($uid),
dbesc($xchan_hash), dbesc($xchan_hash),
intval($their_perms), intval($their_perms),
intval(PERMS_W_STREAM|PERMS_W_MAIL), intval($my_perms),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc(datetime_convert()) dbesc(datetime_convert())
); );
@ -172,6 +186,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
); );
if($r) { if($r) {
$result['abook'] = $r[0]; $result['abook'] = $r[0];
if($is_red)
proc_run('php', 'include/notifier.php', 'permission_update', $result['abook']['abook_id']); proc_run('php', 'include/notifier.php', 'permission_update', $result['abook']['abook_id']);
} }
@ -188,12 +203,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
group_add_member($uid,'',$xchan_hash,$g['id']); group_add_member($uid,'',$xchan_hash,$g['id']);
} }
// Then send a ping/message to the other side
$result['success'] = true; $result['success'] = true;
return $result; return $result;
} }