firewall_nat_out_edit.php 38.2 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 28
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2004 Scott Ullrich
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
    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
29 30
*/

31
require_once("guiconfig.inc");
32
require_once("filter.inc");
Ad Schellevis's avatar
Ad Schellevis committed
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/**
 * return option array for valid translation networks
 */
function formTranslateAddresses() {
    global $config;
    $retval = array();

    // add this hosts ips
    foreach ($config['interfaces'] as $intf => $intfdata) {
        if (isset($intfdata['ipaddr']) && $intfdata['ipaddr'] != 'dhcp') {
            $retval[$intfdata['ipaddr']] = (!empty($intfdata['descr']) ? $intfdata['descr'] : $intf ) . " " . gettext("address");
        }
    }

    // add VIPs's
    if (isset($config['virtualip']['vip'])) {
        foreach ($config['virtualip']['vip'] as $sn) {
            if (!isset($sn['noexpand'])) {
                if ($sn['mode'] == "proxyarp" && $sn['type'] == "network") {
                    $start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits']));
                    $end = ip2long32(gen_subnet_max($sn['subnet'], $sn['subnet_bits']));
                    $len = $end - $start;
                    $retval[$sn['subnet'].'/'.$sn['subnet_bits']] = htmlspecialchars("Subnet: {$sn['subnet']}/{$sn['subnet_bits']} ({$sn['descr']})");
                    for ($i = 0; $i <= $len; $i++) {
                        $snip = long2ip32($start+$i);
                        $retval[$snip] = htmlspecialchars("{$snip} ({$sn['descr']})");
                    }
                } else {
                    $retval[$sn['subnet']] = htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");
                }
            }
        }
    }

    // add Aliases
69
    foreach (legacy_list_aliases("network") as $alias) {
70 71 72 73 74 75
        if ($alias['type'] == "host") {
            $retval[$alias['name']] = $alias['name'];;
        }
    }

    return $retval;
Ad Schellevis's avatar
Ad Schellevis committed
76 77
}

78 79 80 81 82
if (!isset($config['nat']['outbound']['rule'])) {
    if (!isset($config['nat']['outbound'])) {
        $config['nat']['outbound'] = array();
    }
    $config['nat']['outbound']['rule'] = array();
Ad Schellevis's avatar
Ad Schellevis committed
83
}
84
$a_out = &$config['nat']['outbound']['rule'];
Ad Schellevis's avatar
Ad Schellevis committed
85

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // input record id, if valid
    if (isset($_GET['dup']) && isset($a_out[$_GET['dup']]))  {
        $configId = $_GET['dup'];
        $after = $configId;
    } elseif (isset($_GET['id']) && isset($a_out[$_GET['id']])) {
        $id = $_GET['id'];
        $configId = $id;
    }

    // init form data
    $pconfig = array();
    // set defaults
    $pconfig['source'] = 'any';
    $pconfig['source_subnet'] = 24;
    $pconfig['destination'] = "any";
    $pconfig['destination_subnet'] = 24;
    $pconfig['interface'] = "wan";

    if (isset($configId)) {
        // load data from config
        foreach (array('protocol','sourceport','dstport','natport','target','targetip'
108
                ,'targetip_subnet','poolopts','interface','descr','nonat','log'
109
                ,'disabled','staticnatport','nosync','ipprotocol') as $fieldname) {
110 111 112 113 114 115 116 117
              if (isset($a_out[$configId][$fieldname])) {
                  $pconfig[$fieldname] = $a_out[$configId][$fieldname];
              }
        }

        if (strpos($a_out[$configId]['source']['network'], "/") !== false) {
            list($pconfig['source'],$pconfig['source_subnet']) = explode('/', $a_out[$configId]['source']['network']);
        } else {
118
            $pconfig['source'] = $a_out[$configId]['source']['network'];
119 120 121 122 123 124 125 126 127 128 129 130
        }

        if (!is_numeric($pconfig['source_subnet']))
          $pconfig['source_subnet'] = 32;
        address_to_pconfig($a_out[$configId]['destination'], $pconfig['destination'],
          $pconfig['destination_subnet'], $pconfig['destination_not'],
          $none, $none);
    }

    // initialize unused elements
    foreach (array('protocol','sourceport','dstport','natport','target','targetip'
            ,'targetip_subnet','poolopts','interface','descr','nonat'
131
            ,'disabled','staticnatport','nosync','source','source_subnet','ipprotocol') as $fieldname) {
132 133 134 135
          if (!isset($pconfig[$fieldname])) {
              $pconfig[$fieldname] = null;
          }
    }
136 137 138 139 140 141 142
    if (empty($pconfig['ipprotocol'])) {
        if (strpos($pconfig['source'].$pconfig['destination'].$pconfig['targetip'], ":") !== false) {
            $pconfig['ipprotocol'] = 'inet6';
        } else {
            $pconfig['ipprotocol'] = 'inet';
        }
    }
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $input_errors = array();
    $pconfig = $_POST;
    // input record id, if valid
    if (isset($pconfig['id']) && isset($a_out[$pconfig['id']])) {
        $id = $pconfig['id'];
    }
    if (isset($pconfig['after']) && isset($a_out[$pconfig['after']])) {
        $after = $pconfig['after'];
    }

    /* input validation */
    $reqdfields = explode(" ", "interface protocol source source_subnet destination destination_subnet");
    $reqdfieldsn = array(gettext("Interface"),gettext("Protocol"),gettext("Source"),gettext("Source bit count"),gettext("Destination"),gettext("Destination bit count"));

    do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);

    if (in_array($pconfig['protocol'], explode(" ", "any tcp udp tcp/udp"))) {
        if(!empty($pconfig['sourceport']) && !is_portoralias($pconfig['sourceport']))
162
            $input_errors[] = gettext("You must supply either a valid port or port alias for the source port entry.");
163 164

        if(!empty($pconfig['dstport']) && !is_portoralias($pconfig['dstport']))
165
            $input_errors[] = gettext("You must supply either a valid port or port alias for the destination port entry.");
166 167

        if(!empty($pconfig['natport']) && !is_port($pconfig['natport']) && empty($pconfig['nonat']))
168
            $input_errors[] = gettext("You must supply a valid port for the NAT port entry.");
169 170
    }

171
    if (!(in_array($pconfig['source'], array("any","(self)")) || is_ipaddroralias($pconfig['source']))) {
172 173 174
        $input_errors[] = gettext("A valid source must be specified.");
    }
    if (!empty($pconfig['source_subnet']) && !is_numericint($pconfig['source_subnet'])) {
175
        $input_errors[] = gettext("A valid source bit count must be specified.");
176
    }
177
    if (!(in_array($pconfig['destination'], array("any","(self)")) || is_ipaddroralias($pconfig['destination']))) {
178 179 180
        $input_errors[] = gettext("A valid destination must be specified.");
    }
    if (!empty($pconfig['destination_subnet']) && !is_numericint($pconfig['destination_subnet'])) {
181
        $input_errors[] = gettext("A valid destination bit count must be specified.");
182 183
    }
    if ($pconfig['destination'] == "any" && !empty($pconfig['destination_not'])) {
184
        $input_errors[] = gettext("Negating destination address of \"any\" is invalid.");
185 186
    }

187
    if (!empty($pconfig['targetip']) && !is_ipaddr($pconfig['targetip']) && !is_subnet($pconfig['targetip']) && !is_alias($pconfig['targetip']) && empty($pconfig['nonat'])) {
188
        $input_errors[] = gettext("A valid target IP address must be specified.");
189 190
    }
    /* Verify Pool Options */
191
    if (!empty($pconfig['targetip']) && !is_alias($pconfig['targetip']) && substr($pconfig['poolopts'], 0, 11) == "round-robin") {
192 193 194
        $input_errors[] = gettext("Only Round Robin pool options may be chosen when selecting an alias.");
    }

195 196 197 198 199 200 201 202 203 204
    // validate ipv4/v6, addresses should use selected address family
    foreach (array('source', 'destination', 'targetip') as $fieldname) {
        if (is_ipaddrv6($pconfig[$fieldname]) && $pconfig['ipprotocol'] != 'inet6') {
            $input_errors[] = sprintf(gettext("%s is not a valid IPv4 address."), $pconfig[$fieldname]);
        }
        if (is_ipaddrv4($pconfig[$fieldname]) && $pconfig['ipprotocol'] != 'inet') {
            $input_errors[] = sprintf(gettext("%s is not a valid IPv6 address."), $pconfig[$fieldname]);
        }
    }

205 206 207 208 209 210 211
    if (count($input_errors) == 0) {
        $natent = array();
        $natent['source'] = array();
        $natent['destination'] = array();
        $natent['descr'] = $pconfig['descr'];
        $natent['interface'] = $pconfig['interface'];
        $natent['poolopts'] = $pconfig['poolopts'];
212
        $natent['ipprotocol'] = $pconfig['ipprotocol'];
213

214
        if (isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) ){
215 216 217 218
            $natent['created'] = $a_out[$id]['created'];
        }

        // target ip/net
219 220
        if (empty($pconfig['targetip'])) {
            // empty target "Interface address"
221
            $natent['target'] = $pconfig['targetip'];
222 223
            $natent['targetip_subnet'] = 0;
        } elseif (!array_key_exists($pconfig['targetip'], formTranslateAddresses())) {
224 225 226 227 228
            // a bit vague behaviour in "target" and "targetip", if a custom net is given
            // the backend code wants target to be filled with "other-subnet".
            // if any other known net is given, target is used to provide the actual address....
            // -- can't remove this behaviour now without breaking old confid, so let's reimplement
            $natent['target'] = 'other-subnet';
229 230
            $natent['targetip'] = trim($pconfig['targetip']);
            $natent['targetip_subnet'] = $pconfig['targetip_subnet'];
231
        } else {
232
            $natent['target'] = $pconfig['targetip'];
233 234 235 236
        }

        // handle fields containing portnumbers
        if (in_array($pconfig['protocol'], explode(" ", "any tcp udp tcp/udp"))) {
237
            if (isset($pconfig['staticnatport']) && empty($pconfig['nonat'])) {
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
                $natent['staticnatport'] = true;
            }
            $natent['sourceport'] = trim($pconfig['sourceport']);
            if (!empty($pconfig['natport']) && empty($pconfig['nonat'])) {
                $natent['natport'] = trim($pconfig['natport']);
            }
            if (!empty($pconfig['dstport'])) {
                $natent['dstport'] = trim($pconfig['dstport']);
            }
        } else {
            $natent['sourceport'] = "";
        }

        if (!empty($pconfig['protocol']) && $pconfig['protocol'] != "any") {
            $natent['protocol'] = $pconfig['protocol'];
        }

        /* parse source entry */
        if($pconfig['source'] == "any") {
            $natent['source']['network'] = "any";
        } else if($pconfig['source'] == "(self)") {
            $natent['source']['network'] = "(self)";
        } else if(is_alias($pconfig['source'])) {
            $natent['source']['network'] = trim($pconfig['source']);
        } else {
263 264 265 266 267
            if (is_ipaddrv6($pconfig['source'])) {
                $natent['source']['network'] = gen_subnetv6(trim($pconfig['source']), $pconfig['source_subnet']) . "/" . $pconfig['source_subnet'];
            } else {
                $natent['source']['network'] = gen_subnet(trim($pconfig['source']), $pconfig['source_subnet']) . "/" . $pconfig['source_subnet'];
            }
268 269 270 271 272 273 274 275
        }

        // destination address
        if ($pconfig['destination'] == "any") {
            $natent['destination']['any'] = true;
        } elseif (is_alias($pconfig['destination'])){
            $natent['destination']['address'] = trim($pconfig['destination']) ;
        } else {
276 277 278 279 280
            if (is_ipaddrv6($pconfig['destination'])) {
                $natent['destination']['address'] = gen_subnetv6(trim($pconfig['destination']), $pconfig['destination_subnet']) . "/" . $pconfig['destination_subnet'];;
            } else {
                $natent['destination']['address'] = gen_subnet(trim($pconfig['destination']), $pconfig['destination_subnet']) . "/" . $pconfig['destination_subnet'];;
            }
281 282 283 284
        }

        // boolean fields
        if(!empty($pconfig['disabled'])) {
285
            $natent['disabled'] = true;
286 287 288 289
        }
        if(!empty($pconfig['nonat'])) {
            $natent['nonat'] = true;
        }
290 291 292
        if (!empty($pconfig['log'])) {
            $natent['log'] = true;
        }
293 294 295 296 297 298 299 300 301 302 303 304

        if(isset($pconfig['nosync'] ) && $pconfig['nosync'] == "yes") {
            $natent['nosync'] = true;
        }
        if (isset($pconfig['destination_not']) && $pconfig['destination'] != "any") {
            $natent['destination']['not'] = true;
        }

        $natent['updated'] = make_config_revision_entry();
        if (isset($id)) {
            $a_out[$id] = $natent;
        } else {
305 306 307 308 309 310
            $natent['created'] = make_config_revision_entry();
            if (isset($after)) {
                array_splice($a_out, $after+1, 0, array($natent));
            } else {
                $a_out[] = $natent;
            }
311
        }
312 313 314
        write_config();
        mark_subsystem_dirty('natconf');
        header(url_safe('Location: /firewall_nat_out.php'));
315 316
        exit;
    }
Ad Schellevis's avatar
Ad Schellevis committed
317 318
}

319
legacy_html_escape_form_data($pconfig);
320

Ad Schellevis's avatar
Ad Schellevis committed
321
include("head.inc");
322

Ad Schellevis's avatar
Ad Schellevis committed
323
?>
Ad Schellevis's avatar
Ad Schellevis committed
324
<body>
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
  <script type="text/javascript">
  $( document ).ready(function() {

    // select / input combination, link behaviour
    // when the data attribute "data-other" is selected, display related input item(s)
    // push changes from input back to selected option value
    $('[for!=""][for]').each(function(){
        var refObj = $("#"+$(this).attr("for"));
        if (refObj.is("select")) {
            // connect on change event to select box (show/hide)
            refObj.change(function(){
              if ($(this).find(":selected").attr("data-other") == "true") {
                  // show related controls
                  $('*[for="'+$(this).attr("id")+'"]').each(function(){
                    if ($(this).hasClass("selectpicker")) {
                      $(this).selectpicker('show');
                    } else {
                      $(this).removeClass("hidden");
                    }
                  });
              } else {
                  // hide related controls
                  $('*[for="'+$(this).attr("id")+'"]').each(function(){
                    if ($(this).hasClass("selectpicker")) {
                      $(this).selectpicker('hide');
                    } else {
                      $(this).addClass("hidden");
                    }
                  });
              }
            });
            // update initial
            refObj.change();

            // connect on change to input to save data to selector
            if ($(this).attr("name") == undefined) {
              $(this).change(function(){
                  var otherOpt = $('#'+$(this).attr('for')+' > option[data-other="true"]') ;
                  otherOpt.attr("value",$(this).val());
              });
            }
        }
    });

369 370
    // IPv4/IPv6 select
    hook_ipv4v6('ipv4v6net', 'network-id');
371 372
  });
  </script>
Ad Schellevis's avatar
Ad Schellevis committed
373

374 375 376 377 378 379 380
<?php include("fbegin.inc"); ?>
  <section class="page-content-main">
    <div class="container-fluid">
      <div class="row">
        <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
        <section class="col-xs-12">
          <div class="content-box">
381
            <form method="post" name="iform" id="iform">
382 383 384 385 386 387 388 389
              <table class="table table-striped">
                <tr>
                  <td colspan="2">
                    <table>
                        <tr>
                            <td><?=gettext("Edit Advanced Outbound NAT entry");?></td>
                            <td colspan="2" align="right">
                                <small><?=gettext("full help"); ?> </small>
Ad Schellevis's avatar
Ad Schellevis committed
390
                                <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i>
391 392 393 394 395 396 397 398 399
                            </td>
                        </tr>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_disabled" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disabled"); ?></td>
                  <td>
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?= !empty($pconfig['disabled']) ? "checked=\"checked\"" : ""; ?> />
400
                    <strong><?=gettext("Disable this rule"); ?></strong>
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
                    <div class="hidden" for="help_for_disabled">
                      <?=gettext("Set this option to disable this rule without removing it from the list."); ?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_do_not_nat" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Do not NAT");?></td>
                  <td width="78%" class="vtable">
                    <input type="checkbox" name="nonat" <?=!empty($pconfig['nonat']) ? " checked=\"checked\"" : ""; ?> />
                    <div class="hidden" for="help_for_do_not_nat">
                      <?=gettext("Enabling this option will disable NAT for traffic matching this rule and stop processing Outbound NAT rules.");?><br />
                      <?=gettext("Hint: in most cases, you won't use this option.");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_interface" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Interface"); ?></td>
                  <td>
                    <div class="input-group">
420
                      <select name="interface" class="selectpicker" data-width="auto" data-live-search="true">
421
<?php
422
                        foreach (legacy_config_get_interfaces(array("enable" => true)) as $iface => $ifdetail): ?>
423
                        <option value="<?=$iface;?>" <?= $iface == $pconfig['interface'] ? "selected=\"selected\"" : ""; ?>>
424
                          <?=htmlspecialchars($ifdetail['descr']);?>
425 426 427 428 429 430 431 432 433 434
                        </option>
                        <?php endforeach; ?>
                      </select>
                    </div>
                    <div class="hidden" for="help_for_interface">
                      <?=gettext("Choose which interface this rule applies to"); ?>.<br />
                      <?=gettext("Hint: in most cases, you'll want to use WAN here"); ?>
                    </div>
                  </td>
                </tr>
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
                <tr>
                  <td><a id="help_for_ipv46" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("TCP/IP Version");?></td>
                  <td>
                    <select name="ipprotocol" class="selectpicker" data-width="auto" data-live-search="true" data-size="5" >
<?php
                    foreach (array('inet' => 'IPv4','inet6' => 'IPv6') as $proto => $name): ?>
                    <option value="<?=$proto;?>" <?= $proto == $pconfig['ipprotocol'] ? "selected=\"selected\"" : "";?>>
                      <?=$name;?>
                    </option>
<?php
                    endforeach; ?>
                    </select>
                    <div class="hidden" for="help_for_ipv46">
                      <?=gettext("Select the Internet Protocol version this rule applies to");?>
                    </div>
                  </td>
                </tr>
452 453 454 455 456
                <tr>
                  <td><a id="help_for_proto" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Protocol"); ?></td>
                  <td>
                    <div class="input-group">
                      <select id="proto" name="protocol" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
457
<?php                foreach (get_protocols() as $proto):
458
?>
459
              <option value="<?=strtolower($proto);?>" <?= strtolower($proto) == $pconfig['protocol'] ? "selected=\"selected\"" : ""; ?>><?=$proto;?></option>
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
<?php                endforeach; ?>
              </select>
                    </div>
                    <div class="hidden" for="help_for_proto">
                      <?=gettext("Choose which IP protocol " ."this rule should match."); ?><br/>
                      <?=gettext("Hint: in most cases, you should specify"); ?> <em><?=gettext("TCP"); ?></em> &nbsp;<?=gettext("here."); ?>
                    </div>
                  </td>
                </tr>
                <tr>
                    <td><a id="help_for_source" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Source"); ?></td>
                    <td>
                      <table class="table table-condensed">
                        <tr>
                          <td>
                            <select name="source" id="source" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
                              <option data-other=true value="<?=$pconfig['source'];?>" <?=!is_alias($pconfig['source']) && !in_array($pconfig['source'],array('(self)','any'))  ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
                              <option value="any" <?=$pconfig['source'] == "any" ? "selected=\"selected\"" : ""; ?>><?=gettext("any");?></option>
                              <option value="(self)" <?=$pconfig['source'] == "(self)" ? "selected=\"selected\"" : ""; ?>><?=gettext("This Firewall (self)");?></option>
479 480
                              <optgroup label="<?=gettext("Aliases");?>">
<?php                            foreach (legacy_list_aliases("network") as $alias):
481 482 483 484 485 486 487 488 489 490 491
?>
                                <option value="<?=$alias['name'];?>" <?=$alias['name'] == $pconfig['source'] ? "selected=\"selected\"" : "";?>><?=htmlspecialchars($alias['name']);?></option>
<?php                            endforeach; ?>
                              </optgroup>
                          </select>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <div class="input-group">
                          <!-- updates to "other" option in  source -->
492 493 494
                          <input type="text" for="source" id="src_address" value="<?=$pconfig['source'];?>" aria-label="<?=gettext("Source address");?>"/>
                          <select name="source_subnet"  data-network-id="src_address" class="selectpicker ipv4v6net" data-size="5" id="srcmask"  data-width="auto" for="source" >
                          <?php for ($i = 128; $i > 0; $i--): ?>
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
                            <option value="<?=$i;?>" <?= $i == $pconfig['source_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
                          <?php endfor; ?>
                          </select>
                        </div>
                        </td>
                      </tr>
                    </table>
                    <div class="hidden" for="help_for_source">
                      <?=gettext("Enter the source network for the outbound NAT mapping.");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_src_port" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Source port:");?></td>
                  <td>
                    <input name="sourceport" type="text" value="<?=$pconfig['sourceport'];?>" />
                    <div class="hidden" for="help_for_src_port">
                      <?=gettext("(leave blank for any)");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td> <a id="help_for_dst_invert" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination") . " / ".gettext("Invert");?> </td>
                  <td>
                    <input name="destination_not" type="checkbox" value="yes" <?= !empty($pconfig['destination_not']) ? "checked=\"checked\"" : "";?> />
                    <div class="hidden" for="help_for_dst_invert">
                      <?=gettext("Use this option to invert the sense of the match."); ?>
                    </div>
                  </td>
                </tr>
                <tr>
                    <td><a id="help_for_destination" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination"); ?></td>
                    <td>
                      <table class="table table-condensed">
                        <tr>
                          <td>
                            <select name="destination" id="destination" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
                              <option data-other=true value="<?=$pconfig['destination'];?>" <?=!is_alias($pconfig['destination']) && $pconfig['destination'] != 'any' ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
                              <option value="any" <?=$pconfig['destination'] == "any" ? "selected=\"selected\"" : ""; ?>><?=gettext("any");?></option>
534 535
                              <optgroup label="<?=gettext("Aliases");?>">
<?php                        foreach (legacy_list_aliases("network") as $alias):
536 537 538 539 540 541 542 543 544 545 546
?>
                                <option value="<?=$alias['name'];?>" <?=$alias['name'] == $pconfig['destination'] ? "selected=\"selected\"" : "";?>><?=htmlspecialchars($alias['name']);?></option>
<?php                          endforeach; ?>
                              </optgroup>
                          </select>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <div class="input-group">
                          <!-- updates to "other" option in  source -->
547 548 549
                          <input type="text" id="dst_address" for="destination" value="<?=$pconfig['destination'];?>" aria-label="<?=gettext("Destination address");?>"/>
                          <select name="destination_subnet" data-network-id="dst_address" class="selectpicker ipv4v6net" id="dstmask" data-size="5" data-width="auto" for="destination" >
                          <?php for ($i = 128; $i > 0; $i--): ?>
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
                            <option value="<?=$i;?>" <?= $i == $pconfig['destination_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
                          <?php endfor; ?>
                          </select>
                        </div>
                        </td>
                      </tr>
                    </table>
                    <div class="hidden" for="help_for_destination">
                      <?=gettext("Enter the source network for the outbound NAT mapping.");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_dstport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination port:");?></td>
                  <td>
                    <input name="dstport" type="text" value="<?=$pconfig['dstport'];?>" />
                    <div class="hidden" for="help_for_dstport">
                      <?=gettext("(leave blank for any)");?>
                    </div>
                  </td>
                </tr>
                <tr>
572
                    <td><a id="help_for_target" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Translation / target"); ?></td>
573 574 575 576 577
                    <td>
                      <table class="table table-condensed">
                        <tr>
                          <td>
                            <select name="targetip" id="targetip" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
578
                                <option value="" <?= empty($pconfig['targetip']) ? "selected=\"selected\"" : "";?> > <?=gettext("Interface address");?> </option>
579
                                <option data-other=true value="<?=$pconfig['targetip'];?>" <?= !empty($pconfig['target']) && !array_key_exists($pconfig['targetip'], formTranslateAddresses() ) ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
580
<?php                              foreach (formTranslateAddresses() as $optKey => $optValue): ?>
581 582 583
                                    <option value="<?=$optKey;?>" <?= $pconfig['target'] == $optKey ? "selected=\"selected\"" : ""; ?>>
                                      <?=$optValue;?>
                                    </option>
584
<?php                              endforeach; ?>
585 586 587 588 589 590 591
                            </select>
                          </td>
                        </tr>
                        <tr>
                          <td>
                            <div class="input-group">
                              <!-- updates to "other" option in  source -->
592 593 594
                              <input type="text" id="targetip_text" for="targetip" value="<?=$pconfig['targetip'];?>" aria-label="<?=gettext("Translation address");?>"/>
                              <select name="targetip_subnet" data-network-id="targetip_text" class="selectpicker ipv4v6net" id="targetip_subnet" data-size="5" data-width="auto" for="targetip" >
                              <?php for ($i = 128; $i > 0; $i--): ?>
595 596 597 598 599 600 601 602 603
                                <option value="<?=$i;?>" <?= $i == $pconfig['targetip_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
                              <?php endfor; ?>
                              </select>
                            </div>
                          </td>
                        </tr>
                      </table>
                      <div class="hidden" for="help_for_target">
                        <?=gettext("Packets matching this rule will be mapped to the IP address given here.");?><br />
604 605
                        <?=sprintf(gettext("If you want this rule to apply to another IP address rather than the IP address of the interface chosen above, ".
                                "select it here (you will need to define %sVirtual IP addresses%s on the interface first)."),'<a href="firewall_virtual_ip.php">','</a>')?>
606 607 608
                      </div>
                  </td>
                </tr>
609 610 611 612 613 614 615 616 617 618
                <tr>
                  <td><a id="help_for_log" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Log");?></td>
                  <td>
                    <input name="log" type="checkbox" id="log" value="yes" <?= !empty($pconfig['log']) ? "checked=\"checked\"" : ""; ?> />
                    <strong><?=gettext("Log packets that are handled by this rule");?></strong>
                    <div class="hidden" for="help_for_log">
                      <?=sprintf(gettext("Hint: the firewall has limited local log space. Don't turn on logging for everything. If you want to do a lot of logging, consider using a %sremote syslog server%s."),'<a href="diag_logs_settings.php">','</a>') ?>
                    </div>
                  </td>
                </tr>
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
                <tr>
                  <td><a id="help_for_poolopts" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Pool Options:");?></td>
                  <td>
                    <select name="poolopts" class="selectpicker">
                      <option value="" <?=empty($pconfig['poolopts']) ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Default");?>
                      </option>
                      <option value="round-robin" <?=$pconfig['poolopts'] == "round-robin" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Round Robin");?>
                      </option>
                      <option value="round-robin sticky-address" <?=$pconfig['poolopts'] == "round-robin sticky-address" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Round Robin with Sticky Address");?>
                      </option>
                      <option value="random" <?=$pconfig['poolopts'] == "random" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Random");?>
                      </option>
                      <option value="random sticky-address" <?=$pconfig['poolopts'] == "random sticky-address" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Random with Sticky Address");?>
                      </option>
                      <option value="source-hash" <?=$pconfig['poolopts'] == "source-hash" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Source Hash");?>
                      </option>
                      <option value="bitmask" <?=$pconfig['poolopts'] == "bitmask" ? "selected=\"selected\"" : ""; ?>>
                        <?=gettext("Bitmask");?>
                      </option>
                    </select>
                    <div class="hidden" for="help_for_poolopts">
                      <?=gettext("Only Round Robin types work with Host Aliases. Any type can be used with a Subnet.");?><br />
                      * <?=gettext("Round Robin: Loops through the translation addresses.");?><br />
                      * <?=gettext("Random: Selects an address from the translation address pool at random.");?><br />
                      * <?=gettext("Source Hash: Uses a hash of the source address to determine the translation address, ensuring that the redirection address is always the same for a given source.");?><br />
                      * <?=gettext("Bitmask: Applies the subnet mask and keeps the last portion identical; 10.0.1.50 -&gt; x.x.x.50.");?><br />
                      * <?=gettext("Sticky Address: The Sticky Address option can be used with the Random and Round Robin pool types to ensure that a particular source address is always mapped to the same translation address.");?><br />
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_natport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Translation") . " / " .gettext("port:");?></td>
                  <td>
                    <input name="natport" type="text" value="<?=$pconfig['natport'];?>" />
                    <div class="hidden" for="help_for_natport">
                      <?=gettext("Enter the source port for the outbound NAT mapping.");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Static-port:");?></td>
                  <td>
                    <input name="staticnatport" type="checkbox" <?=!empty($pconfig['staticnatport']) ? " checked=\"checked\"" : "";?> >
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_nosync" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a>  <?=gettext("No XMLRPC Sync"); ?></td>
                  <td>
                    <input type="checkbox" value="yes" name="nosync" <?=!empty($pconfig['nosync']) ? "checked=\"checked\"" :"";?> />
                    <div class="hidden" for="help_for_nosync">
                      <?=gettext("Hint: This prevents the rule on Master from automatically syncing to other CARP members. This does NOT prevent the rule from being overwritten on Slave.");?>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td><a id="help_for_descr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td>
                  <td>
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
                    <div class="hidden" for="help_for_descr">
                      <?=gettext("You may enter a description here " ."for your reference (not parsed)."); ?>
                    </div>
                </tr>
<?php
                $has_created_time = (isset($a_out[$id]['created']) && is_array($a_out[$id]['created']));
                $has_updated_time = (isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']));
                if ($has_created_time || $has_updated_time):
?>
                <tr>
                  <td colspan="2">&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><?=gettext("Rule Information");?></td>
                </tr>
<?php
                  if ($has_created_time):
?>
                <tr>
                  <td><?=gettext("Created");?></td>
                  <td>
                    <?= date(gettext("n/j/y H:i:s"), $a_out[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['created']['username'] ?></strong>
                  </td>
                </tr>
<?php
                  endif;
                  if ($has_updated_time):
?>
                <tr>
                  <td><?=gettext("Updated");?></td>
                  <td>
                    <?= date(gettext("n/j/y H:i:s"), $a_out[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['updated']['username'] ?></strong>
                  </td>
                </tr>
<?php
                  endif;
                endif;
?>
                <tr>
                  <td>&nbsp;</td>
                  <td>
                    <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
                    <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_nat_out.php');?>'" />
<?php
727
                    if (isset($id)):
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
?>
                    <input name="id" type="hidden" value="<?=$id;?>" />
<?php
                    endif;
?>
                    <input name="after" type="hidden" value="<?=isset($after) ? $after : "";?>" />
                  </td>
                </tr>
              </table>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
743
<?php include("foot.inc"); ?>