91 lines
2.3 KiB
Ruby
91 lines
2.3 KiB
Ruby
require "jekyll"
|
|
require "jekyll-cve-badge/api-helper"
|
|
require "jekyll-cve-badge/version"
|
|
require "json"
|
|
require "net/http"
|
|
require "uri"
|
|
class CVEBadge < Liquid::Tag
|
|
|
|
include Jekyll::CVEBadge::APIHelper
|
|
|
|
def initialize(tagName, content, tokens)
|
|
super
|
|
@content = content
|
|
end
|
|
|
|
def render(context)
|
|
cve_id = "#{context[@content.strip]}"
|
|
|
|
begin
|
|
(cve_severity, cve_score) = get_cvss_severity_score(cve_id)
|
|
rescue NoMethodError
|
|
cve_severity = ""
|
|
cve_score = ""
|
|
end
|
|
|
|
tmpl_path = File.join Dir.pwd, "_includes", "cve-badge.html"
|
|
if File.exist?(tmpl_path)
|
|
tmpl = File.read tmpl_path
|
|
site = context.registers[:site]
|
|
tmpl = (Liquid::Template.parse tmpl).render site.site_payload.merge!({"cve_id" => @cve_id, "cve_severity" => @cve_severity, "cve_score" => @cve_score})
|
|
else
|
|
%Q{<style>
|
|
.cve-container {
|
|
margin-bottom: 1em;
|
|
}
|
|
|
|
.cve-container > a {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.cve-badge {
|
|
color: #fff;
|
|
padding: 2px 7px;
|
|
font-weight: 300;
|
|
font-size: 1.5rem;
|
|
}
|
|
|
|
.cve-id {
|
|
border-radius: 4px 0px 0px 4px;
|
|
background-color: #8963BA;
|
|
background-image: linear-gradient(to top right, #8963BA, #EF476F);
|
|
}
|
|
|
|
.cve-id.severity- {
|
|
border-radius: 4px 4px 4px 4px;
|
|
}
|
|
|
|
.cve-score {
|
|
border-radius: 0px 4px 4px 0px;
|
|
box-shadow: inset 7px 0 10px -7px rgb(0 0 0 / 0.4);
|
|
}
|
|
|
|
.cve-score.severity-critical {
|
|
background-color: #333333;
|
|
}
|
|
|
|
.cve-score.severity-high {
|
|
background-color: #d62f2c;
|
|
}
|
|
|
|
.cve-score.severity-medium {
|
|
background-color: #de7f0b;
|
|
}
|
|
|
|
.cve-score.severity-low {
|
|
background-color: #eadc38;
|
|
color: #3f3f3f;
|
|
}
|
|
|
|
.cve-score.severity- {
|
|
display: none;
|
|
}
|
|
|
|
</style><div class="cve-container"><a href="https://nvd.nist.gov/vuln/detail/#{cve_id}"><span class="cve-badge cve-id severity-#{cve_severity.downcase}">#{cve_id}</span><span class="cve-badge cve-score severity-#{cve_severity.downcase}">#{cve_severity}: #{cve_score}</span></a></div>}
|
|
end
|
|
end
|
|
|
|
Liquid::Template.register_tag "cve_badge", self
|
|
end
|
|
|