1 |
cb7d18d5
|
Renato Botelho
|
#!/usr/local/bin/php-cgi -f
|
2 |
ae75bcb4
|
Scott Ullrich
|
<?php
|
3 |
|
|
/*
|
4 |
8acd654a
|
Renato Botelho
|
* rc.carpbackup
|
5 |
|
|
*
|
6 |
|
|
* part of pfSense (https://www.pfsense.org)
|
7 |
2a2396a6
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
8 |
8acd654a
|
Renato Botelho
|
* All rights reserved.
|
9 |
|
|
*
|
10 |
|
|
* Redistribution and use in source and binary forms, with or without
|
11 |
|
|
* modification, are permitted provided that the following conditions are met:
|
12 |
|
|
*
|
13 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
* this list of conditions and the following disclaimer.
|
15 |
|
|
*
|
16 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
* notice, this list of conditions and the following disclaimer in
|
18 |
|
|
* the documentation and/or other materials provided with the
|
19 |
|
|
* distribution.
|
20 |
|
|
*
|
21 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
22 |
|
|
* must display the following acknowledgment:
|
23 |
|
|
* "This product includes software developed by the pfSense Project
|
24 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25 |
|
|
*
|
26 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27 |
|
|
* endorse or promote products derived from this software without
|
28 |
|
|
* prior written permission. For written permission, please contact
|
29 |
|
|
* coreteam@pfsense.org.
|
30 |
|
|
*
|
31 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
32 |
|
|
* nor may "pfSense" appear in their names without prior written
|
33 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
34 |
|
|
*
|
35 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
36 |
|
|
* acknowledgment:
|
37 |
|
|
*
|
38 |
|
|
* "This product includes software developed by the pfSense Project
|
39 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40 |
|
|
*
|
41 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53 |
|
|
*/
|
54 |
ae75bcb4
|
Scott Ullrich
|
|
55 |
|
|
require_once("functions.inc");
|
56 |
|
|
require_once("config.inc");
|
57 |
|
|
require_once("notices.inc");
|
58 |
9ea0cb90
|
jim-p
|
require_once("openvpn.inc");
|
59 |
e3449857
|
PiBa-NL
|
require_once("interfaces.inc");
|
60 |
ae75bcb4
|
Scott Ullrich
|
|
61 |
7de4474e
|
Luiz Otavio O Souza
|
if (isset($_GET['interface'])) {
|
62 |
e173dd74
|
Phil Davis
|
$argument = $_GET['interface'];
|
63 |
|
|
} else {
|
64 |
815f1f77
|
Ermal
|
$argument = str_replace("\n", "", $argv[1]);
|
65 |
e173dd74
|
Phil Davis
|
}
|
66 |
|
|
if (!strstr($argument, "@")) {
|
67 |
10e58a70
|
Chris Buechler
|
log_error("CARP master event triggered from wrong source {$argument}");
|
68 |
7de4474e
|
Luiz Otavio O Souza
|
exit;
|
69 |
e173dd74
|
Phil Davis
|
}
|
70 |
77411fa7
|
Ermal
|
|
71 |
|
|
list($vhid, $iface) = explode("@", $argument);
|
72 |
|
|
|
73 |
|
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
74 |
89f171b0
|
Ermal LUÇI
|
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
|
75 |
|
|
$vips = link_interface_to_vips($friendly, '', $vhid);
|
76 |
7de4474e
|
Luiz Otavio O Souza
|
if (!is_array($vips)) {
|
77 |
|
|
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs");
|
78 |
|
|
exit;
|
79 |
|
|
}
|
80 |
|
|
foreach ($vips as $vip) {
|
81 |
|
|
$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "BACKUP" for vhid %4$s',
|
82 |
|
|
$vip['subnet'], $iface, $friendly_descr, $vhid);
|
83 |
95393d43
|
Phil Davis
|
|
84 |
7de4474e
|
Luiz Otavio O Souza
|
notify_via_smtp($notificationmsg);
|
85 |
|
|
notify_via_growl($notificationmsg);
|
86 |
|
|
log_error($notificationmsg);
|
87 |
89f171b0
|
Ermal LUÇI
|
}
|
88 |
ae75bcb4
|
Scott Ullrich
|
|
89 |
9ea0cb90
|
jim-p
|
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */
|
90 |
|
|
global $config;
|
91 |
d20dd658
|
Chris Buechler
|
$a_groups = return_gateway_groups_array();
|
92 |
2156f02a
|
jim-p
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
|
93 |
|
|
foreach ($config['openvpn']['openvpn-client'] as $settings) {
|
94 |
d20dd658
|
Chris Buechler
|
if (substr($settings['interface'], 0, 4) == '_vip') {
|
95 |
|
|
$openvpn_vip = $settings['interface'];
|
96 |
|
|
} else if (is_array($a_groups[$settings['interface']])) {
|
97 |
|
|
// interface is a gateway group, check CARP VIP
|
98 |
|
|
if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
|
99 |
|
|
$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
|
100 |
|
|
}
|
101 |
|
|
} else {
|
102 |
|
|
// this OpenVPN instance not on a CARP IP
|
103 |
|
|
continue;
|
104 |
|
|
}
|
105 |
89f171b0
|
Ermal LUÇI
|
foreach ($vips as $vip) {
|
106 |
d20dd658
|
Chris Buechler
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
107 |
89f171b0
|
Ermal LUÇI
|
log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
|
108 |
|
|
openvpn_restart('client', $settings);
|
109 |
|
|
}
|
110 |
2156f02a
|
jim-p
|
}
|
111 |
9ea0cb90
|
jim-p
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
7de4474e
|
Luiz Otavio O Souza
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
|
115 |
|
|
foreach ($config['openvpn']['openvpn-server'] as $settings) {
|
116 |
51d2e735
|
jim-p
|
if (substr($settings['interface'], 0, 4) == '_vip') {
|
117 |
|
|
$openvpn_vip = $settings['interface'];
|
118 |
|
|
} else if (is_array($a_groups[$settings['interface']])) {
|
119 |
|
|
// interface is a gateway group, check CARP VIP
|
120 |
|
|
if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
|
121 |
|
|
$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
|
122 |
|
|
}
|
123 |
|
|
} else {
|
124 |
|
|
// this OpenVPN instance not on a CARP IP
|
125 |
|
|
continue;
|
126 |
|
|
}
|
127 |
7de4474e
|
Luiz Otavio O Souza
|
foreach ($vips as $vip) {
|
128 |
51d2e735
|
jim-p
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
129 |
|
|
log_error("Stopping OpenVPN server instance on {$friendly_descr} because of transition to CARP backup.");
|
130 |
7de4474e
|
Luiz Otavio O Souza
|
openvpn_restart('server', $settings);
|
131 |
|
|
}
|
132 |
e173dd74
|
Phil Davis
|
}
|
133 |
|
|
}
|
134 |
52b5a223
|
Renato Botelho
|
}
|
135 |
|
|
|
136 |
fcac6e87
|
Chris Buechler
|
/* Reconfigure radvd when necessary */
|
137 |
|
|
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
|
138 |
|
|
$rafound = false;
|
139 |
|
|
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
|
140 |
|
|
foreach ($vips as $vip) {
|
141 |
|
|
if ($dhcpv6ifconf['rainterface'] == "_vip{$vip['uniqid']}") {
|
142 |
|
|
log_error("Stopping radvd instance on {$friendly_descr} because of transition to CARP master.");
|
143 |
|
|
$rafound = true;
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
if ($rafound) {
|
148 |
|
|
services_radvd_configure();
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
|
152 |
eaee3af6
|
PiBa-NL
|
$pluginparams = array();
|
153 |
|
|
$pluginparams['type'] = 'carp';
|
154 |
|
|
$pluginparams['event'] = 'rc.carpbackup';
|
155 |
eda14265
|
jim-p
|
$pluginparams['interface'] = $argument;
|
156 |
331166a8
|
PiBa-NL
|
pkg_call_plugins('plugin_carp', $pluginparams);
|
157 |
2156f02a
|
jim-p
|
|
158 |
77411fa7
|
Ermal
|
?>
|