From 39f0e6fe622b2080bede823d19b36c9961c64f1d Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 8 Jun 2015 16:55:17 -0700 Subject: [PATCH] add site_dead flag to prevent delivery to dead sites. Allow sys channel webpages to be viewed even if site is configured "block public". --- boot.php | 2 +- include/deliver.php | 25 +++++++++++++++++-------- install/schema_mysql.sql | 4 +++- install/schema_postgres.sql | 2 ++ install/update.php | 13 ++++++++++++- mod/page.php | 17 ++++++++++++----- mod/public.php | 5 ++++- version.inc | 2 +- 8 files changed, 52 insertions(+), 18 deletions(-) diff --git a/boot.php b/boot.php index 886ce3670..03f65db2f 100755 --- a/boot.php +++ b/boot.php @@ -49,7 +49,7 @@ define ( 'PLATFORM_NAME', 'redmatrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1142 ); +define ( 'DB_UPDATE_VERSION', 1143 ); /** * @brief Constant with a HTML line break. diff --git a/include/deliver.php b/include/deliver.php index 0fb7a4aeb..5ab44a620 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -30,16 +30,25 @@ function deliver_run($argv, $argc) { if($h) { $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); if($base !== z_root()) { - $y = q("select site_update from site where site_url = '%s' ", + $y = q("select site_update, site_dead from site where site_url = '%s' ", dbesc($base) ); - if($y && $y[0]['site_update'] < datetime_convert('UTC','UTC','now - 1 month')) { - q("update outq set outq_priority = %d where outq_hash = '%s'", - intval($r[0]['outq_priority'] + 10), - dbesc($r[0]['outq_hash']) - ); - logger('immediate delivery deferred for site ' . $base); - continue; + if($y) { + if(intval($y[0]['site_dead'])) { + q("delete from outq where outq_posturl = '%s'", + dbesc($r[0]['outq_posturl']) + ); + logger('dead site ignored ' . $base); + continue; + } + if($y[0]['site_update'] < datetime_convert('UTC','UTC','now - 1 month')) { + q("update outq set outq_priority = %d where outq_hash = '%s'", + intval($r[0]['outq_priority'] + 10), + dbesc($r[0]['outq_hash']) + ); + logger('immediate delivery deferred for site ' . $base); + continue; + } } } } diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql index 8e3d5a7b4..8aca3dff4 100644 --- a/install/schema_mysql.sql +++ b/install/schema_mysql.sql @@ -1266,6 +1266,7 @@ CREATE TABLE IF NOT EXISTS `site` ( `site_location` char(255) NOT NULL DEFAULT '', `site_realm` char(255) NOT NULL DEFAULT '', `site_valid` smallint NOT NULL DEFAULT '0', + `site_dead` smallint NOT NULL DEFAULT '0', PRIMARY KEY (`site_url`), KEY `site_flags` (`site_flags`), KEY `site_update` (`site_update`), @@ -1275,7 +1276,8 @@ CREATE TABLE IF NOT EXISTS `site` ( KEY `site_sellpage` (`site_sellpage`), KEY `site_pull` (`site_pull`), KEY `site_realm` (`site_realm`), - KEY `site_valid` (`site_valid`) + KEY `site_valid` (`site_valid`), + KEY `site_dead` (`site_dead`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql index 48f3fe0fc..a68c7d12b 100644 --- a/install/schema_postgres.sql +++ b/install/schema_postgres.sql @@ -969,6 +969,7 @@ CREATE TABLE "site" ( "site_location" text NOT NULL DEFAULT '', "site_realm" text NOT NULL DEFAULT '', "site_valid" smallint NOT NULL DEFAULT '0', + "site_dead" smallint NOT NULL DEFAULT '0', PRIMARY KEY ("site_url") ); create index "site_flags" on site ("site_flags"); @@ -979,6 +980,7 @@ create index "site_access" on site ("site_access"); create index "site_sellpage" on site ("site_sellpage"); create index "site_realm" on site ("site_realm"); create index "site_valid" on site ("site_valid"); +create index "site_dead" on site ("site_dead"); CREATE TABLE "source" ( "src_id" serial NOT NULL, diff --git a/install/update.php b/install/update.php index 13a45d301..62c976218 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ profile['profile_uid']) head_set_icon($a->profile['thumb']); - - + // load the item here in the init function because we need to extract // the page layout and initialise the correct theme. @@ -22,9 +23,11 @@ function page_init(&$a) { $observer = $a->get_observer(); $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - $perms = get_all_perms($a->profile['profile_uid'],$ob_hash); - if(! $perms['view_pages']) { + // perm_is_allowed is denied unconditionally when 'site blocked to unauthenticated members'. + // This bypasses that restriction for sys channel (public) content + + if((! perm_is_allowed($a->profile['profile_uid'],$ob_hash,'view_pages')) && (! is_sys_channel($a->profile['profile_uid']))) { notice( t('Permission denied.') . EOL); return; } @@ -58,6 +61,8 @@ function page_init(&$a) { require_once('include/security.php'); $sql_options = item_permissions_sql($u[0]['channel_id']); +dbg(1); + $r = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and (( service = 'WEBPAGE' and item_restrict = %d ) or ( service = 'PDL' and item_restrict = %d )) $sql_options $revision limit 1", @@ -77,6 +82,8 @@ function page_init(&$a) { dbesc($page_id), intval(ITEM_WEBPAGE) ); + +dbg(0); if($x) { // Yes, it's there. You just aren't allowed to see it. notice( t('Permission denied.') . EOL); @@ -119,7 +126,7 @@ function page_content(&$a) { return; if($r[0]['item_restrict'] == ITEM_PDL) { - $r[0]['body'] = t('Ipsum Lorem'); + $r[0]['body'] = t('Lorem Ipsum'); $r[0]['mimetype'] = 'text/plain'; $r[0]['title'] = ''; diff --git a/mod/public.php b/mod/public.php index 57c12e283..1f23a1999 100644 --- a/mod/public.php +++ b/mod/public.php @@ -60,17 +60,20 @@ function public_content(&$a, $update = 0, $load = false) { } require_once('include/identity.php'); + require_once('include/security.php'); if(get_config('system','site_firehose')) { - require_once('include/security.php'); $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and (item_flags & " . intval(ITEM_WALL) . " ) > 0 "; } else { $sys = get_sys_channel(); $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $sql_extra = item_permissions_sql($sys['channel_id']); $a->data['firehose'] = intval($sys['channel_id']); } + + $page_mode = 'list'; $simple_update = (($update) ? " and item.item_unseen = 1 " : ''); diff --git a/version.inc b/version.inc index ad6095cb9..669f2bc59 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-06-07.1056 +2015-06-08.1057