Commit b832e86b authored by ale's avatar ale

add an option to run a full scan

parent 3a2c2a64
......@@ -10,9 +10,10 @@ import time
import urllib2
import logging
#from sso.urllib2_handler import SSOProcessor
from sso.urllib2_handler import SSOProcessor
from offlinescan import clamav
from offlinescan import incremental_scan
from offlinescan import full_scan
user_info_pattern = re.compile(
......@@ -68,7 +69,10 @@ def submit(results, submit_url):
def main():
logging.basicConfig(level=logging.INFO)
parser = optparse.OptionParser()
parser = optparse.OptionParser(usage='%prog [<OPTIONS>] <PATH>...')
parser.add_option(
'--full', dest='full_scan', action='store_true',
help='Run a full scan, not an incremental one')
parser.add_option(
'--include', dest='includes', metavar='PATTERN',
action='append', default=[],
......@@ -87,7 +91,11 @@ def main():
if not args:
parser.error('Must specify a PATH')
files = incremental_scan.scan_dirs(args, opts.includes, opts.excludes)
scanfn = incremental_scan.scan_dirs
if opts.full_scan:
scanfn = full_scan.scan_dirs
files = scanfn(args, opts.includes, opts.excludes)
scan_results = clamav.clamscan(files)
if scan_results:
log.info('found new viruses:\n%s', json.dumps(scan_results, indent=4))
......
import fnmatch
import os
def match_any(path, patterns):
for p in patterns:
if fnmatch.fnmatch(path, p):
return True
return False
def scan_dir(root_dir, includes, excludes, changed):
if not root_dir.endswith('/'):
root_dir = root_dir + '/'
for dirpath, dirnames, filenames in os.walk(root_dir):
relpath = dirpath[len(root_dir):]
for path in filenames:
if ((excludes and match_any(path, excludes)) or
(includes and not match_any(path, includes))):
continue
changed.add(os.path.join(root_dir, path))
def scan_dirs(dirs, includes=[], excludes=[]):
"""Run a full recursive scan on 'dirs'."""
changed = set()
for root_dir in dirs:
scan_dir(root_dir, includes, excludes, changed)
return changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment