streams/Code/Daemon/Gprobe.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2021-12-03 03:01:39 +00:00
<?php
/** @file */
2016-05-20 02:42:45 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Daemon;
2016-05-20 02:42:45 +00:00
2022-02-16 04:08:28 +00:00
use Code\Lib\Libzot;
use Code\Lib\Webfinger;
use Code\Lib\Zotfinger;
2016-05-20 02:42:45 +00:00
// performs zot_finger on $argv[1], which is a hex_encoded webbie/reddress
2021-12-03 03:01:39 +00:00
class Gprobe
{
2021-12-03 03:01:39 +00:00
public static function run($argc, $argv)
{
2016-05-20 02:42:45 +00:00
2021-12-03 03:01:39 +00:00
if ($argc != 2) {
return;
}
2016-05-20 02:42:45 +00:00
2022-06-17 02:46:54 +00:00
$address = $argv[1];
2021-12-03 03:01:39 +00:00
$protocols = [];
2016-05-20 02:42:45 +00:00
2022-06-17 02:46:54 +00:00
if (! strpos($address, '@')) {
2021-12-03 03:01:39 +00:00
return;
}
2016-05-20 02:42:45 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
2022-06-17 02:46:54 +00:00
"select * from hubloc where hubloc_addr = '%s' and hubloc_deleted = 0",
dbesc($address)
2021-12-03 03:01:39 +00:00
);
if ($r) {
foreach ($r as $rv) {
if ($rv['hubloc_network'] === 'activitypub') {
$protocols[] = 'activitypub';
continue;
}
if ($rv['hubloc_network'] === 'nomad') {
$protocols[] = 'nomad';
$protocols[] = 'zot6';
continue;
}
2021-12-03 03:01:39 +00:00
if ($rv['hubloc_network'] === 'zot6') {
$protocols[] = 'zot6';
continue;
}
}
}
2022-06-05 22:29:27 +00:00
if ((!in_array('zot6', $protocols)) && (!in_array('nomad', $protocols))) {
2022-06-17 02:46:54 +00:00
$href = Webfinger::zot_url(punify($address));
if ($href) {
2021-12-03 03:01:39 +00:00
$zf = Zotfinger::exec($href, $channel);
2018-06-01 02:42:13 +00:00
}
2021-12-03 03:01:39 +00:00
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid']) && isset($zf['data']) && $zf['data']) {
2018-08-28 02:09:48 +00:00
$xc = Libzot::import_xchan($zf['data']);
2021-12-03 03:01:39 +00:00
}
}
2016-05-20 02:42:45 +00:00
2021-12-03 03:01:39 +00:00
return;
}
2016-05-20 02:42:45 +00:00
}