Bugtracker: More exactly trim CVE information.

This commit is contained in:
Krytarik Raido 2022-10-11 03:34:04 +02:00
parent bfa65ed8c3
commit f2ea4477c0
3 changed files with 8 additions and 5 deletions

View File

@ -23,7 +23,7 @@ import supybot
import supybot.world as world import supybot.world as world
from importlib import reload from importlib import reload
__version__ = "5.5.0" __version__ = "5.6.0"
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com") __author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com")
__contributors__ = { __contributors__ = {
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'], supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],

View File

@ -495,7 +495,7 @@ class Bugtracker(callbacks.PluginRegexp):
else: else:
do_url = False do_url = False
try: try:
report = trackers.CVE().get_bug(cveid, do_url) report = trackers.CVE().get_bug(channel or msg.nick, cveid, do_url)
except trackers.BugNotFoundError: except trackers.BugNotFoundError:
if self.registryValue('replyWhenNotFound'): if self.registryValue('replyWhenNotFound'):
irc.error("Could not find CVE %s" % cveid) irc.error("Could not find CVE %s" % cveid)

View File

@ -72,7 +72,7 @@ cvere = re.compile(r'<th[^>]*>Description</th>.*?<td[^>]*>\s*(?P<cve>.*?)\s*</td
cverre = re.compile(r'<h2[^>]*>\s*(?P<cverr>.*?)\s*</h2>', re.I | re.DOTALL) cverre = re.compile(r'<h2[^>]*>\s*(?P<cverr>.*?)\s*</h2>', re.I | re.DOTALL)
# Define CVE tracker # Define CVE tracker
class CVE: class CVE:
def get_bug(self, cveid, do_url=True): def get_bug(self, channel, cveid, do_url=True):
url = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s" % cveid url = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s" % cveid
try: try:
cvedata = utils.web.getUrl(url).decode('utf-8') cvedata = utils.web.getUrl(url).decode('utf-8')
@ -81,8 +81,11 @@ class CVE:
match = cvere.search(cvedata) match = cvere.search(cvedata)
if match: if match:
cve = utils.web.htmlToText(match.group('cve'), tagReplace='') cve = utils.web.htmlToText(match.group('cve'), tagReplace='')
if len(cve) > 380: desc_max = 450 - len(channel)
cve = cve[:380] + '...' if do_url:
desc_max -= len(url) + 3
if len(cve) > desc_max:
cve = cve[:desc_max-3] + '...'
if do_url: if do_url:
cve += ' <%s>' % url cve += ' <%s>' % url
return cve return cve