Projet

Général

Profil

Télécharger (6,88 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / ipsec.widget.php @ bd0bb466

1
<?php
2
/*
3
        $Id$
4
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
5

    
6
        Copyright 2007 Scott Dale
7
        Part of pfSense widgets (https://www.pfsense.org)
8
        originally based on m0n0wall (http://m0n0.ch/wall)
9

    
10
        Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
11
        and Jonathan Watt <jwatt@jwatt.org>.
12
        All rights reserved.
13

    
14
        Redistribution and use in source and binary forms, with or without
15
        modification, are permitted provided that the following conditions are met:
16

    
17
        1. Redistributions of source code must retain the above copyright notice,
18
           this list of conditions and the following disclaimer.
19

    
20
        2. Redistributions in binary form must reproduce the above copyright
21
           notice, this list of conditions and the following disclaimer in the
22
           documentation and/or other materials provided with the distribution.
23

    
24
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
        POSSIBILITY OF SUCH DAMAGE.
34
*/
35

    
36
$nocsrf = true;
37

    
38
require_once("guiconfig.inc");
39
require_once("functions.inc");
40
require_once("ipsec.inc");
41

    
42
if (isset($config['ipsec']['phase1'])){?>
43
	<div>&nbsp;</div>
44
	<?php
45
	$tab_array = array();
46
	$tab_array[0] = array("Overview", true, "ipsec-Overview");
47
	$tab_array[1] = array("Tunnels", false, "ipsec-tunnel");
48
	$tab_array[2] = array("Mobile", false, "ipsec-mobile");
49
	display_widget_tabs($tab_array);
50

    
51
	$spd = ipsec_dump_spd();
52
	$sad = ipsec_dump_sad();
53
	$mobile = ipsec_dump_mobile();
54
	$ipsec_status = ipsec_smp_dump_status();
55

    
56
	$activecounter = 0;
57
	$inactivecounter = 0;
58

    
59
	$ipsec_detail_array = array();
60
	foreach ($config['ipsec']['phase2'] as $ph2ent){
61
		if ($ph2ent['remoteid']['type'] == "mobile")
62
			continue;
63
		ipsec_lookup_phase1($ph2ent,$ph1ent);
64

    
65
		if (!isset($ph1ent['disabled']) && !isset($ph2ent['disabled'])) {
66

    
67
			if (is_array($ipsec_status['query']) &&
68
			    is_array($ipsec_status['query']['ikesalist']) &&
69
			    is_array($ipsec_status['query']['ikesalist']['ikesa']) &&
70
			    ipsec_phase1_status($ipsec_status['query']['ikesalist']['ikesa'], $ph1ent['ikeid'])) {
71
				/* tunnel is up */
72
				$iconfn = "true";
73
				$activecounter++;
74
			} else {
75
				/* tunnel is down */
76
				$iconfn = "false";
77
				$inactivecounter++;
78
			}
79

    
80
			$ipsec_detail_array[] = array('src' => convert_friendly_interface_to_friendly_descr($ph1ent['interface']),
81
					'dest' => $ph1ent['remote-gateway'],
82
					'remote-subnet' => ipsec_idinfo_to_text($ph2ent['remoteid']),
83
					'descr' => $ph2ent['descr'],
84
					'status' => $iconfn);
85
		}
86
	}
87
}
88

    
89
	if (isset($config['ipsec']['phase2'])){ ?>
90

    
91
<div id="ipsec-Overview" style="display:block;background-color:#EEEEEE;">
92
	<div>
93
	<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="heading">
94
	<tr>
95
		<td class="listhdrr nowrap">Active Tunnels</td>
96
		<td class="listhdrr nowrap">Inactive Tunnels</td>
97
		<td class="listhdrr nowrap">Mobile Users</td>
98
	</tr>
99
	<tr>
100
		<td class="listlr"><?php echo $activecounter; ?></td>
101
		<td class="listr"><?php echo $inactivecounter; ?></td>
102
		<td class="listr"><?php if (is_array($mobile['pool'])) echo htmlspecialchars($mobile['pool'][0]['usage']); else echo 0; ?></td>
103
	</tr>
104
	</table>
105
	</div>
106
</div>
107

    
108
<div id="ipsec-tunnel" style="display:none;background-color:#EEEEEE;">
109
	<div style="padding: 10px">
110
		<div style="display:table-row;">
111
			<div class="widgetsubheader" style="display:table-cell;width:40px">Source</div>
112
			<div class="widgetsubheader" style="display:table-cell;width:100px">Destination</div>
113
			<div class="widgetsubheader" style="display:table-cell;width:90px">Description</div>
114
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
115
		</div>
116
		<div style="max-height:105px;overflow:auto;">
117

    
118
	<?php foreach ($ipsec_detail_array as $ipsec) : ?>
119
	
120
		<div style="display:table-row;">
121
			<div class="listlr" style="display:table-cell;width:39px">
122
				<?php echo htmlspecialchars($ipsec['src']);?>
123
			</div>
124
			<div class="listr"  style="display:table-cell;width:100px">
125
				<?php echo $ipsec['remote-subnet'];?>
126
				<br />
127
				(<?php echo htmlspecialchars($ipsec['dest']);?>)
128
			</div>
129
			<div class="listr"  style="display:table-cell;width:90px"></div>
130
			<div class="listr"  style="display:table-cell;width:37px" align="center">
131
			<?php
132

    
133
			if($ipsec['status'] == "true") {
134
				/* tunnel is up */
135
				$iconfn = "interface_up";
136
			} else {
137
				/* tunnel is down */
138
				$iconfn = "interface_down";
139
			}
140

    
141
			echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif' alt='Tunnel status' width='11' height='11' />";
142
			?>
143
			</div>
144
		</div>
145
	<?php endforeach; ?>
146
	</div>
147
 </div>
148
</div>
149
<div id="ipsec-mobile" style="display:none;background-color:#EEEEEE;">
150
	<div style="padding: 10px">
151
		<div style="display:table-row;">
152
			<div class="widgetsubheader" style="display:table-cell;width:140px">User</div>
153
			<div class="widgetsubheader" style="display:table-cell;width:130px">IP</div>
154
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
155
		</div>
156
		<div style="max-height:105px;overflow:auto;">
157
<?php
158
	if (is_array($mobile['pool'])):
159
	foreach ($mobile['pool'] as $pool):
160
		if (is_array($pool['lease'])): 
161
			foreach ($pool['lease'] as $muser) : ?>
162
		<div style="display:table-row;">
163
			<div class="listlr" style="display:table-cell;width:139px">
164
				<?php echo htmlspecialchars($muser['id']);?><br />
165
			</div>
166
			<div class="listr"  style="display:table-cell;width:130px">
167
				<?php echo htmlspecialchars($muser['host']);?><br />
168
			</div>
169
			<div class="listr"  style="display:table-cell;width:30px">
170
				<?php echo htmlspecialchars($muser['status']);?><br/>
171
			</div>
172
		</div>
173
<?php
174
			endforeach;
175
		endif;
176
	endforeach;
177
	endif;
178
?>
179
		</div>
180
	</div>
181
</div>
182
<?php //end ipsec tunnel
183
}//end if tunnels are configured, else show code below
184
else { ?>
185
<div style="display:block">
186
	 <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="note">
187
	  <tr>
188
	    <td colspan="4">
189
	        <span class="vexpl">
190
	          <span class="red">
191
	            <strong>
192
	              Note: There are no configured IPsec Tunnels<br />
193
	            </strong>
194
	          </span>
195
	          You can configure your IPsec
196
	          <a href="vpn_ipsec.php">here</a>.
197
	        </span>
198
		</td>
199
	  </tr>
200
	</table>
201
</div>
202
<?php } ?>
(9-9/21)