* 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

+251
View File
@@ -0,0 +1,251 @@
import { Platform, Bridge, LogPanel, Webview } from '../types';
import { SESSION_PARTITION, HOOK_POLL_INTERVAL_MS, CALL_CREATOR_INJECT_DELAY_MS } from '../constants';
import { RendererTabManager } from './tab-manager';
declare const window: Window & { bridge: Bridge };
export function renderTabs(tm: RendererTabManager): void {
const bar = document.getElementById('tabBar')!;
let html = '';
Object.keys(tm.tabs).forEach((id) => {
const tab = tm.tabs[id];
const label = tm.getTabLabel(tab);
const cls = id === tm.activeTabId ? 'tab active' : 'tab';
html +=
`<div class="${cls}" data-tab-id="${id}">` +
`<span class="tab-label">${escapeHtml(label)}</span>` +
`<img class="edit" src="resources/icons8-pencil-50.png" data-action="rename">` +
` <span class="close" data-action="close">&#x2715;</span></div>`;
});
html += '<div class="tab-add" data-action="add-tab" title="New tab">+</div>';
bar.innerHTML = html;
}
export function renderContent(tm: RendererTabManager): void {
const content = document.getElementById('content')!;
const welcome = document.getElementById('welcome')!;
const toolbar = document.getElementById('toolbar')!;
const logsPanel = document.getElementById('logsPanel')!;
const headlessInfo = document.getElementById('headlessInfo')!;
const webviews = content.querySelectorAll('webview');
webviews.forEach((wv) => wv.classList.add('hidden'));
if (!tm.activeTabId || !tm.tabs[tm.activeTabId]) {
welcome.style.display = 'flex';
toolbar.style.display = 'none';
logsPanel.style.display = 'none';
return;
}
welcome.style.display = 'none';
logsPanel.style.display = 'flex';
const activeTab = tm.tabs[tm.activeTabId];
if (activeTab.headless) {
toolbar.style.display = 'none';
headlessInfo.style.display = 'block';
const title = activeTab.platform === Platform.Telemost ? 'Headless Telemost' : 'Headless VK';
document.getElementById('headlessTitle')!.textContent = title;
document.getElementById('headlessStatus')!.textContent = activeTab.headlessStatus || 'Starting...';
const callInfo = activeTab.callInfo;
const isTelemost = activeTab.platform === Platform.Telemost;
const callInfoVK = document.getElementById('headlessCallInfo')!;
const callInfoTM = document.getElementById('headlessCallInfoTM')!;
if (callInfo && isTelemost) {
callInfoVK.style.display = 'none';
callInfoTM.style.display = 'block';
document.getElementById('headlessTMJoinLink')!.textContent = callInfo.joinLink || '';
document.getElementById('headlessTMProtocol')!.textContent = callInfo.protocol || '';
} else if (callInfo) {
callInfoTM.style.display = 'none';
callInfoVK.style.display = 'block';
document.getElementById('headlessJoinLink')!.textContent = callInfo.joinLink || '';
document.getElementById('headlessShortLink')!.textContent = callInfo.shortLink || '';
document.getElementById('headlessTurn')!.textContent = callInfo.turn || '';
document.getElementById('headlessProtocol')!.textContent = callInfo.protocol || '';
} else {
callInfoVK.style.display = 'none';
callInfoTM.style.display = 'none';
}
} else {
toolbar.style.display = 'flex';
headlessInfo.style.display = 'none';
(document.getElementById('modeSelect') as HTMLSelectElement).value = activeTab.mode;
if (activeTab.wv) activeTab.wv.classList.remove('hidden');
}
document.getElementById('relayLog')!.textContent = activeTab.relayLogs || '';
document.getElementById('hookLog')!.textContent = activeTab.hookLogs || '';
scrollLogs();
renderBotButton(tm);
}
export function renderBotButton(tm: RendererTabManager): void {
const btn = document.getElementById('tabBot')!;
btn.textContent = tm.botRunning ? 'Bot: On' : 'Bot: Off';
btn.classList.toggle('running', tm.botRunning);
}
export function scrollLogs(): void {
const relayEl = document.getElementById('relayLog');
const hookEl = document.getElementById('hookLog');
if (relayEl) relayEl.scrollTop = relayEl.scrollHeight;
if (hookEl) hookEl.scrollTop = hookEl.scrollHeight;
}
export function loadURL(tm: RendererTabManager, url: string): void {
if (!tm.activeTabId) return;
const activeTab = tm.tabs[tm.activeTabId];
if (activeTab.wv) activeTab.wv.remove();
const webview = document.createElement('webview') as unknown as Webview;
webview.setAttribute('src', url);
webview.setAttribute('partition', SESSION_PARTITION);
webview.setAttribute('nodeintegration', '');
webview.setAttribute('nodeintegrationinsubframes', '');
webview.classList.add('webview-full');
webview.dataset.tabId = tm.activeTabId;
document.getElementById('content')!.appendChild(webview);
webview.addEventListener('dom-ready', () => {
webview.setAudioMuted(true);
const currentTabId = webview.dataset.tabId!;
window.bridge.getHookCode(currentTabId, webview.getURL()).then((code: string) => {
webview.executeJavaScript(code).catch(() => {});
});
window.bridge.getCallCreatorCode('call-checker.js').then((checkerCode: string) => {
const inject = `window.__CALL_CHECKER_TAB_ID = "${currentTabId}"; ${checkerCode}`;
webview.executeJavaScript(inject).catch(() => {});
});
const tabState = tm.tabs[currentTabId];
if (tabState?.isBot) {
setTimeout(() => {
const scriptFile = tabState.platform === Platform.Telemost ? 'tm-call-creator.js' : 'vk-call-creator.js';
window.bridge.getCallCreatorCode(scriptFile).then((code: string) => {
webview.executeJavaScript(code).catch(() => {});
});
}, CALL_CREATOR_INJECT_DELAY_MS);
}
});
webview.addEventListener('did-navigate', () => {
activeTab.url = webview.getURL() || activeTab.url;
renderTabs(tm);
const currentTabId = webview.dataset.tabId!;
webview.executeJavaScript('window.__hookInstalled = false').catch(() => {});
window.bridge.getHookCode(currentTabId, webview.getURL()).then((code: string) => {
webview.executeJavaScript(code).catch(() => {});
});
window.bridge.getCallCreatorCode('call-checker.js').then((checkerCode: string) => {
const inject = `window.__CALL_CHECKER_TAB_ID = "${currentTabId}"; ${checkerCode}`;
webview.executeJavaScript(inject).catch(() => {});
});
});
activeTab.wv = webview;
activeTab.url = url;
renderTabs(tm);
}
export function startHookLogPoller(tm: RendererTabManager): void {
setInterval(() => {
if (!tm.activeTabId || !tm.tabs[tm.activeTabId]?.wv) return;
const webview = tm.tabs[tm.activeTabId].wv!;
webview
.executeJavaScript(
'(window.__hookLogs && window.__hookLogs.length) ? window.__hookLogs.splice(0) : []',
)
.then((logs: string[]) => {
if (!logs.length) return;
const el = document.getElementById('hookLog')!;
logs.forEach((msg) => {
if (el.textContent!.length > 0) el.textContent += '\n';
el.textContent += msg.replace('[HOOK] ', '');
});
el.scrollTop = el.scrollHeight;
})
.catch(() => {});
}, HOOK_POLL_INTERVAL_MS);
}
function escapeHtml(str: string): string {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
export function showError(msg: string): void {
document.getElementById('errorText')!.textContent = msg;
document.getElementById('errorPopup')!.classList.add('visible');
}
export function closeError(): void {
document.getElementById('errorPopup')!.classList.remove('visible');
}
export function clearLog(panel: LogPanel): void {
const id = panel === LogPanel.Relay ? 'relayLog' : 'hookLog';
document.getElementById(id)!.textContent = '';
}
export function saveLogs(): void {
const relay = document.getElementById('relayLog')!.textContent || '';
const hook = document.getElementById('hookLog')!.textContent || '';
const text = '=== RELAY ===\n' + relay + '\n\n=== HOOK ===\n' + hook;
const blob = new Blob([text], { type: 'text/plain' });
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(blob);
anchor.download = 'tunnel-logs-' + new Date().toISOString().replace(/[:.]/g, '-') + '.txt';
anchor.click();
URL.revokeObjectURL(anchor.href);
}
export function exportCookies(domain: string, filename: string, errorMsg: string): void {
window.bridge.getCookies(domain).then((cookies) => {
if (!cookies.length) {
showError(errorMsg);
return;
}
const simple = cookies.map((cookie) => ({ name: cookie.name, value: cookie.value }));
const blob = new Blob([JSON.stringify(simple, null, 2)], { type: 'application/json' });
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(blob);
anchor.download = filename;
anchor.click();
URL.revokeObjectURL(anchor.href);
});
}
export function copyToClipboard(text: string): void {
navigator.clipboard.writeText(text);
}
export function renameTab(tm: RendererTabManager, tabId: string, tabEl: HTMLElement): void {
const span = tabEl.querySelector('.tab-label') as HTMLElement;
if (!span) return;
const input = document.createElement('input');
input.type = 'text';
input.value = tm.tabs[tabId]?.name || '';
input.placeholder = tm.getTabLabel(tm.tabs[tabId]);
input.className = 'tab-rename-input';
span.replaceWith(input);
input.focus();
input.select();
const done = () => {
if (tm.tabs[tabId]) {
tm.tabs[tabId].name = input.value.trim();
}
renderTabs(tm);
};
input.addEventListener('blur', done);
input.addEventListener('keydown', (ev) => {
if (ev.key === 'Enter') input.blur();
if (ev.key === 'Escape') {
input.value = '';
input.blur();
}
});
}
+172
View File
@@ -0,0 +1,172 @@
import { RendererTabManager } from './tab-manager';
import {
renderTabs,
renderContent,
renderBotButton,
loadURL,
startHookLogPoller,
showError,
closeError,
clearLog,
saveLogs,
exportCookies,
copyToClipboard,
renameTab,
} from './dom';
import { VK_IM_URL, TELEMOST_URL } from '../constants';
import { Platform, Bridge, BotTabData, LogPanel, TunnelMode } from '../types';
declare const window: Window & { bridge: Bridge };
const tm = new RendererTabManager(() => {
renderTabs(tm);
renderContent(tm);
});
function bindTabBarEvents(): void {
document.getElementById('tabBar')!.addEventListener('click', (event) => {
const target = event.target as HTMLElement;
const action = target.dataset.action;
const tabEl = target.closest('[data-tab-id]') as HTMLElement | null;
const tabId = tabEl?.dataset.tabId;
if (action === 'add-tab') {
tm.createTab();
return;
}
if (action === 'close' && tabId) {
event.stopPropagation();
tm.closeTab(tabId);
return;
}
if (action === 'rename' && tabId) {
event.stopPropagation();
renameTab(tm, tabId, tabEl!);
return;
}
if (tabId) {
tm.selectTab(tabId);
}
});
}
function bindToolbarEvents(): void {
document.getElementById('btnVk')!.addEventListener('click', () => loadURL(tm, VK_IM_URL));
document.getElementById('btnTelemost')!.addEventListener('click', () => loadURL(tm, TELEMOST_URL));
document.getElementById('btnHeadlessVK')!.addEventListener('click', () => tm.switchToHeadless(Platform.VK));
document.getElementById('btnHeadlessTM')!.addEventListener('click', () => tm.switchToHeadless(Platform.Telemost));
document.getElementById('modeSelect')!.addEventListener('change', (event) => {
tm.setTunnelMode((event.target as HTMLSelectElement).value);
});
document.getElementById('btnSaveLogs')!.addEventListener('click', saveLogs);
}
function bindActionBarEvents(): void {
document.getElementById('btnVkCookies')!.addEventListener('click', () => {
exportCookies('.vk.com', 'vk-cookies.json', 'No VK cookies found.\nPlease log into VK first.');
});
document.getElementById('btnYandexCookies')!.addEventListener('click', () => {
exportCookies(
'yandex',
'cookies-yandex.json',
'No Yandex cookies found.\nPlease log into Yandex (telemost.yandex.ru) first.',
);
});
document.getElementById('btnSettings')!.addEventListener('click', openSettings);
document.getElementById('tabBot')!.addEventListener('click', () => {
if (!tm.botSettings.token || !tm.botSettings.groupId) {
openSettings();
return;
}
tm.toggleBot();
});
}
function bindSettingsEvents(): void {
document.getElementById('btnSettingsCancel')!.addEventListener('click', closeSettings);
document.getElementById('btnSettingsSave')!.addEventListener('click', () => {
tm.botSettings.token = (document.getElementById('vkToken') as HTMLInputElement).value.trim();
tm.botSettings.groupId = (document.getElementById('vkGroupId') as HTMLInputElement).value.trim();
tm.botSettings.userId = (document.getElementById('vkUserId') as HTMLInputElement).value.trim();
tm.saveBotSettings();
closeSettings();
});
}
function bindErrorPopup(): void {
document.getElementById('errorPopup')!.addEventListener('click', closeError);
document.querySelector('#errorPopup .popup')!.addEventListener('click', (event) => event.stopPropagation());
document.getElementById('btnErrorClose')!.addEventListener('click', closeError);
}
function bindLogEvents(): void {
document.getElementById('btnClearRelay')!.addEventListener('click', () => clearLog(LogPanel.Relay));
document.getElementById('btnClearHook')!.addEventListener('click', () => clearLog(LogPanel.Hook));
}
function bindHeadlessEvents(): void {
document.getElementById('headlessJoinLink')!.addEventListener('click', (event) => {
copyToClipboard((event.target as HTMLElement).textContent || '');
});
document.getElementById('headlessShortLink')!.addEventListener('click', (event) => {
copyToClipboard((event.target as HTMLElement).textContent || '');
});
document.getElementById('headlessInfo')!.addEventListener('click', (event) => {
const target = event.target as HTMLElement;
const copyTarget = target.dataset.copy;
if (copyTarget) {
const sourceEl = document.getElementById(copyTarget);
if (sourceEl) copyToClipboard(sourceEl.textContent || '');
}
});
}
function openSettings(): void {
document.getElementById('settingsPopup')!.classList.add('visible');
(document.getElementById('vkToken') as HTMLInputElement).value = tm.botSettings.token;
(document.getElementById('vkGroupId') as HTMLInputElement).value = tm.botSettings.groupId;
(document.getElementById('vkUserId') as HTMLInputElement).value = tm.botSettings.userId;
}
function closeSettings(): void {
document.getElementById('settingsPopup')!.classList.remove('visible');
}
function init(): void {
bindTabBarEvents();
bindToolbarEvents();
bindActionBarEvents();
bindSettingsEvents();
bindErrorPopup();
bindLogEvents();
bindHeadlessEvents();
window.bridge.onRelayLog((tabId: string, msg: string) => {
tm.appendRelayLog(tabId, msg);
});
window.bridge.onBotError((msg: string) => {
showError(msg);
tm.botRunning = false;
localStorage.setItem('botEnabled', 'false');
renderBotButton(tm);
});
window.bridge.onCreateBotTab((data: BotTabData) => {
tm.createBotTab(data);
(document.getElementById('modeSelect') as HTMLSelectElement).value = data.mode;
window.bridge.setTunnelMode(data.tabId, data.mode);
const url = data.platform === Platform.Telemost ? TELEMOST_URL : VK_IM_URL;
loadURL(tm, url);
});
window.bridge.onCloseBotTab((data: { tabId: string }) => {
tm.closeTab(data.tabId);
});
startHookLogPoller(tm);
tm.autoStartBot();
renderBotButton(tm);
}
init();
+213
View File
@@ -0,0 +1,213 @@
import { RendererTab, BotTabData, BotSettings, TunnelMode, Platform, Bridge } from '../types';
import { HeadlessLogMarker } from '../constants';
declare const window: Window & { bridge: Bridge };
export class RendererTabManager {
tabs: Record<string, RendererTab> = {};
activeTabId: string | null = null;
private nextId = 1;
botRunning = false;
botSettings: BotSettings;
private onRender: () => void;
constructor(onRender: () => void) {
this.onRender = onRender;
const saved = localStorage.getItem('botSettings');
this.botSettings = saved
? JSON.parse(saved)
: { token: '', groupId: '', userId: '' };
}
createTab(): string {
const tabId = 'tab-' + this.nextId++;
this.tabs[tabId] = {
wv: null,
url: '',
mode: TunnelMode.DC,
relayLogs: '',
hookLogs: '',
name: '',
isBot: false,
};
window.bridge.startRelay(tabId);
this.selectTab(tabId);
return tabId;
}
switchToHeadless(platform: Platform): void {
if (!this.activeTabId) return;
const tab = this.tabs[this.activeTabId];
if (tab.wv) tab.wv.remove();
const isTelemost = platform === Platform.Telemost;
tab.wv = null;
tab.url = '';
tab.mode = isTelemost ? TunnelMode.HeadlessTelemost : TunnelMode.HeadlessVK;
tab.name = isTelemost ? 'Headless TM' : 'Headless VK';
tab.headless = true;
tab.platform = platform;
tab.callInfo = undefined;
tab.headlessStatus = 'Starting...';
tab.tunnelConnected = false;
tab.relayLogs = '';
tab.hookLogs = '';
window.bridge.startHeadless(this.activeTabId, platform);
this.onRender();
}
createBotTab(data: BotTabData): void {
if (!this.tabs[data.tabId]) {
const botName = data.platform === Platform.Telemost ? 'Bot-Telemost' : 'Bot-VK';
this.tabs[data.tabId] = {
wv: null,
url: '',
mode: data.mode,
relayLogs: '',
hookLogs: '',
name: botName,
isBot: true,
peerId: data.peerId,
platform: data.platform,
};
}
this.selectTab(data.tabId);
}
closeTab(tabId: string): void {
const tab = this.tabs[tabId];
if (tab?.wv) tab.wv.remove();
window.bridge.closeTab(tabId);
delete this.tabs[tabId];
if (this.activeTabId === tabId) {
const ids = Object.keys(this.tabs);
this.activeTabId = ids.length > 0 ? ids[ids.length - 1] : null;
}
this.onRender();
}
selectTab(tabId: string): void {
this.saveCurrentTabLogs();
this.activeTabId = tabId;
this.onRender();
}
saveCurrentTabLogs(): void {
if (this.activeTabId && this.tabs[this.activeTabId]) {
const relayEl = document.getElementById('relayLog');
const hookEl = document.getElementById('hookLog');
if (relayEl) this.tabs[this.activeTabId].relayLogs = relayEl.textContent || '';
if (hookEl) this.tabs[this.activeTabId].hookLogs = hookEl.textContent || '';
}
}
getActiveTab(): RendererTab | null {
if (!this.activeTabId) return null;
return this.tabs[this.activeTabId] || null;
}
getTabLabel(tab: RendererTab): string {
if (tab.name) return tab.name;
if (tab.url) {
if (tab.url.includes('vk.com')) return 'VK';
if (tab.url.includes('telemost')) return 'Telemost';
}
return 'New';
}
appendRelayLog(tabId: string, msg: string): void {
const tab = this.tabs[tabId];
if (!tab) return;
tab.relayLogs += (tab.relayLogs ? '\n' : '') + msg;
let rendered = false;
if (tab.headless) rendered = this.parseHeadlessLog(tabId, msg);
if (tabId === this.activeTabId && !rendered) {
const el = document.getElementById('relayLog');
if (el) {
if (el.textContent!.length > 0) el.textContent += '\n';
el.textContent += msg;
el.scrollTop = el.scrollHeight;
}
}
}
private parseHeadlessLog(tabId: string, msg: string): boolean {
const tab = this.tabs[tabId];
if (!tab) return false;
const trimmed = msg.trim();
let changed = false;
if (trimmed === HeadlessLogMarker.CALL_CREATED) {
tab.callInfo = {};
tab.headlessStatus = 'Call created';
changed = true;
}
if (trimmed.includes(HeadlessLogMarker.JOIN_LINK)) {
if (!tab.callInfo) tab.callInfo = {};
tab.callInfo.joinLink = trimmed.split(HeadlessLogMarker.JOIN_LINK)[1].trim();
changed = true;
}
if (trimmed.includes(HeadlessLogMarker.SHORT_LINK)) {
if (!tab.callInfo) tab.callInfo = {};
tab.callInfo.shortLink = trimmed.split(HeadlessLogMarker.SHORT_LINK)[1].trim();
changed = true;
}
if (trimmed.includes(HeadlessLogMarker.TURN)) {
if (!tab.callInfo) tab.callInfo = {};
tab.callInfo.turn = trimmed.split(HeadlessLogMarker.TURN)[1].trim();
changed = true;
}
if (trimmed.includes(HeadlessLogMarker.PROTOCOL)) {
if (!tab.callInfo) tab.callInfo = {};
tab.callInfo.protocol = trimmed.split(HeadlessLogMarker.PROTOCOL)[1].trim();
changed = true;
}
if (trimmed.includes('[FATAL]')) {
const fatalMessage = trimmed.split('[FATAL]')[1]?.trim() || 'fatal error';
tab.headlessStatus = 'Disconnected: ' + fatalMessage;
tab.tunnelConnected = false;
changed = true;
}
if (changed && tabId === this.activeTabId) this.onRender();
return changed;
}
setTunnelMode(mode: string): void {
if (!this.activeTabId) return;
const tab = this.tabs[this.activeTabId];
if (!tab) return;
tab.mode = mode as TunnelMode;
window.bridge.setTunnelMode(this.activeTabId, mode).then(() => {
if (tab.wv) {
tab.wv.executeJavaScript('window.__hookInstalled = false').catch(() => {});
tab.wv.reload();
}
});
}
saveBotSettings(): void {
localStorage.setItem('botSettings', JSON.stringify(this.botSettings));
}
toggleBot(): void {
if (!this.botSettings.token || !this.botSettings.groupId) return;
this.botRunning = !this.botRunning;
localStorage.setItem('botEnabled', this.botRunning ? 'true' : 'false');
if (this.botRunning) {
window.bridge.startBot(this.botSettings);
} else {
window.bridge.stopBot();
}
this.onRender();
}
autoStartBot(): void {
if (
localStorage.getItem('botEnabled') === 'true' &&
this.botSettings.token &&
this.botSettings.groupId
) {
this.botRunning = true;
window.bridge.startBot(this.botSettings);
}
}
}