|
33 | 33 |
|
34 | 34 | from flask.json.provider import DefaultJSONProvider
|
35 | 35 |
|
36 |
| -DASHBOARD_VERSION = 'v4.0' |
| 36 | +DASHBOARD_VERSION = 'v4.0.1.1' |
37 | 37 | CONFIGURATION_PATH = os.getenv('CONFIGURATION_PATH', '.')
|
38 | 38 | DB_PATH = os.path.join(CONFIGURATION_PATH, 'db')
|
39 | 39 | if not os.path.isdir(DB_PATH):
|
@@ -490,6 +490,7 @@ def __init__(self, name: str = None, data: dict = None):
|
490 | 490 | # Create tables in database
|
491 | 491 | self.__createDatabase()
|
492 | 492 | self.getPeersList()
|
| 493 | + self.getRestrictedPeersList() |
493 | 494 |
|
494 | 495 | def __createDatabase(self):
|
495 | 496 | existingTables = sqldb.cursor().execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
|
@@ -697,6 +698,7 @@ def restrictPeers(self, listOfPublicKeys):
|
697 | 698 | sqldb.cursor().execute("UPDATE '%s_restrict_access' SET status = 'stopped' WHERE id = ?" %
|
698 | 699 | (self.Name,), (pf.id,))
|
699 | 700 | sqldb.cursor().execute("DELETE FROM '%s' WHERE id = ?" % self.Name, (pf.id,))
|
| 701 | + sqldb.commit() |
700 | 702 | numOfRestrictedPeers += 1
|
701 | 703 | except Exception as e:
|
702 | 704 | numOfFailedToRestrictPeers += 1
|
@@ -1115,6 +1117,8 @@ def __init__(self):
|
1115 | 1117 | self.__createAPIKeyTable()
|
1116 | 1118 | self.DashboardAPIKeys = self.__getAPIKeys()
|
1117 | 1119 | self.APIAccessed = False
|
| 1120 | + self.SetConfig("Server", "version", DASHBOARD_VERSION) |
| 1121 | + |
1118 | 1122 |
|
1119 | 1123 | def __createAPIKeyTable(self):
|
1120 | 1124 | existingTable = sqldb.cursor().execute("SELECT name FROM sqlite_master WHERE type='table' AND name = 'DashboardAPIKeys'").fetchall()
|
@@ -1344,6 +1348,14 @@ def _getWireguardConfigurationAvailableIP(configName: str) -> tuple[bool, list[s
|
1344 | 1348 | for i in add:
|
1345 | 1349 | a, c = i.split('/')
|
1346 | 1350 | existedAddress.append(ipaddress.ip_address(a.replace(" ", "")))
|
| 1351 | + |
| 1352 | + for p in configuration.getRestrictedPeersList(): |
| 1353 | + if len(p.allowed_ip) > 0: |
| 1354 | + add = p.allowed_ip.split(',') |
| 1355 | + for i in add: |
| 1356 | + a, c = i.split('/') |
| 1357 | + existedAddress.append(ipaddress.ip_address(a.replace(" ", ""))) |
| 1358 | + |
1347 | 1359 | for i in address:
|
1348 | 1360 | addressSplit, cidr = i.split('/')
|
1349 | 1361 | existedAddress.append(ipaddress.ip_address(addressSplit.replace(" ", "")))
|
@@ -1419,6 +1431,7 @@ def auth_req():
|
1419 | 1431 | and f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}" != request.path)
|
1420 | 1432 | and "validateAuthentication" not in request.path and "authenticate" not in request.path
|
1421 | 1433 | and "getDashboardConfiguration" not in request.path and "getDashboardTheme" not in request.path
|
| 1434 | + and "getDashboardVersion" not in request.path |
1422 | 1435 | and "sharePeer/get" not in request.path
|
1423 | 1436 | and "isTotpEnabled" not in request.path
|
1424 | 1437 | ):
|
@@ -1751,10 +1764,13 @@ def API_addPeers(configName):
|
1751 | 1764 | return ResponseObject(False, "Please fill in all required box.")
|
1752 | 1765 | if not config.getStatus():
|
1753 | 1766 | config.toggleConfiguration()
|
| 1767 | + |
| 1768 | + availableIps = _getWireguardConfigurationAvailableIP(configName) |
| 1769 | + |
1754 | 1770 | if bulkAdd:
|
1755 | 1771 | if bulkAddAmount < 1:
|
1756 | 1772 | return ResponseObject(False, "Please specify amount of peers you want to add")
|
1757 |
| - availableIps = _getWireguardConfigurationAvailableIP(configName) |
| 1773 | + |
1758 | 1774 | if not availableIps[0]:
|
1759 | 1775 | return ResponseObject(False, "No more available IP can assign")
|
1760 | 1776 | if bulkAddAmount > len(availableIps[1]):
|
@@ -1788,6 +1804,11 @@ def API_addPeers(configName):
|
1788 | 1804 | return ResponseObject(False, f"This peer already exist.")
|
1789 | 1805 | name = data['name']
|
1790 | 1806 | private_key = data['private_key']
|
| 1807 | + |
| 1808 | + for i in allowed_ips: |
| 1809 | + if i not in availableIps[1]: |
| 1810 | + return ResponseObject(False, f"This IP is not available: {i}") |
| 1811 | + |
1791 | 1812 | config.addPeers([{"id": public_key, "allowed_ip": ''.join(allowed_ips)}])
|
1792 | 1813 | # subprocess.check_output(
|
1793 | 1814 | # f"wg set {config.Name} peer {public_key} allowed-ips {''.join(allowed_ips)}",
|
@@ -1857,6 +1878,10 @@ def API_getConfigurationInfo():
|
1857 | 1878 | def API_getDashboardTheme():
|
1858 | 1879 | return ResponseObject(data=DashboardConfig.GetConfig("Server", "dashboard_theme")[1])
|
1859 | 1880 |
|
| 1881 | +@app.route(f'{APP_PREFIX}/api/getDashboardVersion') |
| 1882 | +def API_getDashboardVersion(): |
| 1883 | + return ResponseObject(data=DashboardConfig.GetConfig("Server", "version")[1]) |
| 1884 | + |
1860 | 1885 |
|
1861 | 1886 | @app.route(f'{APP_PREFIX}/api/savePeerScheduleJob/', methods=["POST"])
|
1862 | 1887 | def API_savePeerScheduleJob():
|
@@ -2102,6 +2127,7 @@ def backGroundThread():
|
2102 | 2127 | c.getPeersLatestHandshake()
|
2103 | 2128 | c.getPeersEndpoint()
|
2104 | 2129 | c.getPeersList()
|
| 2130 | + c.getRestrictedPeersList() |
2105 | 2131 | except Exception as e:
|
2106 | 2132 | print(f"[WGDashboard] Background Thread #1 Error: {str(e)}", flush=True)
|
2107 | 2133 | time.sleep(10)
|
|
0 commit comments