diff options
author | friendica <info@friendica.com> | 2014-02-17 16:00:17 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-02-17 16:00:17 -0800 |
commit | b3ce1cd87b700073cab23eac4427671577e2f77e (patch) | |
tree | bea76ea3c44d8ea831aaed10d8403faa558527cd /include | |
parent | 08b571c9d0843b19115bd9bb892cb141c508ea3b (diff) | |
download | volse-hubzilla-b3ce1cd87b700073cab23eac4427671577e2f77e.tar.gz volse-hubzilla-b3ce1cd87b700073cab23eac4427671577e2f77e.tar.bz2 volse-hubzilla-b3ce1cd87b700073cab23eac4427671577e2f77e.zip |
project "snakebite"
Diffstat (limited to 'include')
-rw-r--r-- | include/follow.php | 131 |
1 files changed, 70 insertions, 61 deletions
diff --git a/include/follow.php b/include/follow.php index 845ce11da..0508a8b37 100644 --- a/include/follow.php +++ b/include/follow.php @@ -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,82 +39,94 @@ 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(! ($j['success'] && $j['guid'])) { + $result['message'] = t('Response from remote channel was incomplete.'); + logger('mod_follow: ' . $result['message']); + return $result; + } - if(array_key_exists('connect_url',$j) && (! $confirm)) - goaway(zid($j['connect_url'])); + // 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 + // 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']; + $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; - } + 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. + // do we have an xchan and hubloc? + // If not, create them. - $x = import_xchan($j); + $x = import_xchan($j); - if(! $x['success']) - return $x; + if(! $x['success']) + return $x; - $xchan_hash = $x['hash']; + $xchan_hash = $x['hash']; - $their_perms = 0; + $their_perms = 0; - $global_perms = get_perms(); + $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']; + 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]); + 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()) { $aid = get_account_id(); @@ -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; - - - } |