moveme: first successful relocated user

This commit is contained in:
Fabrixxm 2012-10-31 17:13:45 +01:00
parent dbc6cbe024
commit 1a3a5ee8d9
9 changed files with 93 additions and 64 deletions

1
.gitignore vendored
View file

@ -24,3 +24,4 @@ report/
#ignore OSX .DS_Store files
.DS_Store
/nbproject/private/

View file

@ -385,7 +385,7 @@ if(! class_exists('App')) {
function __construct() {
global $default_timezone;
global $default_timezone, $argv, $argc;
$this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
@ -428,6 +428,9 @@ if(! class_exists('App')) {
if(isset($path) && strlen($path) && ($path != $this->path))
$this->path = $path;
}
if (is_array($argv) && $argc>1 && !x($_SERVER,'SERVER_NAME') && substr(end($argv), 0, 4)=="http" ) {
$this->set_baseurl(array_pop($argv) );
}
set_include_path(
"include/$this->hostname" . PATH_SEPARATOR
@ -437,6 +440,7 @@ if(! class_exists('App')) {
. 'library/langdet' . PATH_SEPARATOR
. '.' );
if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
$this->query_string = substr($_SERVER['QUERY_STRING'],2);
// removing trailing / - maybe a nginx problem
@ -1501,9 +1505,15 @@ if(! function_exists('proc_run')) {
if(count($args) && $args[0] === 'php')
$args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
// add baseurl to args. cli scripts can't construct it
$args[] = $a->get_baseurl();
for($x = 0; $x < count($args); $x ++)
$args[$x] = escapeshellarg($args[$x]);
$cmdline = implode($args," ");
if(get_config('system','proc_windows'))
proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo));

View file

@ -232,6 +232,7 @@ function q($sql) {
if($db && $db->connected) {
$stmt = vsprintf($sql,$args);
//logger("dba: q: $stmt", LOGGER_ALL);
if($stmt === false)
logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
return $db->q($stmt);

View file

@ -3,7 +3,7 @@ require_once("boot.php");
require_once('include/queue_fn.php');
require_once('include/html2plain.php');
function delivery_run($argv, $argc){
function delivery_run(&$argv, &$argc){
global $a, $db;
if(is_null($a)){

View file

@ -2168,9 +2168,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
}
function local_delivery($importer,$data) {
$a = get_app();
logger(__function__, LOGGER_TRACE);
if($importer['readonly']) {
// We aren't receiving stuff from this person. But we will quietly ignore them
// rather than a blatant "go away" message.
@ -2322,16 +2323,19 @@ function local_delivery($importer,$data) {
$newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
$newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
$newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
$newloc['site-pubkey'] = notags(unxmlify($base['site-pubkey'][0]['data']));
$newloc['sitepubkey'] = notags(unxmlify($base['sitepubkey'][0]['data']));
/** relocated user must have original key pair */
/*$newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
$newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));*/
log("items:relocate contact ".print_r($newloc, true), LOGGER_DEBUG);
logger("items:relocate contact ".print_r($newloc, true).print_r($importer, true), LOGGER_DEBUG);
// update contact
$r = q("SELECT photo, url FROM contact WHERE WHERE id=%d AND uid=%d;",
intval($importer['importer_uid']),
intval($importer['id']));
$r = q("SELECT photo, url FROM contact WHERE id=%d AND uid=%d;",
intval($importer['id']),
intval($importer['importer_uid']));
if ($r === false)
return 1;
$old = $r[0];
$x = q("UPDATE contact SET
@ -2344,7 +2348,7 @@ function local_delivery($importer,$data) {
confirm = '%s',
notify = '%s',
poll = '%s',
site-pubkey = '%s'
`site-pubkey` = '%s'
WHERE id=%d AND uid=%d;",
dbesc($newloc['name']),
dbesc($newloc['photo']),
@ -2355,10 +2359,12 @@ function local_delivery($importer,$data) {
dbesc($newloc['confirm']),
dbesc($newloc['notify']),
dbesc($newloc['poll']),
dbesc($newloc['site-pubkey']),
intval($importer['importer_uid']),
intval($importer['id']));
dbesc($newloc['sitepubkey']),
intval($importer['id']),
intval($importer['importer_uid']));
if ($x === false)
return 1;
// update items
$fields = array(
'owner-link' => array($old['url'], $newloc['url']),
@ -2366,11 +2372,14 @@ function local_delivery($importer,$data) {
'owner-avatar' => array($old['photo'], $newloc['photo']),
'author-avatar' => array($old['photo'], $newloc['photo']),
);
foreach ($fields as $n=>$f)
foreach ($fields as $n=>$f){
$x = q("UPDATE item SET `%s`='%s' WHERE `%s`='%s' AND uid=%d",
$n, dbesc($f[1]),
$n, dbesc($f[0]),
intval($importer['importer_uid']));
if ($x === false)
return 1;
}
// TODO
// merge with current record, current contents have priority

View file

@ -1,5 +1,4 @@
<?php
require_once("boot.php");
require_once('include/queue_fn.php');
require_once('include/html2plain.php');
@ -206,7 +205,7 @@ function notifier_run($argv, $argc){
// fill this in with a single salmon slap if applicable
$slap = '';
if(! ($mail || $fsuggest)) {
if(! ($mail || $fsuggest || $relocate)) {
require_once('include/group.php');
@ -415,23 +414,31 @@ function notifier_run($argv, $argc){
$sugg_template = get_markup_template('atom_relocate.tpl');
$atom .= replace_macros($sugg_template, array(
'$name' => xmlfy($owner['name']),
'$photo' => xmlfy($owner['photo']),
'$thumb' => xmlfy($owner['thumb']),
'$micro' => xmlfy($owner['micro']),
'$url' => xmlfy($owner['url']),
'$request' => xmlfy($owner['request']),
'$confirm' => xmlfy($owner['confirm']),
'$notify' => xmlfy($owner['notify']),
'$poll' => xmlfy($owner['poll']),
'$site-pubkey' => xmlfy(get_config('system','site_pubkey')),
//'$pubkey' => xmlfy($owner['pubkey']),
//'$prvkey' => xmlfy($owner['prvkey']),
));
$recipients_relocate = q("SELECT * FROM contacts WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
/* get site pubkey. this could be a new installation with no site keys*/
$pubkey = get_config('system','site_pubkey');
if(! $pubkey) {
$res = new_keypair(1024);
set_config('system','site_prvkey', $res['prvkey']);
set_config('system','site_pubkey', $res['pubkey']);
}
$atom .= replace_macros($sugg_template, array(
'$name' => xmlify($owner['name']),
'$photo' => xmlify($owner['photo']),
'$thumb' => xmlify($owner['thumb']),
'$micro' => xmlify($owner['micro']),
'$url' => xmlify($owner['url']),
'$request' => xmlify($owner['request']),
'$confirm' => xmlify($owner['confirm']),
'$notify' => xmlify($owner['notify']),
'$poll' => xmlify($owner['poll']),
'$sitepubkey' => xmlify(get_config('system','site_pubkey')),
//'$pubkey' => xmlify($owner['pubkey']),
//'$prvkey' => xmlify($owner['prvkey']),
));
$recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
}
else {
if($followup) {
@ -525,7 +532,7 @@ function notifier_run($argv, $argc){
if(count($r)) {
foreach($r as $contact) {
if((! $mail) && (! $fsuggest) && (! $followup) && (! $contact['self'])) {
if((! $mail) && (! $fsuggest) && (! $followup) && (!$relocate) && (! $contact['self'])) {
if(($contact['network'] === NETWORK_DIASPORA) && ($public_message))
continue;
q("insert into deliverq ( `cmd`,`item`,`contact` ) values ('%s', %d, %d )",
@ -562,7 +569,7 @@ function notifier_run($argv, $argc){
// potentially more than one recipient. Start a new process and space them out a bit.
// we will deliver single recipient types of message and email recipients here.
if((! $mail) && (! $fsuggest) && (! $followup)) {
if((! $mail) && (! $fsuggest) && (!$relocate) && (! $followup)) {
$this_batch[] = $contact['id'];
@ -577,7 +584,7 @@ function notifier_run($argv, $argc){
$deliver_status = 0;
logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest");
logger("main delivery by notifier: followup=$followup mail=$mail fsuggest=$fsuggest relocate=$relocate");
switch($contact['network']) {
case NETWORK_DFRN:
@ -934,6 +941,7 @@ function notifier_run($argv, $argc){
return;
}
if (array_search(__file__,get_included_files())===0){
notifier_run($argv,$argc);
killme();

View file

@ -228,7 +228,7 @@ function import_account(&$a, $file) {
}
// send relocate messages
proc_run('php', 'include/notifier.php', 'relocate' , $newuid);
//proc_run('php', 'include/notifier.php', 'relocate' , $newuid);
info(t("Done. You can now login with your username and password"));
goaway( $a->get_baseurl() ."/login");

View file

@ -6,7 +6,7 @@ require_once('include/event.php');
function dfrn_notify_post(&$a) {
logger(__function__, LOGGER_TRACE);
$dfrn_id = ((x($_POST,'dfrn_id')) ? notags(trim($_POST['dfrn_id'])) : '');
$dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0);
$challenge = ((x($_POST,'challenge')) ? notags(trim($_POST['challenge'])) : '');

View file

@ -10,7 +10,7 @@
<dfrn:confirm>$confirm</dfrn:confirm>
<dfrn:notify>$notify</dfrn:notify>
<dfrn:poll>$poll</dfrn:poll>
<dfrn:site-pubkey>$site-pubkey</dfrn:site-pubkey>
<dfrn:sitepubkey>$sitepubkey</dfrn:sitepubkey>
</dfrn:relocate>