Commit 45dca6b5 authored by PidgeyL's avatar PidgeyL
Browse files

Merge remote-tracking branch 'upstream/master'

parents 4de02ba9 c9f42bc7
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -7,12 +7,13 @@
#
# Software is free software released under the "Modified BSD license"
#
# Copyright (c) 2014 		Alexandre Dulaunoy - a@foo.be
# Copyright (c) 2014-2015	Alexandre Dulaunoy - a@foo.be
# Copyright (c) 2014-2015 	Pieter-Jan Moreels - pieterjan.moreels@gmail.com

# Imports
import os
import sys
import argparse
runPath = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(runPath, ".."))

@@ -21,8 +22,17 @@ from redis import exceptions as redisExceptions
from lib.Config import Configuration
from lib.Toolkit import pad

argParser = argparse.ArgumentParser(description='CPE entries importer in Redis cache')
argParser.add_argument('-v', action='store_true', default=False, help='Verbose logging')
argParser.add_argument('-o', action='store_true', default=False, help='Import cpeother database in Redis cache')
args = argParser.parse_args()

# connect to db
db = Configuration.getMongoConnection()

if args.o:
    cpe = db.cpeother
else:
    cpe = db.cpe

try:
@@ -32,14 +42,23 @@ except:

for e in cpe.find({}):
    try:
        value = e['cpe_2_2']
        if e['cpe_2_2'].count(':') > 4:
        if args.o is not True:
            prefix = 'cpe_2_2'
            value = e[prefix]
        else:
            value = e['id']
        if args.o is not True:
            if e[prefix].count(':') > 4:
                value = ":".join(value.split(':')[:5])
            (prefix, cpetype, vendor, product, version) = pad(value.split(':'),5)
        else:
            (prefix, cpeversion, cpetype, vendor, product, version, *remaining) = pad(value.split(':'),6)
    except Exception as ex:
        print(ex)
        pass
    try:
        if args.v:
            print(value + " added")
        r.sadd("prefix:" + prefix, cpetype)
        r.sadd("t:" + cpetype, vendor)
        r.sadd("v:" + vendor, product)