Beispiel #1
0
def import_scope(scopetype=""):
    if scopetype == "blacklist":
        importBlacklist = True
        importForm = forms.ImportBlacklistForm()
    elif scopetype == "scope":
        importBlacklist = False
        importForm = forms.ImportScopeForm()
    else:
        return abort(404)
    if importForm.validate_on_submit():
        newScopeItems = importForm.scope.data.split("\n")
        fail, exist, success = ScopeItem.import_scope(newScopeItems,
                                                      importBlacklist)
        db.session.commit()
        current_app.ScopeManager.update()
        if success:
            flash(f"{len(success)} targets added to {scopetype}!", "success")
        if exist:
            flash(f"{len(exist)} targets already existed!", "info")
        if fail:
            flash(f"{len(fail)} targets failed to import!", "danger")
            for item in fail:
                flash(f"{item}", "danger")
    else:
        for field, errors in importForm.errors.items():
            for error in errors:
                flash(error, "danger")
    return redirect(url_for(f"admin.{scopetype}"))
Beispiel #2
0
def import_scope(file, blacklist, verbose):
    with open(file, "r") as scope:
        addresses = scope.readlines()
    fail, exist, success = ScopeItem.import_scope(addresses, blacklist)
    db.session.commit()

    summaryMessages = [
        f"{len(success)} successfully imported.",
        f"{len(exist)} already existed.",
        f"{len(fail)} failed to import.",
    ]

    if verbose:
        print_imports("\nSuccessful Imports:", success)
        print_imports("\nAlready Existed:", exist)
        print_imports("\nFailed Imports:", fail)
    print("\n".join(summaryMessages))