def __init__(self, scan_directory, file_path, file_name, api_key, server, reports_folder, tex_method, tex_folder, features=DEFAULT_FEATURES, reports=DEFAULT_REPORTS, recursive=DEFAULT_RECURSIVE_EMULATION): """ Setting the requested parameters and creating :param scan_directory: the requested directory :param file_path: the requested file path :param file_name: the requested file name :param api_key: API Key for the cloud service :param server: Check Point SandBlast Appliance ip address :param reports_folder: the folder which the reports will be save to :param tex_method: the method to be used with Thereat Extraction :param tex_directory: the folder which the Scrubbing attachments will be save to :param features: the requested features :param reports: type of reports :param recursive: find files in the requested directory recursively """ if api_key: self.headers = {'Authorization': api_key} else: self.headers = {} self.reports_folder = reports_folder self.tex_folder = tex_folder if features: self.features = features else: self.features = DEFAULT_FEATURES self.payload = Payload(reports, tex_method) self.server = server self.verify = True try: if reports_folder and not os.path.exists(reports_folder): os.makedirs(reports_folder) except Exception as e: Logger.log(LogLevel.CRITICAL, 'failed to create the needed folders', e) max_files = DEFAULT_MAX_FILES Logger.log(LogLevel.INFO, 'Calculating hash of files ') if scan_directory: for root, subdir_list, file_list in os.walk(ur'%s' % scan_directory): for fn in file_list: if max_files == 0: Logger.log(LogLevel.INFO, 'Max of %d files' % DEFAULT_MAX_FILES) break else: max_files -= 1 if os.path.isfile(os.path.join(root, fn)): file_data = FileData(fn.encode('utf-8'), os.path.join(root, fn), list(self.features)) file_data.compute_hashes() self.pending[file_data.md5] = file_data if not recursive or max_files == 0: break
Logger.log(LogLevel.INFO, 'Max of %d files' % DEFAULT_MAX_FILES) break else: max_files -= 1 if os.path.isfile(os.path.join(root, fn)): file_data = FileData(fn.encode('utf-8'), os.path.join(root, fn), list(self.features)) file_data.compute_hashes() self.pending[file_data.md5] = file_data if not recursive or max_files == 0: break else: file_data = FileData(file_name, file_path, list(self.features)) file_data.compute_hashes() self.pending[file_data.md5] = file_data def set_cookie(self, response): """ Set the response cookie for all of the requests :param response: the response which contains the cookie """ if 'te_cookie' in response.cookies: self.cookies['te_cookie'] = response.cookies['te_cookie'] def upload_directory(self): # Use copy of the list for proper removal res = True for file_data in self.pending.values():