consolidate hubloc storage

This commit is contained in:
zotlabs 2017-01-30 15:01:22 -08:00
parent eebea70019
commit 7b065365e0
18 changed files with 130 additions and 95 deletions

View File

@ -3,7 +3,6 @@
namespace Zotlabs\Daemon; namespace Zotlabs\Daemon;
require_once('include/zot.php'); require_once('include/zot.php');
require_once('include/hubloc.php');
class Checksites { class Checksites {

View File

@ -76,7 +76,6 @@ class Cron_daily {
Master::Summon(array('Expire')); Master::Summon(array('Expire'));
Master::Summon(array('Cli_suggest')); Master::Summon(array('Cli_suggest'));
require_once('include/hubloc.php');
remove_obsolete_hublocs(); remove_obsolete_hublocs();
call_hooks('cron_daily',datetime_convert()); call_hooks('cron_daily',datetime_convert());

View File

@ -17,7 +17,6 @@ class Cron_weekly {
z_check_cert(); z_check_cert();
require_once('include/hubloc.php');
prune_hub_reinstalls(); prune_hub_reinstalls();
mark_orphan_hubsxchans(); mark_orphan_hubsxchans();

View File

@ -15,7 +15,6 @@ class Queue {
$expert = ((array_key_exists('expert',$_REQUEST)) ? intval($_REQUEST['expert']) : 0); $expert = ((array_key_exists('expert',$_REQUEST)) ? intval($_REQUEST['expert']) : 0);
if($_REQUEST['drophub']) { if($_REQUEST['drophub']) {
require_once('hubloc.php');
hubloc_mark_as_down($_REQUEST['drophub']); hubloc_mark_as_down($_REQUEST['drophub']);
remove_queue_by_posturl($_REQUEST['drophub']); remove_queue_by_posturl($_REQUEST['drophub']);
} }

View File

@ -56,19 +56,21 @@ class Fhublocs extends \Zotlabs\Web\Controller {
// Create a verified hub location pointing to this site. // Create a verified hub location pointing to this site.
$h = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network )
values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", $h = hubloc_store_lowelevel(
dbesc($rr['channel_guid']), [
dbesc($rr['channel_guid_sig']), 'hubloc_guid' => $rr['channel_guid'],
dbesc($rr['channel_hash']), 'hubloc_guid_sig' => $rr['channel_guid_sig'],
dbesc(channel_reddress($rr)), 'hubloc_hash' => $rr['channel_hash'],
intval($primary), 'hubloc_addr' => channel_reddress($rr),
dbesc(z_root()), 'hubloc_network' => 'zot',
dbesc(base64url_encode(rsa_sign(z_root(),$rr['channel_prvkey']))), 'hubloc_primary' => $primary,
dbesc(\App::get_hostname()), 'hubloc_url' => z_root(),
dbesc(z_root() . '/post'), 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$rr['channel_prvkey'])),
dbesc($sitekey), 'hubloc_host' => \App::get_hostname(),
dbesc('zot') 'hubloc_callback' => z_root() . '/post',
'hubloc_sitekey' => $sitekey
]
); );
if($h) if($h)

View File

@ -206,23 +206,24 @@ class Import extends \Zotlabs\Web\Controller {
if($completed < 5) { if($completed < 5) {
// create new hubloc for the new channel at this site // create new hubloc for the new channel at this site
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, $r = hubloc_store_lowelevel(
hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey ) [
values ( '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s' )", 'hubloc_guid' => $channel['channel_guid'],
dbesc($channel['channel_guid']), 'hubloc_guid_sig' => $channel['channel_guid_sig'],
dbesc($channel['channel_guid_sig']), 'hubloc_hash' => $channel['channel_hash'],
dbesc($channel['channel_hash']), 'hubloc_addr' => channel_reddress($channel),
dbesc(channel_reddress($channel)), 'hubloc_network' => 'zot',
dbesc('zot'), 'hubloc_primary' => (($seize) ? 1 : 0),
intval(($seize) ? 1 : 0), 'hubloc_url' => z_root(),
dbesc(z_root()), 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), 'hubloc_host' => \App::get_hostname(),
dbesc(\App::get_hostname()), 'hubloc_callback' => z_root() . '/post',
dbesc(z_root() . '/post'), 'hubloc_sitekey' => get_config('system','pubkey'),
dbesc(get_config('system','pubkey')) 'hubloc_updated' => datetime_convert()
]
); );
// reset the original primary hubloc if it is being seized // reset the original primary hubloc if it is being seized
if($seize) { if($seize) {

View File

@ -46,6 +46,7 @@ require_once('include/connections.php');
require_once('include/account.php'); require_once('include/account.php');
require_once('include/zid.php'); require_once('include/zid.php');
require_once('include/xchan.php'); require_once('include/xchan.php');
require_once('include/hubloc.php');
define ( 'PLATFORM_NAME', 'hubzilla' ); define ( 'PLATFORM_NAME', 'hubzilla' );

View File

@ -1,7 +1,6 @@
<?php <?php
require_once('include/html2bbcode.php'); require_once('include/html2bbcode.php');
require_once('include/hubloc.php');
// Sample module for importing conversation data from Reflection CMS. Some preparation was used to // Sample module for importing conversation data from Reflection CMS. Some preparation was used to
// dump relevant posts, categories and comments into individual JSON files, and also JSON dump of // dump relevant posts, categories and comments into individual JSON files, and also JSON dump of

View File

@ -350,7 +350,6 @@
if(api_user() === false) if(api_user() === false)
return false; return false;
logger('api_xchan'); logger('api_xchan');
require_once('include/hubloc.php');
if($_SERVER['REQUEST_METHOD'] === 'POST') { if($_SERVER['REQUEST_METHOD'] === 'POST') {
$r = xchan_store($_REQUEST); $r = xchan_store($_REQUEST);

View File

@ -7,7 +7,7 @@
require_once('include/oembed.php'); require_once('include/oembed.php');
require_once('include/event.php'); require_once('include/event.php');
require_once('include/zot.php'); require_once('include/zot.php');
require_once('include/hubloc.php');
function tryoembed($match) { function tryoembed($match) {
$url = ((count($match) == 2) ? $match[1] : $match[2]); $url = ((count($match) == 2) ? $match[1] : $match[2]);

View File

@ -23,7 +23,6 @@ function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) {
$iarr['mitem_desc'] = $taxonomy['term']; $iarr['mitem_desc'] = $taxonomy['term'];
$iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0); $iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0);
require_once('include/hubloc.php');
$zrl = is_matrix_url($taxonomy['url']); $zrl = is_matrix_url($taxonomy['url']);
if($zrl) if($zrl)

View File

@ -291,20 +291,21 @@ function create_identity($arr) {
// Create a verified hub location pointing to this site. // Create a verified hub location pointing to this site.
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary, $r = hubloc_store_lowlevel(
hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network ) [
values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", 'hubloc_guid' => $guid,
dbesc($guid), 'hubloc_guid_sig' => $sig,
dbesc($sig), 'hubloc_hash' => $hash,
dbesc($hash), 'hubloc_addr' => channel_reddress($ret['channel']),
dbesc(channel_reddress($ret['channel'])), 'hubloc_primary' => $primary,
intval($primary), 'hubloc_url' => z_root(),
dbesc(z_root()), 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey'])),
dbesc(base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey']))), 'hubloc_host' => App::get_hostname(),
dbesc(App::get_hostname()), 'hubloc_callback' => z_root() . '/post',
dbesc(z_root() . '/post'), 'hubloc_sitekey' => get_config('system','pubkey'),
dbesc(get_config('system','pubkey')), 'hubloc_network' => 'zot',
dbesc('zot') 'hubloc_updated' => datetime_convert()
]
); );
if(! $r) if(! $r)
logger('create_identity: Unable to store hub location'); logger('create_identity: Unable to store hub location');

View File

@ -1,5 +1,36 @@
<?php /** @file */ <?php /** @file */
function hubloc_store_lowlevel($arr) {
$store = [
'hubloc_guid' => ((array_key_exists('hubloc_guid',$arr)) ? $arr['hubloc_guid'] : ''),
'hubloc_guid_sig' => ((array_key_exists('hubloc_guid_sig',$arr)) ? $arr['hubloc_guid_sig'] : ''),
'hubloc_hash' => ((array_key_exists('hubloc_hash',$arr)) ? $arr['hubloc_hash'] : ''),
'hubloc_addr' => ((array_key_exists('hubloc_addr',$arr)) ? $arr['hubloc_addr'] : ''),
'hubloc_network' => ((array_key_exists('hubloc_network',$arr)) ? $arr['hubloc_network'] : ''),
'hubloc_flags' => ((array_key_exists('hubloc_flags',$arr)) ? $arr['hubloc_flags'] : 0),
'hubloc_status' => ((array_key_exists('hubloc_status',$arr)) ? $arr['hubloc_status'] : 0),
'hubloc_url' => ((array_key_exists('hubloc_url',$arr)) ? $arr['hubloc_url'] : ''),
'hubloc_url_sig' => ((array_key_exists('hubloc_url_sig',$arr)) ? $arr['hubloc_url_sig'] : ''),
'hubloc_host' => ((array_key_exists('hubloc_host',$arr)) ? $arr['hubloc_host'] : ''),
'hubloc_callback' => ((array_key_exists('hubloc_callback',$arr)) ? $arr['hubloc_callback'] : ''),
'hubloc_connect' => ((array_key_exists('hubloc_connect',$arr)) ? $arr['hubloc_connect'] : ''),
'hubloc_sitekey' => ((array_key_exists('hubloc_sitekey',$arr)) ? $arr['hubloc_sitekey'] : ''),
'hubloc_updated' => ((array_key_exists('hubloc_updated',$arr)) ? $arr['hubloc_updated'] : NULL_DATE),
'hubloc_connected' => ((array_key_exists('hubloc_connected',$arr)) ? $arr['hubloc_connected'] : NULL_DATE),
'hubloc_primary' => ((array_key_exists('hubloc_primary',$arr)) ? $arr['hubloc_primary'] : 0),
'hubloc_orphancheck' => ((array_key_exists('hubloc_orphancheck',$arr)) ? $arr['hubloc_orphancheck'] : 0),
'hubloc_error' => ((array_key_exists('hubloc_error',$arr)) ? $arr['hubloc_error'] : 0),
'hubloc_deleted' => ((array_key_exists('hubloc_deleted',$arr)) ? $arr['hubloc_deleted'] : 0)
];
return create_table_from_array('hubloc',$store);
}
function prune_hub_reinstalls() { function prune_hub_reinstalls() {
$r = q("select site_url from site where site_type = %d", $r = q("select site_url from site where site_type = %d",

View File

@ -1469,15 +1469,18 @@ function discover_by_webbie($webbie) {
); );
if(! $r) { if(! $r) {
$r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_primary ) values ('%s','%s','%s','%s','%s','%s','%s','%s', 1)", $r = hubloc_store_lowlevel(
dbesc(($diaspora_guid) ? $diaspora_guid : $location), [
dbesc($address), 'hubloc_guid' => (($diaspora_guid) ? $diaspora_guid : $location),
dbesc($address), 'hubloc_hash' => $address,
dbesc($network), 'hubloc_addr' => $address,
dbesc($base), 'hubloc_network' => $network,
dbesc($host), 'hubloc_url' => $base,
dbesc($notify), 'hubloc_host' => $host,
dbescdate(datetime_convert()) 'hubloc_callback' => $notify,
'hubloc_updated' => datetime_convert(),
'hubloc_primary' => 1
]
); );
} }
$photos = import_xchan_photo($avatar,$address); $photos = import_xchan_photo($avatar,$address);

View File

@ -2,8 +2,6 @@
use Zotlabs\Lib as Zlib; use Zotlabs\Lib as Zlib;
require_once('include/hubloc.php');
function oembed_replacecb($matches){ function oembed_replacecb($matches){

View File

@ -4,7 +4,7 @@
*/ */
require_once("include/bbcode.php"); require_once("include/bbcode.php");
require_once('include/hubloc.php');
// random string, there are 86 characters max in text mode, 128 for hex // random string, there are 86 characters max in text mode, 128 for hex
// output is urlsafe // output is urlsafe

View File

@ -170,7 +170,7 @@ function zidify_text($s) {
* @return string * @return string
*/ */
function red_zrl_callback($matches) { function red_zrl_callback($matches) {
require_once('include/hubloc.php');
$zrl = is_matrix_url($matches[2]); $zrl = is_matrix_url($matches[2]);
$t = strip_zids($matches[2]); $t = strip_zids($matches[2]);
@ -215,7 +215,7 @@ function red_unescape_codeblock($m) {
function red_zrlify_img_callback($matches) { function red_zrlify_img_callback($matches) {
require_once('include/hubloc.php');
$zrl = is_matrix_url($matches[2]); $zrl = is_matrix_url($matches[2]);
$t = strip_zids($matches[2]); $t = strip_zids($matches[2]);

View File

@ -10,7 +10,6 @@
require_once('include/crypto.php'); require_once('include/crypto.php');
require_once('include/items.php'); require_once('include/items.php');
require_once('include/hubloc.php');
require_once('include/queue_fn.php'); require_once('include/queue_fn.php');
require_once('include/perm_upgrade.php'); require_once('include/perm_upgrade.php');
@ -2469,22 +2468,25 @@ function sync_locations($sender, $arr, $absolute = false) {
); );
} }
logger('sync_locations: new hub: ' . $location['url']); logger('sync_locations: new hub: ' . $location['url']);
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected)
values ( '%s','%s','%s','%s', '%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", $r = hubloc_store_lowlevel(
dbesc($sender['guid']), [
dbesc($sender['guid_sig']), 'hubloc_guid' => $sender['guid'],
dbesc($sender['hash']), 'hubloc_guid_sig' => $sender['guid_sig'],
dbesc($location['address']), 'hubloc_hash' => $sender['hash'],
dbesc('zot'), 'hubloc_addr' => $location['address'],
intval($location['primary']), 'hubloc_network' => 'zot',
dbesc($location['url']), 'hubloc_primary' => $location['primary'],
dbesc($location['url_sig']), 'hubloc_url' => $location['url'],
dbesc($location['host']), 'hubloc_url_sig' => $location['url_sig'],
dbesc($location['callback']), 'hubloc_host' => $location['host'],
dbesc($location['sitekey']), 'hubloc_callback' => $location['callback'],
dbesc(datetime_convert()), 'hubloc_sitekey' => $location['sitekey'],
dbesc(datetime_convert()) 'hubloc_updated' => datetime_convert(),
'hubloc_connected' => datetime_convert()
]
); );
$what .= 'newhub '; $what .= 'newhub ';
$changed = true; $changed = true;
@ -4057,21 +4059,24 @@ function check_zotinfo($channel,$locations,&$ret) {
q("delete from hubloc where hubloc_hash = '%s'", q("delete from hubloc where hubloc_hash = '%s'",
dbesc($channel['channel_hash']) dbesc($channel['channel_hash'])
); );
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary,
hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network ) $r = hubloc_store_lowelevel(
values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", [
dbesc($channel['channel_guid']), 'hubloc_guid' => $channel['channel_guid'],
dbesc($channel['channel_guid_sig']), 'hubloc_guid_sig' => $channel['channel_guid_sig'],
dbesc($channel['channel_hash']), 'hubloc_hash' => $channel['channel_hash'],
dbesc(channel_reddress($channel)), 'hubloc_addr' => channel_reddress($channel),
intval(1), 'hubloc_network' => 'zot',
dbesc(z_root()), 'hubloc_primary' => 1,
dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), 'hubloc_url' => z_root(),
dbesc(App::get_hostname()), 'hubloc_url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])),
dbesc(z_root() . '/post'), 'hubloc_host' => App::get_hostname(),
dbesc(get_config('system','pubkey')), 'hubloc_callback' => z_root() . '/post',
dbesc('zot') 'hubloc_sitekey' => get_config('system','pubkey'),
'hubloc_updated' => datetime_convert(),
]
); );
if($r) { if($r) {
$x = zot_encode_locations($channel); $x = zot_encode_locations($channel);
if($x) { if($x) {