aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/checksites.php5
-rw-r--r--include/deliver.php25
-rw-r--r--include/dir_fns.php13
-rw-r--r--include/externals.php5
-rw-r--r--include/hubloc.php4
-rwxr-xr-xinclude/items.php6
-rw-r--r--include/language.php16
-rw-r--r--include/notifier.php7
-rw-r--r--include/photo/photo_driver.php108
-rw-r--r--include/queue.php41
-rw-r--r--include/security.php42
-rw-r--r--include/text.php4
-rw-r--r--include/widgets.php4
-rw-r--r--include/zot.php122
14 files changed, 312 insertions, 90 deletions
diff --git a/include/checksites.php b/include/checksites.php
index e14837255..e9c08c202 100644
--- a/include/checksites.php
+++ b/include/checksites.php
@@ -25,8 +25,9 @@ function checksites_run($argv, $argc){
if($days < 1)
$days = 30;
- $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s $sql_options ",
- db_utcnow(), db_quoteinterval($days . ' DAY')
+ $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ",
+ db_utcnow(), db_quoteinterval($days . ' DAY'),
+ intval(SITE_TYPE_ZOT)
);
if(! $r)
diff --git a/include/deliver.php b/include/deliver.php
index 82a1ac6df..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'] : '');
@@ -53,17 +55,36 @@ function deliver_run($argv, $argc) {
continue;
}
}
+ else {
+
+ // zot sites should all have a site record, unless they've been dead for as long as
+ // your site has existed. Since we don't know for sure what these sites are,
+ // call them unknown
+
+ q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ",
+ dbesc($base),
+ dbesc(datetime_convert()),
+ intval(($r[0]['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN)
+ );
+ }
}
}
// "post" queue driver - used for diaspora and friendica-over-diaspora communications.
if($r[0]['outq_driver'] === 'post') {
+
+
$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 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/dir_fns.php b/include/dir_fns.php
index 38c92dd94..e466b7404 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -151,16 +151,18 @@ function sync_directories($dirmode) {
$realm = get_directory_realm();
if ($realm == DIRECTORY_REALM) {
- $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and ( site_realm = '%s' or site_realm = '') ",
+ $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_type = %d and ( site_realm = '%s' or site_realm = '') ",
intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY),
dbesc(z_root()),
+ intval(SITE_TYPE_ZOT),
dbesc($realm)
);
} else {
- $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_realm like '%s' ",
+ $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_realm like '%s' and site_type = %d ",
intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY),
dbesc(z_root()),
- dbesc(protect_sprintf('%' . $realm . '%'))
+ dbesc(protect_sprintf('%' . $realm . '%')),
+ intval(SITE_TYPE_ZOT)
);
}
@@ -187,9 +189,10 @@ function sync_directories($dirmode) {
intval($r[0]['site_valid'])
);
- $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s'",
+ $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_type = %d ",
intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY),
- dbesc(z_root())
+ dbesc(z_root()),
+ intval(SITE_TYPE_ZOT)
);
}
if (! $r)
diff --git a/include/externals.php b/include/externals.php
index 3b6d170d5..18c034bb2 100644
--- a/include/externals.php
+++ b/include/externals.php
@@ -28,9 +28,10 @@ function externals_run($argv, $argc){
}
else {
$randfunc = db_getfunc('RAND');
- $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d order by $randfunc limit 1",
+ $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d order by $randfunc limit 1",
dbesc(z_root()),
- intval(DIRECTORY_MODE_STANDALONE)
+ intval(DIRECTORY_MODE_STANDALONE),
+ intval(SITE_TYPE_ZOT)
);
if($r)
$url = $r[0]['site_url'];
diff --git a/include/hubloc.php b/include/hubloc.php
index 674a3885f..a1171b0e2 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -16,7 +16,9 @@ function is_matrix_url($url) {
function prune_hub_reinstalls() {
- $r = q("select site_url from site where true");
+ $r = q("select site_url from site where site_type = %d",
+ intval(SITE_TYPE_ZOT)
+ );
if($r) {
foreach($r as $rr) {
$x = q("select count(*) as t, hubloc_sitekey, max(hubloc_connected) as c from hubloc where hubloc_url = '%s' group by hubloc_sitekey order by c",
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/language.php b/include/language.php
index 7dbe3dd02..59979aa85 100644
--- a/include/language.php
+++ b/include/language.php
@@ -120,7 +120,11 @@ function load_translation_table($lang, $install = false) {
global $a;
$a->strings = array();
- if(file_exists("view/$lang/strings.php")) {
+
+ if(file_exists("view/$lang/hstrings.php")) {
+ include("view/$lang/hstrings.php");
+ }
+ elseif(file_exists("view/$lang/strings.php")) {
include("view/$lang/strings.php");
}
@@ -129,7 +133,10 @@ function load_translation_table($lang, $install = false) {
if ($plugins !== false) {
foreach($plugins as $p) {
$name = $p['name'];
- if(file_exists("addon/$name/lang/$lang/strings.php")) {
+ if(file_exists("addon/$name/lang/$lang/hstrings.php")) {
+ include("addon/$name/lang/$lang/hstrings.php");
+ }
+ elseif(file_exists("addon/$name/lang/$lang/strings.php")) {
include("addon/$name/lang/$lang/strings.php");
}
}
@@ -139,7 +146,10 @@ function load_translation_table($lang, $install = false) {
// Allow individual strings to be over-ridden on this site
// Either for the default language or for all languages
- if(file_exists("view/local-$lang/strings.php")) {
+ if(file_exists("view/local-$lang/hstrings.php")) {
+ include("view/local-$lang/hstrings.php");
+ }
+ elseif(file_exists("view/local-$lang/strings.php")) {
include("view/local-$lang/strings.php");
}
}
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/photo/photo_driver.php b/include/photo/photo_driver.php
index 2a7d1ae01..32b9bd302 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -591,67 +591,85 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
if(! $type)
$type = 'image/jpeg';
+
$result = z_fetch_url($photo,true);
- if($result['success'])
+ if($result['success']) {
$img_str = $result['body'];
- }
-
- $img = photo_factory($img_str, $type);
- if($img->is_valid()) {
- $width = $img->getWidth();
- $height = $img->getHeight();
-
- if($width && $height) {
- if(($width / $height) > 1.2) {
- // crop out the sides
- $margin = $width - $height;
- $img->cropImage(300,($margin / 2),0,$height,$height);
- }
- elseif(($height / $width) > 1.2) {
- // crop out the bottom
- $margin = $height - $width;
- $img->cropImage(300,0,0,$width,$width);
+ $h = explode("\n",$result['header']);
+ if($h) {
+ foreach($h as $hl) {
+ if(stristr($hl,'content-type:')) {
+ if(! stristr($hl,'image/')) {
+ $photo_failure = true;
+ }
+ }
+ }
}
- else {
- $img->scaleImageSquare(300);
- }
-
}
- else
- $photo_failure = true;
+ }
+ else {
+ $photo_failure = true;
+ }
- $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
+ if(! $photo_failure) {
+ $img = photo_factory($img_str, $type);
+ if($img->is_valid()) {
+ $width = $img->getWidth();
+ $height = $img->getHeight();
+
+ if($width && $height) {
+ if(($width / $height) > 1.2) {
+ // crop out the sides
+ $margin = $width - $height;
+ $img->cropImage(300,($margin / 2),0,$height,$height);
+ }
+ elseif(($height / $width) > 1.2) {
+ // crop out the bottom
+ $margin = $height - $width;
+ $img->cropImage(300,0,0,$width,$width);
- $r = $img->save($p);
+ }
+ else {
+ $img->scaleImageSquare(300);
+ }
- if($r === false)
- $photo_failure = true;
+ }
+ else
+ $photo_failure = true;
- $img->scaleImage(80);
- $p['scale'] = 5;
+ $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
- $r = $img->save($p);
+ $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ if($r === false)
+ $photo_failure = true;
- $img->scaleImage(48);
- $p['scale'] = 6;
+ $img->scaleImage(80);
+ $p['scale'] = 5;
+
+ $r = $img->save($p);
- $r = $img->save($p);
+ if($r === false)
+ $photo_failure = true;
+
+ $img->scaleImage(48);
+ $p['scale'] = 6;
+
+ $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ if($r === false)
+ $photo_failure = true;
- $photo = $a->get_baseurl() . '/photo/' . $hash . '-4';
- $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5';
- $micro = $a->get_baseurl() . '/photo/' . $hash . '-6';
- }
- else {
- logger('import_xchan_photo: invalid image from ' . $photo);
- $photo_failure = true;
+ $photo = $a->get_baseurl() . '/photo/' . $hash . '-4';
+ $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5';
+ $micro = $a->get_baseurl() . '/photo/' . $hash . '-6';
+ }
+ else {
+ logger('import_xchan_photo: invalid image from ' . $photo);
+ $photo_failure = true;
+ }
}
if($photo_failure) {
$photo = $a->get_baseurl() . '/' . get_default_profile_photo();
diff --git a/include/queue.php b/include/queue.php
index 7d2ad3b2d..71ac50c83 100644
--- a/include/queue.php
+++ b/include/queue.php
@@ -22,6 +22,25 @@ 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')
+ );
+ if($r) {
+ foreach($r as $rr) {
+ $site_url = '';
+ $h = parse_url($rr['outq_posturl']);
+ $desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
+ q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s",
+ dbesc($desturl),
+ db_utcnow(), db_quoteinterval('1 MONTH')
+ );
+ }
+ }
+
$r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
db_utcnow(), db_quoteinterval('3 DAY')
);
@@ -69,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 {
@@ -86,6 +124,7 @@ function queue_run($argv, $argc){
dbesc(datetime_convert()),
dbesc($rr['outq_hash'])
);
+ $deadguys[] = $rr['outq_posturl'];
}
continue;
}
diff --git a/include/security.php b/include/security.php
index 380505a79..9a25d9e0e 100644
--- a/include/security.php
+++ b/include/security.php
@@ -245,6 +245,9 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
$observer = (($remote_observer) ? $remote_observer : get_observer_hash());
if($observer) {
+
+ $s = scopes_sql($owner_id,$observer);
+
$groups = init_groups_visitor($observer);
$gs = '<<>>'; // should be impossible to match
@@ -255,9 +258,9 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
}
$regexop = db_getfunc('REGEXP');
$sql = sprintf(
- " AND ( NOT (deny_cid like '%s' OR deny_gid $regexop '%s')
- AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 ) )
- )
+ " AND (( NOT (deny_cid like '%s' OR deny_gid $regexop '%s')
+ AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 ))
+ ) OR ( item_private = 1 $s ))
",
dbesc(protect_sprintf( '%<' . $observer . '>%')),
dbesc($gs),
@@ -271,6 +274,39 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
}
/**
+ * Remote visitors also need to be checked against the public_scope parameter if item_private is set.
+ * This function checks the various permutations of that field for any which apply to this observer.
+ *
+ */
+
+
+
+function scopes_sql($uid,$observer) {
+ $str = " and ( public_policy = 'authenticated' ";
+ if(! is_foreigner($observer))
+ $str .= " or public_policy = 'network: red' ";
+ if(local_channel())
+ $str .= " or public_policy = 'site: " . get_app()->get_hostname() . "' ";
+
+ $ab = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
+ dbesc($observer),
+ intval($uid)
+ );
+ if(! $ab)
+ return $str . " ) ";
+ if($ab[0]['abook_pending'])
+ $str .= " or public_policy = 'any connections' ";
+ $str .= " or public_policy = 'contacts' ) ";
+ return $str;
+}
+
+
+
+
+
+
+
+/**
* @param string $observer_hash
*
* @return string additional SQL where statement
diff --git a/include/text.php b/include/text.php
index 4d9670806..b1af62fc5 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1686,14 +1686,14 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
function lang_selector() {
global $a;
- $langs = glob('view/*/strings.php');
+ $langs = glob('view/*/hstrings.php');
$lang_options = array();
$selected = "";
if(is_array($langs) && count($langs)) {
$langs[] = '';
- if(! in_array('view/en/strings.php',$langs))
+ if(! in_array('view/en/hstrings.php',$langs))
$langs[] = 'view/en/';
asort($langs);
foreach($langs as $l) {
diff --git a/include/widgets.php b/include/widgets.php
index 9f8b88d54..9c8596a66 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -637,6 +637,7 @@ function widget_conversations($arr) {
foreach($r as $rr) {
$messages[] = array(
+ 'mailbox' => $mailbox,
'id' => $rr['id'],
'from_name' => $rr['from']['xchan_name'],
'from_url' => chanlink_hash($rr['from_xchan']),
@@ -648,7 +649,8 @@ function widget_conversations($arr) {
'delete' => t('Delete conversation'),
'body' => $rr['body'],
'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')),
- 'seen' => $rr['seen']
+ 'seen' => $rr['seen'],
+ 'selected' => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id']))
);
}
diff --git a/include/zot.php b/include/zot.php
index 9bddb520d..7707f34fc 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -398,11 +398,6 @@ function zot_refresh($them, $channel = null, $force = false) {
}
}
- $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
- dbesc($x['hash']),
- intval($channel['channel_id'])
- );
-
if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) {
$next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']);
}
@@ -410,8 +405,15 @@ function zot_refresh($them, $channel = null, $force = false) {
$next_birthday = NULL_DATE;
}
+ $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
+ dbesc($x['hash']),
+ intval($channel['channel_id'])
+ );
+
if($r) {
+ // connection exists
+
// if the dob is the same as what we have stored (disregarding the year), keep the one
// we have as we may have updated the year after sending a notification; and resetting
// to the one we just received would cause us to create duplicated events.
@@ -453,6 +455,9 @@ function zot_refresh($them, $channel = null, $force = false) {
}
}
else {
+
+ // new connection
+
$role = get_pconfig($channel['channel_id'],'system','permissions_role');
if($role) {
$xx = get_role_perms($role);
@@ -1582,14 +1587,11 @@ 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() . '>');
-
-// uncomment this once we find out what's stopping the clone sync of the item from working
-// if($d['hash'] === $sender['hash']) {
-// $DR->update('self delivery ignored');
-// $result[] = $DR->get();
-// continue;
-// }
-
+ if($d['hash'] === $sender['hash']) {
+ $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.
@@ -2390,6 +2392,9 @@ function sync_locations($sender, $arr, $absolute = false) {
}
}
}
+ else {
+ logger('No locations to sync!');
+ }
$ret['change_message'] = $what;
$ret['changed'] = $changed;
@@ -2738,7 +2743,7 @@ function import_site($arr, $pubkey) {
// logger('import_site: input: ' . print_r($arr,true));
// logger('import_site: stored: ' . print_r($siterecord,true));
- $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s'
+ $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d
where site_url = '%s'",
dbesc($site_location),
intval($site_directory),
@@ -2748,6 +2753,7 @@ function import_site($arr, $pubkey) {
dbesc(datetime_convert()),
dbesc($sellpage),
dbesc($site_realm),
+ intval(SITE_TYPE_ZOT),
dbesc($url)
);
if(! $r) {
@@ -2764,8 +2770,8 @@ 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 )
- values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s' )",
+ $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', %d )",
dbesc($site_location),
dbesc($url),
intval($access_policy),
@@ -2774,7 +2780,8 @@ function import_site($arr, $pubkey) {
dbesc($directory_url),
intval($register_policy),
dbesc($sellpage),
- dbesc($site_realm)
+ dbesc($site_realm),
+ intval(SITE_TYPE_ZOT)
);
if(! $r) {
logger('import_site: record create failed. ' . print_r($arr,true));
@@ -2816,6 +2823,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
$channel = $r[0];
+ if(intval($channel['channel_removed']))
+ return;
+
$h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($channel['channel_hash'])
);
@@ -2866,7 +2876,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
// don't pass these elements, they should not be synchronised
- $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address');
+ $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address','channel_deleted','channel_removed','channel_system');
if(in_array($k,$disallowed))
continue;
@@ -2993,10 +3003,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
// These flags cannot be sync'd.
// remove the bits from the incoming flags.
- if($arr['channel_pageflags'] & 0x8000)
- $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x8000;
- if($arr['channel_pageflags'] & 0x1000)
- $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x1000;
+ // These correspond to PAGE_REMOVED and PAGE_SYSTEM on redmatrix
+
+ if($arr['channel']['channel_pageflags'] & 0x8000)
+ $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x8000;
+ if($arr['channel']['channel_pageflags'] & 0x1000)
+ $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x1000;
}
@@ -3774,7 +3786,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');
+ }
+ }
+ }
+} \ No newline at end of file