summaryrefslogtreecommitdiff
path: root/src/command_proc_show_vpn.hh
blob: b72b21b2dd4b53fa281ea08ff39633232c918e1b (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
 *    Module: command_proc_show_vpn.hh
 *
 *    Author: Michael Larson
 *    Date: 2006
 *    Description:
 *
 *    This program is free software; you can redistribute it and/or modify 
 *    it under the terms of the GNU General Public License as published 
 *    by the Free Software Foundation; either version 2 of the License, 
 *    or (at your option) any later version.
 *
 *    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
 *
 *    Copyright 2006, Vyatta, Inc.
 */
#ifndef __COMMAND_PROC_SHOW_VPN_HH__
#define __COMMAND_PROC_SHOW_VPN_HH__

#include <sstream>
#include <string>
#include <map>
#include "command_proc_base.hh"

#define XSLDIR          "/opt/vyatta/share/xsl"


using namespace std;

class Dir
{
public:
  Dir() : _session_id("n/a"),_bytes(0),_active_time(0) {}

public:
  string _session_id; //same as tunnel_id
  int _bytes;
  int _active_time;
};

class AllTunnels;
class Peer;
class PeerTunnels;

class Tunnel 
{
public:
  ~Tunnel();
  Tunnel(AllTunnels & all_tunnels, Peer & peer) : _esp_encrypt("n/a"),_esp_hash("n/a"),_esp_state("down"),_keylife(0), _all_tunnels(all_tunnels), _peer(peer) {}

public:

  Dir    _in;
  Dir    _out;

  string _tunnel_name;
  string _tunnel_number;
  string _esp_encrypt;
  string _esp_hash;
  string _pfs_group;

  string _esp_state;

  int    _keylife;
  string _left_net;
  string _right_net;

  Peer & getPeer();
private:
  AllTunnels &  _all_tunnels;
  Peer &        _peer;
};

class Tunnels {
public:
  ~Tunnels();

  const map<string, Tunnel*> & getConstTunnelsMap() const;

  map<string, Tunnel*> & getTunnelsMap();
  void add(const string & strTunnelName, Tunnel * p_tunnel);
  void unlink(const Tunnel * p_tunnel);

protected:
  Tunnels();

private:
  map<string, Tunnel*> _tunnels;

};

class AllTunnels : public Tunnels {

};

class PeerTunnels : public Tunnels {

};

class Peer
{
friend Tunnel::~Tunnel();

public:
  Peer() : _ike_seconds_lifetime(0), _ike_seconds_lifetime_left(0), _ike_encrypt("n/a"),_ike_hash("n/a"), _ike_state("down"), _nat_trav(false), _nat_src_port(0), _nat_dst_port(0) {}

  int _ike_seconds_lifetime;
  int _ike_seconds_lifetime_left;

  string _ike_encrypt;
  string _ike_hash;
  string _ike_dh;
  string _ike_state;

  string _left_ip;
  string _right_ip;

  bool   _nat_trav;
  int    _nat_src_port;
  int    _nat_dst_port;

  const PeerTunnels & getConstPeerTunnels() const;

  PeerTunnels & getPeerTunnels();
protected:
  PeerTunnels  _peer_tunnels;
};

class CommandProcShowVPN : public CommandProcBase
{
public:
//  typedef std::map<std::string, Tunnel> Coll;
//  typedef std::map<std::string, Tunnel>::iterator Iter;

public:
  CommandProcShowVPN();
  ~CommandProcShowVPN();

  static std::string
  name() {return "showvpntable";}

  /**
   *
   **/ 
  bool
  is_valid() {return true;}

  /**
   *
   **/
  std::string
  process(const std::string &cmd, bool debug, std::string &reason);

private:
  /**
   *
   **/
  void 
  convert_to_xml_secrets(const std::string &line, bool debug);

  /**
   *
   **/
  void 
  convert_to_xml_pluto_pid(const std::string &line, bool debug);

  /**
   *
   **/
  void 
  convert_to_xml_setkey_d(bool debug);

  /**
   *
   **/
  void 
  convert_to_xml_setkey_dp(const std::string &line, bool debug, string &net1, string &net2);

  /**
   *
   **/
  void 
  convert_to_xml_setup_status(const std::string &line, bool debug);

  /**
   *
   **/
  void 
  convert_to_xml_auto_status(const std::string &line, bool debug);

  /**
   *
   **/
  void
  process_conf(bool debug);

  /**
   *
   **/
  void
  update_tunnel(const string &tunnel, const string &right, const string &left, const string &rightnet, const string &leftnet, const string &lifetime, bool debug);

protected:
  ostringstream        _xml_out;
  list<Peer*>          _peers;
  AllTunnels           _all_tunnels;

  string               _interface_conf_line;
  vector<std::string>  _pad;

private:
};

#endif //__COMMAND_PROC_SHOW_VPN_H__