* https://github.com/friendica/friendica/blob/master/spec/dfrn2_contact_confirmation.png
*/
-require_once('include/enotify.php');
-require_once('include/group.php');
-require_once('include/Probe.php');
+use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Network\Probe;
+
+require_once 'include/enotify.php';
+require_once 'include/group.php';
function dfrn_confirm_post(App $a, $handsfree = null) {
- if (is_array($handsfree)) {
+ if(is_array($handsfree)) {
/*
* We were called directly from dfrn_request due to automatic friend acceptance.
}
else {
- if ($a->argc > 1)
+ if($a->argc > 1)
$node = $a->argv[1];
}
*
*/
- if (! x($_POST,'source_url')) {
+ if(! x($_POST,'source_url')) {
$uid = ((is_array($handsfree)) ? $handsfree['uid'] : local_user());
- if (! $uid) {
+ if(! $uid) {
notice( t('Permission denied.') . EOL );
return;
}
intval($uid)
);
- if (! $user) {
+ if(! $user) {
notice( t('Profile not found.') . EOL );
return;
}
// These data elements may come from either the friend request notification form or $handsfree array.
- if (is_array($handsfree)) {
+ if(is_array($handsfree)) {
logger('Confirm in handsfree mode');
$dfrn_id = $handsfree['dfrn_id'];
$intro_id = $handsfree['intro_id'];
*
*/
- if (strlen($dfrn_id))
+ if(strlen($dfrn_id))
$cid = 0;
logger('Confirming request for dfrn_id (issued) ' . $dfrn_id);
- if ($cid)
+ if($cid)
logger('Confirming follower with contact_id: ' . $cid);
$network = ((strlen($contact['issued-id'])) ? NETWORK_DFRN : NETWORK_OSTATUS);
- if ($contact['network'])
+ if($contact['network'])
$network = $contact['network'];
- if ($network === NETWORK_DFRN) {
+ if($network === NETWORK_DFRN) {
/*
*
* worried about key leakage than anybody cracking it.
*
*/
- require_once('include/crypto.php');
+ require_once 'include/crypto.php';
$res = new_keypair(4096);
*
*/
- $src_aes_key = random_string();
+ $src_aes_key = openssl_random_pseudo_bytes(64);
$result = '';
- openssl_private_encrypt($dfrn_id,$result,$user[0]['prvkey']);
+ openssl_private_encrypt($dfrn_id, $result, $user[0]['prvkey']);
$params['dfrn_id'] = bin2hex($result);
$params['public_key'] = $public_key;
- $my_url = App::get_baseurl() . '/profile/' . $user[0]['nickname'];
+ $my_url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey);
$params['source_url'] = bin2hex($params['source_url']);
- if ($aes_allow && function_exists('openssl_encrypt')) {
+ if($aes_allow && function_exists('openssl_encrypt')) {
openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey);
$params['aes_key'] = bin2hex($params['aes_key']);
$params['public_key'] = bin2hex(openssl_encrypt($public_key,'AES-256-CBC',$src_aes_key));
}
$params['dfrn_version'] = DFRN_PROTOCOL_VERSION ;
- if ($duplex == 1)
+ if($duplex == 1)
$params['duplex'] = 1;
- if ($user[0]['page-flags'] == PAGE_COMMUNITY)
+ if($user[0]['page-flags'] == PAGE_COMMUNITY)
$params['page'] = 1;
- if ($user[0]['page-flags'] == PAGE_PRVGROUP)
+ if($user[0]['page-flags'] == PAGE_PRVGROUP)
$params['page'] = 2;
logger('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params,true), LOGGER_DATA);
$leading_junk = substr($res,0,strpos($res,'<?xml'));
$res = substr($res,strpos($res,'<?xml'));
- if (! strlen($res)) {
+ if(! strlen($res)) {
// No XML at all, this exchange is messed up really bad.
// We shouldn't proceed, because the xml parser might choke,
return;
}
- if (strlen($leading_junk) && get_config('system','debugging')) {
+ if(strlen($leading_junk) && get_config('system','debugging')) {
// This might be more common. Mixed error text and some XML.
// If we're configured for debugging, show the text. Proceed in either case.
notice( t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL );
}
- if (stristr($res, "<status")===false) {
+ if(stristr($res, "<status")===false) {
// wrong xml! stop here!
notice( t('Unexpected response from remote site: ') . EOL . htmlspecialchars($res) . EOL );
return;
switch($status) {
case 0:
info( t("Confirmation completed successfully.") . EOL);
- if (strlen($message))
+ if(strlen($message))
notice( t('Remote site reported: ') . $message . EOL);
break;
case 1:
case 2:
notice( t("Temporary failure. Please wait and try again.") . EOL);
- if (strlen($message))
+ if(strlen($message))
notice( t('Remote site reported: ') . $message . EOL);
break;
case 3:
notice( t("Introduction failed or was revoked.") . EOL);
- if (strlen($message))
+ if(strlen($message))
notice( t('Remote site reported: ') . $message . EOL);
break;
}
- if (($status == 0) && ($intro_id)) {
+ if(($status == 0) && ($intro_id)) {
// Success. Delete the notification.
}
- if ($status != 0)
+ if($status != 0)
return;
}
*
*/
- require_once('include/Photo.php');
+ require_once 'include/Photo.php';
update_contact_avatar($contact['photo'],$uid,$contact_id);
logger('dfrn_confirm: confirm - imported photos');
- if ($network === NETWORK_DFRN) {
+ if($network === NETWORK_DFRN) {
$new_relation = CONTACT_IS_FOLLOWER;
- if (($relation == CONTACT_IS_SHARING) || ($duplex))
+ if(($relation == CONTACT_IS_SHARING) || ($duplex))
$new_relation = CONTACT_IS_FRIEND;
- if (($relation == CONTACT_IS_SHARING) && ($duplex))
+ if(($relation == CONTACT_IS_SHARING) && ($duplex))
$duplex = 0;
$r = q("UPDATE `contact` SET `rel` = %d,
$notify = (($contact['notify']) ? $contact['notify'] : '');
$poll = (($contact['poll']) ? $contact['poll'] : '');
- if ((! $contact['notify']) || (! $contact['poll'])) {
- $arr = Probe::lrdd($contact['url']);
- if (count($arr)) {
- foreach ($arr as $link) {
- if ($link['@attributes']['rel'] === 'salmon')
- $notify = $link['@attributes']['href'];
- if ($link['@attributes']['rel'] === NAMESPACE_FEED)
- $poll = $link['@attributes']['href'];
- }
- }
+ $arr = Probe::uri($contact['url']);
+ if (empty($contact['notify'])) {
+ $notify = $arr['notify'];
}
+ if (empty($contact['poll'])) {
+ $poll = $arr['poll'];
+ }
+
+ $addr = $arr['addr'];
$new_relation = $contact['rel'];
$writable = $contact['writable'];
- if ($network === NETWORK_DIASPORA) {
- if ($duplex)
+ if($network === NETWORK_DIASPORA) {
+ if($duplex)
$new_relation = CONTACT_IS_FRIEND;
else
$new_relation = CONTACT_IS_FOLLOWER;
- if ($new_relation != CONTACT_IS_FOLLOWER)
+ if($new_relation != CONTACT_IS_FOLLOWER)
$writable = 1;
}
$r = q("UPDATE `contact` SET `name-date` = '%s',
`uri-date` = '%s',
+ `addr` = '%s',
`notify` = '%s',
`poll` = '%s',
`blocked` = 0,
",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
+ dbesc($addr),
dbesc($notify),
dbesc($poll),
dbesc($network),
if ((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) {
if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
- require_once('include/diaspora.php');
+ require_once 'include/diaspora.php';
$ret = Diaspora::send_share($user[0],$r[0]);
logger('share returns: ' . $ret);
}
intval($uid)
);
- if ((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0) && ($activity) && (! $hidden)) {
+ if((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0) && ($activity) && (! $hidden)) {
- require_once('include/items.php');
+ require_once 'include/items.php';
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid)
);
- if (count($self)) {
+ if(count($self)) {
$arr = array();
$arr['guid'] = get_guid(32);
$arr['deny_gid'] = $user[0]['deny_gid'];
$i = item_store($arr);
- if ($i)
+ if($i)
proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i);
}
}
}
$def_gid = get_default_group($uid, $contact["network"]);
- if ($contact && intval($def_gid))
+ if($contact && intval($def_gid))
group_add_member($uid, '', $contact['id'], $def_gid);
// Let's send our user to the contact editor in case they want to
// do anything special with this new friend.
if ($handsfree === null) {
- goaway(App::get_baseurl() . '/contacts/' . intval($contact_id));
+ goaway(System::baseUrl() . '/contacts/' . intval($contact_id));
} else {
return;
}
$local_uid = $r[0]['uid'];
- if (! strstr($my_prvkey,'PRIVATE KEY')) {
+ if(! strstr($my_prvkey,'PRIVATE KEY')) {
$message = t('Our site encryption key is apparently messed up.');
xml_status(3,$message);
}
openssl_private_decrypt($source_url,$decrypted_source_url,$my_prvkey);
- if (! strlen($decrypted_source_url)) {
+ if(! strlen($decrypted_source_url)) {
$message = t('Empty site URL was provided or URL could not be decrypted by us.');
xml_status(3,$message);
// NOTREACHED
// It's possible that the other person also requested friendship.
// If it is a duplex relationship, ditch the issued-id if one exists.
- if ($duplex) {
+ if($duplex) {
$r = q("UPDATE `contact` SET `issued-id` = '' WHERE `id` = %d",
intval($dfrn_record)
);
if (dbm::is_result($r)) {
$photo = $r[0]['photo'];
} else {
- $photo = App::get_baseurl() . '/images/person-175.jpg';
+ $photo = System::baseUrl() . '/images/person-175.jpg';
}
- require_once("include/Photo.php");
+ require_once 'include/Photo.php';
update_contact_avatar($photo,$local_uid,$dfrn_record);
if (dbm::is_result($r))
$combined = $r[0];
- if ((dbm::is_result($r)) && ($r[0]['notify-flags'] & NOTIFY_CONFIRM)) {
+ if((dbm::is_result($r)) && ($r[0]['notify-flags'] & NOTIFY_CONFIRM)) {
$mutual = ($new_relation == CONTACT_IS_FRIEND);
notification(array(
'type' => NOTIFY_CONFIRM,
'to_name' => $r[0]['username'],
'to_email' => $r[0]['email'],
'uid' => $r[0]['uid'],
- 'link' => App::get_baseurl() . '/contacts/' . $dfrn_record,
+ 'link' => System::baseUrl() . '/contacts/' . $dfrn_record,
'source_name' => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : t('[Name Withheld]')),
'source_link' => $r[0]['url'],
'source_photo' => $r[0]['photo'],
// Send a new friend post if we are allowed to...
- if ($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) {
+ if($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) {
$r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
intval($local_uid)
);
- if ((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) {
+ if((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) {
- require_once('include/items.php');
+ require_once 'include/items.php';
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($local_uid)
);
- if (dbm::is_result($self)) {
+ if(count($self)) {
$arr = array();
$arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $local_uid);
$arr['deny_gid'] = $user[0]['deny_gid'];
$i = item_store($arr);
- if ($i) {
+ if($i)
proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i);
- }
}
}
// somebody arrived here by mistake or they are fishing. Send them to the homepage.
- goaway(z_root());
+ goaway(System::baseUrl());
// NOTREACHED
}