From 2221a640af3efea88735bb33bc717065d714c733 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Wed, 3 Sep 2014 15:08:37 -0700 Subject: [PATCH] Implement a client-side blacklist Hostnames in the URL can be blacklisted from running Overdrive functions. Signed-off-by: Steven Chan --- src/od_config_template.coffee | 7 +++++++ src/overdrive.coffee | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/od_config_template.coffee b/src/od_config_template.coffee index 202918c..d20a256 100644 --- a/src/od_config_template.coffee +++ b/src/od_config_template.coffee @@ -41,4 +41,11 @@ define [ # Define whether a user password is required to complete patron authentication password_required: 'false' # or 'true' + + # Define a blacklist based on hostname component, eg, abc.domain1 or xyz.domain2 + blacklisted: ( hn = window.location.hostname, bl = ['abc', 'xyz'] ) -> + return unless hn = hn.match(/^(.+?)\./)?[1] # no proper hostname found + return unless bl?.length > 0 # no blacklist or is empty + return true for v in bl when v is hn # hostname is listed in blacklist + return # not listed in blacklist } diff --git a/src/overdrive.coffee b/src/overdrive.coffee index c8f75b6..b351611 100644 --- a/src/overdrive.coffee +++ b/src/overdrive.coffee @@ -27,10 +27,11 @@ require [ 'lodash' 'cookies' 'od_api' + 'od_config' 'od_pages_opac' 'od_pages_myopac' 'od_action' -], ($, _, C, od) -> +], ($, _, C, od, config) -> # Indicate the logged in status; the value is determined within document # ready handler. @@ -403,6 +404,9 @@ require [ return if window.IAMXUL # Comment out to run inside XUL staff client + # Do not implement if hostname is blacklisted + return if config.blacklisted() + # We are logged into EG if indicated by a cookie or if running # inside XUL staff client. logged_in = Boolean C('eg_loggedin') or window.IAMXUL -- 2.11.0