Skip to content

Commit 181b084

Browse files
authored
Merge pull request #313 from donaldzou/v4.0-fix2
Fixed #312, #311
2 parents cd73aef + b2a82dc commit 181b084

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
lines changed

src/dashboard.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from flask.json.provider import DefaultJSONProvider
3535

36-
DASHBOARD_VERSION = 'v4.0'
36+
DASHBOARD_VERSION = 'v4.0.1.1'
3737
CONFIGURATION_PATH = os.getenv('CONFIGURATION_PATH', '.')
3838
DB_PATH = os.path.join(CONFIGURATION_PATH, 'db')
3939
if not os.path.isdir(DB_PATH):
@@ -490,6 +490,7 @@ def __init__(self, name: str = None, data: dict = None):
490490
# Create tables in database
491491
self.__createDatabase()
492492
self.getPeersList()
493+
self.getRestrictedPeersList()
493494

494495
def __createDatabase(self):
495496
existingTables = sqldb.cursor().execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
@@ -697,6 +698,7 @@ def restrictPeers(self, listOfPublicKeys):
697698
sqldb.cursor().execute("UPDATE '%s_restrict_access' SET status = 'stopped' WHERE id = ?" %
698699
(self.Name,), (pf.id,))
699700
sqldb.cursor().execute("DELETE FROM '%s' WHERE id = ?" % self.Name, (pf.id,))
701+
sqldb.commit()
700702
numOfRestrictedPeers += 1
701703
except Exception as e:
702704
numOfFailedToRestrictPeers += 1
@@ -1115,6 +1117,8 @@ def __init__(self):
11151117
self.__createAPIKeyTable()
11161118
self.DashboardAPIKeys = self.__getAPIKeys()
11171119
self.APIAccessed = False
1120+
self.SetConfig("Server", "version", DASHBOARD_VERSION)
1121+
11181122

11191123
def __createAPIKeyTable(self):
11201124
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
13441348
for i in add:
13451349
a, c = i.split('/')
13461350
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+
13471359
for i in address:
13481360
addressSplit, cidr = i.split('/')
13491361
existedAddress.append(ipaddress.ip_address(addressSplit.replace(" ", "")))
@@ -1419,6 +1431,7 @@ def auth_req():
14191431
and f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}" != request.path)
14201432
and "validateAuthentication" not in request.path and "authenticate" not in request.path
14211433
and "getDashboardConfiguration" not in request.path and "getDashboardTheme" not in request.path
1434+
and "getDashboardVersion" not in request.path
14221435
and "sharePeer/get" not in request.path
14231436
and "isTotpEnabled" not in request.path
14241437
):
@@ -1751,10 +1764,13 @@ def API_addPeers(configName):
17511764
return ResponseObject(False, "Please fill in all required box.")
17521765
if not config.getStatus():
17531766
config.toggleConfiguration()
1767+
1768+
availableIps = _getWireguardConfigurationAvailableIP(configName)
1769+
17541770
if bulkAdd:
17551771
if bulkAddAmount < 1:
17561772
return ResponseObject(False, "Please specify amount of peers you want to add")
1757-
availableIps = _getWireguardConfigurationAvailableIP(configName)
1773+
17581774
if not availableIps[0]:
17591775
return ResponseObject(False, "No more available IP can assign")
17601776
if bulkAddAmount > len(availableIps[1]):
@@ -1788,6 +1804,11 @@ def API_addPeers(configName):
17881804
return ResponseObject(False, f"This peer already exist.")
17891805
name = data['name']
17901806
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+
17911812
config.addPeers([{"id": public_key, "allowed_ip": ''.join(allowed_ips)}])
17921813
# subprocess.check_output(
17931814
# f"wg set {config.Name} peer {public_key} allowed-ips {''.join(allowed_ips)}",
@@ -1857,6 +1878,10 @@ def API_getConfigurationInfo():
18571878
def API_getDashboardTheme():
18581879
return ResponseObject(data=DashboardConfig.GetConfig("Server", "dashboard_theme")[1])
18591880

1881+
@app.route(f'{APP_PREFIX}/api/getDashboardVersion')
1882+
def API_getDashboardVersion():
1883+
return ResponseObject(data=DashboardConfig.GetConfig("Server", "version")[1])
1884+
18601885

18611886
@app.route(f'{APP_PREFIX}/api/savePeerScheduleJob/', methods=["POST"])
18621887
def API_savePeerScheduleJob():
@@ -2102,6 +2127,7 @@ def backGroundThread():
21022127
c.getPeersLatestHandshake()
21032128
c.getPeersEndpoint()
21042129
c.getPeersList()
2130+
c.getRestrictedPeersList()
21052131
except Exception as e:
21062132
print(f"[WGDashboard] Background Thread #1 Error: {str(e)}", flush=True)
21072133
time.sleep(10)

src/static/app/src/components/configurationComponents/newPeersComponents/allowedIPsInput.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ export default {
3636
addAllowedIp(ip){
3737
if(this.store.checkCIDR(ip)){
3838
this.data.allowed_ips.push(ip);
39+
this.customAvailableIp = ''
3940
return true;
4041
}
42+
this.allowedIpFormatError = true;
43+
this.dashboardStore.newMessage('WGDashboard', 'Allowed IP is invalid', 'danger')
4144
return false;
4245
}
4346
},
@@ -80,10 +83,7 @@ export default {
8083
:disabled="bulk">
8184
<button class="btn btn-outline-success btn-sm rounded-end-3"
8285
:disabled="bulk || !this.customAvailableIp"
83-
@click="this.addAllowedIp(this.customAvailableIp)
84-
? this.customAvailableIp = '' :
85-
this.allowedIpFormatError = true;
86-
this.dashboardStore.newMessage('WGDashboard', 'Allowed IP is invalid', 'danger')"
86+
@click="this.addAllowedIp(this.customAvailableIp)"
8787
type="button" id="button-addon2">
8888
<i class="bi bi-plus-lg"></i>
8989
</button>

src/static/app/src/components/configurationComponents/peerList.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export default {
200200
})
201201
this.loading = false;
202202
if (this.configurationPeers.length > 0){
203-
const sent = this.configurationPeers.map(x => x.total_sent + x.cumu_sent).reduce((x,y) => x + y).toFixed(4);
203+
const sent = this.configurationPeers.map(x => x.total_sent + x.cumu_sent)
204+
.reduce((x,y) => x + y).toFixed(4);
204205
const receive = this.configurationPeers.map(x => x.total_receive + x.cumu_receive).reduce((x,y) => x + y).toFixed(4);
205206
if (
206207
this.historyDataSentDifference[this.historyDataSentDifference.length - 1] !== sent
@@ -259,13 +260,13 @@ export default {
259260
connectedPeers: this.configurationPeers.filter(x => x.status === "running").length,
260261
totalUsage: this.configurationPeers.length > 0 ?
261262
this.configurationPeers.filter(x => !x.restricted)
262-
.map(x => x.total_data + x.cumu_data).reduce((a, b) => a + b).toFixed(4) : 0,
263+
.map(x => x.total_data + x.cumu_data).reduce((a, b) => a + b, 0).toFixed(4) : 0,
263264
totalReceive: this.configurationPeers.length > 0 ?
264265
this.configurationPeers.filter(x => !x.restricted)
265-
.map(x => x.total_receive + x.cumu_receive).reduce((a, b) => a + b).toFixed(4) : 0,
266+
.map(x => x.total_receive + x.cumu_receive).reduce((a, b) => a + b, 0).toFixed(4) : 0,
266267
totalSent: this.configurationPeers.length > 0 ?
267268
this.configurationPeers.filter(x => !x.restricted)
268-
.map(x => x.total_sent + x.cumu_sent).reduce((a, b) => a + b).toFixed(4) : 0
269+
.map(x => x.total_sent + x.cumu_sent).reduce((a, b) => a + b, 0).toFixed(4) : 0
269270
}
270271
271272
return k

src/static/app/src/views/signin.vue

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ export default {
1111
const store = DashboardConfigurationStore()
1212
let theme = "dark"
1313
let totpEnabled = false;
14+
let version = undefined;
1415
if (!store.IsElectronApp){
15-
await fetchGet("/api/getDashboardTheme", {}, (res) => {
16-
theme = res.data
17-
});
18-
await fetchGet("/api/isTotpEnabled", {}, (res) => {
19-
totpEnabled = res.data
20-
});
16+
await Promise.all([
17+
fetchGet("/api/getDashboardTheme", {}, (res) => {
18+
theme = res.data
19+
}),
20+
fetchGet("/api/isTotpEnabled", {}, (res) => {
21+
totpEnabled = res.data
22+
}),
23+
fetchGet("/api/getDashboardVersion", {}, (res) => {
24+
version = res.data
25+
})
26+
]);
2127
}
2228
store.removeActiveCrossServer();
23-
return {store, theme, totpEnabled}
29+
return {store, theme, totpEnabled, version}
2430
},
2531
data(){
2632
return {
@@ -146,7 +152,7 @@ export default {
146152
</div>
147153
</div>
148154
<small class="text-muted pb-3 d-block w-100 text-center mt-3">
149-
WGDashboard v4.0 | Developed with ❤️ by
155+
WGDashboard {{ this.version }} | Developed with ❤️ by
150156
<a href="https://github.com/donaldzou" target="_blank"><strong>Donald Zou</strong></a>
151157
</small>
152158
<div class="messageCentre text-body position-absolute end-0 m-3">

0 commit comments

Comments
 (0)