def tasks_create_submit(): files = [] for f in request.files.getlist("file") + request.files.getlist("files"): files.append({ # The pseudo-file "f" has a read() method so passing it along to # the Submit Manager as-is should be fine. "name": f.filename, "data": f, }) if files: submit_type = "files" elif request.form.get("strings"): submit_type = "strings" strings = request.form["strings"].split("\n") else: return json_error(500, "No files or strings have been given!") # Default options. options = { "procmemdump": "yes", } options.update(parse_options(request.form.get("options", ""))) submit_id = sm.pre( submit_type, files or strings, sm.translate_options_to(options) ) if not submit_id: return json_error(500, "Error creating Submit entry") files, errors, options = sm.get_files(submit_id, astree=True) options["full-memory-dump"] = parse_bool( request.form.get("memory", config("cuckoo:cuckoo:memory_dump")) ) options["enforce-timeout"] = parse_bool( request.form.get("enforce_timeout", 0) ) def selected(files, arcname=None): ret = [] for entry in files: if entry.get("selected"): entry["arcname"] = arcname ret.append(entry) ret += selected(entry["children"], arcname or entry["filename"]) return ret task_ids = sm.submit(submit_id, { "global": { "timeout": request.form.get("timeout", ""), "priority": request.form.get("priority", 1), "tags": request.form.get("tags", None), "custom": request.form.get("custom", ""), "owner": request.form.get("owner", ""), "clock": request.form.get("clock", None), "options": options, }, "file_selection": selected(files), }) return jsonify(submit_id=submit_id, task_ids=task_ids, errors=errors)
def tasks_create_file(): data = request.files["file"] package = request.form.get("package", "") timeout = request.form.get("timeout", "") priority = request.form.get("priority", 1) options = request.form.get("options", "") machine = request.form.get("machine", "") platform = request.form.get("platform", "") tags = request.form.get("tags", None) custom = request.form.get("custom", "") owner = request.form.get("owner", "") clock = request.form.get("clock", None) user_id = request.form.get("user_id", "") memory = parse_bool(request.form.get("memory", 0)) unique = parse_bool(request.form.get("unique", 0)) enforce_timeout = parse_bool(request.form.get("enforce_timeout", 0)) content = data.read() if unique and db.find_sample(sha256=hashlib.sha256(content).hexdigest()): return json_error(400, "This file has already been submitted") temp_file_path = Files.temp_named_put(content, data.filename) task_id = db.add_path( file_path=temp_file_path, package=package, timeout=timeout, priority=priority, options=options, machine=machine, platform=platform, tags=tags, custom=custom, owner=owner, memory=memory, enforce_timeout=enforce_timeout, clock=clock, user_id=user_id, ) return jsonify(task_id=task_id)
def tasks_create_file(): data = request.files["file"] package = request.form.get("package", "") timeout = request.form.get("timeout", "") priority = request.form.get("priority", 1) options = request.form.get("options", "") machine = request.form.get("machine", "") platform = request.form.get("platform", "") tags = request.form.get("tags", None) custom = request.form.get("custom", "") owner = request.form.get("owner", "") clock = request.form.get("clock", None) memory = parse_bool(request.form.get("memory", 0)) unique = parse_bool(request.form.get("unique", 0)) enforce_timeout = parse_bool(request.form.get("enforce_timeout", 0)) content = data.read() if unique and db.find_sample(sha256=hashlib.sha256(content).hexdigest()): return json_error(400, "This file has already been submitted") temp_file_path = Files.temp_named_put(content, data.filename) task_id = db.add_path( file_path=temp_file_path, package=package, timeout=timeout, priority=priority, options=options, machine=machine, platform=platform, tags=tags, custom=custom, owner=owner, memory=memory, enforce_timeout=enforce_timeout, clock=clock ) return jsonify(task_id=task_id)
def check(self, value): try: parse_bool(value) return True except: return False
def parse(self, value): try: return parse_bool(value) except: log.error("Incorrect Boolean %s", value)
def test_bool(): assert utils.parse_bool("true") is True assert utils.parse_bool("True") is True assert utils.parse_bool("yes") is True assert utils.parse_bool("on") is True assert utils.parse_bool("1") is True assert utils.parse_bool("false") is False assert utils.parse_bool("False") is False assert utils.parse_bool("None") is False assert utils.parse_bool("no") is False assert utils.parse_bool("off") is False assert utils.parse_bool("0") is False assert utils.parse_bool("2") is True assert utils.parse_bool("3") is True assert utils.parse_bool(True) is True assert utils.parse_bool(1) is True assert utils.parse_bool(2) is True assert utils.parse_bool(False) is False assert utils.parse_bool(0) is False