added download wireguard conf
This commit is contained in:
parent
582312e727
commit
7ce1f05f52
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
25
app/Components/WireguardConfig.tsx
Normal file
25
app/Components/WireguardConfig.tsx
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user