Example #1
0
def dropcollection(collection=None):
    if collection is None:
        return False
    if collection == "cve":
        collection = "cves"
    ret = db.dropCollection(collection)
    return ret
Example #2
0
                if args.v:
                    print("Existing CVE found : {} then update".format(
                        item['id']))
                db.updateCVE(item)
            # if not, create it.
            else:
                db.insertCVE(item)
    elif args.p:
        c = db.getSize('cves')
        if args.v:
            print(str(c))
        if c > 0 and args.a is False:
            print("database already populated")
        else:
            print("Database population started")
            db.dropCollection("cves")
            for x in range(cveStartYear, year):
                getfile = file_prefix + str(x) + file_suffix
                try:
                    (f, r) = Configuration.getFile(
                        Configuration.getFeedURL('cve') + getfile)
                except:
                    sys.exit(
                        "Cannot open url %s. Bad URL or not connected to the internet?"
                        % (Configuration.getFeedURL('cve') + getfile))

                cvej = json.loads(f.read())
                if cvej['CVE_data_type'] != 'CVE':
                    print('JSON data type is not CVE but {}'.format(
                        cvej['CVE_data_type']))
                for cveitem in cvej['CVE_Items']:
        cpeList = []
        for cpeitem in cpej["matches"]:
            item = process_cpe_item(cpeitem)
            cpeList.append(item)
        db.bulkUpdate("cpe", cpeList)

        #update database info after successful program-run
        db.setColUpdate('cpe', last_modified)
    elif args.p:
        c = db.getSize('cpe')
        if args.v:
            print(str(c))
        if c > 0 and args.a is False:
            print("Database already populated")
        else:
            print("Database population started")
            db.dropCollection("cpe")
            try:
                (f, r) = Configuration.getFile(Configuration.getFeedURL('cpe'))
            except:
                sys.exit(
                    "Cannot open url %s. Bad URL or not connected to the internet?"
                    % (Configuration.getFeedURL("cpe")))

            cpej = json.loads(f.read())
            cpeList = []
            for cpeitem in cpej["matches"]:
                item = process_cpe_item(cpeitem)
                cpeList.append(item)
            db.bulkInsert("cpe", cpeList)
Example #4
0
def dropcollection(collection=None):
    if collection is None:
        return False
    return db.dropCollection(collection)
Example #5
0
def dropcollection(collection=None):
    if collection is None:
        return False
    return db.dropCollection(collection)