net/wireguard: make listen port optional, reformat config and header style

This commit is contained in:
Franco Fichtner
2021-03-31 11:41:13 +02:00
parent cd055ae707
commit a4fab385be
4 changed files with 27 additions and 29 deletions
@@ -1,31 +1,29 @@
<?php
/**
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
/*
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
* All rights reserved.
*
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 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.
*
* 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.
* 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.
*/
namespace OPNsense\Wireguard\Api;
@@ -33,7 +33,7 @@
<id>server.port</id>
<label>Listen Port</label>
<type>text</type>
<help>Set port for this instance to listen on.</help>
<help>Optionally set a fixed port for this instance to listen on. The standard port range starts at 51820.</help>
</field>
<field>
<id>server.mtu</id>
@@ -28,8 +28,7 @@
<Required>N</Required>
</privkey>
<port type="PortField">
<default>51820</default>
<Required>Y</Required>
<Required>N</Required>
</port>
<mtu type="IntegerField">
<MinimumValue>1</MinimumValue>
@@ -1,19 +1,20 @@
{% if helpers.exists('OPNsense.wireguard.general.enabled') and OPNsense.wireguard.general.enabled == '1' %}
{% if helpers.exists('OPNsense.wireguard.server.servers.server') %}
{% for server_list in helpers.toList('OPNsense.wireguard.server.servers.server') %}
{% if TARGET_FILTERS['OPNsense.wireguard.server.servers.server.' ~ loop.index0] or TARGET_FILTERS['OPNsense.wireguard.server.servers.server'] %}
{% if server_list.enabled == '1' %}
[Interface]
PrivateKey = {{ server_list.privkey }}
Address = {{ server_list.tunneladdress }}
{% if server_list.port|default('') != '' %}
ListenPort = {{ server_list.port }}
{% endif %}
{% if server_list.dns|default('') != '' %}
DNS = {{ server_list.dns }}
{% endif %}
{% if server_list.mtu|default('') != '' %}
MTU = {{ server_list.mtu }}
{% endif %}
ListenPort = {{ server_list.port }}
PrivateKey = {{ server_list.privkey }}
{% if server_list.disableroutes == '1' %}
Table = off
{% endif %}
@@ -25,6 +26,7 @@ PostDown = route {{- ' -6' if ':' in server_list.gateway }} del {{ server_list.g
{% for peerlist in server_list.peers.split(",") %}
{% set peerlist2_data = helpers.getUUID(peerlist) %}
{% if peerlist2_data != {} and peerlist2_data.enabled == '1' %}
[Peer]
PublicKey = {{ peerlist2_data.pubkey }}
{% if peerlist2_data.psk|default('') != '' %}
@@ -44,5 +46,4 @@ PersistentKeepalive = {{ peerlist2_data.keepalive }}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}