Skip to content

Commit

Permalink
Added option to read paths from an input file
Browse files Browse the repository at this point in the history
  • Loading branch information
SniperSister committed Nov 7, 2014
1 parent 6c68aa8 commit c755a88
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,9 @@ This results in a report file like this:
"version":"6.14",
"path":"\/var\/www\/drupal-6.14"
}
]
]

### Read paths from an input file
It's also possible to pass a file that contains a 0-byte separated list of paths:

cmsscanner.phar cmsscanner:detect --readfromfile /absolute/path/to/file
39 changes: 37 additions & 2 deletions src/Command/DetectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure()
->setDescription('Detects all CMS installations in a given path')
->addArgument(
'paths',
InputArgument::IS_ARRAY,
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Directories where CMS should be detected'
)
->addOption(
Expand All @@ -54,6 +54,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'Write a detailed JSON report to the specified path'
)
->addOption(
'readfromfile',
null,
InputOption::VALUE_NONE,
'Read \\0 separated target directories from a file, passed as the argument'
)
;

}
Expand All @@ -74,7 +80,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Search for files in the directory specified in the CLI argument
$finder->files();

foreach ($input->getArgument('paths') as $path) {
// Get paths to scan in; Either from file or from the CLI arguments
if ($input->getOption('readfromfile')) {
$paths = $input->getArgument('paths');
$pathFile = reset($paths);
$paths = $this->readPathsFromFile($pathFile);
} else {
$paths = $input->getArgument('paths');
}

foreach ($paths as $path) {
$finder->in($path);
}

Expand Down Expand Up @@ -233,4 +248,24 @@ protected function writeReport(array $results, $path)
throw new \RuntimeException("Could not write to report file");
}
}

/**
* Extracts paths to scan in from an input file
*
* @param $pathsFile
*
* @return array
*/
protected function readPathsFromFile($pathsFile)
{
if (!file_exists($pathsFile) || !is_readable($pathsFile)) {
throw new \InvalidArgumentException("Can not read paths file");
}

$fileContent = file_get_contents($pathsFile);

$paths = explode("\0", $fileContent);

return $paths;
}
}

0 comments on commit c755a88

Please sign in to comment.