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.
This commit is contained in:
friendica 2013-12-15 14:36:43 -08:00
parent 950bd72e02
commit 0272ab4cd9
6 changed files with 58 additions and 21 deletions

View File

@ -205,6 +205,7 @@ define ( 'PAGE_DIRECTORY_CHANNEL', 0x0008 ); // system channel used for director
define ( 'PAGE_PREMIUM', 0x0010 );
define ( 'PAGE_ADULT', 0x0020 );
define ( 'PAGE_SYSTEM', 0x1000 );
define ( 'PAGE_REMOVED', 0x8000 );
@ -367,6 +368,7 @@ define ( 'XCHAN_FLAGS_HIDDEN', 0x0001);
define ( 'XCHAN_FLAGS_ORPHAN', 0x0002);
define ( 'XCHAN_FLAGS_CENSORED', 0x0004);
define ( 'XCHAN_FLAGS_SELFCENSORED', 0x0008);
define ( 'XCHAN_FLAGS_SYSTEM', 0x0010);
define ( 'XCHAN_FLAGS_DELETED', 0x1000);
/*
* Traficlights for Administration of HubLoc
@ -478,8 +480,10 @@ define ( 'ACCOUNT_PENDING', 0x0010 );
* Account roles
*/
define ( 'ACCOUNT_ROLE_ADMIN', 0x1000 );
define ( 'ACCOUNT_ROLE_ALLOWCODE', 0x0001 );
define ( 'ACCOUNT_ROLE_SYSTEM', 0x0002 );
define ( 'ACCOUNT_ROLE_ADMIN', 0x1000 );
/**
* Item visibility

View File

@ -33,21 +33,28 @@ function magic_init(&$a) {
if(! $x) {
// Somebody new? Finger them if they've never been seen here before
/*
* 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.
*
*/
if($addr) {
$ret = zot_finger($addr,null);
if($ret['success']) {
$j = json_decode($ret['body'],true);
if($j)
import_xchan($j);
$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
// Now try again
$x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1",
dbesc($basepath)
);
}
$x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1",
dbesc($basepath)
);
}
}

View File

@ -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';

View File

@ -1 +1 @@
2013-12-14.527
2013-12-15.528

View File

@ -35,9 +35,11 @@
margin-top: 10px;
}
#profile-edit-with-label {
#profile-edit-with-label, #profile-edit-howlong-label {
width: 175px;
margin-left: 20px;
margin-left: 50px;
margin-bottom: 20px;
}
#profile-edit-profile-name-label,

View File

@ -108,8 +108,10 @@
<label id="profile-edit-marital-label" for="profile-edit-marital" >{{$lbl_marital}} </label>
{{$marital}}
</div>
<div class="clear"></div>
<label id="profile-edit-with-label" for="profile-edit-with" > {{$lbl_with}} </label>
<input type="text" size="32" name="with" id="profile-edit-with" title="{{$lbl_ex1}}" value="{{$with}}" />
<div class="clear"></div>
<label id="profile-edit-howlong-label" for="profile-edit-howlong" > {{$lbl_howlong}} </label>
<input type="text" size="32" name="howlong" id="profile-edit-howlong" title="{{$lbl_howlong}}" value="{{$howlong}}" />