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