vpn_openvpn_csc.php 36.7 KB
Newer Older
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4 5 6
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2008 Shrew Soft Inc.
    All rights reserved.
7

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

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

14 15 16
    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.
17

18 19 20 21 22 23 24 25 26 27
    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("openvpn.inc");
32
require_once("services.inc");
33
require_once("interfaces.inc");
34
require_once('pfsense-utils.inc');
Ad Schellevis's avatar
Ad Schellevis committed
35

36 37
// define all fields used in this form
$all_form_fields = "custom_options,disable,common_name,block,description
38 39 40 41 42
    ,tunnel_network,local_network,local_networkv6,remote_network
    ,remote_networkv6,gwredir,push_reset,dns_domain,dns_server1
    ,dns_server2,dns_server3,dns_server4,ntp_server1,ntp_server2
    ,netbios_enable,netbios_ntype,netbios_scope,wins_server1
    ,wins_server2,ovpn_servers";
43 44

// read config.
45
if (!isset($config['openvpn']['openvpn-csc'])) {
46 47
    $config['openvpn']['openvpn-csc'] = array();
}
Ad Schellevis's avatar
Ad Schellevis committed
48 49
$a_csc = &$config['openvpn']['openvpn-csc'];

50 51 52
$vpnid = 0;
$act=null;
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
53
    $pconfig = array();
54 55 56 57 58 59 60
    if (isset($_GET['dup']) && isset($a_csc[$_GET['dup']]))  {
        $configId = $_GET['dup'];
    } elseif (isset($_GET['id']) && isset($a_csc[$_GET['id']])) {
        $id = $_GET['id'];
        $configId = $id;
    }

61
    if (isset($_GET['act'])) {
62
        $act = $_GET['act'];
63 64
    }

65 66 67 68 69 70 71 72
    // 1 on 1 copy of config attributes
    foreach (explode(",", $all_form_fields) as $fieldname) {
        $fieldname = trim($fieldname);
        if (isset($a_csc[$configId][$fieldname])) {
            $pconfig[$fieldname] = $a_csc[$configId][$fieldname];
        } elseif (!isset($pconfig[$fieldname])) {
            // initialize element
            $pconfig[$fieldname] = null;
73 74
        }
    }
75 76
    // servers => array
    $pconfig['ovpn_servers'] = explode(',', $pconfig['ovpn_servers']);
77
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
78 79
    $input_errors = array();
    $pconfig = $_POST;
80 81 82
    if (isset($_POST['act'])) {
        $act = $_POST['act'];
    }
83
    if (isset($_POST['id']) && isset($a_csc[$_POST['id']])) {
84 85 86 87
        $id = $_POST['id'];
    }

    if ($act == "del") {
88 89 90 91
        if (isset($id)) {
            @unlink("/var/etc/openvpn-csc/{$a_csc[$id]['common_name']}");
            unset($a_csc[$id]);
            write_config();
92
        }
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        header("Location: vpn_openvpn_csc.php");
        exit;
    } elseif ($act == "del_x") {
        if (!empty($pconfig['rule']) && is_array($pconfig['rule'])) {
            foreach ($pconfig['rule'] as $rulei) {
                if (isset($a_csc[$rulei])) {
                    @unlink("/var/etc/openvpn-csc/{$a_csc[$rulei]['common_name']}");
                    unset($a_csc[$rulei]);
                }
            }
            write_config();
        }
        header("Location: vpn_openvpn_csc.php");
        exit;
    } elseif ($act == "move"){
      // move selected items
      if (!isset($id)) {
          // if id not set/found, move to end
          $id = count($a_csc);
      }
      $a_csc = legacy_move_config_list_items($a_csc, $id,  $pconfig['rule']);
      write_config();
      header("Location: vpn_openvpn_csc.php");
      exit;
    } elseif ($act == "toggle") {
        if (isset($id)) {
            if (isset($a_csc[$id]['disable'])) {
                unset($a_csc[$id]['disable']);
            } else {
                $a_csc[$id]['disable'] = true;
            }
            write_config();
125
            openvpn_resync_csc();
126 127 128
        }
        header("Location: vpn_openvpn_csc.php");
        exit;
129
    } else {
130
        /* perform validations */
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        if ($result = openvpn_validate_cidr($pconfig['tunnel_network'], 'Tunnel network')) {
            $input_errors[] = $result;
        }
        if ($result = openvpn_validate_cidr($pconfig['local_network'], 'IPv4 Local Network', true, "ipv4")) {
            $input_errors[] = $result;
        }
        if ($result = openvpn_validate_cidr($pconfig['local_networkv6'], 'IPv6 Local Network', true, "ipv6")) {
            $input_errors[] = $result;
        }
        if ($result = openvpn_validate_cidr($pconfig['remote_network'], 'IPv4 Remote Network', true, "ipv4")) {
            $input_errors[] = $result;
        }
        if ($result = openvpn_validate_cidr($pconfig['remote_networkv6'], 'IPv6 Remote Network', true, "ipv6")) {
            $input_errors[] = $result;
        }

        if (!empty($pconfig['dns_server_enable'])) {
            if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1']))) {
                $input_errors[] = gettext("The field 'DNS Server #1' must contain a valid IP address");
            }
            if (!empty($pconfig['dns_server2']) && !is_ipaddr(trim($pconfig['dns_server2']))) {
                $input_errors[] = gettext("The field 'DNS Server #2' must contain a valid IP address");
            }
            if (!empty($pconfig['dns_server3']) && !is_ipaddr(trim($pconfig['dns_server3']))) {
                $input_errors[] = gettext("The field 'DNS Server #3' must contain a valid IP address");
            }
            if (!empty($pconfig['dns_server4']) && !is_ipaddr(trim($pconfig['dns_server4']))) {
                $input_errors[] = gettext("The field 'DNS Server #4' must contain a valid IP address");
            }
        }

        if (!empty($pconfig['ntp_server_enable'])) {
            if (!empty($pconfig['ntp_server1']) && !is_ipaddr(trim($pconfig['ntp_server1']))) {
                $input_errors[] = gettext("The field 'NTP Server #1' must contain a valid IP address");
            }
            if (!empty($pconfig['ntp_server2']) && !is_ipaddr(trim($pconfig['ntp_server2']))) {
                $input_errors[] = gettext("The field 'NTP Server #2' must contain a valid IP address");
            }
            if (!empty($pconfig['ntp_server3']) && !is_ipaddr(trim($pconfig['ntp_server3']))) {
                $input_errors[] = gettext("The field 'NTP Server #3' must contain a valid IP address");
            }
            if (!empty($pconfig['ntp_server4']) && !is_ipaddr(trim($pconfig['ntp_server4']))) {
                $input_errors[] = gettext("The field 'NTP Server #4' must contain a valid IP address");
            }
        }

        if (!empty($pconfig['netbios_enable'])) {
            if ($pconfig['wins_server_enable']) {
                if (!empty($pconfig['wins_server1']) && !is_ipaddr(trim($pconfig['wins_server1']))) {
                    $input_errors[] = gettext("The field 'WINS Server #1' must contain a valid IP address");
                }
                if (!empty($pconfig['wins_server2']) && !is_ipaddr(trim($pconfig['wins_server2']))) {
                    $input_errors[] = gettext("The field 'WINS Server #2' must contain a valid IP address");
                }
            }
        }

        $reqdfields[] = 'common_name';
        $reqdfieldsn[] = 'Common name';

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

        if (count($input_errors) == 0) {
            $csc = array();
195
            // 1 on 1 copy of config attributes
196
            foreach (explode(",", $all_form_fields) as $fieldname) {
197
                $fieldname = trim($fieldname);
198
                if (!empty($pconfig[$fieldname])) {
199 200 201 202 203
                    if (is_array($pconfig[$fieldname])) {
                        $csc[$fieldname] = implode(',', $pconfig[$fieldname]);
                    } else {
                        $csc[$fieldname] = $pconfig[$fieldname];
                    }
204 205 206
                }
            }

207
            // handle fields with some kind of logic
208 209 210 211
            if (!empty($pconfig['disable']) && $pconfig['disable'] == "yes") {
                $csc['disable'] = true;
            }

212
            if (isset($id)) {
213 214 215 216 217 218 219
                $old_csc_cn = $a_csc[$id]['common_name'];
                $a_csc[$id] = $csc;
            } else {
                $a_csc[] = $csc;
            }

            if (!empty($old_csc_cn)) {
220
                @unlink('/var/etc/openvpn-csc/' . basename($old_csc_cn));
221
            }
222
            write_config();
223
            openvpn_resync_csc();
224

225 226
            header("Location: vpn_openvpn_csc.php");
            exit;
227 228
        }
    }
229
}
Ad Schellevis's avatar
Ad Schellevis committed
230

231 232
// escape form output before processing
legacy_html_escape_form_data($pconfig);
Ad Schellevis's avatar
Ad Schellevis committed
233 234 235 236

include("head.inc");
?>

237
<body>
238

Ad Schellevis's avatar
Ad Schellevis committed
239 240
<script type="text/javascript">
//<![CDATA[
241
$( document ).ready(function() {
242 243
  // link delete buttons
  $(".act_delete").click(function(){
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    var id = $(this).data("id");
    if (id != 'x') {
      BootstrapDialog.show({
          type:BootstrapDialog.TYPE_DANGER,
          title: "<?= gettext("OpenVPN");?>",
          message: "<?= gettext("Do you really want to delete this csc?"); ?>",
          buttons: [{
                  label: "<?= gettext("No");?>",
                  action: function(dialogRef) {
                      dialogRef.close();
                  }}, {
                    label: "<?= gettext("Yes");?>",
                    action: function(dialogRef) {
                      $.post(window.location, {act: 'del', id:id}, function(data) {
                            location.reload();
                      });
                      dialogRef.close();
                  }
              }]
      });
    } else {
      // delete selected
      BootstrapDialog.show({
267
        type:BootstrapDialog.TYPE_DANGER,
268 269
        title: "<?=gettext("OpenVPN");?>",
        message: "<?=gettext("Do you really want to delete the selected csc's?");?>",
270
        buttons: [{
271 272
                  label: "<?= gettext("No");?>",
                  action: function(dialogRef) {
273
                    dialogRef.close();
274
                  }}, {
275 276
                  label: "<?= gettext("Yes");?>",
                  action: function(dialogRef) {
277 278 279
                    $("#id").val("");
                    $("#action").val("del_x");
                    $("#iform2").submit()
280
                }
281 282 283 284 285
              }]
      });
    }
  });
  // link toggle buttons
286 287
  $(".act_toggle").click(function(event){
      event.preventDefault();
288 289 290
      $.post(window.location, {act: 'toggle', id:$(this).data("id")}, function(data) {
          location.reload();
      });
291
  });
Ad Schellevis's avatar
Ad Schellevis committed
292

293
  // link move buttons
294 295
  $(".act_move").click(function(event){
    event.preventDefault();
296 297 298 299
    $("#id").val($(this).data("id"));
    $("#action").val("move");
    $("#iform2").submit();
  });
Ad Schellevis's avatar
Ad Schellevis committed
300

301 302 303 304 305 306 307 308
  // checkboxes
  $("#dns_domain_enable").change(function(){
      if ($("#dns_domain_enable").is(":checked")) {
          $("#dns_domain_data").show();
      } else {
          $("#dns_domain_data").hide();
      }
  });
Ad Schellevis's avatar
Ad Schellevis committed
309

310 311 312 313 314 315 316
  $("#dns_server_enable").change(function(){
      if ($("#dns_server_enable").is(":checked")) {
          $("#dns_server_data").show();
      } else {
          $("#dns_server_data").hide();
      }
  });
Ad Schellevis's avatar
Ad Schellevis committed
317

318 319 320 321 322 323 324
  $("#wins_server_enable").change(function(){
      if ($("#wins_server_enable").is(":checked")) {
          $("#wins_server_data").show();
      } else {
          $("#wins_server_data").hide();
      }
  });
Ad Schellevis's avatar
Ad Schellevis committed
325

326 327 328 329 330 331 332
  $("#ntp_server_enable").change(function(){
      if ($("#ntp_server_enable").is(":checked")) {
          $("#ntp_server_data").show();
      } else {
          $("#ntp_server_data").hide();
      }
  });
Ad Schellevis's avatar
Ad Schellevis committed
333

334 335 336 337 338 339 340 341 342
  $("#netbios_enable").change(function(){
      if ($("#netbios_enable").is(":checked")) {
          $("#netbios_data").show();
          $("#wins_opts").show();
      } else {
          $("#netbios_data").hide();
          $("#wins_opts").hide();
      }
  });
Ad Schellevis's avatar
Ad Schellevis committed
343 344


345 346 347 348 349 350
  // init form (old stuff)
  if (document.iform != undefined) {
    $("#dns_domain_enable").change();
    $("#dns_server_enable").change();
    $("#wins_server_enable").change();
    $("#ntp_server_enable").change();
351
    $("#netbios_enable").change();
352
  }
353 354
  // watch scroll position and set to last known on page load
  watchScrollPosition();
355
});
Ad Schellevis's avatar
Ad Schellevis committed
356 357
//]]>
</script>
358 359

<?
360 361 362 363
if ($act!="new" && $act!="edit") {
    $main_buttons = array(
        array('href'=>'vpn_openvpn_csc.php?act=new', 'label'=>gettext("add csc")),
    );
364
}
Ad Schellevis's avatar
Ad Schellevis committed
365
?>
366 367

<?php include("fbegin.inc"); ?>
368 369 370 371 372 373 374 375 376 377 378 379 380 381
  <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);
        }
        if (isset($savemsg)) {
            print_info_box($savemsg);
        }?>
        <section class="col-xs-12">
          <div class="tab-content content-box col-xs-12">
<?php
          if ($act=="new" || $act=="edit") :?>
382
              <form method="post" name="iform" id="iform">
383 384 385
               <div class="table-responsive">
                <table class="table table-striped">
                  <tr>
386 387
                    <td><?=gettext("General information"); ?></td>
                    <td align="right">
388
                      <small><?=gettext("full help"); ?> </small>
Ad Schellevis's avatar
Ad Schellevis committed
389
                      <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i>
390 391 392 393 394 395 396 397 398 399 400 401
                    </td>
                  </tr>
                  <tr>
                    <td width="22%"><a id="help_for_disable" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disabled"); ?></td>
                    <td width="78%">
                      <input name="disable" type="checkbox" value="yes" <?= !empty($pconfig['disable']) ? "checked=\"checked\"" : "";?> />
                      <div class="hidden" for="help_for_disable">
                        <?=gettext("Set this option to disable this client-specific override without removing it from the list"); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
                    <td><a id="help_for_servers" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Servers"); ?></td>
                    <td>
                      <select name="ovpn_servers[]" class="selectpicker" multiple="multiple" data-size="5" data-live-search="true">
<?php
                      foreach (openvpn_get_remote_access_servers() as $ra_server_vpnid => $ra_server):?>
                        <option value="<?=$ra_server_vpnid;?>" <?=in_array($ra_server_vpnid, $pconfig['ovpn_servers']) ?  "selected=\"selected\"": "";?>>
                           <?=!empty($ra_server['description']) ? $ra_server['description'] : ""?> ( <?=$ra_server['local_port'];?> / <?=$ra_server['protocol'];?>)
                        </option>
<?php
                      endforeach;?>
                      </select>
                      <div class="hidden" for="help_for_servers">
                        <?=gettext("Select the OpenVPN servers where this override applies to, leave empty for all"); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td><a id="help_for_common_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Common name"); ?></td>
                    <td>
421 422 423 424 425 426 427
                      <input name="common_name" type="text" value="<?=$pconfig['common_name'];?>" />
                      <div class="hidden" for="help_for_common_name">
                        <?=gettext("Enter the client's X.509 common name here"); ?>.
                      </div>
                    </td>
                  </tr>
                  <tr>
428 429
                    <td><a id="help_for_description" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td>
                    <td>
430 431 432 433 434 435 436
                      <input name="description" type="text" value="<?=$pconfig['description'];?>" />
                      <div class="hidden" for="help_for_description">
                        <?=gettext("You may enter a description here for your reference (not parsed)"); ?>.
                      </div>
                    </td>
                  </tr>
                  <tr>
437 438
                    <td><a id="help_for_block" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Connection blocking"); ?></td>
                    <td>
439 440 441 442
                      <input name="block" type="checkbox" value="yes" <?= !empty($pconfig['block']) ? "checked=\"checked\"" : "";?> />
                      <div class="hidden" for="help_for_block">
                          <?=gettext("Block this client connection based on its common name"); ?>.<br/>
                          <?=gettext("Don't use this option to permanently disable a " .
443 444
                                                     "client due to a compromised key or password. " .
                                                     "Use a CRL (certificate revocation list) instead"); ?>.
445 446 447 448 449 450 451 452 453 454
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" height="12"></td>
                  </tr>
                  <tr>
                    <td colspan="2" ><?=gettext("Tunnel Settings"); ?></td>
                  </tr>
                  <tr>
455 456
                    <td><a id="help_for_tunnel_network" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Tunnel Network"); ?></td>
                    <td>
457 458 459
                      <input name="tunnel_network" type="text" size="20" value="<?=$pconfig['tunnel_network'];?>" />
                      <div class="hidden" for="help_for_tunnel_network">
                        <?=gettext("This is the virtual network used for private " .
460 461 462 463 464 465
                                                "communications between this client and the " .
                                                "server expressed using CIDR (eg. 10.0.8.0/24). " .
                                                "The first network address is assumed to be the " .
                                                "server address and the second network address " .
                                                "will be assigned to the client virtual " .
                                                "interface"); ?>.
466 467 468 469
                      </div>
                    </td>
                  </tr>
                  <tr id="local_optsv4">
470 471
                    <td><a id="help_for_local_network" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPv4 Local Network/s"); ?></td>
                    <td>
472 473 474
                      <input name="local_network" type="text" size="40" value="<?=$pconfig['local_network'];?>" />
                      <div class="hidden" for="help_for_local_network">
                        <?=gettext("These are the IPv4 networks that will be accessible " .
475
                                                "from this particular client. Expressed as a comma-separated list of one or more CIDR ranges."); ?>
476
                      <br /><?=gettext("NOTE: You do not need to specify networks here if they have " .
477
                                            "already been defined on the main server configuration.");?>
478 479 480 481
                      </div>
                    </td>
                  </tr>
                  <tr id="local_optsv6">
482 483
                    <td><a id="help_for_local_networkv6" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPv6 Local Network/s"); ?></td>
                    <td>
484 485
                      <input name="local_networkv6" type="text" size="40" value="<?=$pconfig['local_networkv6'];?>" />
                      <div class="hidden" for="help_for_local_networkv6">
486 487 488 489
                                                    <?=gettext("These are the IPv6 networks that will be accessible " .
                                                    "from this particular client. Expressed as a comma-separated list of one or more IP/PREFIX networks."); ?><br />
                                                    <?=gettext("NOTE: You do not need to specify networks here if they have " .
                                                    "already been defined on the main server configuration.");?>
490 491 492 493
                      </div>
                    </td>
                  </tr>
                  <tr id="remote_optsv4">
494 495
                    <td><a id="help_for_remote_network" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPv4 Remote Network/s"); ?></td>
                    <td>
496 497 498
                      <input name="remote_network" type="text" size="40" value="<?=$pconfig['remote_network'];?>" />
                      <div class="hidden" for="help_for_remote_network">
                        <?=gettext("These are the IPv4 networks that will be routed " .
499 500 501 502 503
                                                "to this client specifically using iroute, so that a site-to-site " .
                                                "VPN can be established. " .
                                                "Expressed as a comma-separated list of one or more CIDR ranges. " .
                                                "You may leave this blank if there are no client-side networks to " .
                                                "be routed"); ?>.<br />
504
                        <?=gettext("NOTE: Remember to add these subnets to the " .
505
                                                "IPv4 Remote Networks list on the corresponding OpenVPN server settings.");?>
506 507 508 509
                      </div>
                    </td>
                  </tr>
                  <tr id="remote_optsv6">
510 511
                    <td><a id="help_for_remote_networkv6" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IPv6 Remote Network/s"); ?></td>
                    <td>
512 513 514
                      <input name="remote_networkv6" type="text" size="40" value="<?=$pconfig['remote_networkv6'];?>" />
                      <div class="hidden" for="help_for_remote_networkv6">
                        <?=gettext("These are the IPv6 networks that will be routed " .
515 516 517 518
                                                "to this client specifically using iroute, so that a site-to-site " .
                                                "VPN can be established. " .
                                                "Expressed as a comma-separated list of one or more IP/PREFIX networks. " .
                                                "You may leave this blank if there are no client-side networks to " .
519
                                                "be routed."); ?><br />
520
                        <?=gettext("NOTE: Remember to add these subnets to the " .
521
                                                "IPv6 Remote Networks list on the corresponding OpenVPN server settings.");?>
522 523 524 525
                      </div>
                    </td>
                  </tr>
                  <tr>
526 527
                    <td><a id="help_for_gwredir" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Redirect Gateway"); ?></td>
                    <td>
528 529 530 531 532 533 534 535 536 537 538 539 540
                      <input name="gwredir" type="checkbox" value="yes" <?= !empty($pconfig['gwredir']) ? "checked=\"checked\"" : "";?> />
                      <div class="hidden" for="help_for_gwredir">
                        <?=gettext("Force all client generated traffic through the tunnel"); ?>.
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" height="12"></td>
                  </tr>
                  <tr>
                    <td colspan="2"><?=gettext("Client Settings"); ?></td>
                  </tr>
                  <tr>
541 542
                    <td><a id="help_for_push_reset" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a>  <?=gettext("Server Definitions"); ?></td>
                    <td>
543 544 545 546 547 548 549
                      <input name="push_reset" type="checkbox" value="yes" <?= !empty($pconfig['push_reset']) ? "checked=\"checked\"" : "";?> />
                      <div class="hidden" for="help_for_push_reset">
                          <?=gettext("Prevent this client from receiving any server-defined client settings."); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
550 551
                    <td><a id="help_for_dns_domain" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Default Domain"); ?></td>
                    <td>
552
                      <input name="dns_domain_enable" type="checkbox" id="dns_domain_enable" value="yes" <?= !empty($pconfig['dns_domain']) ? "checked=\"checked\"" : "";?> />
553
                      <div id="dns_domain_data" style="display:none">
554 555 556 557 558 559 560 561
                        <input name="dns_domain" type="text" id="dns_domain" value="<?=$pconfig['dns_domain'];?>" />
                      </div>
                      <div class="hidden" for="help_for_dns_domain">
                        <?=gettext("Provide a default domain name to clients"); ?><br />
                      </div>
                    </td>
                  </tr>
                  <tr>
562 563
                    <td><a id="help_for_dns_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DNS Servers"); ?></td>
                    <td>
564
                      <input name="dns_server_enable" type="checkbox" id="dns_server_enable" value="yes" <?=!empty($pconfig['dns_server1']) || !empty($pconfig['dns_server2']) || !empty($pconfig['dns_server3']) || !empty($pconfig['dns_server4']) ? "checked=\"checked\"" : "" ;?> />
565
                      <div id="dns_server_data" style="display:none">
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
                        <?=gettext("Server #1:"); ?>&nbsp;
                        <input name="dns_server1" type="text" id="dns_server1" size="20" value="<?=htmlspecialchars($pconfig['dns_server1']);?>" />
                        <?=gettext("Server #2:"); ?>&nbsp;
                        <input name="dns_server2" type="text" id="dns_server2" size="20" value="<?=htmlspecialchars($pconfig['dns_server2']);?>" />
                        <?=gettext("Server #3:"); ?>&nbsp;
                        <input name="dns_server3" type="text" id="dns_server3" size="20" value="<?=htmlspecialchars($pconfig['dns_server3']);?>" />
                        <?=gettext("Server #4:"); ?>&nbsp;
                        <input name="dns_server4" type="text" id="dns_server4" size="20" value="<?=htmlspecialchars($pconfig['dns_server4']);?>" />
                      </div>
                      <div class="hidden" for="help_for_dns_server">
                        <?=gettext("Provide a DNS server list to clients"); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
581 582
                    <td><a id="help_for_ntp_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("NTP Servers"); ?></td>
                    <td>
583
                      <input name="ntp_server_enable" type="checkbox" id="ntp_server_enable" value="yes" <?=!empty($pconfig['ntp_server1']) || !empty($pconfig['ntp_server2']) ? "checked=\"checked\"" : "" ;?> />
584
                      <div id="ntp_server_data" style="display:none">
585 586 587 588 589 590 591 592 593 594 595
                        <?=gettext("Server #1:"); ?>&nbsp;
                        <input name="ntp_server1" type="text" id="ntp_server1" size="20" value="<?=$pconfig['ntp_server1'];?>" />
                        <?=gettext("Server #2:"); ?>&nbsp;
                        <input name="ntp_server2" type="text" id="ntp_server2" size="20" value="<?=$pconfig['ntp_server2'];?>" />
                      </div>
                      <div class="hidden" for="help_for_ntp_server">
                        <?=gettext("Provide a NTP server list to clients"); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
596 597
                    <td><a id="help_for_netbios_enable" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("NetBIOS Options"); ?></td>
                    <td>
598
                      <input name="netbios_enable" type="checkbox" id="netbios_enable" value="yes" <?=!empty($pconfig['netbios_enable']) ? "checked=\"checked\"" : "" ;?> />
599
                      <div class="hidden" for="help_for_netbios_enable">
600
                        <?=gettext("Enable NetBIOS over TCP/IP");?><br/>
601 602 603 604 605 606
                        <?=gettext("If this option is not set, all NetBIOS-over-TCP/IP options (including WINS) will be disabled"); ?>.
                      </div>

                      <div id="netbios_data">
                        <?=gettext("Node Type"); ?>:&nbsp;
                        <select name='netbios_ntype'>
607
<?php
608
                        foreach ($netbios_nodetypes as $type => $name) :
Ad Schellevis's avatar
Ad Schellevis committed
609
                            $selected = "";
610
                            if ($pconfig['netbios_ntype'] == $type) {
Ad Schellevis's avatar
Ad Schellevis committed
611
                                $selected = "selected=\"selected\"";
612 613 614 615 616 617 618
                            }?>
                          <option value="<?=$type;?>" <?=$selected;?>><?=$name;?></option>
<?php
                        endforeach; ?>
                        </select>
                        <div class="hidden" for="help_for_netbios_enable">
                          <?=gettext("Possible options: b-node (broadcasts), p-node " .
619 620
                                                    "(point-to-point name queries to a WINS server), " .
                                                    "m-node (broadcast then query name server), and " .
621
                                                    "h-node (query name server, then broadcast)."); ?>
622 623 624 625 626 627
                        </div>
                        Scope ID:&nbsp;
                        <input name="netbios_scope" type="text" id="netbios_scope" value="<?=$pconfig['netbios_scope'];?>" />
                        <div class="hidden" for="help_for_netbios_enable">
                          <?=gettext("A NetBIOS Scope  ID provides an extended naming " .
                                                    "service for  NetBIOS over TCP/IP. The NetBIOS " .
628 629
                                                    "scope ID isolates NetBIOS traffic on a single " .
                                                    "network to only those nodes with the same " .
630
                                                    "NetBIOS scope ID."); ?>
631 632 633 634 635
                        </div>
                      </div>
                    </td>
                  </tr>
                  <tr id="wins_opts">
636 637
                    <td><a id="help_for_wins_server" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("WINS Servers"); ?></td>
                    <td>
638
                      <input name="wins_server_enable" type="checkbox" id="wins_server_enable" value="yes"  <?=!empty($pconfig['wins_server1']) || !empty($pconfig['wins_server2']) ? "checked=\"checked\"" : "" ;?> />
639
                      <div id="wins_server_data" style="display:none">
640 641 642 643 644 645 646 647 648 649 650
                        <?=gettext("Server #1:"); ?>
                        <input name="wins_server1" type="text" id="wins_server1" size="20" value="<?=$pconfig['wins_server1'];?>" />
                        <?=gettext("Server #2:"); ?>
                        <input name="wins_server2" type="text" id="wins_server2" size="20" value="<?=$pconfig['wins_server2'];?>" />
                      </div>
                      <div class="hidden" for="help_for_wins_server">
                        <?=gettext("Provide a WINS server list to clients"); ?>
                      </div>
                    </td>
                  </tr>
                  <tr>
651 652
                    <td><a id="help_for_custom_options" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Advanced"); ?></td>
                    <td>
653 654 655 656 657 658 659 660
                      <textarea rows="6" cols="70" name="custom_options" id="custom_options"><?=$pconfig['custom_options'];?></textarea>
                      <div class="hidden" for="help_for_custom_options">
                        <?=gettext("Enter any additional options you would like to add for this client specific override, separated by a semicolon"); ?><br />
                        <?=gettext("EXAMPLE: push \"route 10.0.0.0 255.255.255.0\""); ?>;
                      </div>
                    </td>
                  </tr>
                  <tr>
661 662
                    <td valign="top">&nbsp;</td>
                    <td>
663 664 665
                      <input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
                      <input name="act" type="hidden" value="<?=$act;?>" />
<?php
666 667
                      if (isset($id)) :?>
                      <input name="id" type="hidden" value="<?=$id;?>" />
668 669 670 671 672 673 674 675 676
<?php
                      endif; ?>
                    </td>
                  </tr>
                </table>
               </div>
              </form>
<?php
              else :?>
677 678 679 680 681 682 683 684 685 686 687 688
              <form method="post" name="iform2" id="iform2">
                <input type="hidden" id="id" name="id" value="" />
                <input type="hidden" id="action" name="act" value="" />
                <div class="table-responsive">
                  <table class="table table-striped">
                    <tr>
                      <td></td>
                      <td><?=gettext("Common Name"); ?></td>
                      <td><?=gettext("Tunnel Network");?></td>
                      <td><?=gettext("Description"); ?></td>
                      <td></td>
                    </tr>
689
<?php
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
                    $i = 0;
                    foreach ($a_csc as $csc):?>
                    <tr>
                      <td>
                        <input type="checkbox" name="rule[]" value="<?=$i;?>"  />
                        &nbsp;
                        <a href="#" class="act_toggle" data-id="<?=$i;?>" data-toggle="tooltip" title="<?=(empty($csc['disable'])) ? gettext("disable") : gettext("enable");?>">
                          <span class="glyphicon glyphicon-play <?=(empty($csc['disable'])) ? "text-success" : "text-muted";?>"></span>
                        </a>
                      </td>
                      <td>
                          <?=htmlspecialchars($csc['common_name']);?>
                      </td>
                      <td>
                          <?=!empty($csc['tunnel_network']) ? htmlspecialchars($csc['tunnel_network']) : "";?>
                      </td>
                      <td>
                          <?=htmlspecialchars($csc['description']);?>
                      </td>
                      <td>
                        <a data-id="<?=$i;?>" data-toggle="tooltip" title="<?=gettext("move selected before this item");?>" class="act_move btn btn-default btn-xs">
                          <span class="glyphicon glyphicon-arrow-left"></span>
                        </a>
                        <a href="vpn_openvpn_csc.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
                        <a data-id="<?=$i;?>" title="<?=gettext("delete csc"); ?>" class="act_delete btn btn-default btn-xs"><span class="fa fa-trash text-muted"></span></a>
                        <a href="vpn_openvpn_csc.php?act=new&dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("clone rule");?>">
                          <span class="fa fa-clone text-muted"></span>
                        </a>
                      </td>
                    </tr>
720
<?php
721 722 723 724
                    $i++;
                    endforeach;?>
                    <tr>
                      <td colspan="4">
725
                        <?=gettext("Additional OpenVPN client specific overrides can be added here.");?>
726 727
                      </td>
                      <td>
Ad Schellevis's avatar
Ad Schellevis committed
728 729
                        <a data-id="<?=$i;?>" data-toggle="tooltip" title="<?=gettext("move selected items to end");?>" class="act_move btn btn-default btn-xs">
                          <span class="glyphicon glyphicon-arrow-down"></span>
730 731 732 733 734 735 736 737 738
                        </a>
                        <a data-id="x" title="<?=gettext("delete selected rules"); ?>" data-toggle="tooltip"  class="act_delete btn btn-default btn-xs">
                          <span class="fa fa-trash text-muted"></span>
                        </a>
                      </td>
                    </tr>
                  </table>
                </div>
              </form>
739 740
<?php
            endif; ?>
741

742 743 744 745 746
          </div>
        </section>
      </div>
    </div>
  </section>
747 748

<?php include("foot.inc"); ?>