def initialize_scan(urllist: UrlList, manual_or_scheduled: str = "scheduled"):
    # We need to store the scan type in the InternetNLV2Scan at creation, because the type in the list might change:
    translated_scan_types = {'web': 'web', 'mail': 'mail_dashboard'}
    new_scan = InternetNLV2Scan()
    new_scan.type = translated_scan_types[urllist.scan_type]
    new_scan.save()
    internet_nl_v2_websecmap.update_state(
        new_scan, "requested and empty",
        "requested a scan to be performed on internet.nl api")

    accountinternetnlscan = AccountInternetNLScan()
    accountinternetnlscan.account = urllist.account
    accountinternetnlscan.urllist = urllist
    accountinternetnlscan.started_on = datetime.now(pytz.utc)
    accountinternetnlscan.scan = new_scan
    accountinternetnlscan.state = ""
    accountinternetnlscan.save()

    # and start the process.
    update_state("requested", accountinternetnlscan)

    # Sprinkling an activity stream action.
    action.send(urllist.account,
                verb=f'started {manual_or_scheduled} scan',
                target=accountinternetnlscan,
                public=False)

    return accountinternetnlscan
Exemple #2
0
def create_scan(internal_scan_type: str,
                urllist: UrlList,
                manual_or_scheduled: str = "scheduled") -> int:
    new_scan = InternetNLV2Scan()
    new_scan.type = internal_scan_type
    new_scan.save()
    internet_nl_v2_websecmap.update_state(
        new_scan.id, "requested and empty",
        "requested a scan to be performed on internet.nl api")

    # We need to store the scan type in the InternetNLV2Scan at creation, because the type in the list might change:
    accountinternetnlscan = AccountInternetNLScan()
    accountinternetnlscan.account = urllist.account
    accountinternetnlscan.urllist = urllist
    accountinternetnlscan.started_on = datetime.now(pytz.utc)
    accountinternetnlscan.scan = new_scan
    accountinternetnlscan.state = ""
    accountinternetnlscan.save()

    # and start the process.
    update_state("requested", accountinternetnlscan.id)

    # Sprinkling an activity stream action.
    action.send(urllist.account,
                verb=f'started {manual_or_scheduled} scan',
                target=accountinternetnlscan,
                public=False)

    return accountinternetnlscan.id