mirror of
https://github.com/PR0M3TH3AN/VoxVera.git
synced 2025-09-08 23:18:42 +00:00
Add Tor placeholders instructions and fallback
This commit is contained in:
@@ -46,7 +46,13 @@ function startOnionShare() {
|
||||
}
|
||||
|
||||
async function runServe (retry = false) {
|
||||
const { torProc, socksPort, controlPort } = await launchTor();
|
||||
let torProc, socksPort, controlPort;
|
||||
try {
|
||||
({ torProc, socksPort, controlPort } = await launchTor());
|
||||
} catch (err) {
|
||||
dialog.showErrorBox('Tor error', err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const env = { ...process.env,
|
||||
TOR_SOCKS_PORT: socksPort.toString(),
|
||||
|
@@ -1,15 +1,39 @@
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const which = require('which');
|
||||
const getPort = (...args) => import('get-port').then(m => m.default(...args));
|
||||
|
||||
async function launchTor() {
|
||||
const socks = await getPort();
|
||||
const control = await getPort();
|
||||
const torBase = path.join(__dirname, '..', '..', 'voxvera', 'resources', 'tor');
|
||||
const exe = path.join(torBase, process.platform,
|
||||
process.platform === 'win32' ? 'tor.exe' : 'tor');
|
||||
const obfs4 = path.join(torBase, process.platform,
|
||||
process.platform === 'win32' ? 'obfs4proxy.exe' : 'obfs4proxy');
|
||||
let exe = path.join(torBase, process.platform,
|
||||
process.platform === 'win32' ? 'tor.exe' : 'tor');
|
||||
let obfs4 = path.join(torBase, process.platform,
|
||||
process.platform === 'win32' ? 'obfs4proxy.exe' : 'obfs4proxy');
|
||||
|
||||
const missing = p => {
|
||||
try {
|
||||
const data = fs.readFileSync(p, 'utf8');
|
||||
return data.includes('placeholder');
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
if (missing(exe)) {
|
||||
const sysTor = which.sync('tor', { nothrow: true });
|
||||
if (sysTor) exe = sysTor;
|
||||
}
|
||||
if (missing(obfs4)) {
|
||||
const sysObfs = which.sync('obfs4proxy', { nothrow: true });
|
||||
if (sysObfs) obfs4 = sysObfs;
|
||||
}
|
||||
|
||||
if (missing(exe) || missing(obfs4)) {
|
||||
throw new Error('Tor or obfs4proxy not found; install them first.');
|
||||
}
|
||||
|
||||
const args = [
|
||||
'SocksPort', socks,
|
||||
|
Reference in New Issue
Block a user