From 09020192d6258fad8c8e7085d2021036f95317fa Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 13 Oct 2017 09:22:05 +0000 Subject: [PATCH 1/4] Diaspora: Support account migration --- include/delivery.php | 3 ++ include/diaspora.php | 76 +++++++++++++++++++++++++++++++++----------- include/notifier.php | 3 +- include/uimport.php | 10 ++++++ 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/include/delivery.php b/include/delivery.php index f95caed29..46ff74a70 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -508,6 +508,9 @@ function delivery_run(&$argv, &$argc){ logger('diaspora retract: '.$loc); Diaspora::send_retraction($target_item,$owner,$contact,$public_message); break; + } elseif ($relocate) { + Diaspora::sendAccountMigration($owner, $uid); + break; } elseif ($followup) { // send comments and likes to owner to relay logger('diaspora followup: '.$loc); diff --git a/include/diaspora.php b/include/diaspora.php index 16bce93e1..686963ed8 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -11,6 +11,7 @@ use Friendica\App; use Friendica\Core\System; use Friendica\Core\Config; +use Friendica\Core\PConfig; require_once 'include/items.php'; require_once 'include/bb2diaspora.php'; @@ -2958,6 +2959,31 @@ class Diaspora { return $return_code; } + /** + * @brief sends an "unshare" + * + * @param array $owner the array of the item owner + * @param array $contact Target of the communication + * + * @return int The result of the transmission + */ + public static function sendAccountMigration($owner, $uid) { + + $old_handle = PConfig::get($uid, 'system', 'previous_addr'); + $profile = self::createProfileData($uid); + + $signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author']; + $signature = rsa_sign($signed_text, $owner["uprvkey"], "sha256"); + + $message = array("author" => $old_handle, + "profile" => $profile, + "signature" => $signature); + + logger("Send account migration ".print_r($message, true), LOGGER_DEBUG); + + return self::build_and_transmit($owner, $contact, "account_migration", $message); + } + /** * @brief Sends a "share" message * @@ -3648,25 +3674,13 @@ class Diaspora { } /** - * @brief Sends profile data + * @brief Create profile data * * @param int $uid The user id + * + * @return array The profile data */ - public static function send_profile($uid, $recips = false) { - - if (!$uid) - return; - - if (!$recips) - $recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s' - AND `uid` = %d AND `rel` != %d", - dbesc(NETWORK_DIASPORA), - intval($uid), - intval(CONTACT_IS_SHARING) - ); - if (!$recips) - return; - + private static function createProfileData($uid) { $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr` FROM `profile` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` @@ -3675,8 +3689,9 @@ class Diaspora { intval($uid) ); - if (!$r) - return; + if (!$r) { + return array(); + } $profile = $r[0]; @@ -3714,7 +3729,7 @@ class Diaspora { $tags = trim($tags); } - $message = array("author" => $handle, + return array("author" => $handle, "first_name" => $first, "last_name" => $last, "image_url" => $large, @@ -3727,6 +3742,29 @@ class Diaspora { "searchable" => $searchable, "nsfw" => "false", "tag_string" => $tags); + } + + /** + * @brief Sends profile data + * + * @param int $uid The user id + */ + public static function send_profile($uid, $recips = false) { + + if (!$uid) + return; + + if (!$recips) + $recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s' + AND `uid` = %d AND `rel` != %d", + dbesc(NETWORK_DIASPORA), + intval($uid), + intval(CONTACT_IS_SHARING) + ); + if (!$recips) + return; + + $message = self::createProfileData($uid); foreach ($recips as $recip) { logger("Send updated profile data for user ".$uid." to contact ".$recip["id"], LOGGER_DEBUG); diff --git a/include/notifier.php b/include/notifier.php index e5e49cf30..e5ead46e3 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -149,7 +149,8 @@ function notifier_run(&$argv, &$argc){ $relocate = true; $uid = $item_id; - $recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN); + $recipients_relocate = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND `network` IN ('%s', '%s')", + intval($uid), NETWORK_DFRN, NETWORK_DIASPORA); } else { // find ancestors $r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1", diff --git a/include/uimport.php b/include/uimport.php index 359fc9067..442df9446 100644 --- a/include/uimport.php +++ b/include/uimport.php @@ -2,6 +2,7 @@ use Friendica\App; use Friendica\Core\System; +use Friendica\Core\PConfig; require_once("include/Photo.php"); define("IMPORT_DEBUG", False); @@ -124,6 +125,12 @@ function import_account(App $a, $file) { $oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl)); $newaddr = str_replace('http://', '@', normalise_link($newbaseurl)); + if (!empty($account['profile']['addr'])) { + $old_handle = $account['profile']['addr']; + } else { + $old_handle = $account['user']['nickname'].$oldaddr; + } + $olduid = $account['user']['uid']; unset($account['user']['uid']); @@ -146,6 +153,8 @@ function import_account(App $a, $file) { $newuid = last_insert_id(); //~ $newuid = 1; + PConfig::set($newuid, 'system', 'previous_addr', $old_handle); + // Generate a new guid for the account. Otherwise there will be problems with diaspora q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d", dbesc(generate_user_guid()), intval($newuid)); @@ -183,6 +192,7 @@ function import_account(App $a, $file) { switch ($contact['network']) { case NETWORK_DFRN: + case NETWORK_DIASPORA: // send relocate message (below) break; case NETWORK_ZOT: From 2b80bf468358f0553c2f7d6ca1a794cab80eb0e6 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 13 Oct 2017 09:26:07 +0000 Subject: [PATCH 2/4] Improved documentation --- include/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 686963ed8..aad4f5c44 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2960,10 +2960,10 @@ class Diaspora { } /** - * @brief sends an "unshare" + * @brief sends an account migration * * @param array $owner the array of the item owner - * @param array $contact Target of the communication + * @param int $uid User ID * * @return int The result of the transmission */ From b31b29c557d544446af06d9d0b896ae54115289f Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 13 Oct 2017 09:41:01 +0000 Subject: [PATCH 3/4] Now it could work --- include/delivery.php | 2 +- include/diaspora.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/delivery.php b/include/delivery.php index 46ff74a70..cddc9cb00 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -509,7 +509,7 @@ function delivery_run(&$argv, &$argc){ Diaspora::send_retraction($target_item,$owner,$contact,$public_message); break; } elseif ($relocate) { - Diaspora::sendAccountMigration($owner, $uid); + Diaspora::sendAccountMigration($owner, $contact, $uid); break; } elseif ($followup) { // send comments and likes to owner to relay diff --git a/include/diaspora.php b/include/diaspora.php index aad4f5c44..2e165a05b 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2963,17 +2963,18 @@ class Diaspora { * @brief sends an account migration * * @param array $owner the array of the item owner + * @param array $contact Target of the communication * @param int $uid User ID * * @return int The result of the transmission */ - public static function sendAccountMigration($owner, $uid) { + public static function sendAccountMigration($owner, $contact, $uid) { $old_handle = PConfig::get($uid, 'system', 'previous_addr'); $profile = self::createProfileData($uid); $signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author']; - $signature = rsa_sign($signed_text, $owner["uprvkey"], "sha256"); + $signature = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256")); $message = array("author" => $old_handle, "profile" => $profile, From 9286f5cf312ca395091f4209b75c899246c45c51 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 13 Oct 2017 10:49:51 +0000 Subject: [PATCH 4/4] Added documentation --- doc/Move-Account.md | 8 +++++--- doc/de/Move-Account.md | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/Move-Account.md b/doc/Move-Account.md index ef8509d8c..c34a93e94 100644 --- a/doc/Move-Account.md +++ b/doc/Move-Account.md @@ -21,9 +21,11 @@ Friendica will recreate your account on the new server, with your contacts and g A message is sent to Friendica contacts, to inform them about your move: If your contacts are runnning on an updated server, your details on their side will be automatically updated. -GNU Social/Diaspora contacts +GNU Social contacts --- -Contacts on GNU Social or Diaspora will be archived, as we can't inform them about your move. +Contacts on GNU Social will be archived, as we can't inform them about your move. You should ask them to remove your contact from their lists and re-add you, and you should do the same with their contact. -Support for the Diaspora account moving is scheduled for the 3.6 release of Friendica. +Diaspora contacts +--- +Newer Diaspora servers are able to process "account migration" messages. diff --git a/doc/de/Move-Account.md b/doc/de/Move-Account.md index 14de05438..1b0c7eb8f 100644 --- a/doc/de/Move-Account.md +++ b/doc/de/Move-Account.md @@ -26,7 +26,9 @@ Friendica wird nun deinen Account auf dem neuen Server wiederherstellen, mit all An deine Friendica Kontakte wird außerdem eine Nachricht gesendet um sie über deine neue Adresse zu informieren. Wenn deine Kontakte ihren Account auf einem aktuellen Server haben werden deine Kontaktdetails automatisch aktualisiert. -Kontakte auf GNU Social oder Diaspora werden archiviert, da wir ihnen keine Information über deinen Umzug zukommen lassen können. +Neuere Diaspora Server unterstützen ebenfalls eine Umzugsbenachrichtigung. + +Kontakte auf GNU Social werden archiviert, da wir ihnen keine Information über deinen Umzug zukommen lassen können. Du solltest sie persönlich anschreiben deinen Eintrag aus ihren Kontaktlisten zu entfernen und dich neu hinzuzufügen, anschließend solltest du da gleiche mit ihren Accounts tun. Nach dem Umzug wird dein Account auf dem alten Server nicht mehr zuverlässig funktionieren und sollte deshalb gelöscht werden.