1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 15:20:09 +01:00

Fixing some of the issue from users ;)

This commit is contained in:
Donald Zou 2024-04-26 00:03:42 +08:00
parent 914a0bf514
commit 57c2e89f00
11 changed files with 112 additions and 155 deletions

View File

@ -499,7 +499,7 @@ class DashboardConfig:
def __init__(self): def __init__(self):
self.__config = configparser.ConfigParser(strict=False) self.__config = configparser.ConfigParser(strict=False)
self.__config.read_file(open(DASHBOARD_CONF)) self.__config.read_file(open(DASHBOARD_CONF, "w+"))
self.hiddenAttribute = ["totp_key"] self.hiddenAttribute = ["totp_key"]
self.__default = { self.__default = {
"Account": { "Account": {
@ -938,7 +938,7 @@ def API_updatePeerSettings(configName):
return ResponseObject(False, f"Allowed IP already taken by another peer.") return ResponseObject(False, f"Allowed IP already taken by another peer.")
if not _checkIPWithRange(endpoint_allowed_ip): if not _checkIPWithRange(endpoint_allowed_ip):
return ResponseObject(False, f"Endpoint Allowed IPs format is incorrect.") return ResponseObject(False, f"Endpoint Allowed IPs format is incorrect.")
if not _checkDNS(dns_addresses): if len(dns_addresses) > 0 and _checkDNS(dns_addresses):
return ResponseObject(False, f"DNS format is incorrect.") return ResponseObject(False, f"DNS format is incorrect.")
if data['mtu'] < 0 or data['mtu'] > 1460: if data['mtu'] < 0 or data['mtu'] > 1460:
return ResponseObject(False, "MTU format is not correct.") return ResponseObject(False, "MTU format is not correct.")
@ -1016,17 +1016,21 @@ def API_downloadPeer(configName):
peerConfiguration = f'''[Interface] peerConfiguration = f'''[Interface]
PrivateKey = {peer.private_key} PrivateKey = {peer.private_key}
Address = {peer.allowed_ip} Address = {peer.allowed_ip}
DNS = {peer.DNS}
MTU = {str(peer.mtu)} MTU = {str(peer.mtu)}
'''
if len(peer.DNS) > 0:
peerConfiguration += f"DNS = {peer.DNS}\n"
peerConfiguration += f'''
[Peer] [Peer]
PublicKey = {configuration.PublicKey} PublicKey = {configuration.PublicKey}
AllowedIPs = {peer.endpoint_allowed_ip} AllowedIPs = {peer.endpoint_allowed_ip}
Endpoint = {DashboardConfig.GetConfig("Peers", "remote_endpoint")[1]}:{configuration.ListenPort} Endpoint = {DashboardConfig.GetConfig("Peers", "remote_endpoint")[1]}:{configuration.ListenPort}
PersistentKeepalive = {str(peer.keepalive)} PersistentKeepalive = {str(peer.keepalive)}
''' '''
if len(peer.preshared_key) > 0: if len(peer.preshared_key) > 0:
peerConfiguration += f"PresharedKey = {peer.preshared_key}" peerConfiguration += f"PresharedKey = {peer.preshared_key}\n"
return ResponseObject(data={ return ResponseObject(data={
"fileName": filename, "fileName": filename,
"file": peerConfiguration "file": peerConfiguration

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -22,19 +22,21 @@ export default {
}, },
methods:{ methods:{
checkDNS(){ checkDNS(){
let i = this.dns.split(',').map(x => x.replaceAll(' ', '')); if(this.dns){
for(let ip in i){ let i = this.dns.split(',').map(x => x.replaceAll(' ', ''));
if (!this.store.regexCheckIP(i[ip])){ for(let ip in i){
if (!this.error){ if (!this.store.regexCheckIP(i[ip])){
this.dashboardStore.newMessage("WGDashboard", "DNS is invalid", "danger"); if (!this.error){
this.dashboardStore.newMessage("WGDashboard", "DNS is invalid", "danger");
}
this.error = true;
this.data.DNS = "";
return;
} }
this.error = true;
this.data.DNS = "";
return;
} }
this.error = false;
this.data.DNS = this.dns;
} }
this.error = false;
this.data.DNS = this.dns;
} }
}, },
watch: { watch: {
@ -48,7 +50,7 @@ export default {
<template> <template>
<div> <div>
<label for="peer_DNS_textbox" class="form-label"> <label for="peer_DNS_textbox" class="form-label">
<small class="text-muted">DNS <code>(Required)</code></small> <small class="text-muted">DNS</small>
</label> </label>
<input type="text" class="form-control form-control-sm rounded-3" <input type="text" class="form-control form-control-sm rounded-3"
:class="{'is-invalid': this.error}" :class="{'is-invalid': this.error}"

View File

@ -23,7 +23,6 @@ export default {
PresharedKeyInput, EndpointAllowedIps, DnsInput, AllowedIPsInput, PrivatePublicKeyInput, NameInput}, PresharedKeyInput, EndpointAllowedIps, DnsInput, AllowedIPsInput, PrivatePublicKeyInput, NameInput},
data(){ data(){
return{ return{
data: { data: {
bulkAdd: false, bulkAdd: false,
bulkAddAmount: "", bulkAddAmount: "",
@ -64,7 +63,7 @@ export default {
} }
}else{ }else{
let requireFields = let requireFields =
["allowed_ip", "private_key", "public_key", "DNS", "endpoint_allowed_ip", "keepalive", "mtu"] ["allowed_ip", "private_key", "public_key", "endpoint_allowed_ip", "keepalive", "mtu"]
requireFields.forEach(x => { requireFields.forEach(x => {
if (this.data[x].length === 0) status = false; if (this.data[x].length === 0) status = false;
@ -89,43 +88,42 @@ export default {
</script> </script>
<template> <template>
<div class="modal fade" id="peerCreateModal" data-bs-backdrop="static"> <div class="container">
<div class="modal-dialog " style="max-width: 700px !important;"> <div class="mb-4 d-flex align-items-center gap-4">
<div class="modal-content rounded-3 border-0 shadow"> <RouterLink to="peers">
<div class="modal-header border-0 pb-0"> <h3 class="mb-0 text-body">
<h1 class="modal-title fs-5" id="staticBackdropLabel">Add Peer</h1> <i class="bi bi-chevron-left"></i>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </h3>
</RouterLink>
<h3 class="text-body mb-0">New Configuration</h3>
</div>
<div class="d-flex flex-column gap-2">
<BulkAdd :saving="saving" :data="this.data" :availableIp="this.availableIp"></BulkAdd>
<hr class="mb-0 mt-2">
<NameInput :saving="saving" :data="this.data" v-if="!this.data.bulkAdd"></NameInput>
<PrivatePublicKeyInput :saving="saving" :data="data" v-if="!this.data.bulkAdd"></PrivatePublicKeyInput>
<AllowedIPsInput :availableIp="this.availableIp" :saving="saving" :data="data" v-if="!this.data.bulkAdd"></AllowedIPsInput>
<EndpointAllowedIps :saving="saving" :data="data"></EndpointAllowedIps>
<DnsInput :saving="saving" :data="data"></DnsInput>
<hr class="mb-0 mt-2">
<div class="row">
<div class="col-sm" v-if="!this.data.bulkAdd">
<PresharedKeyInput :saving="saving" :data="data" :bulk="this.data.bulkAdd"></PresharedKeyInput>
</div> </div>
<div class="modal-body"> <div class="col-sm">
<div class="d-flex flex-column gap-2"> <MtuInput :saving="saving" :data="data"></MtuInput>
<BulkAdd :saving="saving" :data="this.data" :availableIp="this.availableIp"></BulkAdd>
<hr class="mb-0 mt-2">
<NameInput :saving="saving" :data="this.data" v-if="!this.data.bulkAdd"></NameInput>
<PrivatePublicKeyInput :saving="saving" :data="data" v-if="!this.data.bulkAdd"></PrivatePublicKeyInput>
<AllowedIPsInput :availableIp="this.availableIp" :saving="saving" :data="data" v-if="!this.data.bulkAdd"></AllowedIPsInput>
<DnsInput :saving="saving" :data="data"></DnsInput>
<EndpointAllowedIps :saving="saving" :data="data"></EndpointAllowedIps>
<hr class="mb-0 mt-2">
<div class="row">
<div class="col-sm" v-if="!this.data.bulkAdd">
<PresharedKeyInput :saving="saving" :data="data" :bulk="this.data.bulkAdd"></PresharedKeyInput>
</div>
<div class="col-sm">
<MtuInput :saving="saving" :data="data"></MtuInput>
</div>
<div class="col-sm">
<PersistentKeepAliveInput :saving="saving" :data="data"></PersistentKeepAliveInput>
</div>
</div>
<div class="d-flex mt-2">
<button class="ms-auto btn btn-dark btn-brand rounded-3 px-3 py-2 shadow"
:disabled="!this.allRequireFieldsFilled"
>
<i class="bi bi-plus-circle-fill me-2"></i>Add
</button>
</div>
</div>
</div> </div>
<div class="col-sm">
<PersistentKeepAliveInput :saving="saving" :data="data"></PersistentKeepAliveInput>
</div>
</div>
<div class="d-flex mt-2">
<button class="ms-auto btn btn-dark btn-brand rounded-3 px-3 py-2 shadow"
:disabled="!this.allRequireFieldsFilled"
>
<i class="bi bi-plus-circle-fill me-2"></i>Add
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -116,8 +116,19 @@ export default {
} }
} }
}, },
mounted() {
// console.log('mounted')
// this.loading = true;
// let id = this.$route.params.id;
// this.configurationInfo = [];
// this.configurationPeers = [];
// if (id){
// this.getPeers(id)
// this.setInterval();
// }
},
watch: { watch: {
'$route.params': { '$route': {
immediate: true, immediate: true,
handler(){ handler(){
clearInterval(this.interval) clearInterval(this.interval)
@ -446,10 +457,10 @@ export default {
<div class="mb-4"> <div class="mb-4">
<div class="d-flex align-items-center gap-3 mb-2 "> <div class="d-flex align-items-center gap-3 mb-2 ">
<h3>Peers</h3> <h3>Peers</h3>
<a role="button" <RouterLink
data-bs-toggle="modal" data-bs-target="#peerCreateModal" to="create"
class="text-decoration-none ms-auto"> class="text-decoration-none ms-auto">
<i class="bi bi-plus-circle-fill me-2"></i>Add Peer</a> <i class="bi bi-plus-circle-fill me-2"></i>Add Peer</RouterLink>
</div> </div>
<PeerSearch></PeerSearch> <PeerSearch></PeerSearch>
<TransitionGroup name="list" tag="div" class="row gx-2 gy-2 z-0"> <TransitionGroup name="list" tag="div" class="row gx-2 gy-2 z-0">
@ -479,7 +490,7 @@ export default {
<!-- <Transition name="fade">--> <!-- <Transition name="fade">-->
<!-- --> <!-- -->
<!-- </Transition>--> <!-- </Transition>-->
<PeerCreate></PeerCreate>
</div> </div>
</template> </template>

View File

@ -101,15 +101,7 @@ export default {
v-model="this.data.allowed_ip" v-model="this.data.allowed_ip"
id="peer_allowed_ip_textbox"> id="peer_allowed_ip_textbox">
</div> </div>
<div>
<label for="peer_DNS_textbox" class="form-label">
<small class="text-muted">DNS <code>(Required)</code></small>
</label>
<input type="text" class="form-control form-control-sm rounded-3"
:disabled="this.saving"
v-model="this.data.DNS"
id="peer_DNS_textbox">
</div>
<div> <div>
<label for="peer_endpoint_allowed_ips" class="form-label"> <label for="peer_endpoint_allowed_ips" class="form-label">
<small class="text-muted">Endpoint Allowed IPs <code>(Required)</code></small> <small class="text-muted">Endpoint Allowed IPs <code>(Required)</code></small>
@ -119,6 +111,15 @@ export default {
v-model="this.data.endpoint_allowed_ip" v-model="this.data.endpoint_allowed_ip"
id="peer_endpoint_allowed_ips"> id="peer_endpoint_allowed_ips">
</div> </div>
<div>
<label for="peer_DNS_textbox" class="form-label">
<small class="text-muted">DNS</small>
</label>
<input type="text" class="form-control form-control-sm rounded-3"
:disabled="this.saving"
v-model="this.data.DNS"
id="peer_DNS_textbox">
</div>
<hr> <hr>
<div class="accordion mt-2" id="peerSettingsAccordion"> <div class="accordion mt-2" id="peerSettingsAccordion">
<div class="accordion-item"> <div class="accordion-item">

View File

@ -38,7 +38,7 @@ export default {
<template> <template>
<div class="card conf_card rounded-3 shadow text-decoration-none"> <div class="card conf_card rounded-3 shadow text-decoration-none">
<RouterLink :to="'/configuration/' + c.Name" class="card-body d-flex align-items-center gap-3 flex-wrap text-decoration-none"> <RouterLink :to="'/configuration/' + c.Name + '/peers'" class="card-body d-flex align-items-center gap-3 flex-wrap text-decoration-none">
<h6 class="mb-0"><span class="dot" :class="{active: c.Status}"></span></h6> <h6 class="mb-0"><span class="dot" :class="{active: c.Status}"></span></h6>
<h6 class="card-title mb-0"><samp>{{c.Name}}</samp></h6> <h6 class="card-title mb-0"><samp>{{c.Name}}</samp></h6>
<h6 class="mb-0 ms-auto"> <h6 class="mb-0 ms-auto">

View File

@ -29,7 +29,8 @@ export default {
</h6> </h6>
<ul class="nav flex-column"> <ul class="nav flex-column">
<li class="nav-item"> <li class="nav-item">
<RouterLink :to="'/configuration/'+c.Name" class="nav-link nav-conf-link" v-for="c in this.wireguardConfigurationsStore.Configurations"> <RouterLink :to="'/configuration/'+c.Name + '/peers'" class="nav-link nav-conf-link"
v-for="c in this.wireguardConfigurationsStore.Configurations">
<samp>{{c.Name}}</samp> <samp>{{c.Name}}</samp>
</RouterLink> </RouterLink>
</li> </li>

View File

@ -13,6 +13,7 @@ import NewConfiguration from "@/views/newConfiguration.vue";
import Configuration from "@/views/configuration.vue"; import Configuration from "@/views/configuration.vue";
import PeerSettings from "@/components/configurationComponents/peerSettings.vue"; import PeerSettings from "@/components/configurationComponents/peerSettings.vue";
import PeerList from "@/components/configurationComponents/peerList.vue"; import PeerList from "@/components/configurationComponents/peerList.vue";
import PeerCreate from "@/components/configurationComponents/peerCreate.vue";
const checkAuth = async () => { const checkAuth = async () => {
let result = false let result = false
@ -68,9 +69,14 @@ const router = createRouter({
children: [ children: [
{ {
name: "Peers List", name: "Peers List",
path: '', path: 'peers',
component: PeerList component: PeerList
} },
{
name: "Peers Create",
path: 'create',
component: PeerCreate
},
] ]
}, },

View File

@ -1,80 +1,14 @@
<script> <script>
import {fetchGet} from "@/utilities/fetch.js";
import Peer from "@/components/configurationComponents/peer.vue";
import { Line, Bar } from 'vue-chartjs'
import Fuse from "fuse.js";
import {
Chart,
ArcElement,
LineElement,
BarElement,
PointElement,
BarController,
BubbleController,
DoughnutController,
LineController,
PieController,
PolarAreaController,
RadarController,
ScatterController,
CategoryScale,
LinearScale,
LogarithmicScale,
RadialLinearScale,
TimeScale,
TimeSeriesScale,
Decimation,
Filler,
Legend,
Title,
Tooltip
} from 'chart.js';
Chart.register(
ArcElement,
LineElement,
BarElement,
PointElement,
BarController,
BubbleController,
DoughnutController,
LineController,
PieController,
PolarAreaController,
RadarController,
ScatterController,
CategoryScale,
LinearScale,
LogarithmicScale,
RadialLinearScale,
TimeScale,
TimeSeriesScale,
Decimation,
Filler,
Legend,
Title,
Tooltip
);
import dayjs from "dayjs";
import PeerSearch from "@/components/configurationComponents/peerSearch.vue";
import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js";
import {ref} from "vue";
import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js";
import PeerList from "@/components/configurationComponents/peerList.vue";
export default { export default {
name: "configuration", name: "configuration",
components: {PeerList},
} }
</script> </script>
<template> <template>
<div class="mt-5 text-body"> <div class="mt-5 text-body">
<!-- <PeerList></PeerList>--> <RouterView v-slot="{ Component, route }">
<RouterView v-slot="{ Component }">
<Transition name="fade2" mode="out-in"> <Transition name="fade2" mode="out-in">
<Component :is="Component"></Component> <Component :is="Component" :key="route.path"></Component>
</Transition> </Transition>
</RouterView> </RouterView>
</div> </div>