X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fsecurity_review%2Fsrc%2FForm%2FRunForm.php;fp=web%2Fmodules%2Fcontrib%2Fsecurity_review%2Fsrc%2FForm%2FRunForm.php;h=8eeeba95e372c53cefbea10a47a6a55299b34f79;hp=0000000000000000000000000000000000000000;hb=ba1b5c55c66590c41ccc9844d3e62391b0399abb;hpb=93ef30d42f68e55d11d97312531118bbcd4cf318 diff --git a/web/modules/contrib/security_review/src/Form/RunForm.php b/web/modules/contrib/security_review/src/Form/RunForm.php new file mode 100644 index 000000000..8eeeba95e --- /dev/null +++ b/web/modules/contrib/security_review/src/Form/RunForm.php @@ -0,0 +1,100 @@ +checklist = $checklist; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('security_review.checklist') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'security-review-run'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + if (!$this->currentUser()->hasPermission('run security checks')) { + return []; + } + + $form['run_form'] = [ + '#type' => 'details', + '#title' => $this->t('Run'), + '#description' => $this->t('Click the button below to run the security checklist and review the results.') . '
', + '#open' => TRUE, + ]; + + $form['run_form']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Run checklist'), + ]; + + // Return the finished form. + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $batch = [ + 'operations' => [], + 'finished' => '_security_review_batch_run_finished', + 'title' => $this->t('Performing Security Review'), + 'init_message' => $this->t('Security Review is starting.'), + 'progress_message' => $this->t('Progress @current out of @total.'), + 'error_message' => $this->t('An error occurred. Rerun the process or consult the logs.'), + ]; + + foreach ($this->checklist->getEnabledChecks() as $check) { + $batch['operations'][] = [ + '_security_review_batch_run_op', + [$check], + ]; + } + + batch_set($batch); + } + +}