Fix some bad formatting errors where we had entries with no advisories etc
[openssl-web.git] / bin / vulnerabilities.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
4   <xsl:output indent="yes" encoding="UTF-8" method="html" omit-xml-declaration="yes"/>
5
6   <!-- Format a date like "1960-02-10" into "February 10th, 1960" -->
7   <xsl:template name="dateformat">
8     <xsl:param name="date" select="."/>
9     <xsl:variable name="day" select="number(substring($date,7,2))"/>
10     <xsl:variable name="month" select="number(substring($date,5,2))"/>
11     <xsl:variable name="year" select="number(substring($date,1,4))"/>
12
13     <xsl:if test="$day &gt; 0"> 
14       <xsl:value-of select="$day" />
15       <xsl:choose>
16         <xsl:when test="$day=1 or $day=21 or $day=31">st</xsl:when>
17         <xsl:when test="$day=2 or $day=22">nd</xsl:when>
18         <xsl:when test="$day=3 or $day=23">rd</xsl:when>
19         <xsl:otherwise>th</xsl:otherwise>
20       </xsl:choose>
21       <xsl:text> </xsl:text>
22     </xsl:if>
23     <xsl:choose>
24       <xsl:when test="$month=01">January</xsl:when>
25       <xsl:when test="$month=02">February</xsl:when>
26       <xsl:when test="$month=03">March</xsl:when>
27       <xsl:when test="$month=04">April</xsl:when>
28       <xsl:when test="$month=05">May</xsl:when>
29       <xsl:when test="$month=06">June</xsl:when>
30       <xsl:when test="$month=07">July</xsl:when>
31       <xsl:when test="$month=08">August</xsl:when>
32       <xsl:when test="$month=09">September</xsl:when>
33       <xsl:when test="$month=10">October</xsl:when>
34       <xsl:when test="$month=11">November</xsl:when>
35       <xsl:when test="$month=12">December</xsl:when>
36     </xsl:choose>
37     <xsl:if test="$year&gt;0">
38       <xsl:text> </xsl:text>
39       <xsl:value-of select="$year"/>
40     </xsl:if>
41   </xsl:template>
42
43   <xsl:key name="unique-date" match="@public" use="substring(.,1,4)"/>
44   <xsl:key name="unique-base" match="@base" use="."/>
45
46   <xsl:template match="security">
47     <xsl:comment>
48       Do not edit this file; edit vulnerabilities.xml
49     </xsl:comment>
50
51     <h3><a name="toc">Table of Contents</a></h3>
52     <ul>
53       <xsl:for-each select="issue/@public[generate-id()=generate-id(key('unique-date',substring(.,1,4)))]">
54         <xsl:sort select="." order="descending"/>
55         <xsl:variable name="year" select="substring(.,1,4)"/>
56         <li><a href="#y{$year}"><xsl:value-of select="$year"/></a></li>
57       </xsl:for-each>
58     </ul>
59
60     <xsl:for-each select="issue/@public[generate-id()=generate-id(key('unique-date',substring(.,1,4)))]">
61       <xsl:sort select="." order="descending"/>
62       <xsl:variable name="year" select="substring(.,1,4)"/>
63
64       <h3><a name="y{$year}"><xsl:value-of select="$year"/></a>
65         <!-- don't need an UP on each year.
66         <xsl:text>  </xsl:text><a href="#toc"><img src="/img/up.gif"/></a>
67         -->
68       </h3>
69       <dl>
70         <xsl:apply-templates select="../../issue[substring(@public,1,4)=$year]">
71           <xsl:sort select="./@public" order="descending"/>
72         </xsl:apply-templates>
73       </dl>
74     </xsl:for-each>
75   </xsl:template>
76
77   <xsl:template match="issue">
78     <dt>
79       <xsl:apply-templates select="cve"/>
80       <xsl:text> </xsl:text>
81       <xsl:if test="advisory/@url">
82         <a href="{advisory/@url}">(OpenSSL advisory)</a><xsl:text> </xsl:text>
83       </xsl:if>
84       <xsl:if test="impact/@severity">
85         [<xsl:value-of select="impact/@severity"/> severity]
86       </xsl:if>
87       <xsl:call-template name="dateformat">
88         <xsl:with-param name="date" select="@public"/>
89       </xsl:call-template>
90       <xsl:text disable-output-escaping='yes'>:  &lt;a href="#toc">&lt;img src="/img/up.gif"/>&lt;/a></xsl:text>
91     </dt>
92     <dd>
93       <xsl:copy-of select="string(description)"/>
94       <xsl:for-each select="reported">      
95         <xsl:if test="@source">
96           Reported by <xsl:value-of select="@source"/>
97           <xsl:if test="@date">
98             <xsl:text> on </xsl:text>
99             <xsl:call-template name="dateformat">
100               <xsl:with-param name="date" select="@date"/>
101             </xsl:call-template>
102           </xsl:if>
103           <xsl:text>.</xsl:text>
104         </xsl:if>
105       </xsl:for-each>
106       <ul>
107         <xsl:for-each select="fixed">
108           <li>Fixed in OpenSSL  
109             <xsl:value-of select="@version"/>
110             <xsl:if test="git/@hash">
111               <xsl:text> </xsl:text><a href="https://github.com/openssl/openssl/commit/{git/@hash}">(git commit)</a><xsl:text> </xsl:text>
112             </xsl:if>
113             <xsl:variable name="mybase" select="@base"/>
114             <xsl:for-each select="../affects[@base=$mybase]|../maybeaffects[@base=$mybase]">
115               <xsl:sort select="@version" order="descending"/>
116               <xsl:if test="position() =1">
117                 <xsl:text> (Affected </xsl:text>
118               </xsl:if>
119               <xsl:value-of select="@version"/>
120               <xsl:if test="name() = 'maybeaffects'">
121                 <xsl:text>?</xsl:text>
122               </xsl:if>
123               <xsl:if test="position() != last()">
124                 <xsl:text>, </xsl:text>
125               </xsl:if>
126               <xsl:if test="position() = last()">
127                 <xsl:text>) </xsl:text>
128               </xsl:if>
129             </xsl:for-each>
130           </li>
131         </xsl:for-each>
132       </ul>
133     </dd>
134   </xsl:template>
135
136   <xsl:template match="cve">
137     <xsl:if test="@name != ''">
138       <b><a name="{@name}">
139           <xsl:if test="@description = 'full'">
140             The Common Vulnerabilities and Exposures project
141             has assigned the name 
142           </xsl:if>
143           <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-{@name}">CVE-<xsl:value-of select="@name"/> </a>
144           <xsl:if test="@description = 'full'">
145             to this issue.
146           </xsl:if>
147       </a></b>
148     </xsl:if>
149   </xsl:template>
150
151 </xsl:stylesheet>