* refactor go files, add headless telemost support

* js crap -> ts crap

* docker-build (#32)

Co-authored-by: Mimocro <suzumagefag@gmail.com>

* add headless telemost for creator app

* UX improvements (#39)

* Add search in split tunneling app list

* Add captcha detection

* Add autoclick settings

* headless vk joiner

* add headless telemost joiner

* refactor go modules

* redesign settings dialog

* headless option in settings

* headless joiner support in MainActivity

* display headless vk status in statusBar

* update ux for headless in creator app

* fix double log render for headless mode in creator

* unicode for cyrillic

* add socks auth

* put socksPort inf prefs, verify that port is free on start

* proxy only mode

* mask addresses in go network errors

* update docker build, add file write logic for headless

* increment release version, add make-release script

---------

Co-authored-by: kulikov <user@Mac.lan>
Co-authored-by: Mimocro <67226986+Mimocro@users.noreply.github.com>
Co-authored-by: Mimocro <suzumagefag@gmail.com>
Co-authored-by: senya <76913432+senya-sh@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-04-12 17:14:51 +02:00
1 parent c8e1ba444d
commit 029b536250
122 files changed
+9938 -3284

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import { app } from 'electron';
import { TabManager } from './tab-manager';
import { createWindow } from './window';
import { registerIpcHandlers } from './ipc';
const tabManager = new TabManager();
registerIpcHandlers(tabManager);
app.whenReady().then(() => {
const win = createWindow(tabManager);
tabManager.mainWindow = win;
});
app.on('window-all-closed', () => {
tabManager.killAllRelays();
app.quit();
});
app.on('before-quit', () => tabManager.killAllRelays());
process.on('exit', () => tabManager.killAllRelays());
process.on('SIGINT', () => {
tabManager.killAllRelays();
process.exit();
});
process.on('SIGTERM', () => {
tabManager.killAllRelays();
process.exit();
});
+103
View File
@@ -0,0 +1,103 @@
import { ipcMain, session } from 'electron';
import * as path from 'path';
import * as fs from 'fs/promises';
import { TabManager } from './tab-manager';
import { BotManager } from '../bot/bot-manager';
import {
IPC,
SESSION_PARTITION,
VK_COOKIE_DOMAINS,
YANDEX_COOKIE_DOMAINS,
} from '../constants';
import { TunnelMode, Platform, BotSettings } from '../types';
export function registerIpcHandlers(tabManager: TabManager): void {
ipcMain.handle(IPC.GET_HOOK_CODE, async (_e, tabId: string, url: string) => {
const tab = await tabManager.getOrCreateTab(tabId);
return tabManager.loadHook(tabId, url, tab);
});
ipcMain.handle(IPC.GET_CALL_CREATOR_CODE, async (_e, scriptFile: string) => {
const filePath = path.join(__dirname, '..', '..', 'scripts', scriptFile || 'vk-call-creator.js');
return fs.readFile(filePath, 'utf8');
});
ipcMain.handle(IPC.SET_TUNNEL_MODE, (_e, tabId: string, mode: string) => {
if (!Object.values(TunnelMode).includes(mode as TunnelMode)) return;
tabManager.setTunnelMode(tabId, mode as TunnelMode);
});
ipcMain.handle(IPC.START_RELAY, async (_e, tabId: string) => {
const tab = await tabManager.getOrCreateTab(tabId);
tabManager.startRelay(tabId, tab);
});
ipcMain.handle(IPC.START_HEADLESS, async (_e, tabId: string, platform: string) => {
await tabManager.startHeadless(tabId, platform as Platform);
});
ipcMain.handle(IPC.CLOSE_TAB, (_e, tabId: string) => {
tabManager.deleteTab(tabId);
});
ipcMain.handle(IPC.START_BOT, (_e, settings: BotSettings) => {
if (tabManager.botManager) {
tabManager.botManager.stop();
}
const bm = new BotManager(
settings,
async (tabConfig) => {
if (!tabManager.mainWindow || tabManager.mainWindow.isDestroyed()) return;
const tabId = 'bot-tab-' + Date.now();
const tab = await tabManager.getOrCreateTab(tabId);
tab.tunnelMode = tabConfig.mode;
tab.platform = tabConfig.platform || Platform.VK;
tab.peerId = tabConfig.peerId;
tab.isBot = true;
tabManager.addBotTab(tabId);
tabManager.mainWindow.webContents.send(IPC.CREATE_BOT_TAB, {
tabId,
mode: tabConfig.mode,
peerId: tabConfig.peerId,
platform: tabConfig.platform || Platform.VK,
});
console.log('[BOT] Created tab:', tabId, 'mode:', tabConfig.mode, 'platform:', tabConfig.platform);
},
() => tabManager.getTabList(),
(tabId) => {
tabManager.deleteTab(tabId);
console.log('[BOT] Closed tab:', tabId);
if (tabManager.mainWindow && !tabManager.mainWindow.isDestroyed()) {
tabManager.mainWindow.webContents.send(IPC.CLOSE_BOT_TAB, { tabId });
}
},
);
bm.onError = (msg: string) => {
if (tabManager.mainWindow && !tabManager.mainWindow.isDestroyed()) {
tabManager.mainWindow.webContents.send(IPC.BOT_ERROR, msg);
}
};
tabManager.botManager = bm;
bm.start();
return { success: true };
});
ipcMain.handle(IPC.STOP_BOT, () => {
if (tabManager.botManager) {
tabManager.botManager.stop();
tabManager.botManager = null;
}
return { success: true };
});
ipcMain.handle(IPC.GET_COOKIES, async (_e, domain: string) => {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
const domains = domain === 'yandex' ? YANDEX_COOKIE_DOMAINS : VK_COOKIE_DOMAINS;
const filtered = all.filter((cookie) => {
return cookie.domain != null && domains.some((d) => cookie.domain!.includes(d));
});
console.log(`[COOKIES] total: ${all.length} ${domain}: ${filtered.length}`);
return filtered;
});
}
+296
View File
@@ -0,0 +1,296 @@
import { app } from 'electron';
import { spawn, ChildProcess } from 'child_process';
import { BrowserWindow, session } from 'electron';
import * as net from 'net';
import * as path from 'path';
import * as fs from 'fs/promises';
import { TabState, PortPair, TabListEntry, Platform, TunnelMode, RelayMode, CallStatus } from '../types';
import {
INITIAL_PORT_BASE,
IPC,
RELAY_RESTART_DELAY_MS,
SESSION_PARTITION,
VK_COOKIE_DOMAINS,
YANDEX_COOKIE_DOMAINS,
LOG_CAPTURE_SNIPPET,
} from '../constants';
import { BotManager } from '../bot/bot-manager';
function resolveResourcePath(devRelative: string, packedName: string): string {
if (app.isPackaged) {
return path.join(process.resourcesPath!, packedName);
}
return path.join(__dirname, '..', '..', '..', devRelative);
}
function binaryName(base: string): string {
return process.platform === 'win32' ? base + '.exe' : base;
}
export class TabManager {
private tabs = new Map<string, TabState>();
private callStatusCache = new Map<string, CallStatus>();
private botTabIds = new Set<string>();
private nextPortBase = INITIAL_PORT_BASE;
private _mainWindow: BrowserWindow | null = null;
private _botManager: BotManager | null = null;
private relayPath: string;
private headlessVKPath: string;
private headlessTelemostPath: string;
private hooksDir: string;
constructor() {
this.relayPath = resolveResourcePath(
path.join('relay', binaryName('relay')),
binaryName('relay'),
);
this.headlessVKPath = resolveResourcePath(
path.join('headless', 'vk', binaryName('headless-vk-creator')),
binaryName('headless-vk-creator'),
);
this.headlessTelemostPath = resolveResourcePath(
path.join('headless', 'telemost', binaryName('headless-telemost-creator')),
binaryName('headless-telemost-creator'),
);
this.hooksDir = app.isPackaged
? path.join(process.resourcesPath!, 'hooks')
: path.join(__dirname, '..', '..', '..', 'hooks');
}
get mainWindow(): BrowserWindow | null {
return this._mainWindow;
}
set mainWindow(w: BrowserWindow | null) {
this._mainWindow = w;
}
get botManager(): BotManager | null {
return this._botManager;
}
set botManager(bm: BotManager | null) {
this._botManager = bm;
}
private isPortFree(port: number): Promise<boolean> {
return new Promise((resolve) => {
const server = net.createServer();
server.once('error', () => resolve(false));
server.once('listening', () => {
server.close(() => resolve(true));
});
server.listen(port, '127.0.0.1');
});
}
async allocPorts(): Promise<PortPair> {
while (true) {
const dc = this.nextPortBase;
const pion = this.nextPortBase + 1;
this.nextPortBase += 2;
if (await this.isPortFree(dc) && await this.isPortFree(pion)) {
return { dc, pion };
}
}
}
async getOrCreateTab(tabId: string): Promise<TabState> {
if (!this.tabs.has(tabId)) {
const ports = await this.allocPorts();
this.tabs.set(tabId, {
relay: null,
tunnelMode: TunnelMode.DC,
platform: Platform.VK,
dcPort: ports.dc,
pionPort: ports.pion,
});
}
return this.tabs.get(tabId)!;
}
getTab(tabId: string): TabState | undefined {
return this.tabs.get(tabId);
}
deleteTab(tabId: string): void {
const tab = this.tabs.get(tabId);
if (tab) {
this.killRelay(tabId, tab);
this.tabs.delete(tabId);
}
this.botTabIds.delete(tabId);
this.callStatusCache.delete(tabId);
}
addBotTab(tabId: string): void {
this.botTabIds.add(tabId);
}
removeBotTab(tabId: string): void {
this.botTabIds.delete(tabId);
}
isBotTab(tabId: string): boolean {
return this.botTabIds.has(tabId);
}
setCallStatus(tabId: string, status: CallStatus): void {
this.callStatusCache.set(tabId, status);
}
getCallStatus(tabId: string): CallStatus {
return this.callStatusCache.get(tabId) || CallStatus.Inactive;
}
findBotPeerId(platform: Platform): number | null {
for (const [tabId, tab] of this.tabs) {
if (this.botTabIds.has(tabId) && tab.platform === platform && tab.peerId != null) {
return tab.peerId;
}
}
return null;
}
getTabList(): TabListEntry[] {
const result: TabListEntry[] = [];
this.tabs.forEach((tab, tabId) => {
result.push({
id: tabId,
platform: tab.platform,
mode: tab.tunnelMode,
isBot: tab.isBot === true,
callStatus: this.getCallStatus(tabId),
});
});
return result;
}
private sendLog(tabId: string, msg: string): void {
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
this._mainWindow.webContents.send(IPC.RELAY_LOG, { tabId, msg });
}
}
private attachProcessOutput(proc: ChildProcess, tabId: string): void {
const onData = (data: Buffer) => {
data
.toString()
.trim()
.split('\n')
.forEach((msg) => {
if (!msg) return;
console.log(`[relay:${tabId}]`, msg);
this.sendLog(tabId, msg);
});
};
proc.stdout?.on('data', onData);
proc.stderr?.on('data', onData);
}
startRelay(tabId: string, tab: TabState): void {
this.killRelay(tabId, tab);
const port = tab.tunnelMode === TunnelMode.PionVideo ? tab.pionPort : tab.dcPort;
let relayMode: RelayMode = RelayMode.DCCreator;
if (tab.tunnelMode === TunnelMode.PionVideo) {
relayMode = tab.platform === Platform.Telemost
? RelayMode.TelemostVideoCreator
: RelayMode.VKVideoCreator;
}
const proc = spawn(this.relayPath, ['--mode', relayMode, '--ws-port', String(port)], {
stdio: ['ignore', 'pipe', 'pipe'],
});
tab.relay = proc;
this.attachProcessOutput(proc, tabId);
proc.on('close', (code) => {
this.sendLog(tabId, `Relay exited with code ${code}`);
});
}
async startHeadless(tabId: string, platform: Platform): Promise<void> {
const tab = await this.getOrCreateTab(tabId);
const isTelemost = platform === Platform.Telemost;
tab.tunnelMode = isTelemost ? TunnelMode.HeadlessTelemost : TunnelMode.HeadlessVK;
tab.platform = platform;
const cookieStr = isTelemost
? await this.getYandexCookieString()
: await this.getVKCookieString();
if (!cookieStr) {
const name = isTelemost ? 'Yandex' : 'VK';
this.sendLog(tabId, `No ${name} cookies found. Please log into ${name} first.`);
return;
}
this.killRelay(tabId, tab);
const binaryPath = isTelemost ? this.headlessTelemostPath : this.headlessVKPath;
const proc = spawn(binaryPath, ['--cookie-string', cookieStr, '--resources', 'default'], {
stdio: ['ignore', 'pipe', 'pipe'],
});
tab.relay = proc;
this.attachProcessOutput(proc, tabId);
proc.on('close', (code) => {
this.sendLog(tabId, `Headless exited with code ${code}`);
});
}
killRelay(tabId: string, tab: TabState): void {
if (tab.relay) {
console.log(`[${tabId}] killing process pid=${tab.relay.pid}`);
tab.relay.kill();
tab.relay = null;
}
}
killAllRelays(): void {
this.tabs.forEach((tab, tabId) => this.killRelay(tabId, tab));
}
async loadHook(tabId: string, url: string, tab: TabState): Promise<string> {
const isTelemost = url.includes('telemost.yandex');
const newPlatform = isTelemost ? Platform.Telemost : Platform.VK;
if (newPlatform !== tab.platform && tab.tunnelMode === TunnelMode.PionVideo) {
tab.platform = newPlatform;
this.killRelay(tabId, tab);
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
} else {
tab.platform = newPlatform;
}
if (tab.tunnelMode === TunnelMode.PionVideo) {
const hookFile = isTelemost ? 'video-telemost.js' : 'video-vk.js';
const hook = await fs.readFile(path.join(this.hooksDir, hookFile), 'utf8');
return LOG_CAPTURE_SNIPPET + `window.PION_PORT=${tab.pionPort};window.IS_CREATOR=true;` + hook;
}
const hookFile = isTelemost ? 'dc-creator-telemost.js' : 'dc-creator-vk.js';
const hook = await fs.readFile(path.join(this.hooksDir, hookFile), 'utf8');
return LOG_CAPTURE_SNIPPET + `window.WS_PORT=${tab.dcPort};` + hook;
}
setTunnelMode(tabId: string, mode: TunnelMode): void {
const tab = this.tabs.get(tabId);
if (!tab) return;
tab.tunnelMode = mode;
this.killRelay(tabId, tab);
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
}
async getVKCookieString(): Promise<string> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
const vkCookies = all.filter((cookie) => {
return cookie.domain != null && VK_COOKIE_DOMAINS.some((d) => cookie.domain!.includes(d));
});
return vkCookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');
}
async getYandexCookieString(): Promise<string> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
const yaCookies = all.filter((cookie) => {
return cookie.domain != null && YANDEX_COOKIE_DOMAINS.some((d) => cookie.domain!.includes(d));
});
return yaCookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');
}
}
+137
View File
@@ -0,0 +1,137 @@
import { app, BrowserWindow, session, Session } from 'electron';
import * as path from 'path';
import { TabManager } from './tab-manager';
import { VkAutoclick } from '../autoclick/vk';
import { TelemostAutoclick } from '../autoclick/telemost';
import { SESSION_PARTITION, USER_AGENT, WINDOW_WIDTH, WINDOW_HEIGHT } from '../constants';
import { Platform, CallStatus } from '../types';
function stripCSP(ses: Session): void {
ses.webRequest.onHeadersReceived((details, callback) => {
const headers = { ...details.responseHeaders };
delete headers['content-security-policy'];
delete headers['Content-Security-Policy'];
delete headers['content-security-policy-report-only'];
delete headers['Content-Security-Policy-Report-Only'];
callback({ responseHeaders: headers });
});
}
function parseCallStatus(msg: string): { tabId: string; status: CallStatus } | null {
const prefix = '[CALL_STATUS] ';
const idx = msg.indexOf(prefix);
if (idx === -1) return null;
const parts = msg.substring(idx + prefix.length);
const colonIdx = parts.indexOf(':');
if (colonIdx === -1) return null;
const status = parts.substring(colonIdx + 1);
return {
tabId: parts.substring(0, colonIdx),
status: status === CallStatus.Active ? CallStatus.Active : CallStatus.Inactive,
};
}
function extractCallLink(msg: string, prefix: string): string | null {
const idx = msg.indexOf(prefix);
if (idx === -1) return null;
return msg.split(prefix)[1].trim();
}
export function createWindow(tabManager: TabManager): BrowserWindow {
const ses = session.fromPartition(SESSION_PARTITION);
stripCSP(ses);
ses.setPermissionRequestHandler((_wc, _perm, cb) => cb(true));
ses.setPermissionCheckHandler(() => true);
ses.setUserAgent(USER_AGENT);
app.on('session-created', stripCSP);
const win = new BrowserWindow({
width: WINDOW_WIDTH,
height: WINDOW_HEIGHT,
icon: path.join(__dirname, '..', '..', 'resources', 'icon.png'),
webPreferences: {
preload: path.join(__dirname, '..', 'preload', 'index.js'),
nodeIntegration: true,
contextIsolation: false,
webviewTag: true,
},
});
win.loadFile('index.html');
win.on('closed', () => {
tabManager.mainWindow = null;
});
const autoclickers = new Map<number, { telemost: TelemostAutoclick; vk: VkAutoclick }>();
win.webContents.on('did-attach-webview', (_e, wvContents) => {
wvContents.on('before-input-event', (_e, input) => {
if (input.key === 'F12') wvContents.openDevTools();
});
wvContents.on('did-navigate', (_e, url) => {
const wcId = wvContents.id;
if (!autoclickers.has(wcId)) {
autoclickers.set(wcId, {
telemost: new TelemostAutoclick(),
vk: new VkAutoclick(),
});
}
const ac = autoclickers.get(wcId)!;
if (url.includes('telemost.yandex')) {
ac.vk.stop();
ac.telemost.attach(wvContents);
} else if (url.includes('vk.com')) {
ac.telemost.stop();
ac.vk.attach(wvContents);
} else {
ac.telemost.stop();
ac.vk.stop();
}
});
wvContents.on('console-message', (_e, _level, msg) => {
if (msg.includes('state: disconnected') || msg.includes('state: failed')) {
const ac = autoclickers.get(wvContents.id);
if (ac) ac.vk.kickDisconnected();
}
handleBotCallLink(tabManager, msg, Platform.VK, '[BOT] VKCalls: call link:');
handleBotCallLink(tabManager, msg, Platform.Telemost, '[BOT] Telemost: call link:');
const callStatus = parseCallStatus(msg);
if (callStatus) {
console.log('[MAIN] Cached status for', callStatus.tabId, ':', callStatus.status);
tabManager.setCallStatus(callStatus.tabId, callStatus.status);
}
});
wvContents.on('destroyed', () => {
const ac = autoclickers.get(wvContents.id);
if (ac) {
ac.telemost.stop();
ac.vk.stop();
autoclickers.delete(wvContents.id);
}
});
});
return win;
}
function handleBotCallLink(
tabManager: TabManager,
msg: string,
platform: Platform,
prefix: string,
): void {
const link = extractCallLink(msg, prefix);
if (!link) return;
console.log(`[MAIN] ${platform} call link captured:`, link);
const peerId = tabManager.findBotPeerId(platform);
if (peerId != null && tabManager.botManager) {
console.log(`[MAIN] Sending ${platform} link to peer:`, peerId);
tabManager.botManager.sendMessage(peerId, `Call created!\n ${link}`);
}
}