diff options
Diffstat (limited to 'Zotlabs/Daemon')
-rw-r--r-- | Zotlabs/Daemon/Checksites.php | 3 | ||||
-rw-r--r-- | Zotlabs/Daemon/Cron_daily.php | 14 | ||||
-rw-r--r-- | Zotlabs/Daemon/Deliver.php | 70 | ||||
-rw-r--r-- | Zotlabs/Daemon/Directory.php | 3 | ||||
-rw-r--r-- | Zotlabs/Daemon/Gprobe.php | 2 | ||||
-rw-r--r-- | Zotlabs/Daemon/Notifier.php | 127 | ||||
-rw-r--r-- | Zotlabs/Daemon/Onedirsync.php | 20 | ||||
-rw-r--r-- | Zotlabs/Daemon/Poller.php | 4 | ||||
-rw-r--r-- | Zotlabs/Daemon/Ratenotif.php | 5 |
9 files changed, 101 insertions, 147 deletions
diff --git a/Zotlabs/Daemon/Checksites.php b/Zotlabs/Daemon/Checksites.php index a2081967a..3bcfdd7cf 100644 --- a/Zotlabs/Daemon/Checksites.php +++ b/Zotlabs/Daemon/Checksites.php @@ -2,8 +2,7 @@ namespace Zotlabs\Daemon; -require_once('include/zot.php'); - +require_once('include/hubloc.php'); class Checksites { diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php index 07533cc6e..a6daad051 100644 --- a/Zotlabs/Daemon/Cron_daily.php +++ b/Zotlabs/Daemon/Cron_daily.php @@ -2,6 +2,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Lib\Libzotdir; + class Cron_daily { static public function run($argc,$argv) { @@ -14,12 +16,11 @@ class Cron_daily { */ - require_once('include/dir_fns.php'); - check_upstream_directory(); + Libzotdir::check_upstream_directory(); // Fire off the Cron_weekly process if it's the correct day. - + $d3 = intval(datetime_convert('UTC','UTC','now','N')); if($d3 == 7) { Master::Summon(array('Cron_weekly')); @@ -80,15 +81,14 @@ class Cron_daily { downgrade_accounts(); // If this is a directory server, request a sync with an upstream - // directory at least once a day, up to once every poll interval. + // directory at least once a day, up to once every poll interval. // Pull remote changes and push local changes. - // potential issue: how do we keep from creating an endless update loop? + // potential issue: how do we keep from creating an endless update loop? $dirmode = get_config('system','directory_mode'); if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { - require_once('include/dir_fns.php'); - sync_directories($dirmode); + Libzotdir::sync_directories($dirmode); } diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php index 43f426eb7..c853af6a8 100644 --- a/Zotlabs/Daemon/Deliver.php +++ b/Zotlabs/Daemon/Deliver.php @@ -2,12 +2,8 @@ namespace Zotlabs\Daemon; -use Zotlabs\Lib\DReport; - -require_once('include/zot.php'); require_once('include/queue_fn.php'); - class Deliver { static public function run($argc,$argv) { @@ -22,72 +18,16 @@ class Deliver { if(! $argv[$x]) continue; - $dresult = null; - $r = q("select * from outq where outq_hash = '%s' limit 1", + $r = q("select * from outq where outq_hash = '%s'", dbesc($argv[$x]) ); - if($r) { - - $notify = json_decode($r[0]['outq_notify'],true); - - // Messages without an outq_msg will need to go via the web, even if it's a - // local delivery. This includes conversation requests and refresh packets. - - if(($r[0]['outq_posturl'] === z_root() . '/post') && ($r[0]['outq_msg'])) { - logger('deliver: local delivery', LOGGER_DEBUG); - - // local delivery - // we should probably batch these and save a few delivery processes - - if($r[0]['outq_msg']) { - $m = json_decode($r[0]['outq_msg'],true); - if(array_key_exists('message_list',$m)) { - foreach($m['message_list'] as $mm) { - $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $mm))))); - zot_import($msg,z_root()); - } - } - else { - $msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m))))); - $dresult = zot_import($msg,z_root()); - } - - remove_queue_item($r[0]['outq_hash']); - - if($dresult && is_array($dresult)) { - - // delivery reports for local deliveries do not require encryption - - foreach($dresult as $xx) { - if(is_array($xx) && array_key_exists('message_id',$xx)) { - if(DReport::is_storable($xx)) { - q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", - dbesc($xx['message_id']), - dbesc($xx['location']), - dbesc($xx['recipient']), - dbesc(($xx['name']) ? $xx['name'] : EMPTY_STR), - dbesc($xx['status']), - dbesc(datetime_convert($xx['date'])), - dbesc($xx['sender']) - ); - } - } - } - } - - q("delete from dreport where dreport_queue = '%s'", - dbesc($argv[$x]) - ); - - continue; - } - } - - // otherwise it's a remote delivery - call queue_deliver() with the $immediate flag + if($r) { queue_deliver($r[0],true); - } + } + } + } diff --git a/Zotlabs/Daemon/Directory.php b/Zotlabs/Daemon/Directory.php index c698995c2..ab58432de 100644 --- a/Zotlabs/Daemon/Directory.php +++ b/Zotlabs/Daemon/Directory.php @@ -58,7 +58,8 @@ class Directory { // otherwise send the changes upstream $directory = Libzotdir::find_upstream_directory($dirmode); - $url = $directory['url'] . '/post'; + + $url = $directory['url'] . '/zot'; // ensure the upstream directory is updated diff --git a/Zotlabs/Daemon/Gprobe.php b/Zotlabs/Daemon/Gprobe.php index 6951aa1d4..9e74eb8b5 100644 --- a/Zotlabs/Daemon/Gprobe.php +++ b/Zotlabs/Daemon/Gprobe.php @@ -19,7 +19,7 @@ class Gprobe { if(! strpos($url,'@')) return; - $r = q("select * from hubloc where hubloc_addr = '%s' limit 1", + $r = q("select * from hubloc where hubloc_addr = '%s' and hubloc_network = 'zot6' limit 1", dbesc($url) ); diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 8ea75af61..626299661 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -4,6 +4,7 @@ namespace Zotlabs\Daemon; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Activity; +use Zotlabs\Lib\Queue; require_once('include/queue_fn.php'); require_once('include/html2plain.php'); @@ -16,26 +17,26 @@ require_once('include/bbcode.php'); /* * This file was at one time responsible for doing all deliveries, but this caused - * big problems on shared hosting systems, where the process might get killed by the - * hosting provider and nothing would get delivered. + * big problems on shared hosting systems, where the process might get killed by the + * hosting provider and nothing would get delivered. * It now only delivers one message under certain cases, and invokes a queued - * delivery mechanism (include/deliver.php) to deliver individual contacts at + * delivery mechanism (include/deliver.php) to deliver individual contacts at * controlled intervals. * This has a much better chance of surviving random processes getting killed - * by the hosting provider. + * by the hosting provider. * * The basic flow is: * Identify the type of message * Collect any information that needs to be sent * Convert it into a suitable generic format for sending - * Figure out who the recipients are and if we need to relay + * Figure out who the recipients are and if we need to relay * through a conversation owner - * Once we know what recipients are involved, collect a list of + * Once we know what recipients are involved, collect a list of * destination sites * Build and store a queue item for each unique site and invoke * a delivery process for each site or a small number of sites (1-3) * and add a slight delay between each delivery invocation if desired (usually) - * + * */ /* @@ -60,7 +61,7 @@ require_once('include/bbcode.php'); * * and ITEM_ID is the id of the item in the database that needs to be sent to others. * - * ZOT + * ZOT * permission_create abook_id * permission_accept abook_id * permission_reject abook_id @@ -166,7 +167,7 @@ class Notifier { $normal_mode = false; } elseif(in_array($cmd, [ 'permission_update', 'permission_reject', 'permission_accept', 'permission_create' ])) { - // Get the (single) recipient + // Get the (single) recipient $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_self = 0", intval($item_id) ); @@ -175,7 +176,7 @@ class Notifier { // Get the sender $channel = channelx_by_n($uid); if($channel) { - $perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => ''); + $perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => ''); if($cmd === 'permission_create') call_hooks('permissions_create',$perm_update); @@ -191,7 +192,7 @@ class Notifier { $deliveries[] = $perm_update['deliveries']; do_delivery($deliveries); } - return; + return; } else { $recipients[] = $r[0]['abook_xchan']; @@ -235,7 +236,7 @@ class Notifier { } } - $encoded_item = array('locations' => zot_encode_locations($channel),'type' => 'location', 'encoding' => 'zot'); + $encoded_item = array('locations' => Libzot::encode_locations($channel),'type' => 'location', 'encoding' => 'zot'); $target_item = array('aid' => $channel['channel_account_id'],'uid' => $channel['channel_id']); $private = false; $packet_type = 'location'; @@ -292,7 +293,7 @@ class Notifier { xchan_query($r); $r = fetch_post_tags($r); - + $target_item = $r[0]; if(in_array($target_item['author']['xchan_network'], ['rss', 'anon'])) { @@ -328,7 +329,7 @@ class Notifier { // Check for non published items, but allow an exclusion for transmitting hidden file activities if(intval($target_item['item_unpublished']) || intval($target_item['item_delayed']) || - intval($target_item['item_blocked']) || + intval($target_item['item_blocked']) || ( intval($target_item['item_hidden']) && ($target_item['obj_type'] !== ACTIVITY_OBJ_FILE))) { logger('notifier: target item not published, so not forwardable', LOGGER_DEBUG); return; @@ -371,7 +372,7 @@ class Notifier { xchan_query($r); $r = fetch_post_tags($r); - + $parent_item = $r[0]; $top_level_post = false; } @@ -396,7 +397,7 @@ class Notifier { z_root() . ZOT_APSCHEMA_REV ]], Activity::encode_activity($target_item) ); - } + } logger('target_item: ' . print_r($target_item,true), LOGGER_DEBUG); logger('encoded: ' . print_r($activity,true), LOGGER_DEBUG); @@ -404,11 +405,11 @@ class Notifier { // Send comments to the owner to re-deliver to everybody in the conversation // We only do this if the item in question originated on this site. This prevents looping. // To clarify, a site accepting a new comment is responsible for sending it to the owner for relay. - // Relaying should never be initiated on a post that arrived from elsewhere. + // Relaying should never be initiated on a post that arrived from elsewhere. // We should normally be able to rely on ITEM_ORIGIN, but start_delivery_chain() incorrectly set this // flag on comments for an extended period. So we'll also call comment_local_origin() which looks at - // the hostname in the message_id and provides a second (fallback) opinion. + // the hostname in the message_id and provides a second (fallback) opinion. $relay_to_owner = (((! $top_level_post) && (intval($target_item['item_origin'])) && comment_local_origin($target_item)) ? true : false); @@ -425,9 +426,9 @@ class Notifier { // tag_deliver'd post which needs to be sent back to the original author if(($cmd === 'uplink') && intval($parent_item['item_uplink']) && (! $top_level_post)) { - logger('notifier: uplink'); + logger('notifier: uplink'); $uplink = true; - } + } if(($relay_to_owner || $uplink) && ($cmd !== 'relay')) { logger('notifier: followup relay', LOGGER_DEBUG); @@ -444,8 +445,8 @@ class Notifier { logger('notifier: owner relay'); $upstream = false; // if our parent is a tag_delivery recipient, uplink to the original author causing - // a delivery fork. - + // a delivery fork. + if(($parent_item) && intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) { // don't uplink a relayed post to the relay owner if($parent_item['source_xchan'] !== $parent_item['owner_xchan']) { @@ -461,21 +462,14 @@ class Notifier { if ($top_level_post) { // remove clones who will receive the post via sync $recipients = array_diff($recipients, [ $target_item['owner_xchan'] ]); - } + } // FIXME add any additional recipients such as mentions, etc. - // don't send deletions onward for other people's stuff - // TODO verify this is needed - copied logic from same place in old code - - if(intval($target_item['item_deleted']) && (! intval($target_item['item_wall']))) { - logger('notifier: ignoring delete notification for non-wall item', LOGGER_NORMAL, LOG_NOTICE); - return; - } } } - $walltowall = (($top_level_post && $channel['xchan_hash'] === $target_item['author_xchan']) ? true : false); + $walltowall = (($top_level_post && $channel['xchan_hash'] === $target_item['author_xchan']) ? true : false); // Generic delivery section, we have an encoded item and recipients // Now start the delivery process @@ -504,7 +498,7 @@ class Notifier { if($details) { foreach($details as $d) { - $recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')'; + $recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')'; if($private) { $env_recips[] = [ 'guid' => $d['xchan_guid'], @@ -556,19 +550,19 @@ class Notifier { // shouldn't happen logger('notifier: private message with no envelope recipients.' . print_r($argv,true), LOGGER_NORMAL, LOG_NOTICE); } - + logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list,true), LOGGER_DEBUG); - + // Now we have collected recipients (except for external mentions, FIXME) // Let's reduce this to a set of hubs; checking that the site is not dead. - $hubs = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc left join site on site_url = hubloc_url - where hubloc_hash in (" . protect_sprintf(implode(',',$recipients)) . ") + $hubs = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc left join site on site_url = hubloc_url + where hubloc_hash in (" . protect_sprintf(implode(',',$recipients)) . ") and hubloc_error = 0 and hubloc_deleted = 0" ); - // public posts won't make it to the local public stream unless there's a recipient on this site. + // public posts won't make it to the local public stream unless there's a recipient on this site. // This code block sees if it's a public post and localhost is missing, and if so adds an entry for the local sys channel to the $hubs list if (! $private) { @@ -582,7 +576,7 @@ class Notifier { } } if (! $found_localhost) { - $localhub = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc + $localhub = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project, site.site_dead from hubloc left join site on site_url = hubloc_url where hubloc_id_url = '%s' and hubloc_error = 0 and hubloc_deleted = 0", dbesc(z_root() . '/channel/sys') ); @@ -591,14 +585,14 @@ class Notifier { } } } - + if(! $hubs) { logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE); return; } /** - * Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey, + * Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey, * since it may have been a re-install which has not yet been detected and pruned. * For other networks which don't have or require sitekeys, we'll have to use the URL */ @@ -628,7 +622,7 @@ class Notifier { } } } - + if($hub['hubloc_network'] == 'zot') { if(! in_array($hub['hubloc_sitekey'],$keys)) { @@ -639,9 +633,16 @@ class Notifier { } else { if(! in_array($hub['hubloc_url'],$urls)) { - $hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network']; - $dhubs[] = $hub; - $urls[] = $hub['hubloc_url']; + if($hub['hubloc_url'] === z_root()) { + //deliver to local hub first + array_unshift($hublist, $hub['hubloc_host'] . ' ' . $hub['hubloc_network']); + array_unshift($dhubs, $hub); + } + else { + $hublist[] = $hub['hubloc_host'] . ' ' . $hub['hubloc_network']; + $dhubs[] = $hub; + } + $urls[] = $hub['hubloc_url']; } } } @@ -706,8 +707,8 @@ class Notifier { } // Do not change this to a uuid as long as we have traditional zot servers - // in the loop. The signature verification step can't handle dashes in the - // hashes. + // in the loop. The signature verification step can't handle dashes in the + // hashes. $hash = random_string(48); @@ -734,15 +735,17 @@ class Notifier { } if($packet) { - queue_insert(array( - 'hash' => $hash, - 'account_id' => $channel['channel_account_id'], - 'channel_id' => $channel['channel_id'], - 'posturl' => $hub['hubloc_callback'], - 'driver' => $hub['hubloc_network'], - 'notify' => $packet, - 'msg' => (($pmsg) ? json_encode($pmsg) : '') - )); + Queue::insert( + [ + 'hash' => $hash, + 'account_id' => $channel['channel_account_id'], + 'channel_id' => $channel['channel_id'], + 'posturl' => $hub['hubloc_callback'], + 'driver' => $hub['hubloc_network'], + 'notify' => $packet, + 'msg' => (($pmsg) ? json_encode($pmsg) : '') + ] + ); } else { $env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : ''); @@ -756,13 +759,13 @@ class Notifier { } } - $packet_type = (($upstream || $uplink) ? 'response' : 'activity'); + $packet_type = (($upstream || $uplink) ? 'response' : 'activity'); // block zot private reshares from zot6, as this could cause a number of privacy issues // due to parenting differences between the reshare implementations. In zot a reshare is // a standalone parent activity and in zot6 it is a followup/child of the original activity. // For public reshares, some comments to the reshare on the zot fork will not make it to zot6 - // due to these different message models. This cannot be prevented at this time. + // due to these different message models. This cannot be prevented at this time. if($packet_type === 'activity' && $activity['type'] === 'Announce' && intval($target_item['item_private'])) { continue; @@ -772,7 +775,7 @@ class Notifier { } else { // currently zot6 delivery is only performed on normal items and not sync items or mail or anything else - // Eventually we will do this for all deliveries, but for now ensure this is precisely what we are dealing + // Eventually we will do this for all deliveries, but for now ensure this is precisely what we are dealing // with before switching to zot6 as the primary zot6 handler checks for the existence of a message delivery report // to trigger dequeue'ing @@ -803,7 +806,7 @@ class Notifier { } } - queue_insert( + Queue::insert( [ 'hash' => $hash, 'account_id' => $target_item['aid'], @@ -829,9 +832,9 @@ class Notifier { } } - $deliveries[] = $hash; + $deliveries[] = $hash; } - + if($normal_mode) { $x = q("select * from hook where hook = 'notifier_normal'"); if($x) { @@ -847,7 +850,7 @@ class Notifier { if ($dead) { foreach ($dead as $deceased) { if (is_array($target_item) && (! $target_item['item_deleted']) && (! get_config('system','disable_dreport'))) { - q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_queue ) + q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s', '%s','%s','%s','%s','%s','%s','%s' ) ", dbesc($target_item['mid']), dbesc($deceased['hubloc_host']), diff --git a/Zotlabs/Daemon/Onedirsync.php b/Zotlabs/Daemon/Onedirsync.php index cc16c0b58..a952b8117 100644 --- a/Zotlabs/Daemon/Onedirsync.php +++ b/Zotlabs/Daemon/Onedirsync.php @@ -2,6 +2,9 @@ namespace Zotlabs\Daemon; +use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Libzotdir; + require_once('include/zot.php'); require_once('include/dir_fns.php'); @@ -11,7 +14,7 @@ class Onedirsync { static public function run($argc,$argv) { logger('onedirsync: start ' . intval($argv[1])); - + if(($argc > 1) && (intval($argv[1]))) $update_id = intval($argv[1]); @@ -19,7 +22,7 @@ class Onedirsync { logger('onedirsync: no update'); return; } - + $r = q("select * from updates where ud_id = %d limit 1", intval($update_id) ); @@ -50,10 +53,13 @@ class Onedirsync { // 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", + $h = q("select * from hubloc where hubloc_addr = '%s'", dbesc($r[0]['ud_addr']) ); - if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) { + + $h = Libzot::zot_record_preferred($h); + + if(($h) && ($h['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']), @@ -63,13 +69,13 @@ class Onedirsync { return; } - // we might have to pull this out some day, but for now update_directory_entry() + // 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 && $h[0]['hubloc_network'] !== 'zot') + if($h && ! in_array($h['hubloc_network'], ['zot6', 'zot'])) return; - update_directory_entry($r[0]); + Libzotdir::update_directory_entry($r[0]); return; } diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index ebc0584ba..dfa628193 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -55,7 +55,6 @@ class Poller { $force = true; } - $sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : ""); reload_plugins(); @@ -86,7 +85,6 @@ class Poller { ); if($contacts) { - foreach($contacts as $contact) { $update = false; @@ -174,6 +172,8 @@ class Poller { } } + $dirmode = intval(get_config('system', 'directory_mode')); + if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { $r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last <= '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ", intval(UPDATE_FLAGS_UPDATED), diff --git a/Zotlabs/Daemon/Ratenotif.php b/Zotlabs/Daemon/Ratenotif.php index c7bf79854..8afde2c4c 100644 --- a/Zotlabs/Daemon/Ratenotif.php +++ b/Zotlabs/Daemon/Ratenotif.php @@ -10,6 +10,11 @@ class Ratenotif { static public function run($argc,$argv) { + + // Deprecated + return; + + require_once("datetime.php"); require_once('include/items.php'); |