1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
rc.carpmaster
|
6
|
part of pfSense (https://www.pfsense.org)
|
7
|
Copyright (C) 2004 Scott Ullrich
|
8
|
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 the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
require_once("functions.inc");
|
33
|
require_once("config.inc");
|
34
|
require_once("notices.inc");
|
35
|
require_once("openvpn.inc");
|
36
|
require_once("interfaces.inc");
|
37
|
|
38
|
if (isset($_GET)) {
|
39
|
$argument = $_GET['interface'];
|
40
|
} else {
|
41
|
$argument = str_replace("\n", "", $argv[1]);
|
42
|
}
|
43
|
if (!strstr($argument, "@")) {
|
44
|
log_error("Carp MASTER event triggered from wrong source {$argument}");
|
45
|
}
|
46
|
|
47
|
list($vhid, $iface) = explode("@", $argument);
|
48
|
|
49
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
50
|
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
|
51
|
$vips = link_interface_to_vips($friendly, '', $vhid);
|
52
|
$carp_iface = "{$friendly}_vip{$vhid}";
|
53
|
foreach ($vips as $vip) {
|
54
|
$notificationmsg = sprintf('Carp cluster member "(%1$s): (%2$s)" has resumed the state "MASTER" for vhid %3$s', $argument, $friendly_descr, $vhid);
|
55
|
|
56
|
notify_via_smtp($notificationmsg);
|
57
|
notify_via_growl($notificationmsg);
|
58
|
log_error($notificationmsg);
|
59
|
}
|
60
|
|
61
|
/* Start OpenVPN clients running on this VIP, since they should be in the stopped state while the VIP is CARP Backup. */
|
62
|
global $config;
|
63
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
|
64
|
foreach ($config['openvpn']['openvpn-client'] as $settings) {
|
65
|
foreach ($vips as $vip) {
|
66
|
if ($settings['interface'] == "_vip{$vip['uniqid']}") {
|
67
|
log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
|
68
|
openvpn_restart('client', $settings);
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
|
74
|
foreach ($config['openvpn']['openvpn-server'] as $settings) {
|
75
|
if ($settings['interface'] == $carp_iface) {
|
76
|
log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master.");
|
77
|
openvpn_restart('server', $settings);
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
/* Reconfigure radvd when necessary */
|
83
|
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
|
84
|
$found = false;
|
85
|
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
|
86
|
if ($dhcpv6ifconf['rainterface'] != $carp_iface) {
|
87
|
continue;
|
88
|
}
|
89
|
|
90
|
$found = true;
|
91
|
break;
|
92
|
}
|
93
|
|
94
|
if ($found === true) {
|
95
|
services_radvd_configure();
|
96
|
}
|
97
|
}
|
98
|
|
99
|
$pluginparams = array();
|
100
|
$pluginparams['type'] = 'carp';
|
101
|
$pluginparams['event'] = 'rc.carpmaster';
|
102
|
$pluginparams['interface'] = $argument;
|
103
|
pkg_call_plugins('plugin_carp', $pluginparams);
|
104
|
|
105
|
?>
|