@@ -1097,7 +1097,7 @@ def add_peer_bulk(config_name):
1097
1097
if not amount .isdigit () or int (amount ) < 1 :
1098
1098
return "Amount must be integer larger than 0"
1099
1099
amount = int (amount )
1100
- if not check_DNS (dns_addresses ):
1100
+ if len ( dns_addresses ) > 0 and not check_DNS (dns_addresses ):
1101
1101
return "DNS formate is incorrect. Example: 1.1.1.1"
1102
1102
if not check_Allowed_IPs (endpoint_allowed_ip ):
1103
1103
return "Endpoint Allowed IPs format is incorrect."
@@ -1160,7 +1160,7 @@ def add_peer(config_name):
1160
1160
enable_preshared_key = data ["enable_preshared_key" ]
1161
1161
preshared_key = data ['preshared_key' ]
1162
1162
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 :
1164
1164
return "Please fill in all required box."
1165
1165
if not isinstance (keys , list ):
1166
1166
return config_name + " is not running."
@@ -1171,7 +1171,7 @@ def add_peer(config_name):
1171
1171
.fetchone ()
1172
1172
if check_dup_ip [0 ] != 0 :
1173
1173
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 ):
1175
1175
return "DNS formate is incorrect. Example: 1.1.1.1"
1176
1176
if not check_Allowed_IPs (endpoint_allowed_ip ):
1177
1177
return "Endpoint Allowed IPs format is incorrect."
@@ -1263,7 +1263,7 @@ def save_peer_setting(config_name):
1263
1263
check_ip = check_repeat_allowed_ip (id , allowed_ip , config_name )
1264
1264
if not check_IP_with_range (endpoint_allowed_ip ):
1265
1265
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 ):
1267
1267
return jsonify ({"status" : "failed" , "msg" : "DNS format is incorrect." })
1268
1268
if len (data ['MTU' ]) == 0 or not data ['MTU' ].isdigit ():
1269
1269
return jsonify ({"status" : "failed" , "msg" : "MTU format is not correct." })
@@ -1422,12 +1422,30 @@ def download_all(config_name):
1422
1422
filename = filename + "_" + config_name
1423
1423
psk = ""
1424
1424
if preshared_key != "" :
1425
- psk = "\n PresharedKey = " + preshared_key
1426
-
1427
- return_data = "[Interface]\n PrivateKey = " + private_key + "\n Address = " + allowed_ip + "\n DNS = " + \
1428
- dns_addresses + "\n MTU = " + str (mtu_value ) + "\n \n [Peer]\n PublicKey = " + \
1429
- public_key + "\n AllowedIPs = " + endpoint_allowed_ip + "\n Endpoint = " + \
1430
- endpoint + "\n PersistentKeepalive = " + 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
1431
1449
data .append ({"filename" : f"{ filename } .conf" , "content" : return_data })
1432
1450
return jsonify ({"status" : True , "peers" : data , "filename" : f"{ config_name } .zip" })
1433
1451
@@ -1475,12 +1493,30 @@ def download(config_name):
1475
1493
filename = filename + "_" + config_name
1476
1494
psk = ""
1477
1495
if preshared_key != "" :
1478
- psk = "\n PresharedKey = " + preshared_key
1479
-
1480
- return_data = "[Interface]\n PrivateKey = " + private_key + "\n Address = " + allowed_ip + "\n DNS = " + \
1481
- dns_addresses + "\n MTU = " + str (mtu_value ) + "\n \n [Peer]\n PublicKey = " + \
1482
- public_key + "\n AllowedIPs = " + endpoint_allowed_ip + "\n Endpoint = " + \
1483
- endpoint + "\n PersistentKeepalive = " + 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
1484
1520
1485
1521
return jsonify ({"status" : True , "filename" : f"{ filename } .conf" , "content" : return_data })
1486
1522
return jsonify ({"status" : False , "filename" : "" , "content" : "" })
0 commit comments