mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 00:55:19 +00:00
Add fhublocs module/tool to repository (repair damaged or missing hubloc records)
This commit is contained in:
parent
c5c86a23cd
commit
166a69c282
2 changed files with 121 additions and 0 deletions
119
Code/Module/Fhublocs.php
Normal file
119
Code/Module/Fhublocs.php
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
<?php
|
||||||
|
namespace Code\Module;
|
||||||
|
|
||||||
|
use App;
|
||||||
|
use Code\Lib\Libzot;
|
||||||
|
use Code\Lib\Channel;
|
||||||
|
use Code\Web\Controller;
|
||||||
|
|
||||||
|
/* fix missing or damaged hublocs */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The purpose of this procedure is to repair the site signatures of local channels
|
||||||
|
* if that signature changes. This will be an extremely rare event. You will probably
|
||||||
|
* be directed to use this tool if your site is reporting an invalid signature in all
|
||||||
|
* or nearly of its interactions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class Fhublocs extends Controller {
|
||||||
|
|
||||||
|
function get() {
|
||||||
|
|
||||||
|
if (! is_site_admin()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
$r = q("select * from channel where channel_removed = 0");
|
||||||
|
$sitekey = get_config('system','pubkey');
|
||||||
|
|
||||||
|
if ($r) {
|
||||||
|
// For each local channel
|
||||||
|
foreach ($r as $rr) {
|
||||||
|
|
||||||
|
$found = false;
|
||||||
|
$primary_address = '';
|
||||||
|
// Find all the location (hubloc) records
|
||||||
|
$x = Libzot::getLocations($rr['channel_hash']);
|
||||||
|
|
||||||
|
|
||||||
|
// See if this channel has a valid hubloc record for this site.
|
||||||
|
if ($x) {
|
||||||
|
foreach ($x as $xx) {
|
||||||
|
if ($xx['hubloc_url'] === z_root() && $xx['hubloc_sitekey'] === $sitekey) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($found) {
|
||||||
|
$output .= 'Hubloc exists for ' . $rr['channel_name'] . EOL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we got this far, the channel does not have a valid hubloc
|
||||||
|
// record for this site/instance. We will need to create one.
|
||||||
|
|
||||||
|
// Determine if this is the primary location for this channel.
|
||||||
|
// Since we don't have a valid hubloc record, check for this situation
|
||||||
|
// by seeing if this site address matches the associated xchan record.
|
||||||
|
// If the xchan record is also missing (an even more rare event), assume
|
||||||
|
// that this is the primary.
|
||||||
|
|
||||||
|
$y = q("select xchan_addr from xchan where xchan_hash = '%s' limit 1",
|
||||||
|
dbesc($rr['channel_hash'])
|
||||||
|
);
|
||||||
|
if ($y) {
|
||||||
|
$primary_address = $y[0]['xchan_addr'];
|
||||||
|
}
|
||||||
|
$hub_address = Channel::get_webfinger($rr);
|
||||||
|
|
||||||
|
$primary = (($hub_address === $primary_address) ? 1 : 0);
|
||||||
|
if (! $y) {
|
||||||
|
$primary = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any hublocs associated with this channel and this site.
|
||||||
|
// By definition, they are not valid.
|
||||||
|
|
||||||
|
$m = q("delete from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
|
||||||
|
dbesc($rr['channel_hash']),
|
||||||
|
dbesc(z_root())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a verified hub location pointing to this site.
|
||||||
|
|
||||||
|
$h = hubloc_store_lowlevel(
|
||||||
|
[
|
||||||
|
'hubloc_guid' => $rr['channel_guid'],
|
||||||
|
'hubloc_guid_sig' => $rr['channel_guid_sig'],
|
||||||
|
'hubloc_hash' => $rr['channel_hash'],
|
||||||
|
'hubloc_id_url' => Channel::url($rr),
|
||||||
|
'hubloc_addr' => Channel::get_webfinger($rr),
|
||||||
|
'hubloc_primary' => intval($primary),
|
||||||
|
'hubloc_url' => z_root(),
|
||||||
|
'hubloc_url_sig' => Libzot::sign(z_root(), $rr['channel_prvkey']),
|
||||||
|
'hubloc_site_id' => Libzot::make_xchan_hash(z_root(), $sitekey),
|
||||||
|
'hubloc_host' => App::get_hostname(),
|
||||||
|
'hubloc_callback' => z_root() . '/nomad',
|
||||||
|
'hubloc_sitekey' => $sitekey,
|
||||||
|
'hubloc_network' => 'nomad',
|
||||||
|
'hubloc_updated' => datetime_convert(),
|
||||||
|
'hubloc_connected' => datetime_convert()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($h) {
|
||||||
|
$output .= 'local hubloc created for ' . $rr['channel_name'] . EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$output .= 'DB update failed for ' . $rr['channel_name'] . EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,8 +50,10 @@ class Receiver
|
||||||
|
|
||||||
if (!$this->Valid_Httpsig()) {
|
if (!$this->Valid_Httpsig()) {
|
||||||
logger('signature failed');
|
logger('signature failed');
|
||||||
|
logger(print_r($this->sigdata,true));
|
||||||
$this->error = true;
|
$this->error = true;
|
||||||
$this->response['message'] = 'signature invalid';
|
$this->response['message'] = 'signature invalid';
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue