Skip to content

Commit 9e38137

Browse files
committed
Removed DNS as a required field from peer settings
1 parent 210f5ea commit 9e38137

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

src/dashboard.py

+52-16
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ def add_peer_bulk(config_name):
10971097
if not amount.isdigit() or int(amount) < 1:
10981098
return "Amount must be integer larger than 0"
10991099
amount = int(amount)
1100-
if not check_DNS(dns_addresses):
1100+
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
11011101
return "DNS formate is incorrect. Example: 1.1.1.1"
11021102
if not check_Allowed_IPs(endpoint_allowed_ip):
11031103
return "Endpoint Allowed IPs format is incorrect."
@@ -1160,7 +1160,7 @@ def add_peer(config_name):
11601160
enable_preshared_key = data["enable_preshared_key"]
11611161
preshared_key = data['preshared_key']
11621162
keys = get_conf_peer_key(config_name)
1163-
if len(public_key) == 0 or len(dns_addresses) == 0 or len(allowed_ips) == 0 or len(endpoint_allowed_ip) == 0:
1163+
if len(public_key) == 0 or len(allowed_ips) == 0 or len(endpoint_allowed_ip) == 0:
11641164
return "Please fill in all required box."
11651165
if not isinstance(keys, list):
11661166
return config_name + " is not running."
@@ -1171,7 +1171,7 @@ def add_peer(config_name):
11711171
.fetchone()
11721172
if check_dup_ip[0] != 0:
11731173
return "Allowed IP already taken by another peer."
1174-
if not check_DNS(dns_addresses):
1174+
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
11751175
return "DNS formate is incorrect. Example: 1.1.1.1"
11761176
if not check_Allowed_IPs(endpoint_allowed_ip):
11771177
return "Endpoint Allowed IPs format is incorrect."
@@ -1263,7 +1263,7 @@ def save_peer_setting(config_name):
12631263
check_ip = check_repeat_allowed_ip(id, allowed_ip, config_name)
12641264
if not check_IP_with_range(endpoint_allowed_ip):
12651265
return jsonify({"status": "failed", "msg": "Endpoint Allowed IPs format is incorrect."})
1266-
if not check_DNS(dns_addresses):
1266+
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
12671267
return jsonify({"status": "failed", "msg": "DNS format is incorrect."})
12681268
if len(data['MTU']) == 0 or not data['MTU'].isdigit():
12691269
return jsonify({"status": "failed", "msg": "MTU format is not correct."})
@@ -1422,12 +1422,30 @@ def download_all(config_name):
14221422
filename = filename + "_" + config_name
14231423
psk = ""
14241424
if preshared_key != "":
1425-
psk = "\nPresharedKey = " + preshared_key
1426-
1427-
return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
1428-
dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
1429-
public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
1430-
endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
1425+
psk = "PresharedKey = " + preshared_key
1426+
1427+
return_data = f'''[Interface]
1428+
PrivateKey = {private_key}
1429+
Address = {allowed_ip}
1430+
MTU = {str(mtu_value)}
1431+
1432+
'''
1433+
if len(dns_addresses) > 0:
1434+
return_data += f'DNS = {dns_addresses}'
1435+
1436+
return_data += f'''
1437+
[Peer]
1438+
PublicKey = {public_key}
1439+
AllowedIPs = {endpoint_allowed_ip}
1440+
Endpoint = {endpoint}
1441+
PersistentKeepalive = {str(keepalive)}
1442+
{psk}
1443+
'''
1444+
1445+
# return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
1446+
# dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
1447+
# public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
1448+
# endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
14311449
data.append({"filename": f"{filename}.conf", "content": return_data})
14321450
return jsonify({"status": True, "peers": data, "filename": f"{config_name}.zip"})
14331451

@@ -1475,12 +1493,30 @@ def download(config_name):
14751493
filename = filename + "_" + config_name
14761494
psk = ""
14771495
if preshared_key != "":
1478-
psk = "\nPresharedKey = " + preshared_key
1479-
1480-
return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
1481-
dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
1482-
public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
1483-
endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
1496+
psk = "PresharedKey = " + preshared_key
1497+
1498+
return_data = f'''[Interface]
1499+
PrivateKey = {private_key}
1500+
Address = {allowed_ip}
1501+
MTU = {str(mtu_value)}
1502+
1503+
'''
1504+
if len(dns_addresses) > 0:
1505+
return_data += f'DNS = {dns_addresses}'
1506+
1507+
return_data += f'''
1508+
[Peer]
1509+
PublicKey = {public_key}
1510+
AllowedIPs = {endpoint_allowed_ip}
1511+
Endpoint = {endpoint}
1512+
PersistentKeepalive = {str(keepalive)}
1513+
{psk}
1514+
'''
1515+
1516+
# return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
1517+
# dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
1518+
# public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
1519+
# endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
14841520

14851521
return jsonify({"status": True, "filename": f"{filename}.conf", "content": return_data})
14861522
return jsonify({"status": False, "filename": "", "content": ""})

src/static/js/configuration.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
let $enable_preshare_key = $("#enable_preshare_key");
156156
let data_list = [$new_add_DNS, $new_add_endpoint_allowed_ip,$new_add_MTU, $new_add_keep_alive];
157157
if ($new_add_amount.val() > 0 && !$new_add_amount.hasClass("is-invalid")){
158-
if ($new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
158+
if ($new_add_endpoint_allowed_ip.val() !== ""){
159159
let conf = $add_peer.getAttribute('conf_id');
160160
let keys = [];
161161
for (let i = 0; i < $new_add_amount.val(); i++) {
@@ -633,7 +633,7 @@ $add_peer.addEventListener("click",function(){
633633
let $enable_preshare_key = $("#enable_preshare_key");
634634
$add_peer.setAttribute("disabled","disabled");
635635
$add_peer.innerHTML = "Adding...";
636-
if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
636+
if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
637637
let conf = $add_peer.getAttribute('conf_id');
638638
let data_list = [$private_key, $allowed_ips, $new_add_name, $new_add_DNS, $new_add_endpoint_allowed_ip,$new_add_MTU, $new_add_keep_alive];
639639
data_list.forEach((ele) => ele.attr("disabled", "disabled"));
@@ -924,7 +924,7 @@ $("#save_peer_setting").on("click",function (){
924924
let $peer_mtu = $("#peer_mtu");
925925
let $peer_keep_alive = $("#peer_keep_alive");
926926

927-
if ($peer_DNS_textbox.val() !== "" &&
927+
if (
928928
$peer_allowed_ip_textbox.val() !== "" && $peer_endpoint_allowed_ips.val() !== ""){
929929
let peer_id = $(this).attr("peer_id");
930930
let conf_id = $(this).attr("conf_id");

src/templates/configuration.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h5 class="modal-title" id="staticBackdropLabel">Add New Peer</h5>
192192
</div>
193193
<div class="col-sm-6">
194194
<div class="form-group">
195-
<label for="new_add_DNS">DNS <code>(Required)</code></label>
195+
<label for="new_add_DNS">DNS</label>
196196
<input type="text" class="form-control" id="new_add_DNS" value="{{ DNS }}">
197197
</div>
198198
</div>
@@ -297,7 +297,7 @@ <h5 class="modal-title peer_name"></h5>
297297
</div>
298298
<div class="col-sm-6">
299299
<div class="mb-3">
300-
<label for="peer_DNS_textbox" class="form-label">DNS <code>(Required)</code></label>
300+
<label for="peer_DNS_textbox" class="form-label">DNS</label>
301301
<input type="text" class="form-control" id="peer_DNS_textbox">
302302
</div>
303303
</div>
@@ -410,8 +410,8 @@ <h5 class="modal-title">QR Code</h5>
410410
{% include "tools.html" %}
411411
</body>
412412
{% include "footer.html" %}
413-
<script src="{{ url_for('static',filename='js/wireguard.min.js') }}"></script>
414-
<script src="{{ url_for('static',filename='js/configuration.min.js') }}"></script>
413+
<script src="{{ url_for('static',filename='js/wireguard.js') }}"></script>
414+
<script src="{{ url_for('static',filename='js/configuration.js') }}"></script>
415415
<script>
416416
/* global peers */
417417
let load_timeout;

src/templates/footer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
22
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
3-
<script src="{{ url_for('static',filename='js/tools.min.js') }}"></script>
3+
<script src="{{ url_for('static',filename='js/tools.js') }}"></script>

0 commit comments

Comments
 (0)