vpn_ipsec_settings.php 8.75 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
require_once("filter.inc");
32
require_once("plugins.inc.d/ipsec.inc");
33
require_once("services.inc");
34
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
35

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

40 41 42 43
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // fetch form data
    $pconfig  = array();
    $pconfig['noinstalllanspd'] = isset($config['system']['noinstalllanspd']);
44
    $pconfig['disablevpnrules'] = isset($config['system']['disablevpnrules']);
45 46 47 48
    $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
    }
} 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'])) {
59
        unset($config['system']['noinstalllanspd']);
60
    }
61 62 63 64 65
    if (!empty($pconfig['disablevpnrules'])) {
        $config['system']['disablevpnrules'] = true;
    }  elseif (isset($config['system']['disablevpnrules'])) {
        unset($config['system']['disablevpnrules']);
    }
66 67 68 69 70
    if (isset($pconfig['preferoldsa_enable']) && $pconfig['preferoldsa_enable'] == "yes") {
        $config['ipsec']['preferoldsa'] = true;
    } elseif (isset($config['ipsec']['preferoldsa'])) {
        unset($config['ipsec']['preferoldsa']);
    }
71
    if (isset($config['ipsec']) && is_array($config['ipsec'])) {
72 73 74 75
        foreach ($ipsec_loglevels as $lkey => $ldescr) {
            if (empty($_POST["ipsec_{$lkey}"])) {
                if (isset($config['ipsec']["ipsec_{$lkey}"])) {
                    unset($config['ipsec']["ipsec_{$lkey}"]);
76
                }
77 78
            } else {
                $config['ipsec']["ipsec_{$lkey}"] = $_POST["ipsec_{$lkey}"];
79 80
            }
        }
81
    }
82

83
    write_config();
84 85
    $savemsg = get_std_save_message();
    filter_configure();
86
    ipsec_configure_do();
Ad Schellevis's avatar
Ad Schellevis committed
87 88
}

89
$service_hook = 'ipsec';
Ad Schellevis's avatar
Ad Schellevis committed
90 91

include("head.inc");
92

Ad Schellevis's avatar
Ad Schellevis committed
93 94
?>

95
<body>
Ad Schellevis's avatar
Ad Schellevis committed
96
<?php include("fbegin.inc"); ?>
97 98 99
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
100

101
<?php
102 103 104 105 106 107
if (isset($savemsg)) {
    print_info_box($savemsg);
}
if (isset($input_errors) && count($input_errors) > 0) {
    print_input_errors($input_errors);
}
108 109
?>
        <section class="col-xs-12">
110
          <div class="tab-content content-box col-xs-12">
111
              <form method="post" name="iform" id="iform">
112
                <div class="table-responsive">
113
                  <table class="table table-striped opnsense_standard_table_form">
114
                    <tr>
115
                      <td ><strong><?=gettext("IPsec Advanced Settings"); ?></strong></td>
116 117
                      <td align="right">
                        <small><?=gettext("full help"); ?> </small>
Ad Schellevis's avatar
Ad Schellevis committed
118
                        <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i>
119
                      </td>
120 121
                    </tr>
                    <tr>
DokuKaefer's avatar
DokuKaefer committed
122
                      <td><a id="help_for_noinstalllanspd" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("LAN security associations"); ?></td>
123
                      <td>
124 125 126
                        <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">
127
                            <?=gettext("By default, if IPsec is enabled negating SPD are inserted to provide protection. " .
128 129 130
                                                  "This behaviour can be changed by enabling this setting which will prevent installing these SPDs."); ?>
                        </div>
                      </td>
131
                    </tr>
132 133 134 135 136 137 138
                    <tr>
                      <td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Disable Auto-added VPN rules') ?></td>
                      <td>
                        <input name="disablevpnrules" type="checkbox" value="yes" <?=!empty($pconfig['disablevpnrules']) ? "checked=\"checked\"" :"";?> />
                        <strong><?=gettext("Disable all auto-added VPN rules.");?></strong>
                      </td>
                    </tr>
139 140 141
                    <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">
142 143 144
                        <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">
145
                            <?=gettext("By default, if several SAs match, the newest one is " .
146 147 148
                                                  "preferred if it's at least 30 seconds old. Select this " .
                                                  "option to always prefer old SAs over new ones."); ?>
                        </div>
149 150 151 152 153
                      </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>
154
                        <div class="hidden" for="help_for_ipsec_debug">
155
                                      <strong><?=gettext("Start IPsec in debug mode based on sections selected"); ?></strong> <br/>
156 157
                        </div>
<?php                   foreach ($ipsec_loglevels as $lkey => $ldescr) :
158
?>
159 160
                        <?=$ldescr?>
                        <select name="ipsec_<?=$lkey?>" id="ipsec_<?=$lkey?>">
161 162
<?php                   foreach (array("Silent", "Basic", "Audit", "Control", "Raw", "Highest") as $lidx => $lvalue) :
                          $lidx -= 1;
163
?>
164
                          <option value="<?=$lidx?>" <?= (isset($pconfig["ipsec_{$lkey}"]) && $pconfig["ipsec_{$lkey}"] == $lidx) || (!isset($pconfig["ipsec_{$lkey}"]) && $lidx == "0")  ? "selected=\"selected\"" : "";?> ?>
165
                                <?=$lvalue?>
166 167
                          </option>
<?php
168
endforeach; ?>
169
                        </select>
170
<?php
171
endforeach; ?>
172
                        <div class="hidden" for="help_for_ipsec_debug">
173
                        <?=gettext("Launch IPsec in debug mode so that more verbose logs will be generated to aid in troubleshooting."); ?>
174 175 176
                        </div>
                      </td>
                    </tr>
177 178 179 180 181 182 183 184 185 186 187 188 189
                    <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>
190
    </section>
191
<?php include("foot.inc");