aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormrjive <mrjive@mrjive.it>2015-10-02 09:45:03 +0200
committermrjive <mrjive@mrjive.it>2015-10-02 09:45:03 +0200
commit32522b61f235266384c81c0669fceaf58afeb4fe (patch)
tree48427e8f48421b3bb8f344d85f2ebfe1271ea34e /include
parent11c1573b55f278a664a90a2872d06a40b3ac3026 (diff)
parent1da3828a09485a9b2bc6113cbab9ca9ca483ffc0 (diff)
downloadvolse-hubzilla-32522b61f235266384c81c0669fceaf58afeb4fe.tar.gz
volse-hubzilla-32522b61f235266384c81c0669fceaf58afeb4fe.tar.bz2
volse-hubzilla-32522b61f235266384c81c0669fceaf58afeb4fe.zip
Merge pull request #6 from redmatrix/master
updating from original codebase
Diffstat (limited to 'include')
-rw-r--r--include/Contact.php2
-rw-r--r--include/account.php2
-rw-r--r--include/deliver.php14
-rw-r--r--include/enotify.php5
-rwxr-xr-xinclude/items.php6
-rw-r--r--include/notifier.php7
-rw-r--r--include/queue.php25
-rw-r--r--include/taxonomy.php2
-rw-r--r--include/zot.php125
9 files changed, 161 insertions, 27 deletions
diff --git a/include/Contact.php b/include/Contact.php
index 008574d8f..8e22c608e 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -319,6 +319,8 @@ function channel_remove($channel_id, $local = true, $unset_session=true) {
q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($channel_id));
q("DELETE FROM `spam` WHERE `uid` = %d", intval($channel_id));
+ // @FIXME At this stage we need to remove the file resources located under /store/$nickname
+
q("delete from abook where abook_xchan = '%s' and abook_self = 1 ",
dbesc($channel['channel_hash'])
diff --git a/include/account.php b/include/account.php
index 5926e05c1..b3a520fd4 100644
--- a/include/account.php
+++ b/include/account.php
@@ -217,6 +217,8 @@ function create_account($arr) {
$result['email'] = $email;
$result['password'] = $password;
+ call_hooks('register_account',$result);
+
return $result;
}
diff --git a/include/deliver.php b/include/deliver.php
index 86fc90b3f..a338d1a89 100644
--- a/include/deliver.php
+++ b/include/deliver.php
@@ -29,6 +29,8 @@ function deliver_run($argv, $argc) {
* If not, reduce the outq_priority.
*/
+ $base = '';
+
$h = parse_url($r[0]['outq_posturl']);
if($h) {
$base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
@@ -76,11 +78,13 @@ function deliver_run($argv, $argc) {
$result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']);
if($result['success'] && $result['return_code'] < 300) {
logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG);
- q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
- dbesc(datetime_convert()),
- dbesc($site_url)
- );
- q("update dreport set status = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1",
+ if($base) {
+ q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
+ dbesc(datetime_convert()),
+ dbesc($base)
+ );
+ }
+ q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1",
dbesc('accepted for delivery'),
dbesc(datetime_convert()),
dbesc($argv[$x])
diff --git a/include/enotify.php b/include/enotify.php
index d0228bf50..80afe8ed6 100644
--- a/include/enotify.php
+++ b/include/enotify.php
@@ -315,9 +315,12 @@ function notification($params) {
'epreamble' => $epreamble,
'body' => $body,
'sitelink' => $sitelink,
+ 'sitename' => $sitename,
'tsitelink' => $tsitelink,
'hsitelink' => $hsitelink,
- 'itemlink' => $itemlink
+ 'itemlink' => $itemlink,
+ 'sender' => $sender,
+ 'recipient' => $recip
);
call_hooks('enotify', $h);
diff --git a/include/items.php b/include/items.php
index 7793d1fb2..e7cc02579 100755
--- a/include/items.php
+++ b/include/items.php
@@ -3522,11 +3522,17 @@ function mail_store($arr) {
dbesc($arr['mid']),
intval($arr['channel_id'])
);
+
if($r) {
logger('mail_store: duplicate item ignored. ' . print_r($arr,true));
return 0;
}
+ if(! $r && $arr['mail_recalled'] == 1) {
+ logger('mail_store: recalled item not found. ' . print_r($arr,true));
+ return 0;
+ }
+
call_hooks('post_mail',$arr);
if(x($arr,'cancel')) {
diff --git a/include/notifier.php b/include/notifier.php
index 3b29229cf..db1aa9690 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -605,11 +605,16 @@ function notifier_run($argv, $argc){
'request' => $request,
'normal_mode' => $normal_mode,
'packet_type' => $packet_type,
- 'walltowall' => $walltowall
+ 'walltowall' => $walltowall,
+ 'queued' => array()
);
call_hooks('notifier_hub',$narr);
+ if($narr['queued']) {
+ foreach($narr['queued'] as $pq)
+ $deliveries[] = $pq;
+ }
continue;
}
diff --git a/include/queue.php b/include/queue.php
index 18c8c5fa2..71ac50c83 100644
--- a/include/queue.php
+++ b/include/queue.php
@@ -23,6 +23,9 @@ function queue_run($argv, $argc){
logger('queue: start');
+ // delete all queue items more than 3 days old
+ // but first mark these sites dead if we haven't heard from them in a month
+
$r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s",
db_utcnow(), db_quoteinterval('3 DAY')
);
@@ -85,15 +88,34 @@ function queue_run($argv, $argc){
return;
foreach($r as $rr) {
+
+ $dresult = null;
+
if(in_array($rr['outq_posturl'],$deadguys))
continue;
+ $base = '';
+ $h = parse_url($rr['outq_posturl']);
+ if($h)
+ $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
+
if($rr['outq_driver'] === 'post') {
$result = z_post_url($rr['outq_posturl'],$rr['outq_msg']);
if($result['success'] && $result['return_code'] < 300) {
logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG);
+ if($base) {
+ q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ",
+ dbesc(datetime_convert()),
+ dbesc($base)
+ );
+ }
+ q("update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1",
+ dbesc('accepted for delivery'),
+ dbesc(datetime_convert()),
+ dbesc($rr['outq_hash'])
+ );
$y = q("delete from outq where outq_hash = '%s'",
- dbesc($rr['ouq_hash'])
+ dbesc($rr['outq_hash'])
);
}
else {
@@ -102,6 +124,7 @@ function queue_run($argv, $argc){
dbesc(datetime_convert()),
dbesc($rr['outq_hash'])
);
+ $deadguys[] = $rr['outq_posturl'];
}
continue;
}
diff --git a/include/taxonomy.php b/include/taxonomy.php
index a82cf94f7..e68b9659f 100644
--- a/include/taxonomy.php
+++ b/include/taxonomy.php
@@ -185,7 +185,7 @@ function dir_tagadelic($count = 0) {
$count = intval($count);
// Fetch tags
- $r = q("select xtag_term, count(xtag_term) as total from xtag
+ $r = q("select xtag_term, count(xtag_term) as total from xtag where xtag_flags = 0
group by xtag_term order by total desc %s",
((intval($count)) ? "limit $count" : '')
);
diff --git a/include/zot.php b/include/zot.php
index ef9f325d0..dd9222bf3 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -11,6 +11,7 @@
require_once('include/crypto.php');
require_once('include/items.php');
require_once('include/hubloc.php');
+require_once('include/DReport.php');
/**
@@ -901,7 +902,7 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) {
$r = q("delete from xprof where xprof_hash = '%s'",
dbesc($xchan_hash)
);
- $r = q("delete from xtag where xtag_hash = '%s'",
+ $r = q("delete from xtag where xtag_hash = '%s' and xtag_flags = 0",
dbesc($xchan_hash)
);
}
@@ -1556,7 +1557,6 @@ function allowed_public_recips($msg) {
function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $request = false) {
$result = array();
- require_once('include/DReport.php');
$result['site'] = z_root();
@@ -1569,6 +1569,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
}
}
+
foreach($deliveries as $d) {
$local_public = $public;
@@ -1587,11 +1588,21 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
$channel = $r[0];
$DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>');
- if($d['hash'] === $sender['hash']) {
- $DR->update('self delivery ignored');
- $result[] = $DR->get();
- continue;
- }
+ /**
+ * @FIXME: Somehow we need to block normal message delivery from our clones, as the delivered
+ * message doesn't have ACL information in it as the cloned copy does. That copy
+ * will normally arrive first via sync delivery, but this isn't guaranteed.
+ * There's a chance the current delivery could take place before the cloned copy arrives
+ * hence the item could have the wrong ACL and *could* be used in subsequent deliveries or
+ * access checks. So far all attempts at identifying this situation precisely
+ * have caused issues with delivery of relayed comments.
+ */
+
+// if(($d['hash'] === $sender['hash']) && ($sender['url'] !== z_root()) && (! $relay)) {
+// $DR->update('self delivery ignored');
+// $result[] = $DR->get();
+// continue;
+// }
// allow public postings to the sys channel regardless of permissions, but not
// for comments travelling upstream. Wait and catch them on the way down.
@@ -1949,8 +1960,7 @@ function delete_imported_item($sender, $item, $uid, $relay) {
$item_found = false;
$post_id = 0;
-
- $r = q("select id, item_deleted from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
+ $r = q("select id, author_xchan, owner_xchan, source_xchan, item_deleted from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
and mid = '%s' and uid = %d limit 1",
dbesc($sender['hash']),
dbesc($sender['hash']),
@@ -1958,6 +1968,7 @@ function delete_imported_item($sender, $item, $uid, $relay) {
dbesc($item['mid']),
intval($uid)
);
+
if ($r) {
if ($r[0]['author_xchan'] === $sender['hash'] || $r[0]['owner_xchan'] === $sender['hash'] || $r[0]['source_xchan'] === $sender['hash'])
$ownership_valid = true;
@@ -2031,20 +2042,26 @@ function process_mail_delivery($sender, $arr, $deliveries) {
}
foreach($deliveries as $d) {
+
+ $DR = new DReport(z_root(),$sender['hash'],$d['hash'],$arr['mid']);
+
$r = q("select * from channel where channel_hash = '%s' limit 1",
dbesc($d['hash'])
);
if(! $r) {
- $result[] = array($d['hash'],'not found');
+ $DR->update('recipient not found');
+ $result[] = $DR->get();
continue;
}
$channel = $r[0];
+ $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>');
if(! perm_is_allowed($channel['channel_id'],$sender['hash'],'post_mail')) {
logger("permission denied for mail delivery {$channel['channel_id']}");
- $result[] = array($d['hash'],'permission denied',$channel['channel_name'],$arr['mid']);
+ $DR->update('permission denied');
+ $result[] = $DR->get();
continue;
}
@@ -2058,11 +2075,13 @@ function process_mail_delivery($sender, $arr, $deliveries) {
intval($r[0]['id']),
intval($channel['channel_id'])
);
- $result[] = array($d['hash'],'mail recalled',$channel['channel_name'],$arr['mid']);
+ $DR->update('mail recalled');
+ $result[] = $DR->get();
logger('mail_recalled');
}
else {
- $result[] = array($d['hash'],'duplicate mail received',$channel['channel_name'],$arr['mid']);
+ $DR->update('duplicate mail received');
+ $result[] = $DR->get();
logger('duplicate mail received');
}
continue;
@@ -2071,7 +2090,8 @@ function process_mail_delivery($sender, $arr, $deliveries) {
$arr['account_id'] = $channel['channel_account_id'];
$arr['channel_id'] = $channel['channel_id'];
$item_id = mail_store($arr);
- $result[] = array($d['hash'],'mail delivered',$channel['channel_name'],$arr['mid']);
+ $DR->update('mail delivered');
+ $result[] = $DR->get();
}
}
@@ -2392,6 +2412,9 @@ function sync_locations($sender, $arr, $absolute = false) {
}
}
}
+ else {
+ logger('No locations to sync!');
+ }
$ret['change_message'] = $what;
$ret['changed'] = $changed;
@@ -2577,7 +2600,7 @@ function import_directory_profile($hash, $profile, $addr, $ud_flags = UPDATE_FLA
function import_directory_keywords($hash, $keywords) {
$existing = array();
- $r = q("select * from xtag where xtag_hash = '%s'",
+ $r = q("select * from xtag where xtag_hash = '%s' and xtag_flags = 0",
dbesc($hash)
);
@@ -2595,14 +2618,14 @@ function import_directory_keywords($hash, $keywords) {
foreach($existing as $x) {
if(! in_array($x, $clean))
- $r = q("delete from xtag where xtag_hash = '%s' and xtag_term = '%s'",
+ $r = q("delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0",
dbesc($hash),
dbesc($x)
);
}
foreach($clean as $x) {
if(! in_array($x, $existing)) {
- $r = q("insert into xtag ( xtag_hash, xtag_term) values ( '%s' ,'%s' )",
+ $r = q("insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 )",
dbesc($hash),
dbesc($x)
);
@@ -2768,7 +2791,7 @@ function import_site($arr, $pubkey) {
else {
$update = true;
$r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type )
- values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s' )",
+ values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s', %d )",
dbesc($site_location),
dbesc($url),
intval($access_policy),
@@ -3783,7 +3806,73 @@ function zotinfo($arr) {
$ret['site']['realm'] = get_directory_realm();
}
+
+ check_zotinfo($e,$x,$ret);
+
+
call_hooks('zot_finger',$ret);
return($ret);
}
+
+
+function check_zotinfo($channel,$locations,&$ret) {
+
+
+// logger('locations: ' . print_r($locations,true),LOGGER_DATA);
+
+ // This function will likely expand as we find more things to detect and fix.
+ // 1. Because magic-auth is reliant on it, ensure that the system channel has a valid hubloc
+ // Force this to be the case if anything is found to be wrong with it.
+
+ // @FIXME ensure that the system channel exists in the first place and has an xchan
+
+ if($channel['channel_system']) {
+ // the sys channel must have a location (hubloc)
+ $valid_location = false;
+ if((count($locations) === 1) && ($locations[0]['primary']) && (! $locations[0]['deleted'])) {
+ if((rsa_verify($locations[0]['url'],base64url_decode($locations[0]['url_sig']),$channel['channel_pubkey']))
+ && ($locations[0]['sitekey'] === get_config('system','pubkey'))
+ && ($locations[0]['url'] === z_root()))
+ $valid_location = true;
+ else
+ logger('sys channel: invalid url signature');
+ }
+
+ if((! $locations) || (! $valid_location)) {
+
+ logger('System channel locations are not valid. Attempting repair.');
+
+ // Don't trust any existing records. Just get rid of them, but only do this
+ // for the sys channel as normal channels will be trickier.
+
+ q("delete from hubloc where hubloc_hash = '%s'",
+ 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 )
+ values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
+ dbesc($channel['channel_guid']),
+ dbesc($channel['channel_guid_sig']),
+ dbesc($channel['channel_hash']),
+ dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()),
+ intval(1),
+ dbesc(z_root()),
+ dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))),
+ dbesc(get_app()->get_hostname()),
+ dbesc(z_root() . '/post'),
+ dbesc(get_config('system','pubkey')),
+ dbesc('zot')
+ );
+ if($r) {
+ $x = zot_encode_locations($channel);
+ if($x) {
+ $ret['locations'] = $x;
+ }
+ }
+ else {
+ logger('Unable to store sys hub location');
+ }
+ }
+ }
+}