diff --git a/app/Components/ServerList.tsx b/app/Components/ServerList.tsx index 79eb831..3298c30 100644 --- a/app/Components/ServerList.tsx +++ b/app/Components/ServerList.tsx @@ -9,7 +9,8 @@ import AttachMoneyIcon from '@mui/icons-material/AttachMoney'; import StarIcon from '@mui/icons-material/Star'; import Rating from '@mui/material/Rating'; import useAuth from '~/hooks/useAuth'; -import { getPublicKey,signMessage } from './Metamask/Connections'; +import { signMessage } from './Metamask/Connections'; +import { downloadWireguardConfig } from './WireguardConfig'; import axios from 'axios'; interface Node { @@ -36,6 +37,7 @@ function NodeItem({node}: {node: Node}) { const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig; let response = await axios.post(getUrl() + "/connect", res_string); console.log(response.data); + downloadWireguardConfig("", "", "", "", node.ip, "51820", "0.0.0.0/0"); } catch (error) { console.error('Error:', error); } diff --git a/app/Components/WireguardConfig.tsx b/app/Components/WireguardConfig.tsx new file mode 100644 index 0000000..638afcf --- /dev/null +++ b/app/Components/WireguardConfig.tsx @@ -0,0 +1,25 @@ + + +export const downloadWireguardConfig = (privateKey: string, publicKey: string, localCIDR: string, dns: string, peerIp: string, peerPort: string, allowedIPs: string) => { + const content = `[Interface]`+'\n'+ + `PrivateKey = ${privateKey}`+'\n'+ + `Address = ${localCIDR}`+'\n'+ + `DNS = ${dns}`+'\n'+ + '\n'+ + `[Peer]`+'\n'+ + `PublicKey = ${publicKey}`+'\n'+ + `AllowedIPs = ${allowedIPs}`+'\n'+ + `Endpoint = ${peerIp}:${peerPort}`; + + const blob = new Blob([content], { type: 'text/plain' }); + const fileUrl = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = fileUrl; + link.download = peerIp + '.conf'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + URL.revokeObjectURL(fileUrl); +} +