Projet

Général

Profil

Télécharger (7,08 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / ipsec.widget.php @ 048dd7b9

1
<?php
2
/*
3
        $Id$
4
        Copyright 2007 Scott Dale
5
        Part of pfSense widgets (https://www.pfsense.org)
6
        originally based on m0n0wall (http://m0n0.ch/wall)
7

    
8
        Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
9
        and Jonathan Watt <jwatt@jwatt.org>.
10
        All rights reserved.
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
$nocsrf = true;
35

    
36
require_once("guiconfig.inc");
37
require_once("functions.inc");
38
require_once("ipsec.inc");
39

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

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

    
54
	$activecounter = 0;
55
	$inactivecounter = 0;
56

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

    
64
		$tun_disabled = "false";
65
		$foundsrc = false;
66
		$founddst = false;
67

    
68
		if (isset($ph1ent['disabled']) || isset($ph2ent['disabled'])) {
69
			$tun_disabled = "true";
70
			continue;
71
		}
72

    
73
		if (if(ipsec_phase1_status($ipsec_status, $ph1ent)) {
74
			/* tunnel is up */
75
			$iconfn = "true";
76
			$activecounter++;
77
		} else {
78
			/* tunnel is down */
79
			$iconfn = "false";
80
			$inactivecounter++;
81
		}
82

    
83
		$ipsec_detail_array[] = array('src' => $ph1ent['interface'],
84
					'dest' => $ph1ent['remote-gateway'],
85
					'remote-subnet' => ipsec_idinfo_to_text($ph2ent['remoteid']),
86
					'descr' => $ph2ent['descr'],
87
					'status' => $iconfn,
88
					'disabled' => $tun_disabled);
89
	}
90
}
91

    
92
	if (isset($config['ipsec']['phase2'])){ ?>
93

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

    
111
<div id="ipsec-tunnel" style="display:none;background-color:#EEEEEE;">
112
	<div style="padding: 10px">
113
		<div style="display:table-row;">
114
			<div class="widgetsubheader" style="display:table-cell;width:40px">Source</div>
115
			<div class="widgetsubheader" style="display:table-cell;width:100px">Destination</div>
116
			<div class="widgetsubheader" style="display:table-cell;width:90px">Description</div>
117
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
118
		</div>
119
		<div style="max-height:105px;overflow:auto;">
120
	<?php
121
	foreach ($ipsec_detail_array as $ipsec) :
122

    
123
		if ($ipsec['disabled'] == "true"){
124
			$spans = "<span class=\"gray\">";
125
			$spane = "</span>";
126
		}
127
		else {
128
			$spans = $spane = "";
129
		}
130

    
131
		?>
132

    
133
		<div style="display:table-row;">
134
			<div class="listlr" style="display:table-cell;width:39px">
135
				<?php echo $spans;?>
136
					<?php echo htmlspecialchars($ipsec['src']);?>
137
				<?php echo $spane;?>
138
			</div>
139
			<div class="listr"  style="display:table-cell;width:100px"><?php echo $spans;?>
140
				<?php echo $ipsec['remote-subnet'];?>
141
				<br />
142
				(<?php echo htmlspecialchars($ipsec['dest']);?>)<?php echo $spane;?>
143
			</div>
144
			<div class="listr"  style="display:table-cell;width:90px"><?php echo $spans;?><?php echo htmlspecialchars($ipsec['descr']);?><?php echo $spane;?></div>
145
			<div class="listr"  style="display:table-cell;width:37px" align="center"><?php echo $spans;?>
146
			<?php
147

    
148
			if($ipsec['status'] == "true") {
149
				/* tunnel is up */
150
				$iconfn = "interface_up";
151
			} else {
152
				/* tunnel is down */
153
				$iconfn = "interface_down";
154
			}
155

    
156
			echo "<img src ='/themes/{$g['theme']}/images/icons/icon_{$iconfn}.gif' alt='Tunnel status' width='11' height='11' />";
157

    
158
			?><?php echo $spane;?></div>
159
		</div>
160
	<?php endforeach; ?>
161
	</div>
162
 </div>
163
</div>
164
<div id="ipsec-mobile" style="display:none;background-color:#EEEEEE;">
165
	<div style="padding: 10px">
166
		<div style="display:table-row;">
167
			<div class="widgetsubheader" style="display:table-cell;width:140px">User</div>
168
			<div class="widgetsubheader" style="display:table-cell;width:130px">IP</div>
169
			<div class="widgetsubheader" style="display:table-cell;width:30px">Status</div>
170
		</div>
171
		<div style="max-height:105px;overflow:auto;">
172
<?php
173
	if (is_array($mobile['pool'])):
174
	foreach ($mobile['pool'] as $pool):
175
		if (is_array($pool['lease'])): 
176
			foreach ($pool['lease'] as $muser) : ?>
177
		<div style="display:table-row;">
178
			<div class="listlr" style="display:table-cell;width:139px">
179
				<?php echo htmlspecialchars($muser['id']);?><br />
180
			</div>
181
			<div class="listr"  style="display:table-cell;width:130px">
182
				<?php echo htmlspecialchars($muser['host']);?><br />
183
			</div>
184
			<div class="listr"  style="display:table-cell;width:30px">
185
				<?php echo htmlspecialchars($muser['status']);?><br/>
186
			</div>
187
		</div>
188
<?php
189
			endforeach;
190
		endif;
191
	endforeach;
192
	endif;
193
?>
194
		</div>
195
	</div>
196
</div>
197
<?php //end ipsec tunnel
198
}//end if tunnels are configured, else show code below
199
else { ?>
200
<div style="display:block">
201
	 <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="note">
202
	  <tr>
203
	    <td colspan="4">
204
	        <span class="vexpl">
205
	          <span class="red">
206
	            <strong>
207
	              Note: There are no configured IPsec Tunnels<br />
208
	            </strong>
209
	          </span>
210
	          You can configure your IPsec
211
	          <a href="vpn_ipsec.php">here</a>.
212
	        </span>
213
		</td>
214
	  </tr>
215
	</table>
216
</div>
217
<?php } ?>
(9-9/21)