refactor magic-auth
This commit is contained in:
parent
3fdc3515b5
commit
d9f67876dc
@ -489,62 +489,6 @@ function unmark_for_death($contact) {
|
||||
);
|
||||
}}
|
||||
|
||||
if(! function_exists('contact_photo_menu')){
|
||||
function contact_photo_menu($contact) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$contact_url="";
|
||||
$pm_url="";
|
||||
$status_link="";
|
||||
$photos_link="";
|
||||
$posts_link="";
|
||||
$poke_link="";
|
||||
|
||||
$sparkle = false;
|
||||
if($contact['xchan_network'] === NETWORK_ZOT) {
|
||||
$sparkle = true;
|
||||
$profile_link = $a->get_baseurl() . '/magic?f=&id=' . $contact['abook_id'];
|
||||
}
|
||||
else
|
||||
$profile_link = $contact['xchan_url'];
|
||||
|
||||
if($sparkle) {
|
||||
$status_link = $profile_link . "&url=status";
|
||||
$photos_link = $profile_link . "&url=photos";
|
||||
$profile_link = $profile_link . "&url=profile";
|
||||
$pm_url = $a->get_baseurl() . '/message/new/' . $contact['xchan_hash'];
|
||||
}
|
||||
|
||||
$poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['abook_id'];
|
||||
$contact_url = $a->get_baseurl() . '/connections/' . $contact['abook_id'];
|
||||
$posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['abook_id'];
|
||||
|
||||
$menu = Array(
|
||||
t("Poke") => $poke_link,
|
||||
t("View Status") => $status_link,
|
||||
t("View Profile") => $profile_link,
|
||||
t("View Photos") => $photos_link,
|
||||
t("Network Posts") => $posts_link,
|
||||
t("Edit Contact") => $contact_url,
|
||||
t("Send PM") => $pm_url,
|
||||
);
|
||||
|
||||
|
||||
$args = array('contact' => $contact, 'menu' => &$menu);
|
||||
|
||||
call_hooks('contact_photo_menu', $args);
|
||||
|
||||
$o = "";
|
||||
foreach($menu as $k=>$v){
|
||||
if ($v!="") {
|
||||
$o .= "<li><a href=\"$v\">$k</a></li>\n";
|
||||
}
|
||||
}
|
||||
return $o;
|
||||
}}
|
||||
|
||||
|
||||
function random_profile() {
|
||||
$r = q("select xchan_url from xchan where 1 order by rand() limit 1");
|
||||
if($r)
|
||||
@ -553,26 +497,3 @@ function random_profile() {
|
||||
}
|
||||
|
||||
|
||||
function contacts_not_grouped($uid,$start = 0,$count = 0) {
|
||||
|
||||
if(! $count) {
|
||||
$r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
|
||||
intval($uid),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
return $r;
|
||||
|
||||
|
||||
}
|
||||
|
||||
$r = q("select * from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) and blocked = 0 and pending = 0 limit %d, %d",
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
intval($start),
|
||||
intval($count)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1084,7 @@ function format_categories(&$item,$writeable) {
|
||||
if(! trim($term))
|
||||
continue;
|
||||
$removelink = (($writeable) ? z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . urlencode($t['term']) : '');
|
||||
$categories[] = array('term' => $term, 'writeable' => $writeable, 'removelink' => $removelink, 'url' => $t['url']);
|
||||
$categories[] = array('term' => $term, 'writeable' => $writeable, 'removelink' => $removelink, 'url' => zid($t['url']));
|
||||
}
|
||||
}
|
||||
$s = replace_macros(get_markup_template('item_categories.tpl'),array(
|
||||
|
@ -669,7 +669,6 @@ function connections_content(&$a) {
|
||||
$contacts[] = array(
|
||||
'img_hover' => sprintf( t('%1$s [%2$s]'),$rr['xchan_name'],$rr['xchan_url']),
|
||||
'edit_hover' => t('Edit contact'),
|
||||
'photo_menu' => contact_photo_menu($rr),
|
||||
'id' => $rr['abook_id'],
|
||||
'alt_text' => $alt_text,
|
||||
'dir_icon' => $dir_icon,
|
||||
|
@ -91,8 +91,8 @@ function magic_init(&$a) {
|
||||
if($rev)
|
||||
goaway($dest);
|
||||
else {
|
||||
logger('mod_magic: channel not found.' . print_r($_REQUEST,true));
|
||||
notice( t('Channel not found.') . EOL);
|
||||
logger('mod_magic: no channels found for requested hub.' . print_r($_REQUEST,true));
|
||||
notice( t('Hub not found.') . EOL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -113,24 +113,9 @@ function magic_init(&$a) {
|
||||
goaway($dest);
|
||||
|
||||
if($x[0]['hubloc_url'] === z_root()) {
|
||||
$webbie = substr($x[0]['hubloc_addr'],0,strpos('@',$x[0]['hubloc_addr']));
|
||||
switch($dest) {
|
||||
case 'channel':
|
||||
$desturl = z_root() . '/channel/' . $webbie;
|
||||
break;
|
||||
case 'photos':
|
||||
$desturl = z_root() . '/photos/' . $webbie;
|
||||
break;
|
||||
case 'profile':
|
||||
$desturl = z_root() . '/profile/' . $webbie;
|
||||
break;
|
||||
default:
|
||||
$desturl = $dest;
|
||||
break;
|
||||
}
|
||||
// We are already authenticated on this site and a registered observer.
|
||||
// Just redirect.
|
||||
goaway($desturl);
|
||||
goaway($dest);
|
||||
}
|
||||
|
||||
if(local_user()) {
|
||||
@ -142,20 +127,15 @@ function magic_init(&$a) {
|
||||
$channel['token'] = $token;
|
||||
$channel['token_sig'] = $token_sig;
|
||||
|
||||
|
||||
$recip = array(array('guid' => $x[0]['hubloc_guid'],'guid_sig' => $x[0]['hubloc_guid_sig']));
|
||||
|
||||
$hash = random_string();
|
||||
|
||||
$r = q("insert into verify ( type, channel, token, meta, created) values ('%s','%d','%s','%s','%s')",
|
||||
dbesc('auth'),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($token),
|
||||
dbesc($x[0]['hubloc_hash']),
|
||||
dbesc($x[0]['hubloc_url']),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
|
||||
$target_url = $x[0]['hubloc_callback'] . '/' . substr($x[0]['hubloc_addr'],0,strpos($x[0]['hubloc_addr'],'@')) ;
|
||||
$target_url = $x[0]['hubloc_callback'];
|
||||
logger('mod_magic: redirecting to: ' . $target_url, LOGGER_DEBUG);
|
||||
|
||||
goaway($target_url
|
||||
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('include/Contact.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/contact_selectors.php');
|
||||
|
||||
function nogroup_init(&$a) {
|
||||
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
require_once('include/group.php');
|
||||
require_once('include/contact_widgets.php');
|
||||
|
||||
if(! x($a->page,'aside'))
|
||||
$a->page['aside'] = '';
|
||||
|
||||
$a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
|
||||
}
|
||||
|
||||
|
||||
function nogroup_content(&$a) {
|
||||
|
||||
if(! local_user()) {
|
||||
notice( t('Permission denied.') . EOL);
|
||||
return '';
|
||||
}
|
||||
|
||||
require_once('include/Contact.php');
|
||||
$r = contacts_not_grouped(local_user());
|
||||
if(count($r)) {
|
||||
$a->set_pager_total($r[0]['total']);
|
||||
}
|
||||
$r = contacts_not_grouped(local_user(),$a->pager['start'],$a->pager['itemspage']);
|
||||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
|
||||
|
||||
$contacts[] = array(
|
||||
'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
|
||||
'edit_hover' => t('Edit contact'),
|
||||
'photo_menu' => contact_photo_menu($rr),
|
||||
'id' => $rr['id'],
|
||||
'alt_text' => $alt_text,
|
||||
'dir_icon' => $dir_icon,
|
||||
'thumb' => $rr['thumb'],
|
||||
'name' => $rr['name'],
|
||||
'username' => $rr['name'],
|
||||
'sparkle' => $sparkle,
|
||||
'itemurl' => $rr['url'],
|
||||
'link' => $url,
|
||||
'network' => network_to_name($rr['network']),
|
||||
);
|
||||
}
|
||||
}
|
||||
$tpl = get_markup_template("nogroup-template.tpl");
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$header' => t('Contacts who are not members of a group'),
|
||||
'$contacts' => $contacts,
|
||||
'$paginate' => paginate($a),
|
||||
));
|
||||
|
||||
return $o;
|
||||
|
||||
}
|
22
mod/post.php
22
mod/post.php
@ -89,24 +89,11 @@ function post_init(&$a) {
|
||||
if(array_key_exists('auth',$_REQUEST)) {
|
||||
logger('mod_zot: auth request received.');
|
||||
$address = $_REQUEST['auth'];
|
||||
$dest = $_REQUEST['dest'];
|
||||
$desturl = $_REQUEST['dest'];
|
||||
$sec = $_REQUEST['sec'];
|
||||
$version = $_REQUEST['version'];
|
||||
|
||||
switch($dest) {
|
||||
case 'channel':
|
||||
$desturl = z_root() . '/channel/' . $webbie;
|
||||
break;
|
||||
case 'photos':
|
||||
$desturl = z_root() . '/photos/' . $webbie;
|
||||
break;
|
||||
case 'profile':
|
||||
$desturl = z_root() . '/profile/' . $webbie;
|
||||
break;
|
||||
default:
|
||||
$desturl = $dest;
|
||||
break;
|
||||
}
|
||||
|
||||
if($webbie) {
|
||||
$c = q("select * from channel where channel_address = '%s' limit 1",
|
||||
dbesc($webbie)
|
||||
@ -707,6 +694,7 @@ function post_post(&$a) {
|
||||
$y = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($sender_hash)
|
||||
);
|
||||
|
||||
// We created a unique hash in mod/magic.php when we invoked remote auth, and stored it in
|
||||
// the verify table. It is now coming back to us as 'secret' and is signed by the other site.
|
||||
// First verify their signature.
|
||||
@ -731,13 +719,13 @@ function post_post(&$a) {
|
||||
|
||||
$confirm = base64url_encode(rsa_sign($data['secret'] . $recip_hash,$c[0]['channel_prvkey']));
|
||||
|
||||
// This additionally checks for forged senders since we already stored the expected result in meta
|
||||
// This additionally checks for forged sites since we already stored the expected result in meta
|
||||
// and we've already verified that this is them via zot_gethub() and that their key signed our token
|
||||
|
||||
$z = q("select id from verify where channel = %d and type = 'auth' and token = '%s' and meta = '%s' limit 1",
|
||||
intval($c[0]['channel_id']),
|
||||
dbesc($data['secret']),
|
||||
dbesc($sender_hash)
|
||||
dbesc($data['sender']['url'])
|
||||
);
|
||||
if(! $z) {
|
||||
logger('mod_zot: auth_check: verification key not found.');
|
||||
|
@ -1 +1 @@
|
||||
2013-12-01.514
|
||||
2013-12-02.515
|
||||
|
@ -23,11 +23,6 @@
|
||||
<div id="sidebar-new-group">
|
||||
<a href="group/new">{{$createtext}}</a>
|
||||
</div>
|
||||
{{if $ungrouped}}
|
||||
<div id="sidebar-ungrouped">
|
||||
<a href="nogroup">{{$ungrouped}}</a>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user