diff options
author | zotlabs <mike@macgirvin.com> | 2018-11-12 16:08:22 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2018-11-12 16:08:22 -0800 |
commit | 770fdb2b7d095d763d43ffe8d2f6b5b2182673cb (patch) | |
tree | b3e991040552b9f7b1d71487bf24b806b2e86aa3 | |
parent | 171ff54ea407595a85e971f62abc556faf3dec73 (diff) | |
download | volse-hubzilla-770fdb2b7d095d763d43ffe8d2f6b5b2182673cb.tar.gz volse-hubzilla-770fdb2b7d095d763d43ffe8d2f6b5b2182673cb.tar.bz2 volse-hubzilla-770fdb2b7d095d763d43ffe8d2f6b5b2182673cb.zip |
dreport updates
-rw-r--r-- | Zotlabs/Daemon/Deliver.php | 7 | ||||
-rw-r--r-- | Zotlabs/Lib/DReport.php | 84 | ||||
-rw-r--r-- | Zotlabs/Module/Dreport.php | 20 | ||||
-rw-r--r-- | include/zot.php | 10 | ||||
-rw-r--r-- | install/schema_mysql.sql | 1 | ||||
-rw-r--r-- | install/schema_postgres.sql | 1 |
6 files changed, 110 insertions, 13 deletions
diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php index b809cba91..43f426eb7 100644 --- a/Zotlabs/Daemon/Deliver.php +++ b/Zotlabs/Daemon/Deliver.php @@ -2,6 +2,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Lib\DReport; + require_once('include/zot.php'); require_once('include/queue_fn.php'); @@ -58,11 +60,12 @@ class Deliver { foreach($dresult as $xx) { if(is_array($xx) && array_key_exists('message_id',$xx)) { - if(delivery_report_is_storable($xx)) { - q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", + 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']) diff --git a/Zotlabs/Lib/DReport.php b/Zotlabs/Lib/DReport.php index a68d6c18f..21b320cac 100644 --- a/Zotlabs/Lib/DReport.php +++ b/Zotlabs/Lib/DReport.php @@ -14,6 +14,7 @@ class DReport { $this->location = $location; $this->sender = $sender; $this->recipient = $recipient; + $this->name = EMPTY_STR; $this->message_id = $message_id; $this->status = $status; $this->date = datetime_convert(); @@ -24,8 +25,8 @@ class DReport { $this->date = datetime_convert(); } - function addto_recipient($name) { - $this->recipient = $this->recipient . ' ' . $name; + function set_name($name) { + $this->name = $name; } function addto_update($status) { @@ -37,6 +38,7 @@ class DReport { $this->location = $arr['location']; $this->sender = $arr['sender']; $this->recipient = $arr['recipient']; + $this->name = $arr['name']; $this->message_id = $arr['message_id']; $this->status = $arr['status']; $this->date = $arr['date']; @@ -47,9 +49,87 @@ class DReport { 'location' => $this->location, 'sender' => $this->sender, 'recipient' => $this->recipient, + 'name' => $this->name, 'message_id' => $this->message_id, 'status' => $this->status, 'date' => $this->date ); } + + /** + * @brief decide whether to store a returned delivery report + * + * @param array $dr + * @return boolean + */ + + static function is_storable($dr) { + + if(get_config('system', 'disable_dreport')) + return false; + + /** + * @hooks dreport_is_storable + * Called before storing a dreport record to determine whether to store it. + * * \e array + */ + + call_hooks('dreport_is_storable', $dr); + + // let plugins accept or reject - if neither, continue on + if(array_key_exists('accept',$dr) && intval($dr['accept'])) + return true; + if(array_key_exists('reject',$dr) && intval($dr['reject'])) + return false; + + if(! ($dr['sender'])) + return false; + + // Is the sender one of our channels? + + $c = q("select channel_id from channel where channel_hash = '%s' limit 1", + dbesc($dr['sender']) + ); + if(! $c) + return false; + + + // is the recipient one of our connections, or do we want to store every report? + + + $rxchan = $dr['recipient']; + $pcf = get_pconfig($c[0]['channel_id'],'system','dreport_store_all'); + if($pcf) + return true; + + // We always add ourself as a recipient to private and relayed posts + // So if a remote site says they can't find us, that's no big surprise + // and just creates a lot of extra report noise + + if(($dr['location'] !== z_root()) && ($dr['sender'] === $rxchan) && ($dr['status'] === 'recipient_not_found')) + return false; + + // If you have a private post with a recipient list, every single site is going to report + // back a failed delivery for anybody on that list that isn't local to them. We're only + // concerned about this if we have a local hubloc record which says we expected them to + // have a channel on that site. + + $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_url = '%s'", + dbesc($rxchan), + dbesc($dr['location']) + ); + if((! $r) && ($dr['status'] === 'recipient_not_found')) + return false; + + $r = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($rxchan), + intval($c[0]['channel_id']) + ); + if($r) + return true; + + return false; + } + + } diff --git a/Zotlabs/Module/Dreport.php b/Zotlabs/Module/Dreport.php index 76e07b147..16ae7941f 100644 --- a/Zotlabs/Module/Dreport.php +++ b/Zotlabs/Module/Dreport.php @@ -17,9 +17,17 @@ class Dreport extends \Zotlabs\Web\Controller { $mid = ((argc() > 1) ? argv(1) : ''); + if(strpos($mid,'b64.') === 0) + $mid = @base64url_decode(substr($mid,4)); + + if($mid === 'push') { $table = 'push'; $mid = ((argc() > 2) ? argv(2) : ''); + + if(strpos($mid,'b64.') === 0) + $mid = @base64url_decode(substr($mid,4)); + if($mid) { $i = q("select id from item where mid = '%s' and uid = %d and ( author_xchan = '%s' or ( owner_xchan = '%s' and item_wall = 1 )) ", dbesc($mid), @@ -38,6 +46,9 @@ class Dreport extends \Zotlabs\Web\Controller { if($mid === 'mail') { $table = 'mail'; $mid = ((argc() > 2) ? argv(2) : ''); + if(strpos($mid,'b64.') === 0) + $mid = @base64url_decode(substr($mid,4)); + } @@ -80,7 +91,6 @@ class Dreport extends \Zotlabs\Web\Controller { } for($x = 0; $x < count($r); $x++ ) { - $r[$x]['name'] = escape_tags(substr($r[$x]['dreport_recip'],strpos($r[$x]['dreport_recip'],' '))); // This has two purposes: 1. make the delivery report strings translateable, and // 2. assign an ordering to item delivery results so we can group them and provide @@ -138,14 +148,14 @@ class Dreport extends \Zotlabs\Web\Controller { $entries = array(); foreach($r as $rr) { $entries[] = [ - 'name' => $rr['name'], + 'name' => escape_tags($rr['dreport_name'] ?: $rr['dreport_recip']), 'result' => escape_tags($rr['dreport_result']), 'time' => escape_tags(datetime_convert('UTC',date_default_timezone_get(),$rr['dreport_time'])) ]; } $o = replace_macros(get_markup_template('dreport.tpl'), array( - '$title' => sprintf( t('Delivery report for %1$s'),substr($mid,0,32)) . '...', + '$title' => sprintf( t('Delivery report for %1$s'),basename($mid)) . '...', '$table' => $table, '$mid' => urlencode($mid), '$options' => t('Options'), @@ -162,9 +172,9 @@ class Dreport extends \Zotlabs\Web\Controller { private static function dreport_gravity_sort($a,$b) { if($a['gravity'] == $b['gravity']) { - if($a['name'] === $b['name']) + if($a['dreport_name'] === $b['dreport_name']) return strcmp($a['dreport_time'],$b['dreport_time']); - return strcmp($a['name'],$b['name']); + return strcmp($a['dreport_name'],$b['dreport_name']); } return (($a['gravity'] > $b['gravity']) ? 1 : (-1)); } diff --git a/include/zot.php b/include/zot.php index 49fc89e33..756a5bde6 100644 --- a/include/zot.php +++ b/include/zot.php @@ -8,6 +8,8 @@ * */ +use Zotlabs\Lib\DReport; + require_once('include/crypto.php'); require_once('include/items.php'); require_once('include/queue_fn.php'); @@ -1120,7 +1122,7 @@ function zot_process_response($hub, $arr, $outq) { foreach($x['delivery_report'] as $xx) { call_hooks('dreport_process',$xx); - if(is_array($xx) && array_key_exists('message_id',$xx) && delivery_report_is_storable($xx)) { + if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) { q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ", dbesc($xx['message_id']), dbesc($xx['location']), @@ -1748,7 +1750,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ } $channel = $r[0]; - $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); + $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); /* blacklisted channels get a permission denied, no special message to tip them off */ @@ -2297,7 +2299,7 @@ function process_mail_delivery($sender, $arr, $deliveries) { } $channel = $r[0]; - $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); + $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); /* blacklisted channels get a permission denied, no special message to tip them off */ @@ -3987,7 +3989,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('item',$arr) && is_array($arr['item'][0])) { $DR = new Zotlabs\Lib\DReport(z_root(),$d['hash'],$d['hash'],$arr['item'][0]['message_id'],'channel sync processed'); - $DR->addto_recipient($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); + $DR->set_name($channel['channel_name'] . ' <' . channel_reddress($channel) . '>'); } else $DR = new Zotlabs\Lib\DReport(z_root(),$d['hash'],$d['hash'],'sync packet','channel sync delivered'); diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql index fb8cd63f7..c820fca25 100644 --- a/install/schema_mysql.sql +++ b/install/schema_mysql.sql @@ -405,6 +405,7 @@ CREATE TABLE IF NOT EXISTS `dreport` ( `dreport_site` char(191) NOT NULL DEFAULT '', `dreport_recip` char(191) NOT NULL DEFAULT '', `dreport_result` char(191) NOT NULL DEFAULT '', + `dreport_name` char(191) NOT NULL DEFAULT '', `dreport_time` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', `dreport_xchan` char(191) NOT NULL DEFAULT '', `dreport_queue` char(191) NOT NULL DEFAULT '', diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql index 2fdb2b105..3bc256377 100644 --- a/install/schema_postgres.sql +++ b/install/schema_postgres.sql @@ -377,6 +377,7 @@ CREATE TABLE IF NOT EXISTS "dreport" ( "dreport_site" varchar(255) NOT NULL DEFAULT '', "dreport_recip" varchar(255) NOT NULL DEFAULT '', "dreport_result" varchar(255) NOT NULL DEFAULT '', + "dreport_name" varchar(255) NOT NULL DEFAULT '', "dreport_time" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00', "dreport_xchan" varchar(255) NOT NULL DEFAULT '', "dreport_queue" varchar(255) NOT NULL DEFAULT '', |