diff options
author | Mario <mario@mariovavti.com> | 2023-04-28 21:50:01 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-04-28 21:50:01 +0000 |
commit | 39d78064da3748ed31f71c9a219433bfe9cd2d56 (patch) | |
tree | dc5d0776608147f22bd2709d963a8328e2640faa | |
parent | a2bcbb90ed269d0df2a886b3343ff75dbe5f9be4 (diff) | |
parent | 354e341d69eb748a6ae1582fadade9d1012de7e4 (diff) | |
download | volse-hubzilla-39d78064da3748ed31f71c9a219433bfe9cd2d56.tar.gz volse-hubzilla-39d78064da3748ed31f71c9a219433bfe9cd2d56.tar.bz2 volse-hubzilla-39d78064da3748ed31f71c9a219433bfe9cd2d56.zip |
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
-rw-r--r-- | Zotlabs/Daemon/Poller.php | 3 | ||||
-rw-r--r-- | Zotlabs/Lib/Activity.php | 4 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 5 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzotdir.php | 87 | ||||
-rw-r--r-- | Zotlabs/Module/Dircensor.php | 2 | ||||
-rw-r--r-- | Zotlabs/Module/Dirsearch.php | 2 | ||||
-rw-r--r-- | boot.php | 5 |
7 files changed, 71 insertions, 37 deletions
diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index e5a1c6f39..77a428ec3 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -170,8 +170,7 @@ class Poller { $dirmode = intval(get_config('system', 'directory_mode')); if ($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { - $r = q("SELECT * FROM updates WHERE ud_update != %d AND (ud_last = '%s' OR ud_last > %s - INTERVAL %s)", - intval(DIRECTORY_UPDATE_OK), + $r = q("SELECT * FROM updates WHERE ud_update = 1 AND (ud_last = '%s' OR ud_last > %s - INTERVAL %s)", dbesc(NULL_DATE), db_utcnow(), db_quoteinterval('7 DAY') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 09f31eaec..7a64d3de1 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -591,9 +591,9 @@ class Activity { foreach ($item['term'] as $t) { switch ($t['ttype']) { case TERM_HASHTAG: - // id is required so if we don't have a url in the taxonomy, ignore it and keep going. + // href is required so if we don't have a url in the taxonomy, ignore it and keep going. if ($t['url']) { - $ret[] = ['type' => 'Hashtag', 'id' => $t['url'], 'name' => '#' . $t['term']]; + $ret[] = ['type' => 'Hashtag', 'href' => $t['url'], 'name' => '#' . $t['term']]; } break; diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 1843a081d..093670338 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -674,7 +674,6 @@ class Libzot { $arr['hash'] = $xchan_hash; $import_photos = false; - $xchan_censored = 0; $sig_methods = ((array_key_exists('signing', $arr) && is_array($arr['signing'])) ? $arr['signing'] : ['sha256']); $verified = false; @@ -706,8 +705,6 @@ class Libzot { if ($arr['photo'] && array_key_exists('updated', $arr['photo']) && $arr['photo']['updated'] > $r[0]['xchan_photo_date']) $import_photos = true; - $xchan_censored = $r[0]['xchan_censored'] ?? 0; - // if we import an entry from a site that's not ours and either or both of us is off the grid - hide the entry. /** @TODO: check if we're the same directory realm, which would mean we are allowed to see it */ @@ -969,7 +966,7 @@ class Libzot { } // update updates if anything changed bump the ud_date - Libzotdir::update($xchan_hash, $address, $changed, $xchan_censored); + Libzotdir::update($xchan_hash, $address, $changed); if (empty($ret['message'])) { $ret['success'] = true; diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index d3772f2dc..fd5778e5a 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -282,16 +282,27 @@ class Libzotdir { } // there is more recent xchan information - if ($r[0]['ud_date'] >= $t['timestamp']) { - $update = DIRECTORY_UPDATE_XCHAN; + if ($r[0]['ud_date'] <= $t['timestamp']) { + $update = 1; } - // the host is trusted and flags have changed + // the host is trusted and flags have changed - update flags immediately if (in_array($t['host'], $dir_trusted_hosts) && - $rr['site_directory'] === $t['host'] && + $rr['site_url'] === $t['host'] && intval($r[0]['ud_flags']) !== intval($t['flags'])) { - $update = (($update) ? DIRECTORY_UPDATE_BOTH : DIRECTORY_UPDATE_FLAGS); + q("UPDATE updates SET ud_update = %d, ud_flags = %d WHERE ud_id = %d", + intval($update), + intval($t['flags']), + dbesc($r[0]['ud_id']) + ); + + q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", + intval($t['flags']), + dbesc($r[0]['ud_hash']) + ); + + continue; } if (!$update) { @@ -338,23 +349,27 @@ class Libzotdir { logger('update_directory_entry: ' . print_r($ud,true), LOGGER_DATA); - // set the flag if requested? - if (in_array($ud['ud_flags'], [DIRECTORY_UPDATE_FLAGS, DIRECTORY_UPDATE_BOTH])) { - q("UPDATE xchan SET xchan_censored = %d WHERE xchan_hash = '%s'", - intval($ud['ud_flags']), - dbesc($ud['ud_hash']) - ); - } - - if (intval($ud['ud_flags']) === DIRECTORY_UPDATE_FLAGS) { - return true; - } - + // TODO: remove this check after all directory servers have version > 8.4 + // ud_addr will always be the channel url at that time $href = ((strpos($ud['ud_addr'], '://') === false) ? Webfinger::zot_url(punify($ud['ud_addr'])) : punify($ud['ud_addr'])); if($href) { $zf = Zotfinger::exec($href); if($zf && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) { $xc = Libzot::import_xchan($zf['data']); + + // xchan_hash mismatch - this can happen after a site re-install at the same url + if ($xc['success'] && $xc['hash'] !== $ud['ud_hash']) { + self::delete_by_hash($ud['ud_hash']); + } + + // backwards compatibility: Libzot::import_xchan(), where self::update() is called, + // will fail with versions < 8.4 if the channel has been locally deleted. + // In this case we will update the updates record here without bumping the date + // since we could not verify if anything changed. + if (!$xc['success'] && !empty($zf['data']['deleted_locally'])) { + self::update($ud['ud_hash'], $ud['ud_addr'], false); + } + // This is a workaround for a missing xchan_updated column // TODO: implement xchan_updated in the xchan table and update this column instead if($zf['data']['primary_location']['address'] && $zf['data']['primary_location']['url']) { @@ -363,6 +378,7 @@ class Libzotdir { dbesc($zf['data']['primary_location']['url']) ); } + return true; } } @@ -667,11 +683,9 @@ class Libzotdir { * @param bool $bump_date (optional) default true */ - static function update($hash, $addr, $bump_date = true, $flag = DIRECTORY_FLAG_OK) { -hz_syslog('flag: '. print_r($flag, true)); + static function update($hash, $addr, $bump_date = true, $flag = null) { $dirmode = intval(get_config('system', 'directory_mode')); -hz_syslog('gothere'); if($dirmode == DIRECTORY_MODE_NORMAL) { return; @@ -690,12 +704,17 @@ hz_syslog('gothere'); $date_sql = "ud_date = '" . dbesc(datetime_convert()) . "',"; } + $flag_sql = ''; + if ($flag !== null) { + $flag_sql = "ud_flags = '" . intval($flag) . "',"; + } + + if ($u) { - $x = q("UPDATE updates SET $date_sql ud_last = '%s', ud_host = '%s', ud_addr = '%s', ud_update = 0, ud_flags = %d WHERE ud_id = %d", + $x = q("UPDATE updates SET $date_sql $flag_sql ud_last = '%s', ud_host = '%s', ud_addr = '%s', ud_update = 0 WHERE ud_id = %d", dbesc(NULL_DATE), dbesc(z_root()), dbesc($addr), - intval($flag), intval($u[0]['ud_id']) ); @@ -714,4 +733,28 @@ hz_syslog('gothere'); } + + /** + * @brief deletes a entry in updates by hash + * + * @param string $hash the channel hash + * @return boolean + */ + + static function delete_by_hash($hash) { + if (!$hash) { + return false; + } + + $x = q("DELETE FROM updates WHERE ud_hash = '%s'", + dbesc($hash) + ); + + if ($x) { + return true; + } + + return false; + } + } diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php index 90759e58d..44c9148e8 100644 --- a/Zotlabs/Module/Dircensor.php +++ b/Zotlabs/Module/Dircensor.php @@ -44,7 +44,7 @@ class Dircensor extends Controller { if ($severity === 2) { $flag = DIRECTORY_FLAG_HIDDEN; } -hz_syslog('flag: '. print_r($flag, true)); + Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag); q("update xchan set xchan_censored = %d where xchan_hash = '%s'", diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index d4af0f91a..acf1b64e4 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -229,7 +229,7 @@ class Dirsearch extends Controller { 'hash' => $rr['ud_hash'], 'address' => $rr['ud_addr'], 'host' => $rr['ud_host'], - 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 + 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 - can be removed after dir servers at version >= 8.4 'timestamp' => $rr['ud_date'], 'flags' => $rr['ud_flags'] ]; @@ -84,11 +84,6 @@ define('DIRECTORY_MODE_PRIMARY', 0x0001); // There can only be *one* primary dir define('DIRECTORY_MODE_SECONDARY', 0x0002); // All other mirror directory servers define('DIRECTORY_MODE_STANDALONE', 0x0100); // A detached (off the grid) hub with itself as directory server. -define('DIRECTORY_UPDATE_OK', 0); -define('DIRECTORY_UPDATE_XCHAN', 1); -define('DIRECTORY_UPDATE_FLAGS', 2); -define('DIRECTORY_UPDATE_BOTH', 3); - define('DIRECTORY_FLAG_OK', 0); define('DIRECTORY_FLAG_UNSAFE', 1); define('DIRECTORY_FLAG_HIDDEN', 2); |