summaryrefslogtreecommitdiff
path: root/src/xsl/show_vpn_ipsec_sa.xsl
blob: 22eabb063f085d90eb3b657a31fa7d38daa714f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?xml version="1.0"?>
<!DOCTYPE stylesheet [
<!ENTITY newln "&#10;">
]>

<!-- /*
      *  Copyright 2007, Vyatta, Inc.
      *
      *  GNU General Public License
      *
      *  This program is free software; you can redistribute it and/or modify
      *  it under the terms of the GNU General Public License, version 2,
      *  as published by the Free Software Foundation.
      *
      *  This program is distributed in the hope that it will be useful,
      *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      *  GNU General Public License for more details.
      *
      *  You should have received a copy of the GNU General Public License
      *  along with this program; if not, write to the Free Software
      *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      *  02110-1301 USA
      *
      * Module: show_vpn_ipsec_sa.xsl 
      *
      * Author: Mike Horn, Marat Nepomnyashy
      * Date: 2007
      *
      */ -->

<!--XSL template for formatting the output of a number of "show vpn ipsec sa" commands-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="conn"/>
<xsl:param name="detail"/>
<xsl:param name="nat"/>
<xsl:param name="peer"/>

<xsl:variable name="pad4" select="'    '"/>
<xsl:variable name="pad4_len" select="string-length($pad4)"/>
<xsl:variable name="pad5" select="'     '"/>
<xsl:variable name="pad5_len" select="string-length($pad5)"/>
<xsl:variable name="pad6" select="'      '"/>
<xsl:variable name="pad6_len" select="string-length($pad6)"/>
<xsl:variable name="pad7" select="'       '"/>
<xsl:variable name="pad7_len" select="string-length($pad7)"/>
<xsl:variable name="pad8" select="'        '"/>
<xsl:variable name="pad8_len" select="string-length($pad8)"/>
<xsl:variable name="pad9" select="'         '"/>
<xsl:variable name="pad9_len" select="string-length($pad9)"/>
<xsl:variable name="pad11" select="'           '"/>
<xsl:variable name="pad11_len" select="string-length($pad11)"/>
<xsl:variable name="pad16" select="'                '"/>
<xsl:variable name="pad16_len" select="string-length($pad16)"/>

<xsl:template match="/">
<xsl:text>&newln;</xsl:text>

<xsl:if test="$detail != 'y'">
  <xsl:text>Peer IP         Tunnel# Dir SPI      Encrypt    Hash       NAT-T A-Time L-Time</xsl:text>
  <xsl:text>&newln;</xsl:text>
  <xsl:text>-------         ------- --- ---      -------    ----       ----- ------ ------</xsl:text>
  <xsl:text>&newln;</xsl:text>
</xsl:if>

<xsl:for-each select="opcommand/format/peer/setkey">
  <xsl:choose>
    <xsl:when test="string-length($conn) > 0">
      <xsl:if test="$conn = conn_name">
        <xsl:call-template name="show_ipsec_sa">
          <xsl:with-param name="row" select="." />
        </xsl:call-template>
      </xsl:if>
    </xsl:when>
    <xsl:when test="string-length($nat) > 0">
      <xsl:if test="$nat = ../nat_traversal">
        <xsl:call-template name="show_ipsec_sa">
          <xsl:with-param name="row" select="." />
        </xsl:call-template>
      </xsl:if>
    </xsl:when>
    <xsl:when test="string-length($peer) > 0">
      <xsl:if test="$peer=../peer_ip">
        <xsl:call-template name="show_ipsec_sa">
          <xsl:with-param name="row" select="." />
        </xsl:call-template>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="show_ipsec_sa">
        <xsl:with-param name="row" select="." />
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:for-each>
</xsl:template>

  <xsl:template name="show_ipsec_sa">
    <xsl:param name="row" />
    <xsl:choose>
      <xsl:when test="$detail = 'y'">
        <xsl:if test="position() > 1">
          <xsl:text>---------</xsl:text><xsl:text>&newln;</xsl:text>
          <xsl:text>&newln;</xsl:text>
	</xsl:if>
        <xsl:text>Conn Name:            </xsl:text><xsl:value-of select="conn_name"/><xsl:text>&newln;</xsl:text>
	<xsl:text>State:                </xsl:text><xsl:value-of select="../ike_state"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Peer IP:              </xsl:text><xsl:value-of select="../peer_ip"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Direction:            </xsl:text><xsl:value-of select="dir"/><xsl:text>&newln;</xsl:text>
        <!--<xsl:text>Outbound interface: !!</xsl:text>  <xsl:text>&newln;</xsl:text>-->
        <xsl:text>Source Net:           </xsl:text><xsl:value-of select="left"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Dest Net:             </xsl:text><xsl:value-of select="right"/><xsl:text>&newln;</xsl:text>
        <xsl:text>SPI:                  </xsl:text><xsl:value-of select="spi"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Encryption:           </xsl:text><xsl:value-of select="esp_encrypt"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Hash:                 </xsl:text><xsl:value-of select="esp_hash"/><xsl:text>&newln;</xsl:text>
        <xsl:text>PFS Group:            </xsl:text><xsl:value-of select="pfs_group"/><xsl:text>&newln;</xsl:text>
        <xsl:text>DH Group:             </xsl:text><xsl:value-of select="../ike_dh"/><xsl:text>&newln;</xsl:text>
        <xsl:text>NAT Traversal:        </xsl:text><xsl:if test="../nat_traversal='enabled'"><xsl:text>Yes</xsl:text></xsl:if><xsl:if test="../nat_traversal='disabled'"><xsl:text>No</xsl:text></xsl:if><xsl:text>&newln;</xsl:text>
        <xsl:text>NAT Source Port:      </xsl:text><xsl:value-of select="../nat_src_port"/><xsl:text>&newln;</xsl:text>
        <xsl:text>NAT Dest Port:        </xsl:text><xsl:value-of select="../nat_dst_port"/><xsl:text>&newln;</xsl:text>
        <!--<xsl:text>Packets: !!           </xsl:text>  <xsl:text>&newln;</xsl:text>-->
        <xsl:text>Bytes:                </xsl:text><xsl:value-of select="bytes"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Active time (s):      </xsl:text><xsl:value-of select="active_time"/><xsl:text>&newln;</xsl:text>
        <xsl:text>Lifetime (s):         </xsl:text><xsl:value-of select="keylife"/><xsl:text>&newln;</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="t_peer_ip" select="substring(../peer_ip,1,15)"/>
        <xsl:variable name="t_tunnel" select="substring(tunnel,1,8)"/>
        <xsl:variable name="t_dir" select="substring(dir,1,3)"/>
        <xsl:variable name="t_spi" select="substring(spi,1,8)"/>
        <xsl:variable name="t_esp_encrypt" select="substring(esp_encrypt,1,10)"/>
        <xsl:variable name="t_esp_hash" select="substring(esp_hash,1,10)"/>
        <xsl:variable name="t_active_time" select="substring(active_time,1,6)"/>
        <xsl:variable name="t_keylife" select="substring(keylife,1,6)"/>

        <xsl:value-of select="$t_peer_ip"/>
        <xsl:value-of select="substring($pad16,1,$pad16_len - string-length($t_peer_ip))"/>
        <xsl:value-of select="$t_tunnel"/>
        <xsl:value-of select="substring($pad8,1,$pad8_len - string-length($t_tunnel))"/>
        <xsl:value-of select="$t_dir"/>
        <xsl:value-of select="substring($pad4,1,$pad4_len - string-length($t_dir))"/>
        <xsl:value-of select="$t_spi"/>
        <xsl:value-of select="substring($pad9,1,$pad9_len - string-length($t_spi))"/>
        <xsl:value-of select="$t_esp_encrypt"/>
        <xsl:value-of select="substring($pad11,1,$pad11_len - string-length($t_esp_encrypt))"/>
        <xsl:value-of select="$t_esp_hash"/>
        <xsl:value-of select="substring($pad11,1,$pad11_len - string-length($t_esp_hash))"/>
	<xsl:if test="../nat_traversal='enabled'"><xsl:text>Yes   </xsl:text></xsl:if>
	<xsl:if test="../nat_traversal='disabled'"><xsl:text>No    </xsl:text></xsl:if>
        <xsl:value-of select="$t_active_time"/>
        <xsl:value-of select="substring($pad7,1,$pad7_len - string-length($t_active_time))"/>
        <xsl:value-of select="$t_keylife"/>
        <xsl:text>&newln;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>