aboutsummaryrefslogtreecommitdiffstats
path: root/include/follow.php
diff options
context:
space:
mode:
authorPaolo T <tuscanhobbit@users.noreply.github.com>2014-02-25 16:33:40 +0100
committerPaolo T <tuscanhobbit@users.noreply.github.com>2014-02-25 16:33:40 +0100
commit0a98f6b878ec89be7282621192d9daf80f125e6c (patch)
tree718a4771ce1fb86931531226898b0b5d00e4a337 /include/follow.php
parent34d30e4d7eb48bd801482531a0d775328bd43ab4 (diff)
parentb1021df485fb6129acda5bba616bac10aea75a45 (diff)
downloadvolse-hubzilla-0a98f6b878ec89be7282621192d9daf80f125e6c.tar.gz
volse-hubzilla-0a98f6b878ec89be7282621192d9daf80f125e6c.tar.bz2
volse-hubzilla-0a98f6b878ec89be7282621192d9daf80f125e6c.zip
Merge pull request #1 from friendica/master
Update this fork
Diffstat (limited to 'include/follow.php')
-rw-r--r--include/follow.php131
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;
-
-
-
}