Skip to content

Commit

Permalink
Removed DNS as a required field from peer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldzou committed May 3, 2024
1 parent 210f5ea commit 9e38137
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
68 changes: 52 additions & 16 deletions src/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ def add_peer_bulk(config_name):
if not amount.isdigit() or int(amount) < 1:
return "Amount must be integer larger than 0"
amount = int(amount)
if not check_DNS(dns_addresses):
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
return "DNS formate is incorrect. Example: 1.1.1.1"
if not check_Allowed_IPs(endpoint_allowed_ip):
return "Endpoint Allowed IPs format is incorrect."
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def add_peer(config_name):
enable_preshared_key = data["enable_preshared_key"]
preshared_key = data['preshared_key']
keys = get_conf_peer_key(config_name)
if len(public_key) == 0 or len(dns_addresses) == 0 or len(allowed_ips) == 0 or len(endpoint_allowed_ip) == 0:
if len(public_key) == 0 or len(allowed_ips) == 0 or len(endpoint_allowed_ip) == 0:
return "Please fill in all required box."
if not isinstance(keys, list):
return config_name + " is not running."
Expand All @@ -1171,7 +1171,7 @@ def add_peer(config_name):
.fetchone()
if check_dup_ip[0] != 0:
return "Allowed IP already taken by another peer."
if not check_DNS(dns_addresses):
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
return "DNS formate is incorrect. Example: 1.1.1.1"
if not check_Allowed_IPs(endpoint_allowed_ip):
return "Endpoint Allowed IPs format is incorrect."
Expand Down Expand Up @@ -1263,7 +1263,7 @@ def save_peer_setting(config_name):
check_ip = check_repeat_allowed_ip(id, allowed_ip, config_name)
if not check_IP_with_range(endpoint_allowed_ip):
return jsonify({"status": "failed", "msg": "Endpoint Allowed IPs format is incorrect."})
if not check_DNS(dns_addresses):
if len(dns_addresses) > 0 and not check_DNS(dns_addresses):
return jsonify({"status": "failed", "msg": "DNS format is incorrect."})
if len(data['MTU']) == 0 or not data['MTU'].isdigit():
return jsonify({"status": "failed", "msg": "MTU format is not correct."})
Expand Down Expand Up @@ -1422,12 +1422,30 @@ def download_all(config_name):
filename = filename + "_" + config_name
psk = ""
if preshared_key != "":
psk = "\nPresharedKey = " + preshared_key

return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
psk = "PresharedKey = " + preshared_key

return_data = f'''[Interface]
PrivateKey = {private_key}
Address = {allowed_ip}
MTU = {str(mtu_value)}
'''
if len(dns_addresses) > 0:
return_data += f'DNS = {dns_addresses}'

return_data += f'''
[Peer]
PublicKey = {public_key}
AllowedIPs = {endpoint_allowed_ip}
Endpoint = {endpoint}
PersistentKeepalive = {str(keepalive)}
{psk}
'''

# return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
# dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
# public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
# endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
data.append({"filename": f"{filename}.conf", "content": return_data})
return jsonify({"status": True, "peers": data, "filename": f"{config_name}.zip"})

Expand Down Expand Up @@ -1475,12 +1493,30 @@ def download(config_name):
filename = filename + "_" + config_name
psk = ""
if preshared_key != "":
psk = "\nPresharedKey = " + preshared_key

return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk
psk = "PresharedKey = " + preshared_key

return_data = f'''[Interface]
PrivateKey = {private_key}
Address = {allowed_ip}
MTU = {str(mtu_value)}
'''
if len(dns_addresses) > 0:
return_data += f'DNS = {dns_addresses}'

return_data += f'''
[Peer]
PublicKey = {public_key}
AllowedIPs = {endpoint_allowed_ip}
Endpoint = {endpoint}
PersistentKeepalive = {str(keepalive)}
{psk}
'''

# return_data = "[Interface]\nPrivateKey = " + private_key + "\nAddress = " + allowed_ip + "\nDNS = " + \
# dns_addresses + "\nMTU = " + str(mtu_value) + "\n\n[Peer]\nPublicKey = " + \
# public_key + "\nAllowedIPs = " + endpoint_allowed_ip + "\nEndpoint = " + \
# endpoint + "\nPersistentKeepalive = " + str(keepalive) + psk

return jsonify({"status": True, "filename": f"{filename}.conf", "content": return_data})
return jsonify({"status": False, "filename": "", "content": ""})
Expand Down
6 changes: 3 additions & 3 deletions src/static/js/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
let $enable_preshare_key = $("#enable_preshare_key");
let data_list = [$new_add_DNS, $new_add_endpoint_allowed_ip,$new_add_MTU, $new_add_keep_alive];
if ($new_add_amount.val() > 0 && !$new_add_amount.hasClass("is-invalid")){
if ($new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
if ($new_add_endpoint_allowed_ip.val() !== ""){
let conf = $add_peer.getAttribute('conf_id');
let keys = [];
for (let i = 0; i < $new_add_amount.val(); i++) {
Expand Down Expand Up @@ -633,7 +633,7 @@ $add_peer.addEventListener("click",function(){
let $enable_preshare_key = $("#enable_preshare_key");
$add_peer.setAttribute("disabled","disabled");
$add_peer.innerHTML = "Adding...";
if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
let conf = $add_peer.getAttribute('conf_id');
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];
data_list.forEach((ele) => ele.attr("disabled", "disabled"));
Expand Down Expand Up @@ -924,7 +924,7 @@ $("#save_peer_setting").on("click",function (){
let $peer_mtu = $("#peer_mtu");
let $peer_keep_alive = $("#peer_keep_alive");

if ($peer_DNS_textbox.val() !== "" &&
if (
$peer_allowed_ip_textbox.val() !== "" && $peer_endpoint_allowed_ips.val() !== ""){
let peer_id = $(this).attr("peer_id");
let conf_id = $(this).attr("conf_id");
Expand Down
8 changes: 4 additions & 4 deletions src/templates/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h5 class="modal-title" id="staticBackdropLabel">Add New Peer</h5>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="new_add_DNS">DNS <code>(Required)</code></label>
<label for="new_add_DNS">DNS</label>
<input type="text" class="form-control" id="new_add_DNS" value="{{ DNS }}">
</div>
</div>
Expand Down Expand Up @@ -297,7 +297,7 @@ <h5 class="modal-title peer_name"></h5>
</div>
<div class="col-sm-6">
<div class="mb-3">
<label for="peer_DNS_textbox" class="form-label">DNS <code>(Required)</code></label>
<label for="peer_DNS_textbox" class="form-label">DNS</label>
<input type="text" class="form-control" id="peer_DNS_textbox">
</div>
</div>
Expand Down Expand Up @@ -410,8 +410,8 @@ <h5 class="modal-title">QR Code</h5>
{% include "tools.html" %}
</body>
{% include "footer.html" %}
<script src="{{ url_for('static',filename='js/wireguard.min.js') }}"></script>
<script src="{{ url_for('static',filename='js/configuration.min.js') }}"></script>
<script src="{{ url_for('static',filename='js/wireguard.js') }}"></script>
<script src="{{ url_for('static',filename='js/configuration.js') }}"></script>
<script>
/* global peers */
let load_timeout;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/footer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
<script src="{{ url_for('static',filename='js/tools.min.js') }}"></script>
<script src="{{ url_for('static',filename='js/tools.js') }}"></script>

0 comments on commit 9e38137

Please sign in to comment.