Commit 512abf52 authored by Alexandre Dulaunoy's avatar Alexandre Dulaunoy
Browse files

Merge branch 'master' of github.com:adulau/cve-search

parents 5384885c d843d700
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ def progressbar(it, prefix="Preparing ", size=50):
    count = len(it)

    def _show(_i):
        if count != 0:
            x = int(size * _i / count)
            sys.stdout.write("%s[%s%s] %i/%i\r" % (prefix, "#" * x, " " * (size - x), _i, count))
            sys.stdout.flush()
+11 −4
Original line number Diff line number Diff line
@@ -185,6 +185,12 @@ class CVEHandler(ContentHandler):
            self.inPUBElem = 0
            self.cves[-1]['Modified'] = self.PUB

def getFile(getfile):
    try:
        return urlopen(Configuration.getCVEDict() + getfile)
    except:
        sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))

if __name__ == '__main__':
    # connect to the DB.
    db = Configuration.getMongoConnection()
@@ -197,11 +203,12 @@ if __name__ == '__main__':
    if args.u:
        # get the 'modified' file
        getfile = file_prefix + file_mod + file_suffix
        f = urlopen(Configuration.getCVEDict() + getfile)
        f = getFile(getfile)
        i = info.find_one({'db': 'cve'})
        if i is not None:
            if f.headers['last-modified'] == i['last-modified']:
                sys.exit("Not modified")
                print("Not modified")
                sys.exit(0)
        info.update({'db': 'cve'}, {"$set": {'last-modified': f.headers['last-modified']}}, upsert=True)

        # get your parser on !!
@@ -225,7 +232,7 @@ if __name__ == '__main__':
                collection.insert(item)
        # get the 'recent' file
        getfile = file_prefix + file_rec + file_suffix
        f = urlopen(Configuration.getCVEDict() + getfile)
        f = getFile(getfile)
        parser = make_parser()
        ch = CVEHandler()
        parser.setContentHandler(ch)
@@ -264,7 +271,7 @@ if __name__ == '__main__':
                ch = CVEHandler()
                parser.setContentHandler(ch)
                getfile = file_prefix + str(x) + file_suffix
                f = urlopen(Configuration.getCVEDict() + getfile)
                f = getFile(getfile)
                parser.parse(f)
                if args.v:
                    for item in ch.cves:
+6 −2
Original line number Diff line number Diff line
@@ -167,11 +167,15 @@ parser = make_parser()
ch = CapecHandler()
parser.setContentHandler(ch)
# check modification date
try:
    f = urlopen(capecurl)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(capecurl))
i = info.find_one({'db': 'capec'})
if i is not None:
    if f.headers['last-modified'] == i['last-modified']:
        sys.exit("Not modified")
        print("Not modified")
        sys.exit(0)
# parse xml and store in database
parser.parse(f)
bulk = capec.initialize_ordered_bulk_op()
+6 −2
Original line number Diff line number Diff line
@@ -81,11 +81,15 @@ parser = make_parser()
ch = CPEHandler()
parser.setContentHandler(ch)
# check modification date
try:
    f = urlopen(cpedict)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(cpedict))
i = info.find_one({'db': 'cpe'})
if i is not None:
    if f.headers['last-modified'] == i['last-modified']:
        sys.exit("Not modified")
        print("Not modified")
        sys.exit(0)
# parse xml and store in database
parser.parse(f)
bulk = cpe.initialize_ordered_bulk_op()
+4 −2
Original line number Diff line number Diff line
@@ -50,7 +50,8 @@ date = False
if icve is not None and icpeo is not None:
    # Go check date
    if icve['last-modified'] >= icpeo['last-modified']:
        sys.exit("Not modified")
        print("Not modified")
        sys.exit(0)
    else:
        date = True

@@ -84,6 +85,7 @@ for item in progressbar(col):

                title = title.title()
                batch.append({'id': cpeentry, 'title': title})
if len(batch) != 0:
    cpeother.insert(batch)

#update database info after successful program-run
Loading