pdml2html.xsl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <!-- This XSLT will convert a PDML file, saved by Wireshark, into
  4. HTML. The HTML page should look similar to Wireshark. See
  5. https://gitlab.com/wireshark/wireshark/-/wikis/PDML for information
  6. on how to generate such a HTML file from PDML.
  7. For questions contact Dirk Jagdmann (doj@cubic.org).
  8. Version: 2010-06-09
  9. Wireshark - Network traffic analyzer
  10. By Gerald Combs <gerald@wireshark.org>
  11. Copyright 1998 Gerald Combs
  12. SPDX-License-Identifier: GPL-2.0-or-later
  13. -->
  14. <!-- set parameters of the HTML output -->
  15. <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="no" standalone="yes" indent="yes"/>
  16. <!-- this matches the "field" tag -->
  17. <xsl:template match="field">
  18. &#160;&#160;&#160; <!-- indent with 3 non-breaking spaces -->
  19. <!-- output either the "showname" or "show" attribute -->
  20. <xsl:choose>
  21. <xsl:when test="string-length(@showname)>0">
  22. <xsl:value-of select="@showname"/><br/>
  23. </xsl:when>
  24. <xsl:otherwise>
  25. <!--<xsl:value-of select="@name"/>:--> <xsl:value-of select="@show"/><br/>
  26. </xsl:otherwise>
  27. </xsl:choose>
  28. <xsl:apply-templates/> <!-- we expect to match "field" tags -->
  29. </xsl:template>
  30. <!-- this matches the "packet" tag -->
  31. <xsl:template match="packet">
  32. <!-- declare some variables for later use -->
  33. <xsl:variable name="frame_num" select="proto[@name='frame']/field[@name='frame.number']/@show"/>
  34. <xsl:variable name="frame_id" select="concat('f',$frame_num)"/>
  35. <xsl:variable name="frame_c" select="concat($frame_id,'c')"/>
  36. <!-- the "title" bar of the frame -->
  37. <div width="100%" id="{$frame_id}">
  38. <a href="javascript:toggle_node('{$frame_c}')">&#8658;</a> <!-- #8658 is a "rArr" (double right arrow) character -->
  39. Frame <xsl:value-of select="$frame_num"/>:
  40. <xsl:for-each select="proto[@name!='geninfo']">
  41. <xsl:value-of select="@name"/>,
  42. </xsl:for-each>
  43. <small><a href="javascript:hide_node('{$frame_id}')">[X]</a></small>
  44. </div>
  45. <!-- the frame contents are stored in a div, so we can toggle it -->
  46. <div width="100%" id="{$frame_c}" style="display:none">
  47. <!-- loop through all proto tags, but skip the "geninfo" one -->
  48. <xsl:for-each select="proto[@name!='geninfo']">
  49. <xsl:variable name="proto" select="concat($frame_id,@name,count(preceding-sibling::proto)+1)"/>
  50. <!-- the "title" bar of the proto -->
  51. <div width="100%" style="background-color:#e5e5e5; margin-bottom: 2px">
  52. &#160;<a href="javascript:toggle_node('{$proto}')">&#8658;</a>&#160;<xsl:value-of select="@showname"/>
  53. <!-- print "proto" details inside another div -->
  54. <div width="100%" id="{$proto}" style="display:none">
  55. <xsl:apply-templates/> <!-- we expect to match "field" tags -->
  56. </div>
  57. </div>
  58. </xsl:for-each>
  59. </div>
  60. <!-- use the javascript function set_node_color() to set the color
  61. of the frame title bar. Defer colorization until the full page has
  62. been loaded. If the browser would support the XPath function
  63. replace() we could simply set the class attribute of the title bar div,
  64. but for now we're stuck with class names from Wireshark's colorfilters
  65. that contain spaces and we can't handle them in CSS. -->
  66. <script type="text/javascript">
  67. dojo.addOnLoad(function(){
  68. set_node_color(
  69. '<xsl:value-of select="$frame_id"/>',
  70. '<xsl:value-of select="proto[@name='frame']/field[@name='frame.coloring_rule.name']/@show"/>'
  71. );
  72. });
  73. </script>
  74. </xsl:template>
  75. <xsl:template match="pdml">
  76. Capture Filename: <b><xsl:value-of select="@capture_file"/></b>
  77. PDML created: <b><xsl:value-of select="@time"/></b>
  78. <tt>
  79. <xsl:apply-templates/> <!-- we expect to match the "packet" nodes -->
  80. </tt>
  81. </xsl:template>
  82. <!-- this block matches the start of the PDML file -->
  83. <xsl:template match="/">
  84. <html>
  85. <head>
  86. <title>poor man's Wireshark</title>
  87. <script src="https://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" type="text/javascript"></script>
  88. <script type="text/javascript">
  89. function set_node(node, str)
  90. {
  91. if(dojo.isString(node))
  92. node = dojo.byId(node);
  93. if(!node) return;
  94. node.style.display = str;
  95. }
  96. function toggle_node(node)
  97. {
  98. if(dojo.isString(node))
  99. node = dojo.byId(node);
  100. if(!node) return;
  101. set_node(node, (node.style.display != 'none') ? 'none' : 'block');
  102. }
  103. function hide_node(node)
  104. {
  105. set_node(node, 'none');
  106. }
  107. // this function was generated by colorfilters2js.pl
  108. function set_node_color(node,colorname)
  109. {
  110. if(dojo.isString(node))
  111. node = dojo.byId(node);
  112. if(!node) return;
  113. var fg;
  114. var bg;
  115. if(colorname == 'Bad TCP') {
  116. bg='#000000';
  117. fg='#ff5f5f';
  118. }
  119. if(colorname == 'HSRP State Change') {
  120. bg='#000000';
  121. fg='#fff600';
  122. }
  123. if(colorname == 'Spanning Tree Topology Change') {
  124. bg='#000000';
  125. fg='#fff600';
  126. }
  127. if(colorname == 'OSPF State Change') {
  128. bg='#000000';
  129. fg='#fff600';
  130. }
  131. if(colorname == 'ICMP errors') {
  132. bg='#000000';
  133. fg='#00ff0e';
  134. }
  135. if(colorname == 'ARP') {
  136. bg='#d6e8ff';
  137. fg='#000000';
  138. }
  139. if(colorname == 'ICMP') {
  140. bg='#c2c2ff';
  141. fg='#000000';
  142. }
  143. if(colorname == 'TCP RST') {
  144. bg='#900000';
  145. fg='#fff680';
  146. }
  147. if(colorname == 'TTL low or unexpected') {
  148. bg='#900000';
  149. fg='#ffffff';
  150. }
  151. if(colorname == 'Checksum Errors') {
  152. bg='#000000';
  153. fg='#ff5f5f';
  154. }
  155. if(colorname == 'SMB') {
  156. bg='#fffa99';
  157. fg='#000000';
  158. }
  159. if(colorname == 'HTTP') {
  160. bg='#8dff7f';
  161. fg='#000000';
  162. }
  163. if(colorname == 'IPX') {
  164. bg='#ffe3e5';
  165. fg='#000000';
  166. }
  167. if(colorname == 'DCERPC') {
  168. bg='#c797ff';
  169. fg='#000000';
  170. }
  171. if(colorname == 'Routing') {
  172. bg='#fff3d6';
  173. fg='#000000';
  174. }
  175. if(colorname == 'TCP SYN/FIN') {
  176. bg='#a0a0a0';
  177. fg='#000000';
  178. }
  179. if(colorname == 'TCP') {
  180. bg='#e7e6ff';
  181. fg='#000000';
  182. }
  183. if(colorname == 'UDP') {
  184. bg='#70e0ff';
  185. fg='#000000';
  186. }
  187. if(colorname == 'Broadcast') {
  188. bg='#ffffff';
  189. fg='#808080';
  190. }
  191. if(fg.length > 0)
  192. node.style.color = fg;
  193. if(bg.length > 0)
  194. node.style.background = bg;
  195. }
  196. </script>
  197. </head>
  198. <body>
  199. <xsl:apply-templates/> <!-- we expect to match the "pdml" node -->
  200. </body>
  201. </html>
  202. </xsl:template>
  203. </xsl:stylesheet>