예제 #1
0
 /**
  * Execute the "info" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  * @throws \Exception
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $setting = $input->getOption('setting');
     $options = array();
     if ($setting === null) {
         throw new \Exception('No setting provided!');
     }
     $scan = new \Psecio\Iniscan\Scan();
     $ruleSet = $scan->getRules();
     // see if we can find info about the setting
     $found = array();
     foreach ($ruleSet as $section => $rules) {
         foreach ($rules as $rule) {
             if (isset($rule->test->key) && $rule->test->key === $setting) {
                 if (isset($rule->info)) {
                     $found[] = $rule;
                 }
             }
         }
     }
     if (!empty($found)) {
         $outputHandler = new \Psecio\Iniscan\Command\InfoCommand\Output\Console($output, $options);
         return $outputHandler->render($found);
     } else {
         $output->writeLn('No information found for setting ' . $setting);
     }
 }
예제 #2
0
 /**
  * Execute the "list" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  * @throws \Psecio\Iniscan\Exceptions\FormatNotFoundException
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $format = $input->getOption('format');
     $scan = new \Psecio\Iniscan\Scan();
     $rules = $scan->getRules();
     $options = array();
     $format = $format === null ? 'console' : $format;
     $formatClass = "\\Psecio\\Iniscan\\Command\\ListCommand\\Output\\" . ucwords(strtolower($format));
     if (!class_exists($formatClass)) {
         throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "' . $format . '" not found');
     }
     $outputHandler = new $formatClass($output, $options);
     return $outputHandler->render($rules);
 }
예제 #3
0
 /**
  * Execute the "fix" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  * @throws \Exception
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getOption('path');
     $context = array();
     // if we're not given a path at all, try to figure it out
     if ($path === null) {
         $path = php_ini_loaded_file();
     }
     if (!is_file($path)) {
         throw new \Exception('Path is null or not accessible: "' . $path . '"');
     }
     $scan = new \Psecio\Iniscan\Scan($path, $context);
     $scan->execute();
     $scan->getMarked();
     $result = pathinfo($path);
     // to start, we need a backup of the file (overwrite if there)
     $backupPath = './' . $result['basename'] . '-' . date('mdy');
     copy($path, $backupPath);
     // Now les get our rules and parse them
     $scan = new \Psecio\Iniscan\Scan($path, $context);
     $rules = get_object_vars($scan->getRules());
     $output->writeLn($this->generateIniOutput($rules));
 }
예제 #4
0
 /**
  * Execute the "scan" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  * @throws \Psecio\Iniscan\Exceptions\FormatNotFoundException
  * @throws \Exception
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getOption('path');
     $failOnly = $input->getOption('fail-only');
     $format = $input->getOption('format');
     $context = $input->getOption('context');
     $threshold = $input->getOption('threshold');
     $version = $input->getOption('php');
     $outputPath = $input->getOption('output');
     if ($format === 'html' && $outputPath === null) {
         throw new \InvalidArgumentException('Output path must be set for format "HTML"');
     }
     $context = $context !== null ? explode(', ', $context) : array();
     // If we're not given a version, assume the current version
     if ($version === null) {
         $version = PHP_VERSION;
     }
     // if we're not given a path at all, try to figure it out
     if ($path === null) {
         $path = php_ini_loaded_file();
     }
     if (!is_file($path)) {
         throw new \Exception('Path is null or not accessible: "' . $path . '"');
     }
     $scan = new \Psecio\Iniscan\Scan($path, $context, $threshold, $version);
     $results = $scan->execute();
     $deprecated = $scan->getMarked();
     $options = array('path' => $path, 'failOnly' => $failOnly, 'deprecated' => $deprecated, 'verbose' => $input->getOption('verbose'), 'output' => $outputPath);
     $format = $format === null ? 'console' : $format;
     $formatClass = "\\Psecio\\Iniscan\\Command\\ScanCommand\\Output\\" . ucwords(strtolower($format));
     if (!class_exists($formatClass)) {
         throw new \Psecio\Iniscan\Exceptions\FormatNotFoundException('Output format "' . $format . '" not found');
     }
     $outputHandler = new $formatClass($output, $options);
     return $outputHandler->render($results);
 }