vpn_ipsec_settings.php 7.88 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("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 44 45 46 47
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}"];
48
        } else {
49
            $pconfig["ipsec_{$lkey}"] = null;
50
        }
51 52 53 54 55 56 57
    }
} 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'])) {
58
        unset($config['system']['noinstalllanspd']);
59 60 61 62 63 64
    }
    if (isset($pconfig['preferoldsa_enable']) && $pconfig['preferoldsa_enable'] == "yes") {
        $config['ipsec']['preferoldsa'] = true;
    } elseif (isset($config['ipsec']['preferoldsa'])) {
        unset($config['ipsec']['preferoldsa']);
    }
65
    if (isset($config['ipsec']) && is_array($config['ipsec'])) {
66 67 68 69
        foreach ($ipsec_loglevels as $lkey => $ldescr) {
            if (empty($_POST["ipsec_{$lkey}"])) {
                if (isset($config['ipsec']["ipsec_{$lkey}"])) {
                    unset($config['ipsec']["ipsec_{$lkey}"]);
70
                }
71 72
            } else {
                $config['ipsec']["ipsec_{$lkey}"] = $_POST["ipsec_{$lkey}"];
73 74
            }
        }
75
    }
76

77
    write_config();
78 79
    $savemsg = get_std_save_message();
    filter_configure();
80
    ipsec_configure();
Ad Schellevis's avatar
Ad Schellevis committed
81 82
}

83
$service_hook = 'ipsec';
Ad Schellevis's avatar
Ad Schellevis committed
84 85

include("head.inc");
86

Ad Schellevis's avatar
Ad Schellevis committed
87 88
?>

89
<body>
Ad Schellevis's avatar
Ad Schellevis committed
90
<?php include("fbegin.inc"); ?>
91 92 93
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
94

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