From 299b6037c99eafe13c94284029d55beddb571a5e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 27 Apr 2023 11:24:26 +0200 Subject: remove logging --- Zotlabs/Lib/Libzotdir.php | 2 -- Zotlabs/Module/Dircensor.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index d3772f2dc..b000c0a69 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -668,10 +668,8 @@ class Libzotdir { */ static function update($hash, $addr, $bump_date = true, $flag = DIRECTORY_FLAG_OK) { -hz_syslog('flag: '. print_r($flag, true)); $dirmode = intval(get_config('system', 'directory_mode')); -hz_syslog('gothere'); if($dirmode == DIRECTORY_MODE_NORMAL) { return; 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'", -- cgit v1.2.3 From 5da58d42f6b86d6aa026444a9163909eb5e0d49d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 27 Apr 2023 22:26:53 +0200 Subject: adjust args in libzotdir update and some dir sync fixes --- Zotlabs/Lib/Libzot.php | 2 +- Zotlabs/Lib/Libzotdir.php | 8 +++++--- Zotlabs/Module/Dircensor.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 1843a081d..d34afb83d 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -969,7 +969,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, $xchan_censored, $changed); if (empty($ret['message'])) { $ret['success'] = true; diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index b000c0a69..5677d2263 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -282,7 +282,7 @@ class Libzotdir { } // there is more recent xchan information - if ($r[0]['ud_date'] >= $t['timestamp']) { + if ($r[0]['ud_date'] <= $t['timestamp']) { $update = DIRECTORY_UPDATE_XCHAN; } @@ -347,6 +347,7 @@ class Libzotdir { } if (intval($ud['ud_flags']) === DIRECTORY_UPDATE_FLAGS) { + self::update($ud['ud_hash'], $ud['ud_addr'], $ud['ud_flags'], false); return true; } @@ -355,6 +356,7 @@ class Libzotdir { $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']); + // 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']) { @@ -459,7 +461,7 @@ class Libzotdir { ); } - self::update($hash, $p[0]['xchan_url']); + self::update($hash, $p[0]['xchan_url'], $p[0]['xchan_censored']); } @@ -667,7 +669,7 @@ class Libzotdir { * @param bool $bump_date (optional) default true */ - static function update($hash, $addr, $bump_date = true, $flag = DIRECTORY_FLAG_OK) { + static function update($hash, $addr, $flag, $bump_date = true) { $dirmode = intval(get_config('system', 'directory_mode')); diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php index 44c9148e8..b372bbf25 100644 --- a/Zotlabs/Module/Dircensor.php +++ b/Zotlabs/Module/Dircensor.php @@ -45,7 +45,7 @@ class Dircensor extends Controller { $flag = DIRECTORY_FLAG_HIDDEN; } - Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag); + Libzotdir::update($xchan, $r[0]['xchan_url'], $flag); q("update xchan set xchan_censored = %d where xchan_hash = '%s'", intval($flag), -- cgit v1.2.3 From 1f81a2cb1b0974bf8fe6d0daf2c06a23f27afc98 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 27 Apr 2023 22:54:45 +0200 Subject: remove updates entry if a xchan_hash mismatch is encountered --- Zotlabs/Lib/Libzotdir.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index 5677d2263..d9b5d7a35 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -357,6 +357,11 @@ class Libzotdir { 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']); + } + // 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']) { @@ -365,6 +370,7 @@ class Libzotdir { dbesc($zf['data']['primary_location']['url']) ); } + return true; } } @@ -714,4 +720,28 @@ class Libzotdir { } + + /** + * @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; + } + } -- cgit v1.2.3 From 5412ba617dfbba9161484094427075480ae4b80c Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 00:58:46 +0200 Subject: more dir sync testing --- Zotlabs/Lib/Libzotdir.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index d9b5d7a35..908f60765 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -288,7 +288,7 @@ class Libzotdir { // the host is trusted and flags have changed 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); @@ -298,6 +298,15 @@ class Libzotdir { continue; } + if (in_array($update, [DIRECTORY_UPDATE_FLAGS, DIRECTORY_UPDATE_BOTH])) { + q("UPDATE updates SET ud_update = %d, ud_flags = %d WHERE ud_id = %d", + intval($update), + intval($t['flags']), + dbesc($r[0]['ud_id']) + ); + continue; + } + q("UPDATE updates SET ud_update = %d WHERE ud_id = %d", intval($update), dbesc($r[0]['ud_id']) @@ -339,14 +348,15 @@ 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])) { + if (in_array($ud['ud_update'], [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) { + if (intval($ud['ud_update']) === DIRECTORY_UPDATE_FLAGS) { self::update($ud['ud_hash'], $ud['ud_addr'], $ud['ud_flags'], false); return true; } -- cgit v1.2.3 From 3543e6dd32bd7e518a0deec2038eafe6a183dc6b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 08:57:21 +0200 Subject: slightly refactor dir sync --- Zotlabs/Lib/Libzot.php | 5 +---- Zotlabs/Lib/Libzotdir.php | 51 ++++++++++++++++++++------------------------ Zotlabs/Module/Dircensor.php | 2 +- 3 files changed, 25 insertions(+), 33 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index d34afb83d..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, $xchan_censored, $changed); + 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 908f60765..c3ff026d7 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -283,27 +283,29 @@ class Libzotdir { // there is more recent xchan information if ($r[0]['ud_date'] <= $t['timestamp']) { - $update = DIRECTORY_UPDATE_XCHAN; + $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_url'] === $t['host'] && intval($r[0]['ud_flags']) !== intval($t['flags'])) { - $update = (($update) ? DIRECTORY_UPDATE_BOTH : DIRECTORY_UPDATE_FLAGS); - } - - if (!$update) { - continue; - } - - if (in_array($update, [DIRECTORY_UPDATE_FLAGS, DIRECTORY_UPDATE_BOTH])) { 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) { continue; } @@ -347,20 +349,8 @@ class Libzotdir { logger('update_directory_entry: ' . print_r($ud,true), LOGGER_DATA); - // set the flag if requested? - if (in_array($ud['ud_update'], [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_update']) === DIRECTORY_UPDATE_FLAGS) { - self::update($ud['ud_hash'], $ud['ud_addr'], $ud['ud_flags'], false); - 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); @@ -477,7 +467,7 @@ class Libzotdir { ); } - self::update($hash, $p[0]['xchan_url'], $p[0]['xchan_censored']); + self::update($hash, $p[0]['xchan_url']); } @@ -685,7 +675,7 @@ class Libzotdir { * @param bool $bump_date (optional) default true */ - static function update($hash, $addr, $flag, $bump_date = true) { + static function update($hash, $addr, $bump_date = true, $flag = null) { $dirmode = intval(get_config('system', 'directory_mode')); @@ -706,12 +696,17 @@ class Libzotdir { $date_sql = "ud_date = '" . dbesc(datetime_convert()) . "',"; } + $flag_sql = ''; + if ($flag !== null) { + $flag_sql = "ud_flag = '" . 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']) ); diff --git a/Zotlabs/Module/Dircensor.php b/Zotlabs/Module/Dircensor.php index b372bbf25..44c9148e8 100644 --- a/Zotlabs/Module/Dircensor.php +++ b/Zotlabs/Module/Dircensor.php @@ -45,7 +45,7 @@ class Dircensor extends Controller { $flag = DIRECTORY_FLAG_HIDDEN; } - Libzotdir::update($xchan, $r[0]['xchan_url'], $flag); + Libzotdir::update($xchan, $r[0]['xchan_url'], true, $flag); q("update xchan set xchan_censored = %d where xchan_hash = '%s'", intval($flag), -- cgit v1.2.3 From c3267a27d36ad66ec2dd19a5613a3827010eebf2 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 09:04:02 +0200 Subject: fix column name --- Zotlabs/Lib/Libzotdir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index c3ff026d7..1b8d8436b 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -698,7 +698,7 @@ class Libzotdir { $flag_sql = ''; if ($flag !== null) { - $flag_sql = "ud_flag = '" . intval($flag) . "',"; + $flag_sql = "ud_flags = '" . intval($flag) . "',"; } -- cgit v1.2.3 From 29aa52df6a29042178cdc9e70fc51711e70a72ee Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 09:29:15 +0200 Subject: fix poller after refactor --- Zotlabs/Daemon/Poller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs') 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') -- cgit v1.2.3 From 13946b2b761d38bd7623cf2704616309922b75d7 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 10:03:05 +0200 Subject: fix and document edge case --- Zotlabs/Lib/Libzotdir.php | 8 ++++++++ Zotlabs/Module/Dirsearch.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index 1b8d8436b..fd5778e5a 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -362,6 +362,14 @@ class Libzotdir { 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']) { 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'] ]; -- cgit v1.2.3 From 354e341d69eb748a6ae1582fadade9d1012de7e4 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 12:50:57 +0200 Subject: mastodon says hashtag is a subset of link - issue #1750 --- Zotlabs/Lib/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index cb9d0f1b3..dff996231 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; -- cgit v1.2.3