vpn_ipsec_settings.php 11.7 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2014 Electric Sheep Fencing, LLC
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
Ad Schellevis's avatar
Ad Schellevis committed
28 29
*/

30
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
31 32
require_once("filter.inc");
require_once("vpn.inc");
33
require_once("services.inc");
34
require_once("pfsense-utils.inc");
35
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
36

37
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
38
    $config['ipsec'] = array();
39
}
40

41 42 43 44 45 46 47 48
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // fetch form data
    $pconfig  = array();
    $pconfig['noinstalllanspd'] = isset($config['system']['noinstalllanspd']);
    $pconfig['preferoldsa_enable'] = isset($config['ipsec']['preferoldsa']);
    foreach ($ipsec_loglevels as $lkey => $ldescr) {
        if (!empty($config['ipsec']["ipsec_{$lkey}"])) {
            $pconfig["ipsec_{$lkey}"] = $config['ipsec']["ipsec_{$lkey}"];
49
        } else {
50
            $pconfig["ipsec_{$lkey}"] = null;
51
        }
52 53 54 55 56 57 58 59 60 61
    }
    $pconfig['failoverforcereload'] = isset($config['ipsec']['failoverforcereload']);
    $pconfig['maxmss_enable'] = isset($config['system']['maxmss_enable']);
    $pconfig['maxmss'] = isset($config['system']['maxmss']) ? $config['system']['maxmss'] : null;
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // save form data
    $pconfig = $_POST;
    if (isset($pconfig['noinstalllanspd']) && $pconfig['noinstalllanspd'] == "yes") {
        $config['system']['noinstalllanspd'] = true;
    } elseif (isset($config['system']['noinstalllanspd'])) {
62
        unset($config['system']['noinstalllanspd']);
63 64 65 66 67 68
    }
    if (isset($pconfig['preferoldsa_enable']) && $pconfig['preferoldsa_enable'] == "yes") {
        $config['ipsec']['preferoldsa'] = true;
    } elseif (isset($config['ipsec']['preferoldsa'])) {
        unset($config['ipsec']['preferoldsa']);
    }
69
    if (isset($config['ipsec']) && is_array($config['ipsec'])) {
70 71 72 73
        foreach ($ipsec_loglevels as $lkey => $ldescr) {
            if (empty($_POST["ipsec_{$lkey}"])) {
                if (isset($config['ipsec']["ipsec_{$lkey}"])) {
                    unset($config['ipsec']["ipsec_{$lkey}"]);
74
                }
75 76
            } else {
                $config['ipsec']["ipsec_{$lkey}"] = $_POST["ipsec_{$lkey}"];
77 78
            }
        }
79
    }
80

81 82 83 84
    if (isset($pconfig['failoverforcereload']) && $pconfig['failoverforcereload'] == "yes") {
        $config['ipsec']['failoverforcereload'] = true;
    } elseif (isset($config['ipsec']['failoverforcereload']))
        unset($config['ipsec']['failoverforcereload']);
85

86 87 88 89 90 91 92
    if (isset($pconfig['maxmss_enable']) && $pconfig['maxmss_enable'] == "yes") {
        $config['system']['maxmss_enable'] = true;
        if (!empty($pconfig['maxmss']) && is_numericint($pconfig['maxmss'])) {
            $config['system']['maxmss'] = $pconfig['maxmss'];
        }
    } else {
        if (isset($config['system']['maxmss_enable'])) {
93 94
            unset($config['system']['maxmss_enable']);
        }
95 96
        if (isset($config['system']['maxmss'])) {
            unset($config['system']['maxmss']);
97
        }
98
    }
99

100
    write_config();
101 102 103
    $savemsg = get_std_save_message();

    filter_configure();
104
    vpn_ipsec_configure();
Ad Schellevis's avatar
Ad Schellevis committed
105 106
}

107
$shortcut_section = 'ipsec';
Ad Schellevis's avatar
Ad Schellevis committed
108 109

include("head.inc");
110

Ad Schellevis's avatar
Ad Schellevis committed
111 112
?>

113
<body>
Ad Schellevis's avatar
Ad Schellevis committed
114 115 116 117
<?php include("fbegin.inc"); ?>

<script type="text/javascript">
//<![CDATA[
118 119 120
$( document ).ready(function() {
    maxmss_checked()
});
Ad Schellevis's avatar
Ad Schellevis committed
121 122

function maxmss_checked(obj) {
123
  if ($('#maxmss_enable').is(":checked")) {
124 125 126 127 128 129 130 131 132
    $('#maxmss').attr('disabled',false);
    $("#maxmss").addClass('show');
    $("#maxmss").removeClass('hidden');
  } else {
    $('#maxmss').attr('disabled',true);
    $("#maxmss").addClass('hidden');
    $("#maxmss").removeClass('show');
  }

Ad Schellevis's avatar
Ad Schellevis committed
133 134 135 136
}

//]]>
</script>
137 138 139
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
140

141
<?php
142 143 144 145 146 147
if (isset($savemsg)) {
    print_info_box($savemsg);
}
if (isset($input_errors) && count($input_errors) > 0) {
    print_input_errors($input_errors);
}
148 149
?>
        <section class="col-xs-12">
150 151 152 153
          <div class="tab-content content-box col-xs-12">
              <form action="vpn_ipsec_settings.php" method="post" name="iform" id="iform">
                <div class="table-responsive">
                  <table class="table table-striped">
154 155 156 157
                    <tr>
                      <td ><strong><?=gettext("IPSec Advanced Settings"); ?></strong></td>
                      <td align="right">
                        <small><?=gettext("full help"); ?> </small>
158
                        <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i></a>
159
                      </td>
160 161
                    </tr>
                    <tr>
DokuKaefer's avatar
DokuKaefer committed
162
                      <td><a id="help_for_noinstalllanspd" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("LAN security associations"); ?></td>
163
                      <td>
164 165 166
                        <input name="noinstalllanspd" type="checkbox" id="noinstalllanspd" value="yes" <?=!empty($pconfig['noinstalllanspd']) ? "checked=\"checked\""  : "";?> />
                        <strong><?=gettext("Do not install LAN SPD"); ?></strong>
                        <div class="hidden" for="help_for_noinstalllanspd">
167
                            <?=gettext("By default, if IPSec is enabled negating SPD are inserted to provide protection. " .
168 169 170
                                                  "This behaviour can be changed by enabling this setting which will prevent installing these SPDs."); ?>
                        </div>
                      </td>
171 172 173 174
                    </tr>
                    <tr>
                      <td><a id="help_for_preferoldsa_enable" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Security Associations"); ?></td>
                      <td width="78%" class="vtable">
175 176 177
                        <input name="preferoldsa_enable" type="checkbox" id="preferoldsa_enable" value="yes" <?= !empty($pconfig['preferoldsa_enable']) ? "checked=\"checked\"" : "";?> />
                        <strong><?=gettext("Prefer older IPsec SAs"); ?></strong>
                        <div class="hidden" for="help_for_preferoldsa_enable">
178
                            <?=gettext("By default, if several SAs match, the newest one is " .
179 180 181
                                                  "preferred if it's at least 30 seconds old. Select this " .
                                                  "option to always prefer old SAs over new ones."); ?>
                        </div>
182 183 184 185 186
                      </td>
                    </tr>
                    <tr>
                      <td><a id="help_for_ipsec_debug" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPsec Debug"); ?></td>
                      <td>
187
                        <div class="hidden" for="help_for_ipsec_debug">
188
                                      <strong><?=gettext("Start IPSec in debug mode based on sections selected"); ?></strong> <br/>
189 190
                        </div>
<?php                   foreach ($ipsec_loglevels as $lkey => $ldescr) :
191
?>
192 193
                        <?=$ldescr?>
                        <select name="ipsec_<?=$lkey?>" id="ipsec_<?=$lkey?>">
194
<?php                   foreach (array("Silent", "Audit", "Control", "Diag", "Raw", "Highest") as $lidx => $lvalue) :
195 196
?>
                          <option value="<?=$lidx?>" <?= isset($pconfig["ipsec_{$lkey}"]) && $pconfig["ipsec_{$lkey}"] == $lidx ? "selected=\"selected\"" : "";?> ?>
197
                                <?=$lvalue?>
198 199
                          </option>
<?php
200
endforeach; ?>
201
                        </select>
202
<?php
203
endforeach; ?>
204
                        <div class="hidden" for="help_for_ipsec_debug">
205
                        <?=gettext("Launches IPSec in debug mode so that more verbose logs " .
206 207 208 209
                                                    "will be generated to aid in troubleshooting."); ?>
                        </div>
                      </td>
                    </tr>
210 211 212
                    <tr>
                      <td><a id="help_for_failoverforcereloadg" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPsec Reload on Failover"); ?></td>
                      <td>
213 214 215
                        <input name="failoverforcereload" type="checkbox" id="failoverforcereload" value="yes" <?= !empty($pconfig['failoverforcereload']) ? "checked=\"checked\"" : "";?> />
                        <strong><?=gettext("Force IPsec Reload on Failover"); ?></strong>
                        <div class="hidden" for="help_for_failoverforcereloadg">
216
                            <?=gettext("In some circumstances using a gateway group as the interface for " .
217 218 219 220
                                                  "an IPsec tunnel does not function properly, and IPsec must be forcefully reloaded " .
                                                  "when a failover occurs. Because this will disrupt all IPsec tunnels, this behavior" .
                                                  " is disabled by default. Check this box to force IPsec to fully reload on failover."); ?>
                        </div>
221 222 223 224 225 226 227
                      </td>
                    </tr>
                    <tr>
                      <td><a id="help_for_maxmss_enable" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Maximum MSS"); ?></td>
                      <td>
                        <input name="maxmss_enable" type="checkbox" id="maxmss_enable" value="yes" <?= !empty($pconfig['maxmss_enable']) ? "checked=\"checked\"" : "" ;?> onclick="maxmss_checked()" />
                        <strong><?=gettext("Enable MSS clamping on VPN traffic"); ?></strong>
228 229
                        <input name="maxmss" id="maxmss" type="text" value="<?= !empty($pconfig['maxmss']) ? $pconfig['maxmss'] : "1400";
?>" <?= !empty($pconfig['maxmss_enable']) ? "disabled=\"disabled\"" : "" ;?> />
230
                        <div class="hidden" for="help_for_maxmss_enable">
231
                        <?=gettext("Enable MSS clamping on TCP flows over VPN. " .
232 233
                                                  "This helps overcome problems with PMTUD on IPsec VPN links. If left blank, the default value is 1400 bytes. "); ?>
                        </div>
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
                      </td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>
                        <input name="submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
                      </td>
                    </tr>
                  </table>
                </div>
              </form>
            </div>
          </section>
        </div>
      </div>
249
    </section>
250
<?php include("foot.inc");