diff --git a/back/Dockerfile.dashboard b/back/dashboard.Dockerfile similarity index 100% rename from back/Dockerfile.dashboard rename to back/dashboard.Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 17af937..1f0155f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: dashboard-backend: build: context: back - dockerfile: Dockerfile.dashboard + dockerfile: dashboard.Dockerfile container_name: wgapi-dashboard-backend cap_add: - NET_ADMIN @@ -17,7 +17,7 @@ services: dashboard-frontend: build: context: front - dockerfile: Dockerfile.dashboard + dockerfile: dashboard.Dockerfile container_name: wgapi-dashboard-frontend volumes: - '/var/log/wgapi:/var/log/wgapi' diff --git a/front/Dockerfile.dashboard b/front/dashboard.Dockerfile similarity index 100% rename from front/Dockerfile.dashboard rename to front/dashboard.Dockerfile diff --git a/front/dashboard.js b/front/dashboard.js index 6db14c3..2021974 100644 --- a/front/dashboard.js +++ b/front/dashboard.js @@ -2,6 +2,7 @@ const API_URL = 'https://wgapi-test-dashboard-backend.ksn.gf4' function Peer(data) { this.name = ko.observable(data.name) + this.pubkey = data.pubkey this.ipv4 = ko.observable(data.ipv4) this.ipv6 = ko.observable(`:${data.ipv6.split(':').slice(-2).join(':')}`) this.isDeleting = ko.observable(false) @@ -20,14 +21,11 @@ function PeerList() { self.getUser = async () => { let res; try { res = await fetch(`${API_URL}/`) - } catch (err) { - console.error(`Failed to GET ${API_URL}/`) + } catch (err) || (!res.ok) if (err) console.error(err) - } - if (!res.ok) { - console.log(`Got ${res.status} from GET ${API_URL}/`) + if (res.status) console.log(res.status) alert('Failed to contact API and load peers list. Check your wireguard connection. ') - } else { + else { let user; try { user = await res.json() } catch (err) { @@ -56,17 +54,9 @@ function PeerList() { alert(`You already have a peer named ${validName}!`) self.isAdding(false) } else { - const url = `${API_URL}/?token=${self.token}` + const url = `${API_URL}/?t=${self.token}&name=${validName}` let res; try { - res = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - name: validName, - }), - }) + res = await fetch(url, {method: 'POST'}) } catch (err) { alert('Failed to contact server. Are you online?') if (err) console.error(err) @@ -78,7 +68,7 @@ function PeerList() { if (err) console.error(err) } finally { self.isAdding(false) } if (!res.ok) { - alert(parsedRes) + alert(res.status) } else { self.newPeerName('') self.newConfigText(parsedRes) @@ -101,7 +91,6 @@ function PeerList() { } } } - // Listen for user hitting enter key self.addKeyPress = (d,e) => { if (e.keyCode === 13) self.addPeer() @@ -109,20 +98,11 @@ function PeerList() { } self.delPeer = async (peer) => { - const name = peer.name() - if (confirm(`Are you sure you want to delete ${name}?`)) { + if (confirm(`Are you sure you want to delete ${peer.name()}?`)) { peer.isDeleting(true) - const url = `${API_URL}/?token=${self.token}` + const url = `${API_URL}/?t=${self.token}&pubkey=${peer.pubkey()}` try { - const res = await fetch(url, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - name: name, - }), - }) + const res = await fetch(url, {method: 'DELETE'}) if (res.ok) self.peers.remove(peer) else { if (res.status===404) self.peers.remove(peer)