Here is a patch that makes it possible to use an include method. Its basically a rip off of the excluded method but I added some choices to the form so you can pick which method of shield protection you require:

Protect all - require auth on all pages
Excluded method - protect all except these paths
Included method - only protect these paths

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kalman.hosszu’s picture

Status: Needs review » Fixed

Thanks for your patch. I committed it: http://drupalcode.org/project/shield.git/commit/434aeb3

azinck’s picture

Status: Fixed » Needs work

This patch, as-is, will break existing functionality. The default shield_method should be '1', not '0'. Anyone with paths excluded from shield's protection will no longer have those paths excluded once applying this patch. In fact, there's really no need for a "protect all" mode. It's redundant with "exclude" mode. If you want to protect all, just use "exclude" and don't add any paths to exclude.

Also, there's a lot of duplicated logic here. I will re-roll.

kalman.hosszu’s picture

You are right, I was careless.

azinck’s picture

Status: Needs work » Needs review
FileSize
5.58 KB
kalman.hosszu’s picture

Status: Needs review » Needs work

I can't apply your patch:

▶ git pull origin 7.x-1.x
From git.drupal.org:project/shield
 * branch            7.x-1.x    -> FETCH_HEAD
Already up-to-date.
[08:45:40] kalmanhosszu@Kalman-Hosszus-MacBook-Pro:~/work/contrib/drupal-7/sites/all/modules/custom/shield (7.x-1.x)
▶ git apply -v shield-include_exclude_method-1898216-4.patch
Checking patch shield.admin.inc...
error: while searching for:
    '#default_value' => variable_get('shield_allow_cli', 1),
  );

  $methods = array(0 => t('Protect all'), 1 => t('Use excluded method'), 2 => t('Use included method'));
  $form['general']['shield_method'] = array(
    '#type' => 'radios',
    '#title' => t('Shield method'),
    '#default_value' => variable_get('shield_method', 0),
    '#options' => $methods,
    '#description' => t('Choose which method of shield protection you require. Protect all - require auth on all pages. Excluded method - protect all except these paths. Included method - only protect these paths'),
  );

  $form['general']['shield_excluded_paths'] = array(
    '#type' => 'textarea',
    '#title' => t('Exclude these paths from Shield protection'),
    '#description' => t('Enter a list of paths that should be accessible without Shield credentials. Leave blank to protect all paths.'),
    '#default_value' => variable_get('shield_excluded_paths', ''),
  );

  $form['general']['shield_included_paths'] = array(
    '#type' => 'textarea',
    '#title' => t('Only include these paths in Shield protection'),
    '#description' => t('Enter a list of paths that should require Shield credentials.'),
    '#default_value' => variable_get('shield_included_paths', ''),
  );


  $form['credentials'] = array(
    '#type' => 'fieldset',
    '#title' => t('Credentials'),

error: patch failed: shield.admin.inc:33
error: shield.admin.inc: patch does not apply
Checking patch shield.install...
Hunk #1 succeeded at 16 (offset 1 line).
Checking patch shield.module...
Hunk #1 succeeded at 53 (offset 5 lines).
kalman.hosszu’s picture

Status: Needs work » Fixed

I updated the patch and created some minor changes: http://drupalcode.org/project/shield.git/commit/8372de7

Thank you @azinck!

azinck’s picture

Thanks for taking care of it -- looks like the cron patch hit 1.x-dev in the time between I re-rolled this and you applied it. Also: I like that you renamed the paths variable and added the update hook. I wasn't sure you'd be amenable to that but it's a definite improvement.

kalman.hosszu’s picture

Thanks! If you have any suggestion feel free to open an issue to discuss!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

peterletten’s picture

Issue summary: View changes

Hi, I've successfully installed the 2012 basic version of the module and would like to install the 2015 version (with the exclude option). I followed the following process: uninstall in admin/modules the 'php authentication shield' module, delete the corresponding module from my sites/all/modules, empty the cache through admin/configuration/development and installing the new module version 2015. I run into problems configuring the new module 'shield' as my screen turns white upon clicking the 'save configuration' button at the bottum. PS: I went through the process twice with the same result. Can somebody provide me some help? Thanks.