From b309deef110843c24320422d94e8a4a64e2e08f8 Mon Sep 17 00:00:00 2001 From: riking Date: Mon, 21 Apr 2014 13:59:53 -0700 Subject: [PATCH] Add site setting for domains to never download images from --- app/jobs/regular/pull_hotlinked_images.rb | 3 ++- app/models/site_setting.rb | 10 ++++++++++ config/locales/server.en.yml | 1 + config/site_settings.yml | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index e7142b9ee..694cbabea 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -87,7 +87,8 @@ module Jobs def is_valid_image_url(src) src.present? && !Discourse.store.has_been_uploaded?(src) && - !src.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix) + !src.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix) && + SiteSetting.should_download_images?(src) end end diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index ee820aaed..f1636335b 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -72,6 +72,16 @@ class SiteSetting < ActiveRecord::Base .first end + def self.should_download_images?(src) + setting = disabled_image_download_domains + return true unless setting.present? + host = URI.parse(src).host + + return !(setting.split('|').include?(host)) + rescue URI::InvalidURIError + return true + end + def self.scheme use_https? ? "https" : "http" end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 1cae3c99e..9ac832422 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -605,6 +605,7 @@ en: crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions" download_remote_images_to_local: "Download a copy of remote images hotlinked in posts" download_remote_images_threshold: "Amount of minimum available disk space required to download remote images locally (in percent)" + disabled_image_download_domains: "A pipe-delimited list of domains from which linked images will never be downloaded." ninja_edit_window: "Number of seconds after posting where edits do not create a new version" post_edit_time_limit: "Amount of time in minutes in which posts can be edited and deleted by the author. Set to 0 to allow editing and deleting posts at any time." edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view edit history." diff --git a/config/site_settings.yml b/config/site_settings.yml index fd08b32a6..2362f9b93 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -302,6 +302,9 @@ files: test: false default: true download_remote_images_threshold: 20 + disabled_image_download_domains: + list: true + default: '' create_thumbnails: true clean_up_uploads: false clean_orphan_uploads_grace_period_hours: 1