Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDST-388] add http and https schemes as options #114

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Form/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,29 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('islandora_spreadsheet_ingest.settings');
$current_whitelist = $config->get('binary_directory_whitelist');
$scheme_options = $this->streamWrapperManager->getNames(StreamWrapperInterface::READ_VISIBLE) + [
'http' => 'HTTP',
'https' => 'HTTPS',
'ftp' => 'FTP',
];
$form['schemes'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Schemes'),
'#description' => $this->t('Allowed list of schemes for which binaries can be referenced from.'),
'#default_value' => $config->get('schemes') ?? [],
'#options' => $this->streamWrapperManager->getNames(StreamWrapperInterface::READ_VISIBLE),
'#options' => $scheme_options,
];
$form['paths'] = [
'#type' => 'textarea',
'#title' => $this->t('Binary path whitelist'),
'#default_value' => $current_whitelist ? implode(',', $current_whitelist) : '',
'#description' => $this->t('A comma separated list of local locations from which spreadsheet ingests can use binaries.'),
];
$form['info'] = [
'#type' => 'item',
'#title' => $this->t('If nothing is whitelisted, everything is whitelisted.'),
'#description' => $this->t('The plugin that expects to use this information will log warnings if this configuration is missing.'),
];
JojoVes marked this conversation as resolved.
Show resolved Hide resolved
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
Expand Down
16 changes: 16 additions & 0 deletions src/Plugin/migrate/process/AccessibleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\Url;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -99,6 +101,20 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$allowed_paths = $this->configFactory->get('islandora_spreadsheet_ingest.settings')->get('binary_directory_whitelist');
$allowed_schemes = $this->configFactory->get('islandora_spreadsheet_ingest.settings')->get('schemes');

// Ignore this check if relevant configuration has not been set, and advise
// that the configuration should be set.
if (empty($allowed_paths) && empty($allowed_schemes)) {
$migrate_executable->saveMessage(
strtr("Skipping this process to check (:file) since nothing has been configured to check against in the approved list of directories or schemes. For site security, it is highly recommended to set appropriate configuration at :config_url.", [
JojoVes marked this conversation as resolved.
Show resolved Hide resolved
':file' => $value,
':config_url' => Url::fromRoute('islandora_spreadsheet_ingest.admin')->toString(),
]),
MigrationInterface::MESSAGE_INFORMATIONAL
JojoVes marked this conversation as resolved.
Show resolved Hide resolved
);

return $value;
}

// If it's a local path check to see if it's in our allowed list.
$file_path = $this->fileSystem->realpath($value);
if ($file_path) {
Expand Down