Added new flag options

Added a single short flag for every long flag and a single long flag for every short flag.
This now gives us 2 ways to set each flag.
Also updated the showhelp.
Dropped an unnecessary 'else' statement.
This commit is contained in:
nichogenius
2017-08-15 09:14:31 -06:00
committed by GitHub
parent d7d85f13c7
commit ab8a6c471a

View File

@@ -38,40 +38,42 @@ class MalwareScanner
public function __construct() public function __construct()
{ {
$options = getopt('hd:e::i::', array('hide-ok', 'hide-whitelist', 'extra-check', 'follow-symlink')); $options = getopt('he:i:kwxd:l', array('help', 'extension:', 'ignore:', 'hide-ok', 'hide-whitelist', 'extra-check', 'directory:', 'follow-symlink'));
if (isset($options['h'])) { if (isset($options['help']) || isset($options['h'])) {
$this->showHelp(); $this->showHelp();
} else { exit;
if (isset($options['e'])) { }
$ext = $options['e']; if (isset($options['extension']) || isset($options['e'])) {
$ext = isset($options['extension']) ? $options['extension'] : $options['e'];
if ($ext[0] != '.') { if ($ext[0] != '.') {
$ext = '.' . $ext; $ext = '.' . $ext;
} }
$this->extension = strtolower($ext); $this->extension = strtolower($ext);
} }
if (isset($options['i'])) { if (isset($options['ignore']) || isset($options['i'])) {
$this->ignore = is_array($options['i']) ? $options['i'] : array($options['i']); $tmp = isset($options['ignore']) ? $options['ignore'] : $options['i'];
$this->ignore = is_array($tmp) ? $tmp : array($tmp);
} }
if (isset($options['hide-ok'])) { if (isset($options['hide-ok']) || isset($options['k'])) {
$this->flagHideOk = true; $this->flagHideOk = true;
} }
if (isset($options['hide-whitelist'])) { if (isset($options['hide-whitelist']) || isset($options['w'])) {
$this->flagHideWhitelist = true; $this->flagHideWhitelist = true;
} }
if (isset($options['extra-check'])) { if (isset($options['extra-check']) || isset($options['x'])) {
$this->extraCheck = true; $this->extraCheck = true;
} }
if (isset($options['follow-symlink'])) { if (isset($options['follow-symlink']) || isset($options['l'])) {
$this->followSymlink = true; $this->followSymlink = true;
} }
if (isset($options['d'])) { if (isset($options['directory']) || isset($options['d'])) {
$this->run($options['d']); $tmp = isset($options['directory']) ? $options['directory'] : $options['d'];
$this->run($tmp);
} else { } else {
$this->out(MalwareScanner::ANSI_RED, 'ER', 'No directory specified'); $this->out(MalwareScanner::ANSI_RED, 'ER', 'No directory specified');
$this->showHelp(); $this->showHelp();
} }
} }
}
public function run($dir) public function run($dir)
{ {
@@ -279,14 +281,15 @@ class MalwareScanner
private function showHelp() private function showHelp()
{ {
echo 'Usage scan.php -d <directory> [-i=<directory|file>] [-e=.php] [--hide-ok] [--hide-whitelist]' . PHP_EOL; echo 'Usage: scan.php -d <directory>' . PHP_EOL;
echo ' -d Directory for searching' . PHP_EOL; echo ' -h --help Show this help message' . PHP_EOL;
echo ' -e=.php Extension' . PHP_EOL; echo ' -d <directory> --directory Directory for searching' . PHP_EOL;
echo ' -i=<directory|file> Directory of file to igonre' . PHP_EOL; echo ' -e .php --extension File Extension to Scan' . PHP_EOL;
echo ' --hide-ok Hide OK aka not infected messages' . PHP_EOL; echo ' -i <directory|file> --ignore Directory of file to igonre' . PHP_EOL;
echo ' --hide-whitelist Hide whitelisted messages' . PHP_EOL; echo ' -k --hide-ok Hide OK aka not infected messages' . PHP_EOL;
echo ' --extra-check Adds GoogleBot and htaccess to Scan List' . PHP_EOL; echo ' -w --hide-whitelist Hide whitelisted messages' . PHP_EOL;
echo ' --follow-symlink Follow symlinked directories' . PHP_EOL; echo ' -x --extra-check Adds GoogleBot and htaccess to Scan List' . PHP_EOL;
echo ' -l --follow-symlink Follow symlinked directories' . PHP_EOL;
} }
} }