1 |
cb7d18d5
|
Renato Botelho
|
#!/usr/local/bin/php-cgi -f
|
2 |
ae75bcb4
|
Scott Ullrich
|
<?php
|
3 |
|
|
/*
|
4 |
34cd5348
|
Chris Buechler
|
rc.carpmaster
|
5 |
|
|
part of pfSense (https://www.pfsense.org)
|
6 |
|
|
Copyright (C) 2004 Scott Ullrich
|
7 |
|
|
All rights reserved.
|
8 |
f3dadbb4
|
Chris Buechler
|
|
9 |
34cd5348
|
Chris Buechler
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, are permitted provided that the following conditions are met:
|
11 |
f3dadbb4
|
Chris Buechler
|
|
12 |
34cd5348
|
Chris Buechler
|
1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
this list of conditions and the following disclaimer.
|
14 |
f3dadbb4
|
Chris Buechler
|
|
15 |
34cd5348
|
Chris Buechler
|
2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
notice, this list of conditions and the following disclaimer in the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
f3dadbb4
|
Chris Buechler
|
|
19 |
34cd5348
|
Chris Buechler
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
ae75bcb4
|
Scott Ullrich
|
*/
|
30 |
|
|
|
31 |
|
|
require_once("functions.inc");
|
32 |
|
|
require_once("config.inc");
|
33 |
|
|
require_once("notices.inc");
|
34 |
9ea0cb90
|
jim-p
|
require_once("openvpn.inc");
|
35 |
e3449857
|
PiBa-NL
|
require_once("interfaces.inc");
|
36 |
ae75bcb4
|
Scott Ullrich
|
|
37 |
7de4474e
|
Luiz Otavio O Souza
|
if (isset($_GET['interface'])) {
|
38 |
815f1f77
|
Ermal
|
$argument = $_GET['interface'];
|
39 |
e173dd74
|
Phil Davis
|
} else {
|
40 |
815f1f77
|
Ermal
|
$argument = str_replace("\n", "", $argv[1]);
|
41 |
e173dd74
|
Phil Davis
|
}
|
42 |
|
|
if (!strstr($argument, "@")) {
|
43 |
10e58a70
|
Chris Buechler
|
log_error("CARP master event triggered from wrong source {$argument}");
|
44 |
7de4474e
|
Luiz Otavio O Souza
|
exit;
|
45 |
e173dd74
|
Phil Davis
|
}
|
46 |
77411fa7
|
Ermal
|
|
47 |
|
|
list($vhid, $iface) = explode("@", $argument);
|
48 |
|
|
|
49 |
|
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
50 |
34cd5348
|
Chris Buechler
|
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
|
51 |
|
|
$vips = link_interface_to_vips($friendly, '', $vhid);
|
52 |
7de4474e
|
Luiz Otavio O Souza
|
if (!is_array($vips)) {
|
53 |
|
|
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs");
|
54 |
|
|
exit;
|
55 |
|
|
}
|
56 |
34cd5348
|
Chris Buechler
|
foreach ($vips as $vip) {
|
57 |
7de4474e
|
Luiz Otavio O Souza
|
$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "MASTER" for vhid %4$s',
|
58 |
|
|
$vip['subnet'], $iface, $friendly_descr, $vhid);
|
59 |
ae75bcb4
|
Scott Ullrich
|
|
60 |
34cd5348
|
Chris Buechler
|
notify_via_smtp($notificationmsg);
|
61 |
|
|
notify_via_growl($notificationmsg);
|
62 |
|
|
log_error($notificationmsg);
|
63 |
|
|
}
|
64 |
ae75bcb4
|
Scott Ullrich
|
|
65 |
9ea0cb90
|
jim-p
|
/* Start OpenVPN clients running on this VIP, since they should be in the stopped state while the VIP is CARP Backup. */
|
66 |
|
|
global $config;
|
67 |
d20dd658
|
Chris Buechler
|
$a_groups = return_gateway_groups_array();
|
68 |
2156f02a
|
jim-p
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
|
69 |
|
|
foreach ($config['openvpn']['openvpn-client'] as $settings) {
|
70 |
d20dd658
|
Chris Buechler
|
if (substr($settings['interface'], 0, 4) == '_vip') {
|
71 |
|
|
$openvpn_vip = $settings['interface'];
|
72 |
|
|
} else if (is_array($a_groups[$settings['interface']])) {
|
73 |
|
|
// interface is a gateway group, check CARP VIP
|
74 |
|
|
if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
|
75 |
|
|
$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
|
76 |
|
|
}
|
77 |
|
|
} else {
|
78 |
|
|
// this OpenVPN instance not on a CARP IP
|
79 |
|
|
continue;
|
80 |
|
|
}
|
81 |
34cd5348
|
Chris Buechler
|
foreach ($vips as $vip) {
|
82 |
d20dd658
|
Chris Buechler
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
83 |
89f171b0
|
Ermal LUÇI
|
log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
|
84 |
|
|
openvpn_restart('client', $settings);
|
85 |
|
|
}
|
86 |
2156f02a
|
jim-p
|
}
|
87 |
9ea0cb90
|
jim-p
|
}
|
88 |
|
|
}
|
89 |
e61a6db2
|
jim-p
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
|
90 |
|
|
foreach ($config['openvpn']['openvpn-server'] as $settings) {
|
91 |
7de4474e
|
Luiz Otavio O Souza
|
foreach ($vips as $vip) {
|
92 |
|
|
if ($settings['interface'] == "_vip{$vip['uniqid']}") {
|
93 |
|
|
log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master.");
|
94 |
|
|
openvpn_restart('server', $settings);
|
95 |
|
|
}
|
96 |
e173dd74
|
Phil Davis
|
}
|
97 |
|
|
}
|
98 |
52b5a223
|
Renato Botelho
|
}
|
99 |
|
|
|
100 |
eaee3af6
|
PiBa-NL
|
$pluginparams = array();
|
101 |
|
|
$pluginparams['type'] = 'carp';
|
102 |
|
|
$pluginparams['event'] = 'rc.carpmaster';
|
103 |
eda14265
|
jim-p
|
$pluginparams['interface'] = $argument;
|
104 |
331166a8
|
PiBa-NL
|
pkg_call_plugins('plugin_carp', $pluginparams);
|
105 |
eaee3af6
|
PiBa-NL
|
|
106 |
34cd5348
|
Chris Buechler
|
?>
|