X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fsecurity_review%2Fsecurity_review.module;fp=web%2Fmodules%2Fcontrib%2Fsecurity_review%2Fsecurity_review.module;h=0000000000000000000000000000000000000000;hp=508f6253412566511383fec66b7ca19d886ecd32;hb=419f97be044f1aebd0713921ee604841127e9e84;hpb=052617e40b525f8b817d84c29b1c04951f427069 diff --git a/web/modules/contrib/security_review/security_review.module b/web/modules/contrib/security_review/security_review.module deleted file mode 100644 index 508f62534..000000000 --- a/web/modules/contrib/security_review/security_review.module +++ /dev/null @@ -1,229 +0,0 @@ -log($level, $message, $context); -} - -/** - * Implements hook_modules_uninstalled(). - */ -function security_review_modules_uninstalled($modules) { - /** @var \Drupal\security_review\SecurityReview $security_review */ - $security_review = Drupal::service('security_review'); - - // Clean orphaned checks. - $security_review->cleanStorage(); -} - -/** - * Implements hook_modules_installed(). - */ -function security_review_modules_installed($modules) { - // Post-install hook. - if (in_array('security_review', $modules)) { - - /** @var \Drupal\security_review\SecurityReview $security_review */ - $security_review = Drupal::service('security_review'); - - // Clean orphaned checks. - $security_review->cleanStorage(); - - // Store the web server's user. - $security_review->setServerData(); - } -} - -/** - * Implements hook_theme(). - */ -function security_review_theme($existing, $type, $theme, $path) { - return [ - 'check_evaluation' => [ - 'template' => 'check_evaluation', - 'variables' => [ - 'paragraphs' => [], - 'items' => [], - ], - ], - 'check_help' => [ - 'template' => 'check_help', - 'variables' => [ - 'title' => [], - 'paragraphs' => [], - ], - ], - 'general_help' => [ - 'template' => 'general_help', - 'variables' => [ - 'paragraphs' => [], - 'checks' => [], - ], - ], - 'run_and_review' => [ - 'template' => 'run_and_review', - 'variables' => [ - 'date' => [], - 'checks' => [], - ], - ], - ]; -} - -/** - * Preprocesses variables for template 'run_and_review'. - */ -function template_preprocess_run_and_review(&$variables) { - // Get icon list. - $icons_root = '/core/misc/icons/'; - $variables['icons'] = [ - 'success' => $icons_root . '73b355/check.svg', - 'warning' => $icons_root . 'e29700/warning.svg', - 'fail' => $icons_root . 'e32700/error.svg', - ]; - - // Generate full URLs. - foreach ($variables['icons'] as $icon => $path) { - $variables['icons'][$icon] = Url::fromUserInput($path)->setAbsolute() - ->toString(); - } - - // Format date. - $variables['date'] = \Drupal::service('date.formatter')->format($variables['date']); - - // Convert check result integers to strings. - foreach ($variables['checks'] as &$check) { - if (isset($check['result'])) { - switch ($check['result']) { - case CheckResult::SUCCESS: - $check['result'] = 'success'; - break; - - case CheckResult::FAIL: - $check['result'] = 'fail'; - break; - - case CheckResult::WARN: - $check['result'] = 'warning'; - break; - - case CheckResult::INFO: - $check['result'] = 'info'; - break; - } - } - } -} - -/** - * Implements hook_cron(). - */ -function security_review_cron() { - // Store the web server's user. - Drupal::service('security_review')->setServerData(); -} - -/** - * Batch operation: runs a single check. - * - * @param \Drupal\security_review\Check $check - * The check to run. - * @param array $context - * The Batch context. - */ -function _security_review_batch_run_op(Check $check, array &$context) { - // Inform the user about the progress. - $context['message'] = $check->getTitle(); - - // Run the check. - $results = Drupal::service('security_review.checklist') - ->runChecks([$check]); - - // Store the results. - $context['results'] = array_merge($context['results'], $results); -} - -/** - * Callback for finishing the batch job of running the checklist. - * - * @param bool $success - * Whether the batch job was successful. - * @param \Drupal\security_review\CheckResult[] $results - * The results of the batch job. - * @param array $operations - * The array of batch operations. - */ -function _security_review_batch_run_finished($success, array $results, array $operations) { - /** @var \Drupal\security_review\SecurityReview $security_review */ - $security_review = Drupal::service('security_review'); - - /** @var \Drupal\security_review\Checklist $checklist */ - $checklist = Drupal::service('security_review.checklist'); - - $security_review->setLastRun(time()); - if ($success) { - if (!empty($results)) { - $checklist->storeResults($results); - } - drupal_set_message(t('Review complete')); - } - else { - // Show error information. - $error_operation = reset($operations); - $message = t( - 'An error occurred while processing %error_operation with arguments: @arguments', - [ - '%error_operation' => $error_operation[0], - '@arguments' => print_r($error_operation[1], TRUE), - ] - ); - $security_review->log(NULL, $message, [], RfcLogLevel::ERROR); - drupal_set_message(t('The review did not store all results, please run again or check the logs for details.')); - } -}