added download wireguard conf

This commit is contained in:
Jincheng Lu 2025-12-03 13:10:45 +08:00
parent 582312e727
commit 7ce1f05f52
2 changed files with 28 additions and 1 deletions

View File

@ -9,7 +9,8 @@ import AttachMoneyIcon from '@mui/icons-material/AttachMoney';
import StarIcon from '@mui/icons-material/Star'; import StarIcon from '@mui/icons-material/Star';
import Rating from '@mui/material/Rating'; import Rating from '@mui/material/Rating';
import useAuth from '~/hooks/useAuth'; import useAuth from '~/hooks/useAuth';
import { getPublicKey,signMessage } from './Metamask/Connections'; import { signMessage } from './Metamask/Connections';
import { downloadWireguardConfig } from './WireguardConfig';
import axios from 'axios'; import axios from 'axios';
interface Node { interface Node {
@ -36,6 +37,7 @@ function NodeItem({node}: {node: Node}) {
const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig; const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig;
let response = await axios.post(getUrl() + "/connect", res_string); let response = await axios.post(getUrl() + "/connect", res_string);
console.log(response.data); console.log(response.data);
downloadWireguardConfig("", "", "", "", node.ip, "51820", "0.0.0.0/0");
} catch (error) { } catch (error) {
console.error('Error:', error); console.error('Error:', error);
} }

View File

@ -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);
}