diff options
author | friendica <info@friendica.com> | 2013-12-15 14:36:43 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-12-15 14:36:43 -0800 |
commit | 0272ab4cd9a6428396489d88c7a1a89be76e5810 (patch) | |
tree | 78ae24629cb4fd9b52442fdad2f307107460b048 /mod | |
parent | 950bd72e020daf887ac487c95d6f4f2e42b1dee9 (diff) | |
download | volse-hubzilla-0272ab4cd9a6428396489d88c7a1a89be76e5810.tar.gz volse-hubzilla-0272ab4cd9a6428396489d88c7a1a89be76e5810.tar.bz2 volse-hubzilla-0272ab4cd9a6428396489d88c7a1a89be76e5810.zip |
Provide a fallback channel to probe for magic-auth when we have no prior communications with a site.
This will be a system channel if one exists, otherwise any channel will do. We'll try to use the first
valid channel on the site because that was probably created when the site was installed and is the
closest thing to a system channel we've got.
Diffstat (limited to 'mod')
-rw-r--r-- | mod/magic.php | 37 | ||||
-rw-r--r-- | mod/zfinger.php | 32 |
2 files changed, 49 insertions, 20 deletions
diff --git a/mod/magic.php b/mod/magic.php index 03d09e70d..aead559a7 100644 --- a/mod/magic.php +++ b/mod/magic.php @@ -33,21 +33,28 @@ function magic_init(&$a) { if(! $x) { - // Somebody new? Finger them if they've never been seen here before - - if($addr) { - $ret = zot_finger($addr,null); - if($ret['success']) { - $j = json_decode($ret['body'],true); - if($j) - import_xchan($j); - - // Now try again - - $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", - dbesc($basepath) - ); - } + /* + * We have no records for, or prior communications with this hub. + * If an address was supplied, let's finger them to create a hub record. + * Otherwise we'll use the special address '[system]' which will return + * either a system channel or the first available normal channel. We don't + * really care about what channel is returned - we need the hub information + * from that response so that we can create signed auth packets destined + * for that hub. + * + */ + + $ret = zot_finger((($addr) ? $addr : '[system]@' . $parsed['host']),null); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) + import_xchan($j); + + // Now try again + + $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", + dbesc($basepath) + ); } } diff --git a/mod/zfinger.php b/mod/zfinger.php index 0827f3424..aad8e224d 100644 --- a/mod/zfinger.php +++ b/mod/zfinger.php @@ -52,11 +52,33 @@ function zfinger_init(&$a) { ); } elseif(strlen($zaddr)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", - dbesc($zaddr), - dbesc($zaddr) - ); + if(strpos($zaddr,'[system]') === false) { /* normal address lookup */ + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", + dbesc($zaddr), + dbesc($zaddr) + ); + } + + else { + + /** + * The special address '[system]' will return a system channel if one has been defined, + * Or the first valid channel we find if there are no system channels. + * + * This is used by magic-auth if we have no prior communications with this site - and + * returns an identity on this site which we can use to create a valid hub record so that + * we can exchange signed messages. The precise identity is irrelevant. It's the hub + * information that we really need at the other end - and this will return it. + * + */ + + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + where (( channel_pageflags & %d ) or not ( channel_pageflags & %d )) order by channel_id limit 1", + intval(PAGE_SYSTEM), + intval(PAGE_REMOVED) + ); + } } else { $ret['message'] = 'Invalid request'; |