#!/usr/bin/python # Copyright (c) 2016-2016 David Anderson. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of the example nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY David Anderson ''AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL David Anderson BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. import sys # Do to a single text line. def xmlize(linea): outi = [] l = linea if l.find("
") != -1: s2 = l + '\n' return s2 if l.find("") != -1: s2 = l + '\n' return s2 for c in l: if c == '<': outi += ["<"] elif c == '>': outi += [">"] elif c == "&": outi += ["&"] elif c == "'": outi += ["'"] elif c == '"': outi += ["""] else: outi += [c] outi += ["\n"] s2 = ''.join(outi) return s2 def paraline(name,linea): out = '' if len(linea) <1: out = "
" + name + ":"+ "
" return out out = "" + name + ": " out +=linea out += "
" return out; def paralines(name,lines): if len(lines) <1: out = "" + name + ":"+ "
" return out out = "" + name + ": " for lin in lines: f = xmlize(lin) out += f out += "
" return out; def para(name,str): if str == None: out = "" + name + ":"+ "
" elif len(str) > 0: out = "" + name + ": " + str + "
" else: out = "" + name + ":"+ "
" return out class bugrecord: def __init__(self,dwid): self._id= dwid.strip() self._cve = '' self._datereported = '' self._reportedby = '' self._vulnerability = [] self._product = '' self._description = [] self._datefixed = '' self._references = [] self._gitfixid = '' self._tarrelease = '' def setcve(self,pubid): if self._cve != '': print "Duplicate cve ",self._cve,pubid sys.exit(1) self._cve = pubid.strip() def setdatereported(self,rep): if self._datereported != '': print "Duplicate datereported ",self._datereported,rep sys.exit(1) self._datereported = rep.strip() def setreportedby(self,rep): if self._reportedby != '': print "Duplicate reportedby ",self._reportedby,rep sys.exit(1) self._reportedby = rep.strip() def setvulnerability(self,vuln): if len(self._vulnerability) != 0: print "Duplicate vulnerability ",self._vulnerability,vuln sys.exit(1) self._vulnerability = vuln def setproduct(self,p): if len(self._product) != 0: print "Duplicate product ",self._product,p sys.exit(1) self._product = p.strip() def setdescription(self,d): if len(self._description) != 0: print "Duplicate description ",self._description,d sys.exit(1) self._description = d def setdatefixed(self,d): if len(self._datefixed) != 0: print "Duplicate datefixed ",self._datefixed,d sys.exit(1) self._datefixed = d.strip() def setreferences(self,r): if len(self._references) != 0: print "Duplicate references ",self._references,r sys.exit(1) self._references = r def setgitfixid(self,g): if len(self._gitfixid) != 0: print "Duplicate gitfixid ",self._gitfixid,g sys.exit(1) self._gitfixid = g.strip() def settarrelease(self,g): if len(self._tarrelease) != 0: print "Duplicate tarrelease ",self._tarrelease,g sys.exit(1) self._tarrelease = g.strip() def plist(self,title,lines): if lines == None: print title return if len(lines) == 1: print title,lines[0] return print title for l in lines: print l def printbug(self): print "" print "id:",self._id print "cve:",self._cve print "datereported:",self._datereported print "reportedby:",self._reportedby self.plist("vulnerability:",self._vulnerability) print "product:",self._product self.plist("description:",self._description) print "datefixed:",self._datefixed self.plist("references:",self._references) print "gitfixid:",self._gitfixid print "tarrelease:",self._tarrelease def generate_html(self): s5= ''.join(self._id) t = ''.join(['