From ab8a6c471a8d26ca4e41a8b5a0f3701773baf1dd Mon Sep 17 00:00:00 2001 From: nichogenius Date: Tue, 15 Aug 2017 09:14:31 -0600 Subject: [PATCH] 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. --- scan.php | 79 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/scan.php b/scan.php index e2a2a02..a9715a9 100644 --- a/scan.php +++ b/scan.php @@ -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 [-i=] [-e=.php] [--hide-ok] [--hide-whitelist]' . PHP_EOL; - echo ' -d Directory for searching' . PHP_EOL; - echo ' -e=.php Extension' . PHP_EOL; - echo ' -i= 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 ' . PHP_EOL; + echo ' -h --help Show this help message' . PHP_EOL; + echo ' -d --directory Directory for searching' . PHP_EOL; + echo ' -e .php --extension File Extension to Scan' . PHP_EOL; + echo ' -i --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; } }