diff options
author | Haakon Meland Eriksen <haakon.eriksen@far.no> | 2015-09-30 12:21:36 +0200 |
---|---|---|
committer | Haakon Meland Eriksen <haakon.eriksen@far.no> | 2015-09-30 12:21:36 +0200 |
commit | e07ff7d3fbb9bef720831dc71470b70a882abfdf (patch) | |
tree | 68934f0deb2fb9edef69954d1016734bc8662957 /include/zot.php | |
parent | b22fa9f7f4b77569c29b0fc881373393281b7bf4 (diff) | |
parent | e769fbaffb09aa673d7475c598e7df7e7978d210 (diff) | |
download | volse-hubzilla-e07ff7d3fbb9bef720831dc71470b70a882abfdf.tar.gz volse-hubzilla-e07ff7d3fbb9bef720831dc71470b70a882abfdf.tar.bz2 volse-hubzilla-e07ff7d3fbb9bef720831dc71470b70a882abfdf.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include/zot.php')
-rw-r--r-- | include/zot.php | 122 |
1 files changed, 100 insertions, 22 deletions
diff --git a/include/zot.php b/include/zot.php index 9bddb520d..7707f34fc 100644 --- a/include/zot.php +++ b/include/zot.php @@ -398,11 +398,6 @@ function zot_refresh($them, $channel = null, $force = false) { } } - $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", - dbesc($x['hash']), - intval($channel['channel_id']) - ); - if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) { $next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']); } @@ -410,8 +405,15 @@ function zot_refresh($them, $channel = null, $force = false) { $next_birthday = NULL_DATE; } + $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", + dbesc($x['hash']), + intval($channel['channel_id']) + ); + if($r) { + // connection exists + // if the dob is the same as what we have stored (disregarding the year), keep the one // we have as we may have updated the year after sending a notification; and resetting // to the one we just received would cause us to create duplicated events. @@ -453,6 +455,9 @@ function zot_refresh($them, $channel = null, $force = false) { } } else { + + // new connection + $role = get_pconfig($channel['channel_id'],'system','permissions_role'); if($role) { $xx = get_role_perms($role); @@ -1582,14 +1587,11 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $channel = $r[0]; $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); - -// uncomment this once we find out what's stopping the clone sync of the item from working -// if($d['hash'] === $sender['hash']) { -// $DR->update('self delivery ignored'); -// $result[] = $DR->get(); -// continue; -// } - + if($d['hash'] === $sender['hash']) { + $DR->update('self delivery ignored'); + $result[] = $DR->get(); + continue; + } // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. @@ -2390,6 +2392,9 @@ function sync_locations($sender, $arr, $absolute = false) { } } } + else { + logger('No locations to sync!'); + } $ret['change_message'] = $what; $ret['changed'] = $changed; @@ -2738,7 +2743,7 @@ function import_site($arr, $pubkey) { // logger('import_site: input: ' . print_r($arr,true)); // logger('import_site: stored: ' . print_r($siterecord,true)); - $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s' + $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d where site_url = '%s'", dbesc($site_location), intval($site_directory), @@ -2748,6 +2753,7 @@ function import_site($arr, $pubkey) { dbesc(datetime_convert()), dbesc($sellpage), dbesc($site_realm), + intval(SITE_TYPE_ZOT), dbesc($url) ); if(! $r) { @@ -2764,8 +2770,8 @@ function import_site($arr, $pubkey) { } else { $update = true; - $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm ) - values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s' )", + $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type ) + values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s', %d )", dbesc($site_location), dbesc($url), intval($access_policy), @@ -2774,7 +2780,8 @@ function import_site($arr, $pubkey) { dbesc($directory_url), intval($register_policy), dbesc($sellpage), - dbesc($site_realm) + dbesc($site_realm), + intval(SITE_TYPE_ZOT) ); if(! $r) { logger('import_site: record create failed. ' . print_r($arr,true)); @@ -2816,6 +2823,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $channel = $r[0]; + if(intval($channel['channel_removed'])) + return; + $h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", dbesc($channel['channel_hash']) ); @@ -2866,7 +2876,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { // don't pass these elements, they should not be synchronised - $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address'); + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address','channel_deleted','channel_removed','channel_system'); if(in_array($k,$disallowed)) continue; @@ -2993,10 +3003,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { // These flags cannot be sync'd. // remove the bits from the incoming flags. - if($arr['channel_pageflags'] & 0x8000) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x8000; - if($arr['channel_pageflags'] & 0x1000) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x1000; + // These correspond to PAGE_REMOVED and PAGE_SYSTEM on redmatrix + + if($arr['channel']['channel_pageflags'] & 0x8000) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x8000; + if($arr['channel']['channel_pageflags'] & 0x1000) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x1000; } @@ -3774,7 +3786,73 @@ function zotinfo($arr) { $ret['site']['realm'] = get_directory_realm(); } + + check_zotinfo($e,$x,$ret); + + call_hooks('zot_finger',$ret); return($ret); } + + +function check_zotinfo($channel,$locations,&$ret) { + + +// logger('locations: ' . print_r($locations,true),LOGGER_DATA); + + // This function will likely expand as we find more things to detect and fix. + // 1. Because magic-auth is reliant on it, ensure that the system channel has a valid hubloc + // Force this to be the case if anything is found to be wrong with it. + + // @FIXME ensure that the system channel exists in the first place and has an xchan + + if($channel['channel_system']) { + // the sys channel must have a location (hubloc) + $valid_location = false; + if((count($locations) === 1) && ($locations[0]['primary']) && (! $locations[0]['deleted'])) { + if((rsa_verify($locations[0]['url'],base64url_decode($locations[0]['url_sig']),$channel['channel_pubkey'])) + && ($locations[0]['sitekey'] === get_config('system','pubkey')) + && ($locations[0]['url'] === z_root())) + $valid_location = true; + else + logger('sys channel: invalid url signature'); + } + + if((! $locations) || (! $valid_location)) { + + logger('System channel locations are not valid. Attempting repair.'); + + // Don't trust any existing records. Just get rid of them, but only do this + // for the sys channel as normal channels will be trickier. + + q("delete from hubloc where hubloc_hash = '%s'", + dbesc($channel['channel_hash']) + ); + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary, + hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network ) + values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", + dbesc($channel['channel_guid']), + dbesc($channel['channel_guid_sig']), + dbesc($channel['channel_hash']), + dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), + intval(1), + dbesc(z_root()), + dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), + dbesc(get_app()->get_hostname()), + dbesc(z_root() . '/post'), + dbesc(get_config('system','pubkey')), + dbesc('zot') + ); + if($r) { + $x = zot_encode_locations($channel); + if($x) { + $ret['locations'] = $x; + } + } + else { + logger('Unable to store sys hub location'); + } + } + } +}
\ No newline at end of file |