1
|
<?php
|
2
|
//set variable for custom title
|
3
|
$ipsec_title = "IPsec";
|
4
|
|
5
|
function get_ipsec_tunnel_sad() {
|
6
|
/* query SAD */
|
7
|
$fd = @popen("/sbin/setkey -D", "r");
|
8
|
$sad = array();
|
9
|
if ($fd) {
|
10
|
while (!feof($fd)) {
|
11
|
$line = chop(fgets($fd));
|
12
|
if (!$line)
|
13
|
continue;
|
14
|
if ($line == "No SAD entries.")
|
15
|
break;
|
16
|
if ($line[0] != "\t") {
|
17
|
if (is_array($cursa))
|
18
|
$sad[] = $cursa;
|
19
|
$cursa = array();
|
20
|
list($cursa['src'],$cursa['dst']) = explode(" ", $line);
|
21
|
$i = 0;
|
22
|
} else {
|
23
|
$linea = explode(" ", trim($line));
|
24
|
if ($i == 1) {
|
25
|
$cursa['proto'] = $linea[0];
|
26
|
$cursa['spi'] = substr($linea[2], strpos($linea[2], "x")+1, -1);
|
27
|
} else if ($i == 2) {
|
28
|
$cursa['ealgo'] = $linea[1];
|
29
|
} else if ($i == 3) {
|
30
|
$cursa['aalgo'] = $linea[1];
|
31
|
}
|
32
|
}
|
33
|
$i++;
|
34
|
}
|
35
|
if (is_array($cursa) && count($cursa))
|
36
|
$sad[] = $cursa;
|
37
|
pclose($fd);
|
38
|
}
|
39
|
return($sad);
|
40
|
}
|
41
|
|
42
|
function get_ipsec_tunnel_src($tunnel) {
|
43
|
global $g, $config, $sad;
|
44
|
$if = "WAN";
|
45
|
if ($tunnel['interface']) {
|
46
|
$if = $tunnel['interface'];
|
47
|
$realinterface = convert_friendly_interface_to_real_interface_name($if);
|
48
|
$interfaceip = find_interface_ip($realinterface);
|
49
|
}
|
50
|
return $interfaceip;
|
51
|
}
|
52
|
|
53
|
function output_ipsec_tunnel_status($tunnel) {
|
54
|
global $g, $config, $sad;
|
55
|
$if = "WAN";
|
56
|
$interfaceip = get_ipsec_tunnel_src($tunnel);
|
57
|
$foundsrc = false;
|
58
|
$founddst = false;
|
59
|
|
60
|
if(!is_array($sad)) {
|
61
|
/* we have no sad array, bail */
|
62
|
return(false);
|
63
|
}
|
64
|
foreach($sad as $sa) {
|
65
|
if($sa['src'] == $interfaceip)
|
66
|
$foundsrc = true;
|
67
|
if($sa['dst'] == $tunnel['remote-gateway'])
|
68
|
$founddst = true;
|
69
|
}
|
70
|
if($foundsrc && $founddst) {
|
71
|
/* tunnel is up */
|
72
|
$iconfn = "pass";
|
73
|
return(true);
|
74
|
} else {
|
75
|
/* tunnel is down */
|
76
|
$iconfn = "reject";
|
77
|
return(false);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
?>
|