VPN Code UPdate
This commit is contained in:
parent
2306e54515
commit
d7128000be
|
|
@ -1,10 +1,11 @@
|
|||
|
||||
[Interface]
|
||||
PrivateKey = CEzCd25ufxbOjvRhMqLfkcdP/OziG5i6OkXCfMZrI1I=
|
||||
Address = 10.0.0.2/32
|
||||
PrivateKey = EA2j6mOQB17w497cZS4B91m/xDzEcGz9lU3jKtc1wU8=
|
||||
Address = 10.0.0.27/32
|
||||
DNS = 1.1.1.1
|
||||
|
||||
[Peer]
|
||||
PublicKey = jG+7H5thEiNjxY1XqI1R9oyMAMTIegLwE3tZkS1Rj2U=
|
||||
Endpoint = 35.95.209.161:51820
|
||||
AllowedIPs = 10.0.0.0/32
|
||||
AllowedIPs = 10.0.0.0/24
|
||||
PersistentKeepalive = 25
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const httpsAgent = new https.Agent({
|
|||
console.log('Base_URL$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' ,Base_URL)
|
||||
|
||||
const api: AxiosInstance = axios.create({
|
||||
// baseURL: 'https://quality-friendly-goldfish.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||
// baseURL: 'https://portal-sf.docva.com/api/v1/va', // 🔁 your backend
|
||||
baseURL: `${Base_URL}/api/v1/va`,
|
||||
httpsAgent
|
||||
// timeout: 10000,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// let CURRENT_BASE_URL = "https://quality-friendly-goldfish.ngrok-free.app/api/v1/va";
|
||||
let CURRENT_BASE_URL = "https://quality-friendly-goldfish.ngrok-free.app";
|
||||
// let CURRENT_BASE_URL = "https://portal-sf.docva.com/api/v1/va";
|
||||
let CURRENT_BASE_URL = "https://portal-sf.docva.com";
|
||||
|
||||
export const getBaseURL = () => CURRENT_BASE_URL;
|
||||
export const setBaseURL = (url: string) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ export const checkRegion = async () => {
|
|||
|
||||
const res = await axios.get(`${baseURL}/health`, {
|
||||
headers: { "ngrok-skip-browser-warning": "true" },
|
||||
httpsAgent
|
||||
httpsAgent,
|
||||
timeout: 4000
|
||||
});
|
||||
|
||||
console.log(res , "checkRegion")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { exec, execFile } from "child_process";
|
|||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import axios from "axios";
|
||||
|
||||
//
|
||||
// ------------------ HELPERS ------------------
|
||||
|
|
@ -51,20 +52,72 @@ function getWireGuardInstallerPath(): string {
|
|||
|
||||
|
||||
// OS-specific wg0.conf
|
||||
function getConfigPath(): string {
|
||||
// function getConfigPath(): string {
|
||||
// const base = isDev()
|
||||
// ? path.join(process.cwd(), "resources", "wireguard")
|
||||
// : path.join(process.resourcesPath, "wireguard");
|
||||
|
||||
// if (process.platform === "win32") {
|
||||
// return path.join(base, "windows", "wg0.conf");
|
||||
// }
|
||||
|
||||
// if (process.platform === "darwin") {
|
||||
// return path.join(base, "macos", "wg0.conf");
|
||||
// }
|
||||
|
||||
// throw new Error("Unsupported OS");
|
||||
// }
|
||||
|
||||
export async function getConfigPath(): Promise<string> {
|
||||
if (process.platform !== "win32") {
|
||||
throw new Error("Only Windows supported for dynamic WireGuard config");
|
||||
}
|
||||
console.log("Calling http://35.95.209.161/api/v1/vpn/connect")
|
||||
// 1️⃣ Call API to get dynamic config
|
||||
let response = null;
|
||||
try {
|
||||
response = await axios.post(
|
||||
"http://35.95.209.161/api/v1/vpn/connect",
|
||||
{},
|
||||
{ timeout: 15000 }
|
||||
);
|
||||
} catch (err: any) {
|
||||
console.error("VPN API error:", {
|
||||
message: err.message,
|
||||
code: err.code,
|
||||
response: err.response?.data,
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
console.log("Called http://35.95.209.161/api/v1/vpn/connect", JSON.stringify(response.data));
|
||||
|
||||
if (!response.data?.success || !response.data.clientConf) {
|
||||
throw new Error("Invalid VPN config response");
|
||||
}
|
||||
|
||||
const clientConf: string = response.data.clientConf;
|
||||
|
||||
// 2️⃣ Decide base directory (same idea as your existing logic)
|
||||
const base = isDev()
|
||||
? path.join(process.cwd(), "resources", "wireguard")
|
||||
: path.join(process.resourcesPath, "wireguard");
|
||||
? path.join(process.cwd(), "resources", "wireguard", "windows")
|
||||
: path.join(process.resourcesPath, "wireguard", "windows");
|
||||
|
||||
if (process.platform === "win32") {
|
||||
return path.join(base, "windows", "wg0.conf");
|
||||
}
|
||||
// Ensure directory exists
|
||||
fs.mkdirSync(base, { recursive: true });
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
return path.join(base, "macos", "wg0.conf");
|
||||
}
|
||||
// 3️⃣ Create temp / runtime conf file
|
||||
// IMPORTANT: name must stay stable (WireGuard service name depends on it)
|
||||
const confPath = path.join(base, "wg0.conf");
|
||||
|
||||
throw new Error("Unsupported OS");
|
||||
// 4️⃣ Write config to file
|
||||
fs.writeFileSync(confPath, clientConf, {
|
||||
encoding: "utf-8",
|
||||
mode: 0o600, // secure permissions
|
||||
});
|
||||
|
||||
console.log("VPN config written to:", confPath);
|
||||
// 5️⃣ Return path (same contract as before)
|
||||
return confPath;
|
||||
}
|
||||
|
||||
// Detect installed WireGuard.exe on Windows
|
||||
|
|
@ -145,8 +198,16 @@ async function ensureWireGuardInstalled(): Promise<string> {
|
|||
|
||||
|
||||
async function connectWindows(): Promise<string> {
|
||||
|
||||
try {
|
||||
const response = await axios.get('http://35.95.209.161')
|
||||
console.log("Response from test API:", response.data);
|
||||
} catch (error) {
|
||||
console.error("Error connecting to test API:", error);
|
||||
}
|
||||
|
||||
const cli = await ensureWireGuardInstalled();
|
||||
const conf = getConfigPath();
|
||||
const conf = await getConfigPath();
|
||||
|
||||
// Disable GUI popup and silent mode (ignore errors)
|
||||
await execPromise(`reg add "HKCU\\Software\\WireGuard" /v HideTrayIcon /t REG_DWORD /d 1 /f`).catch(() => { });
|
||||
|
|
|
|||
|
|
@ -590,7 +590,7 @@ const DashboardLayout = () => {
|
|||
if (!selectedProject?.projectId) return
|
||||
|
||||
console.log(selectedProject?.projectId, "SelectedProject ID")
|
||||
socketRef.current = io("https://quality-friendly-goldfish.ngrok-free.app", {
|
||||
socketRef.current = io("https://portal-sf.docva.com", {
|
||||
transports: ["websocket"],
|
||||
secure: true,
|
||||
rejectUnauthorized: false,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,21 @@ import { Provider } from "react-redux";
|
|||
import { store } from "./store";
|
||||
import { ToastProvider } from './helper/ToastContext';
|
||||
|
||||
// renderer only
|
||||
window.addEventListener("online", (e) => {
|
||||
console.log("Network online (ignored)");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
window.addEventListener("offline", (e) => {
|
||||
console.log("Network offline (ignored)");
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// Extra safety
|
||||
window.onbeforeunload = () => false;
|
||||
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<Provider store={store}>
|
||||
<ToastProvider>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ interface Props {
|
|||
const VpnGuard: React.FC<Props> = ({ children }) => {
|
||||
|
||||
const VPN_API = "http://10.0.0.1:3000";
|
||||
const DEFAULT_API = "https://quality-friendly-goldfish.ngrok-free.app"
|
||||
const DEFAULT_API = "https://portal-sf.docva.com"
|
||||
|
||||
const [checking, setChecking] = useState(true);
|
||||
const [vpnConnected, setVpnConnected] = useState(true);
|
||||
|
|
@ -20,9 +20,12 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
|||
|
||||
const res = await window.electron?.checkRegion();
|
||||
console.log("VpnGuard", res);
|
||||
if (res.status === 200) {
|
||||
setVpnConnected(true);
|
||||
} else {
|
||||
setVpnConnected(false);
|
||||
return
|
||||
|
||||
return;
|
||||
}
|
||||
// setVpnConnected(res?.success === true);
|
||||
} catch (error) {
|
||||
console.error("VPN check failed:", error);
|
||||
|
|
@ -58,6 +61,16 @@ const VpnGuard: React.FC<Props> = ({ children }) => {
|
|||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
const vpnRes = await window.electron.updateBaseURL(VPN_API);
|
||||
console.log("vpnRes", vpnRes);
|
||||
|
||||
if (vpnRes) {
|
||||
// Run VPN check again AFTER URL changes
|
||||
await checkVPN();
|
||||
} else {
|
||||
console.warn("Base URL updated but health check failed");
|
||||
}
|
||||
} finally {
|
||||
setChecking(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
// vite.config.ts
|
||||
import { defineConfig } from "file:///C:/Users/user/OneDrive/Desktop/electron-main/node_modules/vite/dist/node/index.js";
|
||||
import react from "file:///C:/Users/user/OneDrive/Desktop/electron-main/node_modules/@vitejs/plugin-react/dist/index.js";
|
||||
import tailwindcss from "file:///C:/Users/user/OneDrive/Desktop/electron-main/node_modules/@tailwindcss/vite/dist/index.mjs";
|
||||
var vite_config_default = defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
base: "./",
|
||||
build: {
|
||||
outDir: "dist-react"
|
||||
},
|
||||
server: {
|
||||
port: 5123,
|
||||
strictPort: true
|
||||
}
|
||||
});
|
||||
export {
|
||||
vite_config_default as default
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCJDOlxcXFxVc2Vyc1xcXFx1c2VyXFxcXE9uZURyaXZlXFxcXERlc2t0b3BcXFxcZWxlY3Ryb24tbWFpblwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlbmFtZSA9IFwiQzpcXFxcVXNlcnNcXFxcdXNlclxcXFxPbmVEcml2ZVxcXFxEZXNrdG9wXFxcXGVsZWN0cm9uLW1haW5cXFxcdml0ZS5jb25maWcudHNcIjtjb25zdCBfX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