begin hubloc refactor

This commit is contained in:
Mike Macgirvin 2022-06-16 19:46:54 -07:00
parent a20156597a
commit 35e02f25d6
34 changed files with 145 additions and 296 deletions

View file

@ -20,16 +20,16 @@ class Gprobe
return;
}
$url = hex2bin($argv[1]);
$address = $argv[1];
$protocols = [];
if (! strpos($url, '@')) {
if (! strpos($address, '@')) {
return;
}
$r = q(
"select * from hubloc where hubloc_addr = '%s'",
dbesc($url)
"select * from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0",
dbesc($address)
);
if ($r) {
@ -51,7 +51,7 @@ class Gprobe
}
if ((!in_array('zot6', $protocols)) && (!in_array('nomad', $protocols))) {
$href = Webfinger::zot_url(punify($url));
$href = Webfinger::zot_url(punify($address));
if ($href) {
$zf = Zotfinger::exec($href, $channel);
}

View file

@ -1,87 +0,0 @@
<?php
/** @file */
namespace Code\Daemon;
use Code\Lib\Libzotdir;
class Onedirsync
{
public static function run($argc, $argv)
{
logger('onedirsync: start ' . intval($argv[1]));
if (($argc > 1) && (intval($argv[1]))) {
$update_id = intval($argv[1]);
}
if (! $update_id) {
logger('onedirsync: no update');
return;
}
$r = q(
"select * from updates where ud_id = %d limit 1",
intval($update_id)
);
if (! $r) {
return;
}
if (($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr'])) {
return;
}
// Have we probed this channel more recently than the other directory server
// (where we received this update from) ?
// If we have, we don't need to do anything except mark any older entries updated
$x = q(
"select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
dbesc($r[0]['ud_addr']),
dbesc($r[0]['ud_date']),
intval(UPDATE_FLAGS_UPDATED)
);
if ($x) {
$y = q(
"update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
intval(UPDATE_FLAGS_UPDATED),
dbesc($r[0]['ud_addr']),
intval(UPDATE_FLAGS_UPDATED),
dbesc($x[0]['ud_date'])
);
return;
}
// ignore doing an update if this ud_addr refers to a known dead hubloc
$h = q(
"select * from hubloc where hubloc_addr = '%s' limit 1",
dbesc($r[0]['ud_addr'])
);
if (($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
$y = q(
"update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
intval(UPDATE_FLAGS_UPDATED),
dbesc($r[0]['ud_addr']),
intval(UPDATE_FLAGS_UPDATED)
);
return;
}
// we might have to pull this out some day, but for now update_directory_entry()
// runs zot_finger() and is kind of zot specific
if ($h && in_array($h[0]['hubloc_network'],['nomad','zot6'])) {
return;
}
Libzotdir::update_directory_entry($r[0]);
return;
}
}

View file

@ -565,11 +565,7 @@ class Activity
// The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need
// to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have
$r = q(
"select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($url),
dbesc($url)
);
$r = hubloc_id_query($url, 1);
if ($r) {
if ($r[0]['hubloc_network'] === 'activitypub') {
@ -961,7 +957,7 @@ class Activity
foreach ($ret['tag'] as $mention) {
if (is_array($mention) && array_key_exists('ttype', $mention) && in_array($mention['ttype'], [TERM_FORUM, TERM_MENTION]) && array_key_exists('href', $mention) && $mention['href']) {
$h = q(
"select * from hubloc where hubloc_id_url = '%s' limit 1",
"select * from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0 limit 1",
dbesc($mention['href'])
);
if ($h) {
@ -1399,11 +1395,7 @@ class Activity
if ($ret['tag']) {
foreach ($ret['tag'] as $mention) {
if (is_array($mention) && array_key_exists('ttype', $mention) && in_array($mention['ttype'], [TERM_FORUM, TERM_MENTION]) && array_key_exists('href', $mention) && $mention['href']) {
$h = q(
"select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($mention['href']),
dbesc($mention['href'])
);
$h = hubloc_id_query($mention['href'], 1);
if ($h) {
if ($h[0]['hubloc_network'] === 'activitypub') {
$addr = $h[0]['hubloc_hash'];
@ -1521,7 +1513,7 @@ class Activity
$tmp = expand_acl($i['allow_cid']);
$list = stringify_array($tmp, true);
if ($list) {
$details = q("select hubloc_id_url, hubloc_hash, hubloc_network from hubloc where hubloc_hash in (" . $list . ") ");
$details = q("select hubloc_id_url, hubloc_hash, hubloc_network from hubloc where hubloc_hash in (" . $list . ") and hubloc_deleted = 0");
if ($details) {
foreach ($details as $d) {
if ($d['hubloc_network'] === 'activitypub') {
@ -1561,7 +1553,7 @@ class Activity
return $ret;
}
$h = q("select * from hubloc where hubloc_hash = '%s'",
$h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($p['xchan_hash'])
);
if ($h) {
@ -2068,7 +2060,7 @@ class Activity
logger("New ActivityPub follower for {$channel['channel_name']}");
$new_connection = q(
"select * from abook left join xchan on abook_xchan = xchan_hash left join hubloc on hubloc_hash = xchan_hash where abook_channel = %d and abook_xchan = '%s' order by abook_created desc limit 1",
"select * from abook left join xchan on abook_xchan = xchan_hash left join hubloc on hubloc_hash = xchan_hash where abook_channel = %d and abook_xchan = '%s' and hubloc_deleted = 0 order by abook_created desc limit 1",
intval($channel['channel_id']),
dbesc($ret['xchan_hash'])
);
@ -2213,10 +2205,11 @@ class Activity
$name = escape_tags(t('Unknown'));
}
$webfinger = EMPTY_STR;
$username = escape_tags($person_obj['preferredUsername']);
$h = parse_url($url);
if ($h && $h['host']) {
$username .= '@' . $h['host'];
$webfinger = $username . '@' . $h['host'];
}
if ($person_obj['icon']) {
@ -2374,7 +2367,7 @@ class Activity
'xchan_hash' => $url,
'xchan_guid' => $url,
'xchan_pubkey' => $pubkey,
'xchan_addr' => ((strpos($username, '@')) ? $username : ''),
'xchan_addr' => $webfinger,
'xchan_url' => $profile,
'xchan_name' => $name,
'xchan_hidden' => intval($hidden),
@ -2413,10 +2406,10 @@ class Activity
dbesc($url)
);
if (strpos($username, '@') && ($r[0]['xchan_addr'] !== $username)) {
if ($webfinger !== $r[0]['xchan_addr']) {
$r = q(
"update xchan set xchan_addr = '%s' where xchan_hash = '%s'",
dbesc($username),
dbesc($webfinger),
dbesc($url)
);
}
@ -2480,7 +2473,7 @@ class Activity
}
$h = q(
"select * from hubloc where hubloc_hash = '%s' limit 1",
"select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 limit 1",
dbesc($url)
);
@ -2497,7 +2490,7 @@ class Activity
'hubloc_guid' => $url,
'hubloc_hash' => $url,
'hubloc_id_url' => $profile,
'hubloc_addr' => ((strpos($username, '@')) ? $username : ''),
'hubloc_addr' => $webfinger,
'hubloc_network' => 'activitypub',
'hubloc_url' => $baseurl,
'hubloc_host' => $hostname,
@ -2507,10 +2500,10 @@ class Activity
]
);
} else {
if (strpos($username, '@') && ($h[0]['hubloc_addr'] !== $username)) {
if ($webfinger !== $h[0]['hubloc_addr']) {
$r = q(
"update hubloc set hubloc_addr = '%s' where hubloc_hash = '%s'",
dbesc($username),
dbesc($webfinger),
dbesc($url)
);
}
@ -2545,11 +2538,11 @@ class Activity
if (strpos($url, '/channel/') !== false) {
$zx = q(
"select * from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad')",
"select * from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') and hubloc_deleted = 0",
dbesc($url)
);
if (($username) && strpos($username, '@') && (!$zx)) {
Run::Summon(['Gprobe', bin2hex($username)]);
if ($webfinger && (!$zx)) {
Run::Summon(['Gprobe', $webfinger]);
}
}
@ -2619,11 +2612,7 @@ class Activity
public static function get_actor_bbmention($id)
{
$x = q(
"select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' or hubloc_id_url = '%s' limit 1",
dbesc($id),
dbesc($id)
);
$x = hublocx_id_query($id, 1);
if ($x) {
// a name starting with a left paren can trick the markdown parser into creating a link so insert a zero-width space
@ -3689,7 +3678,7 @@ class Activity
// don't allow pubstream posts if the sender even has a clone on a pubstream denied site
$h = q(
"select hubloc_url from hubloc where hubloc_hash = '%s'",
"select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($observer_hash)
);
if ($h) {
@ -3852,7 +3841,7 @@ class Activity
$item['replyto'] = $item['owner_xchan'];
}
else {
$r = q("select hubloc_id_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1",
$r = q("select hubloc_id_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 and hubloc_deleted = 0",
dbesc($item['owner_xchan'])
);
if ($r) {
@ -4242,7 +4231,7 @@ class Activity
{
$recip = q(
"select * from hubloc where hubloc_hash = '%s' limit 1",
"select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 limit 1",
dbesc($observer_hash)
);
if (!$recip) {
@ -4440,11 +4429,7 @@ class Activity
if ($act && $act->is_valid()) {
$z = Activity::decode_note($act);
$r = q(
"select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_hash = '%s' OR hubloc_id_url = '%s'",
dbesc(is_array($act->actor) ? $act->actor['id'] : $act->actor),
dbesc(is_array($act->actor) ? $act->actor['id'] : $act->actor)
);
$r = hubloc_id_query((is_array($act->actor)) ? $act->actor['id'] : $act->actor);
if ($r) {
$r = Libzot::zot_record_preferred($r);

View file

@ -705,7 +705,7 @@ class Channel
$modified = $r[0];
$h = q(
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_deleted = 0 ",
dbesc($stored['old_hash']),
dbesc(z_root())
);
@ -807,7 +807,7 @@ class Channel
);
$h = q(
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_deleted = 0 ",
dbesc($channel['channel_hash']),
dbesc(z_root())
);
@ -1025,7 +1025,7 @@ class Channel
$ret['xchan'] = $r;
}
$r = q("select * from hubloc where hubloc_hash in ( " . implode(',', $xchans) . " ) ");
$r = q("select * from hubloc where hubloc_hash in ( " . implode(',', $xchans) . " ) and hubloc_deleted = 0");
if ($r) {
$ret['hubloc'] = $r;
}
@ -1427,11 +1427,11 @@ class Channel
if (! local_channel()) {
$r = q(
"select * from hubloc where hubloc_addr = '%s' order by hubloc_connected desc limit 1",
"select * from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0 order by hubloc_connected desc limit 1",
dbesc($tmp_str)
);
if (! $r) {
Run::Summon([ 'Gprobe', bin2hex($tmp_str) ]);
Run::Summon([ 'Gprobe', $tmp_str]);
}
if ($r && remote_channel() && remote_channel() === $r[0]['hubloc_hash']) {
return;
@ -1445,7 +1445,7 @@ class Channel
if ($r && ($r[0]['hubloc_url'] != z_root()) && (! strstr($dest, '/magic')) && (! strstr($dest, '/rmagic'))) {
goaway($r[0]['hubloc_url'] . '/magic' . '?f=&rev=1&owa=1&bdest=' . bin2hex(z_root() . $dest));
} else {
logger('No hubloc found.');
logger(sprintf('No hubloc found for \'%s\'.', $tmp_str);
}
}
}
@ -1611,7 +1611,7 @@ class Channel
$result = false;
$r = q(
"select * from hubloc where hubloc_addr = '%s' limit 1",
"select * from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0 limit 1",
dbesc($webbie)
);
if (! $r) {

View file

@ -91,7 +91,7 @@ class Connect
if (in_array($r['xchan_network'], ['nomad', 'zot6', 'activitypub'])) {
$h = q(
"select * from hubloc where hubloc_hash = '%s'",
"select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($r['xchan_hash'])
);
if (!$h) {

View file

@ -134,7 +134,7 @@ class DReport
// have a channel on that site.
$r = q(
"select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_url = '%s'",
"select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_deleted = 0",
dbesc($rxchan),
dbesc($dr['location'])
);

View file

@ -955,7 +955,7 @@ class Libsync
Libzot::check_location_move($sender['hash'], $arr['locations']);
$xisting = q(
"select * from hubloc where hubloc_hash = '%s'",
"select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0 ",
dbesc($sender['hash'])
);
@ -1012,7 +1012,7 @@ class Libsync
// match as many fields as possible in case anything at all changed.
$r = q(
"select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
"select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' and hubloc_deleted = 0 ",
dbesc($sender['hash']),
dbesc($sender['id']),
dbesc($sender['id_sig']),
@ -1256,7 +1256,7 @@ class Libsync
$channel = $r[0];
$h = q(
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
"select * from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' and hubloc_deleted = 0",
dbesc($arr['keychange']['old_hash']),
dbesc(z_root())
);

View file

@ -626,6 +626,7 @@ class Libzot
where hubloc_guid = '%s' and hubloc_guid_sig = '%s'
and hubloc_url = '%s' and hubloc_url_sig = '%s'
and hubloc_site_id = '%s' and hubloc_network in ('nomad','zot6')
and hubloc_deleted = 0
$limit",
dbesc($arr['id']),
dbesc($arr['id_sig']),
@ -648,7 +649,7 @@ class Libzot
{
$r = q(
"select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_site_id = '%s' limit 1",
"select hubloc.*, site.site_crypto from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_site_id = '%s' and hubloc_deleted = 0 limit 1",
dbesc($sender),
dbesc($site_id)
);
@ -1341,7 +1342,7 @@ class Libzot
}
$r = q(
"select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s'",
"select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($AS->actor['id'])
);
if (! $r) {
@ -1349,7 +1350,7 @@ class Libzot
$z = discover_by_webbie($AS->actor['id']);
if ($z) {
$r = q(
"select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s'",
"select hubloc_hash, hubloc_network, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($AS->actor['id'])
);
}
@ -1366,7 +1367,7 @@ class Libzot
}
$s = q(
"select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') limit 1",
"select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') and hubloc_deleted = 0 limit 1",
dbesc($env['sender'])
);
@ -1746,7 +1747,7 @@ class Libzot
$siteallowed = true;
$h = q(
"select hubloc_url from hubloc where hubloc_hash = '%s'",
"select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($sender)
);
if ($h) {
@ -1802,7 +1803,7 @@ class Libzot
$blocked = LibBlock::fetch($channel['channel_id'], BLOCKTYPE_SERVER);
if ($blocked) {
$h = q(
"select hubloc_url from hubloc where hubloc_hash = '%s'",
"select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($sender)
);
if ($h) {
@ -2183,7 +2184,7 @@ class Libzot
$signer = q(
"select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') limit 1",
"select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') and hubloc_deleted = 0 limit 1",
dbesc($a['signature']['signer'])
);
@ -2208,20 +2209,12 @@ class Libzot
// logger($AS->debug());
$r = q(
"select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($AS->actor['id']),
dbesc($AS->actor['id'])
);
$r = hubloc_id_query($AS->actor['id'], 1);
if (!$r) {
$y = import_author_xchan(['url' => $AS->actor['id']]);
if ($y) {
$r = q(
"select * from hubloc where hubloc_id_url = '%s' or hubloc_hash = '%s' limit 1",
dbesc($AS->actor['id']),
dbesc($AS->actor['id'])
);
$r = hubloc_id_query($AS->actor['id'], 1);
}
if (!$r) {
logger('FOF Activity: no actor');
@ -2898,7 +2891,7 @@ class Libzot
$r1 = q(
"select hubloc_url, hubloc_updated, site_dead from hubloc left join site on
hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1",
hubloc_url = site_url where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 and hubloc_deleted = 0 limit 1",
dbesc($x['id']),
dbesc($x['id_sig'])
);
@ -2938,7 +2931,7 @@ class Libzot
$r = q(
"select hubloc_id_url from hubloc left join site on hubloc_url = site_url
where hubloc_hash = '%s' and site_dead = 0",
where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0",
dbesc($hash)
);
if ($r) {
@ -2974,7 +2967,7 @@ class Libzot
$feed = ((x($arr, 'feed')) ? intval($arr['feed']) : 0);
if ($ztarget) {
$t = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_network in ('nomad','zot6') order by hubloc_id desc limit 1",
$t = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_network in ('nomad','zot6') and hubloc_deleted = 0 order by hubloc_id desc limit 1",
dbesc($ztarget)
);
if ($t) {

View file

@ -543,7 +543,7 @@ class ThreadItem
}
}
if ($additional_mentions) {
$r = q("select hubloc_addr, hubloc_id_url, hubloc_hash from hubloc where hubloc_id_url in (" . protect_sprintf(stringify_array($additional_mentions, true)) . ") ");
$r = q("select hubloc_addr, hubloc_id_url, hubloc_hash from hubloc where hubloc_deleted = 0 and hubloc_id_url in (" . protect_sprintf(stringify_array($additional_mentions, true)) . ") ");
if ($r) {
foreach ($r as $rv) {
$ment = (($r[0]['hubloc_addr']) ? $r[0]['hubloc_addr'] : $r[0]['hubloc_id_url']);

View file

@ -79,7 +79,7 @@ class ZotURL
{
$r = q(
"select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
"select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0 order by hubloc_primary desc",
dbesc($portable_id)
);

View file

@ -42,82 +42,6 @@ class Api extends Controller
public function get()
{
if (App::$cmd === 'api/oauth/authorize') {
/*
* api/oauth/authorize interact with the user. return a standard page
*/
App::$page['template'] = 'minimal';
// get consumer/client from request token
try {
$request = OAuth1Request::from_request();
} catch (Exception $e) {
logger('OAuth exception: ' . print_r($e, true));
// echo "<pre>"; var_dump($e);
killme();
}
if (x($_POST, 'oauth_yes')) {
$app = $this->oauth_get_client($request);
if (is_null($app)) {
return "Invalid request. Unknown token.";
}
$consumer = new OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']);
$verifier = md5($app['secret'] . local_channel());
set_config('oauth', $verifier, local_channel());
if ($consumer->callback_url != null) {
$params = $request->get_parameters();
$glue = '?';
if (strstr($consumer->callback_url, $glue)) {
$glue = '?';
}
goaway($consumer->callback_url . $glue . "oauth_token=" . OAuth1Util::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuth1Util::urlencode_rfc3986($verifier));
killme();
}
$tpl = Theme::get_template("oauth_authorize_done.tpl");
$o = replace_macros($tpl, array(
'$title' => t('Authorize application connection'),
'$info' => t('Return to your app and insert this Security Code:'),
'$code' => $verifier,
));
return $o;
}
if (!local_channel()) {
// TODO: we need login form to redirect to this page
notice(t('Please login to continue.') . EOL);
return login(false, 'api-login', $request->get_parameters());
}
$app = $this->oauth_get_client($request);
if (is_null($app)) {
return "Invalid request. Unknown token.";
}
$tpl = Theme::get_template('oauth_authorize.tpl');
$o = replace_macros($tpl, array(
'$title' => t('Authorize application connection'),
'$app' => $app,
'$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
'$yes' => t('Yes'),
'$no' => t('No'),
));
// echo "<pre>"; var_dump($app); killme();
return $o;
}
echo api_call();
killme();
}

View file

@ -81,10 +81,7 @@ class Cdav extends Controller
if ($sigblock) {
$keyId = str_replace('acct:', '', $sigblock['keyId']);
if ($keyId) {
$r = q(
"select * from hubloc where hubloc_addr = '%s' limit 1",
dbesc($keyId)
);
$r = hubloc_id_addr_query($keyId, 1);
if ($r) {
$c = Channel::from_hash($r[0]['hubloc_hash']);
if ($c) {

View file

@ -45,7 +45,7 @@ class Chanview extends Controller
// the most useful consistently ascending table item we have.
$r = q(
"select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_url = '%s' or hubloc_id_url = '%s' order by xchan_name_date desc limit 1",
"select * from hubloc left join xchan on hubloc_hash = xchan_hash where (hubloc_url = '%s' or hubloc_id_url = '%s') and hubloc_deleted = 0 order by xchan_name_date desc limit 1",
dbesc($_REQUEST['url']),
dbesc($_REQUEST['url'])
);

View file

@ -62,7 +62,7 @@ class Dav extends Controller
$keyId = str_replace('acct:', '', $sigblock['keyId']);
if ($keyId) {
$r = q(
"select * from hubloc where ( hubloc_addr = '%s' OR hubloc_id_url = '%s' OR hubloc_hash = '%s') limit 1",
"select * from hubloc where ( hubloc_addr = '%s' OR hubloc_id_url = '%s' OR hubloc_hash = '%s') and hubloc_deleted = 0 limit 1",
dbesc($keyId),
dbesc($keyId),
dbesc($keyId)

View file

@ -103,17 +103,13 @@ class Dirsearch extends Controller
}
if ($hub) {
$hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') ";
$hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_deleted = 0 and hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') ";
} else {
$hub_query = '';
}
if ($url) {
$r = q(
"select xchan_name from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_url = '%s' or hubloc_id_url = '%s'",
dbesc($url),
dbesc($url)
);
$r = hublocx_id_query($url, 1);
if ($r && $r[0]['xchan_name']) {
$name = $r[0]['xchan_name'];
}

View file

@ -64,11 +64,7 @@ class Getfile extends Controller
$verified = HTTPSig::verify('');
if ($verified && $verified['header_signed'] && $verified['header_valid']) {
$r = q(
"select hubloc_hash from hubloc where hubloc_id_url = '%s' or hubloc_addr = '%s' limit 1",
dbesc($verified['signer']),
dbesc(str_replace('acct:', '', $verified['signer']))
);
$r = hubloc_id_addr_query($verified['signer'], 1);
if ($r && $r[0]['hubloc_hash'] === $hash) {
$header_verified = true;
}

View file

@ -56,7 +56,7 @@ class Home extends Controller
if ($sigdata && $sigdata['signer'] && $sigdata['header_valid']) {
$data = json_encode(Libzot::zotinfo(['guid_hash' => $channel['channel_hash'], 'target_url' => $sigdata['signer']]));
$s = q(
"select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') limit 1",
"select site_crypto, hubloc_sitekey from site left join hubloc on hubloc_url = site_url where hubloc_id_url = '%s' and hubloc_network in ('zot6','nomad') and hubloc_deleted = 0 limit 1",
dbesc($sigdata['signer'])
);

View file

@ -72,7 +72,7 @@ class Inspect extends Controller
if ($item_type === 'xchan') {
$items = q(
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_hash = '%s' or hubloc_addr = '%s' ",
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where (hubloc_hash = '%s' or hubloc_addr = '%s') and hubloc_deleted = 0 ",
dbesc($item_id),
dbesc($item_id)
);

View file

@ -1048,7 +1048,7 @@ class Item extends Controller
if (array_key_exists('collections', $_REQUEST) && is_array($_REQUEST['collections']) && count($_REQUEST['collections'])) {
foreach ($_REQUEST['collections'] as $clct) {
$r = q(
"select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1",
"select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_addr = '%s' and hubloc_deleted = 0 limit 1",
dbesc($clct)
);
if ($r) {

View file

@ -24,7 +24,7 @@ class Locs extends Controller
$hubloc_id = intval($_REQUEST['primary']);
if ($hubloc_id) {
$r = q(
"select hubloc_id from hubloc where hubloc_id = %d and hubloc_hash = '%s' limit 1",
"select hubloc_id from hubloc where hubloc_id = %d and hubloc_hash = '%s' and hubloc_deleted = 0 limit 1",
intval($hubloc_id),
dbesc($channel['channel_hash'])
);
@ -45,7 +45,7 @@ class Locs extends Controller
);
$x = q(
"select * from hubloc where hubloc_id = %d and hubloc_hash = '%s' ",
"select * from hubloc where hubloc_id = %d and hubloc_hash = '%s' and hubloc_deleted = 0 ",
intval($hubloc_id),
dbesc($channel['channel_hash'])
);
@ -64,7 +64,7 @@ class Locs extends Controller
if ($hubloc_id) {
$r = q(
"select * from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1",
"select * from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' and hubloc_deleted = 0 limit 1",
intval($hubloc_id),
dbesc(z_root()),
dbesc($channel['channel_hash'])
@ -76,7 +76,7 @@ class Locs extends Controller
}
if (intval($r[0]['hubloc_primary'])) {
$x = q(
"select hubloc_id from hubloc where hubloc_primary = 1 and hubloc_hash = '%s'",
"select hubloc_id from hubloc where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_deleted = 0 ",
dbesc($channel['channel_hash'])
);
if (!$x) {
@ -120,7 +120,7 @@ class Locs extends Controller
$r = q(
"select * from hubloc where hubloc_hash = '%s'",
"select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($channel['channel_hash'])
);

View file

@ -70,7 +70,7 @@ class Magic extends Controller
if ($delegate) {
$r = q(
"select * from channel left join hubloc on channel_hash = hubloc_hash where hubloc_addr = '%s' limit 1",
"select * from channel left join hubloc on channel_hash = hubloc_hash where hubloc_addr = '%s' and hubloc_deleted = 0 limit 1",
dbesc($delegate)
);

View file

@ -249,7 +249,7 @@ class Outbox extends Controller
$item['allow_gid'] .= '<connections:' . $channel['channel_hash'] . '>';
continue;
}
$r = q("select * from hubloc where hubloc_id_url = '%s'",
$r = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($recip)
);
if ($r) {

View file

@ -35,7 +35,7 @@ class Owa extends Controller
if ($keyId) {
$r = q(
"select * from hubloc left join xchan on hubloc_hash = xchan_hash
where ( hubloc_addr = '%s' or hubloc_id_url = '%s' ) and xchan_pubkey != '' ",
where ( hubloc_addr = '%s' or hubloc_id_url = '%s' ) and hubloc_deleted = 0 and xchan_pubkey != '' ",
dbesc(str_replace('acct:', '', $keyId)),
dbesc($keyId)
);
@ -44,7 +44,7 @@ class Owa extends Controller
if ($found) {
$r = q(
"select * from hubloc left join xchan on hubloc_hash = xchan_hash
where ( hubloc_addr = '%s' or hubloc_id_url = '%s' ) and xchan_pubkey != '' ",
where ( hubloc_addr = '%s' or hubloc_id_url = '%s' ) and hubloc_deleted = 0 and xchan_pubkey != '' ",
dbesc(str_replace('acct:', '', $keyId)),
dbesc($keyId)
);

View file

@ -18,7 +18,7 @@ class Q extends Controller
}
$r = q(
"select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0",
"select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0",
dbesc($h)
);
if ($r) {

View file

@ -22,7 +22,7 @@ class Rmagic extends Controller
$me = Channel::get_my_address();
if ($me) {
$r = q(
"select hubloc_url from hubloc where hubloc_addr = '%s' limit 1",
"select hubloc_url from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0 limit 1",
dbesc($me)
);
if ($r) {
@ -58,7 +58,7 @@ class Rmagic extends Controller
$r = null;
if ($address) {
$r = q(
"select hubloc_url from hubloc where hubloc_addr = '%s' limit 1",
"select hubloc_url from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0 limit 1",
dbesc($address)
);
}

View file

@ -1526,7 +1526,7 @@ function fix_system_urls($oldurl, $newurl) {
// that they can clean up their hubloc tables (this includes directories).
// It's a very expensive operation so you don't want to have to do it often or after your site gets to be large.
$r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url like '%s'",
$r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url like '%s' and hublod_deleted = 0",
dbesc($oldurl . '%')
);

View file

@ -92,18 +92,10 @@ function api_login()
if ($sigblock) {
$keyId = str_replace('acct:', '', $sigblock['keyId']);
if ($keyId) {
$r = q(
"select * from hubloc where hubloc_addr = '%s' or hubloc_id_url = '%s'",
dbesc($keyId),
dbesc($keyId)
);
$r = hubloc_id_addr_query($keyId);
if (! $r) {
HTTPSig::get_zotfinger_key($keyId);
$r = q(
"select * from hubloc where hubloc_addr = '%s' or hubloc_id_url = '%s'",
dbesc($keyId),
dbesc($keyId)
);
$r = hubloc_id_addr_query($keyId);
}
if ($r) {

View file

@ -244,7 +244,7 @@ if (
}
} else {
$r = q(
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s' ",
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s' and hubloc_deleted = 0",
dbesc($_SESSION['visitor_id'])
);
}

View file

@ -79,7 +79,7 @@ function rconnect_url($channel_id, $xchan)
}
$r = q(
"select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 limit 1",
"select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 and hubloc_deleted = 0 limit 1",
dbesc($xchan)
);
@ -580,7 +580,7 @@ function random_profile()
for ($i = 0; $i < $retryrandom; $i++) {
$r = q("select xchan_url, xchan_hash from xchan left join hubloc on hubloc_hash = xchan_hash where
xchan_hidden = 0 and xchan_network in ('nomad','zot6') and xchan_deleted = 0
xchan_hidden = 0 and xchan_network in ('nomad','zot6') and xchan_deleted = 0 and hubloc_deleted = 0
and hubloc_connected > %s - interval %s order by $randfunc limit 1",
db_utcnow(),
db_quoteinterval('30 day')

View file

@ -1706,7 +1706,7 @@ function conv_sort($arr, $order)
if ($cnt) {
foreach ($matches as $match) {
$r = q(
"select hubloc_hash from hubloc where hubloc_id_url = '%s'",
"select hubloc_hash from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($match[2])
);
if ($r) {

View file

@ -346,3 +346,56 @@ function get_hubloc_addrs_by_hash($hash)
dbesc($hash)
);
}
function hubloc_id_query($s, $limit = 0) {
if ($limit) {
$qlimit = 'limit ' . intval($limit);
}
$r = q("select * from hubloc where (hubloc_id_url = '%s' or hubloc_hash = '%s') and hubloc_deleted = 0 $qlimit",
dbesc($s),
dbesc($s)
);
return $r;
}
function hublocx_id_query($s, $limit = 0) {
if ($limit) {
$qlimit = 'limit ' . intval($limit);
}
$r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where (hubloc_id_url = '%s' or hubloc_hash = '%s') and hubloc_deleted = 0 and $qlimit",
dbesc($s),
dbesc($s)
);
return $r;
}
function hubloc_id_addr_query($s, $limit = 0) {
if ($limit) {
$qlimit = 'limit ' . intval($limit);
}
$r = q("select * from hubloc where (hubloc_id_url = '%s' or hubloc_hash = '%s' or hubloc_addr = '%s') and hubloc_deleted = 0 $qlimit",
dbesc($s),
dbesc($s),
dbesc(str_replace('acct:' , '', $s))
);
return $r;
}
function hublocx_id_addr_query($s, $limit = 0) {
if ($limit) {
$qlimit = 'limit ' . intval($limit);
}
$r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where (hubloc_id_url = '%s' or hubloc_hash = '%s' or hubloc_addr = '%s') and hubloc_deleted = 0 $qlimit",
dbesc($s),
dbesc($s),
dbesc(str_replace('acct:' , '', $s))
);
return $r;
}

View file

@ -881,7 +881,7 @@ function import_author_activitypub($x) {
// let somebody upgrade from an 'unknown' connection which has no xchan_addr and resolve issues with identities from multiple protocols using the same url
$r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s'",
$r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($x['url'])
);
if(! $r) {
@ -907,7 +907,7 @@ function import_author_activitypub($x) {
$z = discover_by_webbie($x['url']);
if($z) {
$r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s'",
$r = q("select xchan_hash, xchan_url, xchan_network, xchan_name, xchan_photo_s from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s' and hubloc_deleted = 0",
dbesc($x['url'])
);
if(! $r) {

View file

@ -435,7 +435,7 @@ function dir_tagadelic($count = 0, $hub = '', $type = 0, $safe = '')
$r = q(
"select xtag_term as term, count(xtag_term) as total from xtag
left join hubloc on xtag_hash = hubloc_hash
where xtag_flags = 0 and xtag_hash in (select hubloc_hash from hubloc where hubloc_host = '%s' )
where xtag_flags = 0 and xtag_hash in (select hubloc_hash from hubloc where hubloc_host = '%s' and hubloc_deleted = 0)
$sql_extra
group by xtag_term order by total desc %s",
dbesc($hub),

View file

@ -2676,12 +2676,12 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0)
if ($abook) {
$chans = q(
"select * from xchan left join hubloc on hubloc_hash = xchan_hash left join abook on abook_xchan = xchan_hash and abook_channel = %d
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") order by hubloc_primary desc",
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_deleted = 0 order by hubloc_primary desc",
intval($item['uid'])
);
} else {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") order by hubloc_primary desc");
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_deleted = 0 order by hubloc_primary desc");
}
$xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and xchan_network in ('rss','unknown', 'anon')");
if (! $chans) {
@ -2714,7 +2714,7 @@ function xchan_mail_query(&$item)
if (count($arr)) {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1");
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1 and hubloc_deleted = 0");
}
if ($chans) {
$item['from'] = find_xchan_in_array($item['from_xchan'], $chans);
@ -3108,7 +3108,7 @@ function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true)
if ((! $r) && strpos($newname, '@')) {
$r = q(
"SELECT * FROM xchan left join hubloc on xchan_hash = hubloc_hash
WHERE hubloc_addr = '%s' ",
WHERE hubloc_addr = '%s' and hubloc_deleted = 0",
dbesc($newname)
);
}