def test_ewsdate(self): self.assertEqual(EWSDate(2000, 1, 1).ewsformat(), '2000-01-01') self.assertEqual(EWSDate.from_string('2000-01-01'), EWSDate(2000, 1, 1)) self.assertEqual(EWSDate.from_string('2000-01-01Z'), EWSDate(2000, 1, 1)) self.assertEqual(EWSDate.from_string('2000-01-01+01:00'), EWSDate(2000, 1, 1)) self.assertEqual(EWSDate.from_string('2000-01-01-01:00'), EWSDate(2000, 1, 1)) self.assertIsInstance( EWSDate(2000, 1, 2) - EWSDate(2000, 1, 1), datetime.timedelta) self.assertIsInstance( EWSDate(2000, 1, 2) + datetime.timedelta(days=1), EWSDate) self.assertIsInstance( EWSDate(2000, 1, 2) - datetime.timedelta(days=1), EWSDate) # Test in-place add and subtract dt = EWSDate(2000, 1, 2) dt += datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDate) self.assertEqual(dt, EWSDate(2000, 1, 3)) dt = EWSDate(2000, 1, 2) dt -= datetime.timedelta(days=1) self.assertIsInstance(dt, EWSDate) self.assertEqual(dt, EWSDate(2000, 1, 1)) with self.assertRaises(ValueError): EWSDate.from_date(EWSDate(2000, 1, 2))
def __init__(self, scan_id): multiprocessing.Process.__init__(self) print('Program started') self.scan_id = scan_id django.setup() from os2webscanner.models.scan_model import Scan scan_object = Scan.objects.get(pk=self.scan_id) valid_domains = scan_object.domains.filter( validation_status=Domain.VALID ) """Making scan dir if it does not exists""" if not os.path.exists(scan_object.scan_dir): print('Creating scan dir {}'.format(scan_object.scan_dir)) os.makedirs(scan_object.scan_dir) scan_dir = scan_object.scan_dir + '/' """Handling last scannings date""" last_scannings_date = None if scan_object.do_last_modified_check: last_scannings_date = scan_object.exchangescan.last_scannings_date if last_scannings_date: last_scannings_date = EWSDate.from_date( last_scannings_date) """Foreach domain x number of mail processors are started.""" for domain in valid_domains: credentials = (domain.authentication.username, domain.authentication.get_password()) self.user_queue = multiprocessing.Queue() read_users(self.user_queue, domain.exchangedomain.get_userlist_file_path()) self.done_queue = multiprocessing.Queue() mail_ending = domain.url scanners = {} for i in range(0, NUMBER_OF_EMAIL_THREADS): scanners[i] = ExchangeServerScan(credentials, self.user_queue, self.done_queue, scan_dir, mail_ending, start_date= last_scannings_date) scanners[i].start() print('Started scanner {}'.format(i)) time.sleep(1) self.scanners = scanners print('Scanners started...')
def __init__(self, scan_id): multiprocessing.Process.__init__(self) print('Program started') self.scan_id = scan_id django.setup() from os2webscanner.models.scan_model import Scan scan_object = Scan.objects.get(pk=self.scan_id) valid_domains = scan_object.domains.filter( validation_status=Domain.VALID) """Making scan dir if it does not exists""" if not os.path.exists(scan_object.scan_dir): print('Creating scan dir {}'.format(scan_object.scan_dir)) os.makedirs(scan_object.scan_dir) scan_dir = scan_object.scan_dir + '/' """Handling last scannings date""" last_scannings_date = None if scan_object.do_last_modified_check: last_scannings_date = scan_object.exchangescan.last_scannings_date if last_scannings_date: last_scannings_date = EWSDate.from_date(last_scannings_date) """Foreach domain x number of mail processors are started.""" for domain in valid_domains: credentials = (domain.authentication.username, domain.authentication.get_password()) self.user_queue = multiprocessing.Queue() read_users(self.user_queue, domain.exchangedomain.get_userlist_file_path()) self.done_queue = multiprocessing.Queue() mail_ending = domain.url scanners = {} for i in range(0, NUMBER_OF_EMAIL_THREADS): scanners[i] = ExchangeServerScan( credentials, self.user_queue, self.done_queue, scan_dir, mail_ending, start_date=last_scannings_date) scanners[i].start() print('Started scanner {}'.format(i)) time.sleep(1) self.scanners = scanners print('Scanners started...')
if len(user.strip()) == 0: users.remove(user) for user in users: user_queue.put(user) if __name__ == '__main__': import settings_local as settings import password amqp = True credentials = ('mailscan', password.password) number_of_threads = int(sys.argv[1]) try: start_arg = datetime.strptime(sys.argv[2], '%Y-%m-%d') start_date = EWSDate.from_date(start_arg) except IndexError: start_date = None # Scan from beginning of time # Populate user queue user_queue = Queue() done_queue = Queue() read_users(user_queue, settings.user_path) # Stats should be run before the scanners to allow stats to mke the # correct initial-value measurements stats = Stats(user_queue, log_data=True) for i in range(0, number_of_threads): scanner = ExchangeServerExport(credentials, user_queue, done_queue, settings.export_path,