macos build, linux tun hack
This commit is contained in:
1 parent
9639defdd4
commit
76ab72db2e
18 files changed
+719
-64
No files matched your search
@@ -1,5 +1,7 @@
|
||||
desktop-joiner-windows-*.exe
|
||||
desktop-joiner-linux-*
|
||||
desktop-joiner-darwin
|
||||
desktop-joiner-darwin-*
|
||||
desktop-joiner-bundle
|
||||
desktop-joiner-bundle.exe
|
||||
wintun-*.dll
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
"whitelist-bypass/relay/pion"
|
||||
"whitelist-bypass/relay/tunnel"
|
||||
"whitelist-bypass/relay/wbstream"
|
||||
"whitelist-bypass/relay/wintunnel"
|
||||
"whitelist-bypass/relay/desktoptun"
|
||||
)
|
||||
|
||||
type statusEmitter struct{}
|
||||
@@ -108,12 +108,12 @@ func main() {
|
||||
}
|
||||
common.MaskingEnabled = true
|
||||
|
||||
// One wintunnel.Tunnel covers both platforms. Created up-front so
|
||||
// One desktoptun.Tunnel covers both platforms. Created up-front so
|
||||
// signaling-host bypass routes can be installed before any platform
|
||||
// code touches the network.
|
||||
var tun *wintunnel.Tunnel
|
||||
var tun *desktoptun.Tunnel
|
||||
if !*noTun {
|
||||
cfg := wintunnel.Config{
|
||||
cfg := desktoptun.Config{
|
||||
AdapterName: tunAdapter,
|
||||
TunnelIP: tunIP,
|
||||
TunnelMask: tunMask,
|
||||
@@ -127,9 +127,9 @@ func main() {
|
||||
LogFn: log.Printf,
|
||||
}
|
||||
var err error
|
||||
tun, err = wintunnel.New(cfg)
|
||||
tun, err = desktoptun.New(cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("[wintunnel] init: %v", err)
|
||||
log.Fatalf("[desktoptun] init: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +151,7 @@ func main() {
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
watchStdinQuit(sig)
|
||||
|
||||
tunReady := make(chan struct{})
|
||||
var tunOnce sync.Once
|
||||
@@ -161,7 +162,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
if err := tun.Start(); err != nil {
|
||||
log.Fatalf("[wintunnel] start: %v", err)
|
||||
log.Fatalf("[desktoptun] start: %v", err)
|
||||
}
|
||||
// Now that the tunnel knows the original gateway,
|
||||
// pin /32 bypass routes for the signaling hosts.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func watchStdinQuit(sig chan<- os.Signal) {
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
if strings.TrimSpace(scanner.Text()) == "QUIT" {
|
||||
sig <- syscall.SIGTERM
|
||||
return
|
||||
}
|
||||
}
|
||||
sig <- syscall.SIGTERM
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !linux
|
||||
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func watchStdinQuit(_ chan<- os.Signal) {}
|
||||
@@ -52,6 +52,18 @@
|
||||
"to": "desktop-joiner"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mac": {
|
||||
"target": "dmg",
|
||||
"artifactName": "${productName}-${version}-${arch}.${ext}",
|
||||
"icon": "resources/icon.icns",
|
||||
"category": "public.app-category.utilities",
|
||||
"extraResources": [
|
||||
{
|
||||
"from": "desktop-joiner/desktop-joiner-darwin",
|
||||
"to": "desktop-joiner"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,12 +43,15 @@ function resolveJoinerExe(): string {
|
||||
const packaged = join(process.resourcesPath || '', exeName);
|
||||
if (existsSync(packaged)) return packaged;
|
||||
|
||||
const baseDir = join(__dirname, '..', '..', 'desktop-joiner');
|
||||
if (process.platform === 'darwin') {
|
||||
return join(baseDir, 'desktop-joiner-darwin');
|
||||
}
|
||||
const archMap: Record<string, string> = { x64: 'x64', arm64: 'arm64', ia32: 'ia32' };
|
||||
const archTag = archMap[process.arch] ?? 'x64';
|
||||
const platTag = process.platform === 'win32' ? 'windows' : 'linux';
|
||||
const suffix = process.platform === 'win32' ? '.exe' : '';
|
||||
return join(__dirname, '..', '..', 'desktop-joiner',
|
||||
`desktop-joiner-${platTag}-${archTag}${suffix}`);
|
||||
const platTag = process.platform === 'win32' ? 'windows' : 'linux';
|
||||
return join(baseDir, `desktop-joiner-${platTag}-${archTag}${suffix}`);
|
||||
}
|
||||
|
||||
function send(channel: string, payload: unknown) {
|
||||
@@ -94,9 +97,12 @@ ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
|
||||
if (!existsSync(exe)) {
|
||||
return { ok: false, error: `desktop-joiner binary not found at ${exe}` };
|
||||
}
|
||||
// wintun is Windows-only; on Linux always run in SOCKS5-only mode
|
||||
// regardless of the noTun checkbox.
|
||||
const noTun = process.platform !== 'win32' ? true : settings.noTun;
|
||||
const tunSupported =
|
||||
process.platform === 'win32' || process.platform === 'linux' || process.platform === 'darwin';
|
||||
const noTun = tunSupported ? settings.noTun : true;
|
||||
if (process.platform !== 'win32' && !noTun && process.getuid && process.getuid() !== 0) {
|
||||
send(IPC.LOG, `[main] WARNING: ${process.platform} TUN routing needs root; relaunch with sudo or untick the TUN option\n`);
|
||||
}
|
||||
const args = [
|
||||
'--platform', settings.platform,
|
||||
'--link', settings.link,
|
||||
@@ -112,10 +118,15 @@ ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
|
||||
if (settings.socksPass) args.push('--socks-pass', settings.socksPass);
|
||||
if (noTun) args.push('--no-tun');
|
||||
|
||||
const commandLine = [exe, ...args].map((s) => (/\s/.test(s) ? `"${s}"` : s)).join(' ');
|
||||
const elevateOnLinux =
|
||||
process.platform === 'linux' && !noTun &&
|
||||
process.getuid && process.getuid() !== 0;
|
||||
const spawnCmd = elevateOnLinux ? 'pkexec' : exe;
|
||||
const spawnArgs = elevateOnLinux ? [exe, ...args] : args;
|
||||
const commandLine = [spawnCmd, ...spawnArgs].map((s) => (/\s/.test(s) ? `"${s}"` : s)).join(' ');
|
||||
send(IPC.LOG, `[main] spawning: ${commandLine}\n`);
|
||||
try {
|
||||
joinerProcess = spawn(exe, args, { windowsHide: true });
|
||||
joinerProcess = spawn(spawnCmd, spawnArgs, { windowsHide: true });
|
||||
} catch (err) {
|
||||
return { ok: false, error: `spawn failed: ${(err as Error).message}` };
|
||||
}
|
||||
@@ -159,10 +170,13 @@ ipcMain.handle(IPC.STOP, async () => {
|
||||
function stopJoiner() {
|
||||
closeCaptchaWindow();
|
||||
if (!joinerProcess) return;
|
||||
// On Linux when the Go binary was spawned via pkexec, it runs as
|
||||
// root and we (the user) cannot SIGTERM it. The binary watches
|
||||
// stdin: writing "QUIT\n" and closing the pipe triggers the same
|
||||
// shutdown path as SIGTERM.
|
||||
try { joinerProcess.stdin?.write('QUIT\n'); } catch {}
|
||||
try { joinerProcess.stdin?.end(); } catch {}
|
||||
try {
|
||||
// SIGTERM on Windows ends up as TerminateProcess for the child.
|
||||
// The Go binary registers a signal handler for SIGTERM which
|
||||
// triggers Tunnel.Stop and tears down routes cleanly.
|
||||
joinerProcess.kill('SIGTERM');
|
||||
} catch {}
|
||||
}
|
||||
Reference in new issue
Block a user