You are here

function security_review_drush in Security Review 6

Same name and namespace in other branches
  1. 8 security_review.drush.inc \security_review_drush()
  2. 7 security_review.drush.inc \security_review_drush()

Run checklist and display results command.

1 string reference to 'security_review_drush'
security_review_drush_command in ./security_review.drush.inc
Implementation of hook_drush_command().

File

./security_review.drush.inc, line 64
Drush commands for Security Review module.

Code

function security_review_drush() {
  module_load_include('inc', 'security_review');
  $store = drush_get_option('store');
  $log = drush_get_option('log');
  $lastrun = drush_get_option('lastrun');
  $checklist = module_invoke_all('security_checks');
  $output = array();
  if (!$lastrun) {

    // Unset file_perms of security_review because drush is running as a
    // different user.
    unset($checklist['security_review']['file_perms']);
    if ($store) {

      // Remove checks that are being skipped.
      $skipped = security_review_skipped_checks();
      if (!empty($skipped)) {
        foreach ($skipped as $module => $checks) {
          foreach ($checks as $check_name => $check) {
            unset($checklist[$module][$check_name]);
          }
          if (empty($checklist[$module])) {
            unset($checklist[$module]);
          }
        }
      }
    }

    // Run the checklist.
    $checklist_results = security_review_run($checklist, $log);
    if ($store) {
      security_review_store_results($checklist_results);
    }

    // Collect results.
    foreach ($checklist_results as $module => $checks) {
      foreach ($checks as $check_name => $check) {
        $check_name = $module . '-' . $check_name;
        if (!is_null($check['result'])) {
          $status = $check['result'] ? 'success' : 'error';
          if ($check_result = _security_review_drush_format_result($check, $status)) {
            $output[$check_name] = $check_result;
          }
        }
      }
    }
  }
  elseif ($lastrun) {

    // Retrieve results from last run of the checklist.
    $results = db_query("SELECT namespace, reviewcheck, result, lastrun, skip, skiptime, skipuid FROM {security_review}");
    while ($result = db_fetch_array($results)) {
      $checks[] = $result;
    }

    // Collect results.
    if (!empty($checks)) {
      foreach ($checks as $check) {
        $check_name = $check['namespace'] . '-' . $check['reviewcheck'];
        $check_data = array_merge($check, $checklist[$check['namespace']][$check['reviewcheck']]);
        $status = $check['result'] ? 'success' : 'error';
        if ($check_result = _security_review_drush_format_result($check_data, $status)) {
          $output[$check_name] = $check_result;
        }
      }
    }
  }
  return $output;
}