1 |
4661598e
|
smos
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
diag_ipsec_xml.php
|
5 |
|
|
Copyright (C) 2007 pfSense Project
|
6 |
|
|
Copyright (C) 2010 Seth Mos
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Parts of this code was originally based on vpn_ipsec_sad.php
|
10 |
|
|
Copyright (C) 2003-2004 Manuel Kasper
|
11 |
|
|
|
12 |
|
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
|
|
|
15 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
|
|
|
18 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
19 |
|
|
notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
documentation and/or other materials provided with the distribution.
|
21 |
|
|
|
22 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
##|+PRIV
|
35 |
|
|
##|*IDENT=page-ipsecxml
|
36 |
|
|
##|*NAME=Diag IPsec XML page
|
37 |
|
|
##|*DESCR=Allow access to the 'Diag IPsec XML' page.
|
38 |
|
|
##|*MATCH=diag_ipsec_xml.php
|
39 |
|
|
##|-PRIV
|
40 |
|
|
|
41 |
|
|
global $g;
|
42 |
|
|
|
43 |
|
|
require("guiconfig.inc");
|
44 |
|
|
require("ipsec.inc");
|
45 |
|
|
|
46 |
|
|
if (!is_array($config['ipsec']['phase2']))
|
47 |
|
|
$config['ipsec']['phase2'] = array();
|
48 |
|
|
|
49 |
|
|
$ipsec_status = array();
|
50 |
|
|
|
51 |
|
|
$a_phase2 = &$config['ipsec']['phase2'];
|
52 |
|
|
|
53 |
|
|
$spd = ipsec_dump_spd();
|
54 |
|
|
$sad = ipsec_dump_sad();
|
55 |
|
|
|
56 |
|
|
if(is_array($a_phase2)) {
|
57 |
|
|
foreach ($a_phase2 as $ph2ent) {
|
58 |
|
|
ipsec_lookup_phase1($ph2ent,$ph1ent);
|
59 |
|
|
$tunnel = array();
|
60 |
|
|
if (!isset($ph2ent['disabled']) && !isset($ph1ent['disabled'])) {
|
61 |
|
|
if(ipsec_phase2_status($spd,$sad,$ph1ent,$ph2ent))
|
62 |
|
|
$tunnel['state'] = "up";
|
63 |
|
|
elseif(!isset($config['ipsec']['enable']))
|
64 |
|
|
$tunnel['state'] = "disabled";
|
65 |
|
|
else
|
66 |
|
|
$tunnel['state'] = "down";
|
67 |
|
|
|
68 |
|
|
$tunnel['src'] = ipsec_get_phase1_src($ph1ent);
|
69 |
|
|
$tunnel['endpoint'] = $ph1ent['remote-gateway'];
|
70 |
|
|
$tunnel['local'] = ipsec_idinfo_to_text($ph2ent['localid']);
|
71 |
|
|
$tunnel['remote'] = ipsec_idinfo_to_text($ph2ent['remoteid']);
|
72 |
|
|
$tunnel['name'] = "{$ph2ent['descr']}";
|
73 |
|
|
$ipsec_status['tunnel'][] = $tunnel;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
$listtags = array("tunnel");
|
79 |
|
|
$xml = dump_xml_config($ipsec_status, "ipsec");
|
80 |
|
|
|
81 |
|
|
echo $xml;
|
82 |
|
|
?>
|