single export cookies button

This commit is contained in:
kulikov0 committed 2026-05-16 08:32:36 +02:00
1 parent b341370904
commit beccc40522
12 files changed
+158 -132

No files matched your search

+1 -4
View File
@@ -9,10 +9,7 @@
<div class="tab-add" data-action="add-tab" title="New tab">+</div>
</div>
<div class="tab-bar-actions">
<div class="tab-action-btn" id="btnVkCookies" title="Export VK cookies to vk-cookies.json for headless mode">VK Cookies</div>
<div class="tab-action-btn" id="btnYandexCookies" title="Export Yandex cookies to cookies-yandex.json for headless mode">Yandex Cookies</div>
<div class="tab-action-btn" id="btnDionCookies" title="Export DION cookies to cookies-dion.json for headless mode">DION Cookies</div>
<div class="tab-action-btn" id="btnWBStreamCookies" title="Export WB Stream cookies to cookies-wbstream.json for headless mode">WB Cookies</div>
<div class="tab-action-btn" id="btnExportCookies" title="Export all cookies to cookies.zip for headless mode">Export Cookies</div>
<div class="tab-action-btn settings" id="btnSettings" title="Settings">Settings</div>
<div class="tab-action-btn bot" id="tabBot">Bot: Off</div>
</div>
+1 -1
View File
@@ -58,7 +58,7 @@ export enum IPC {
CLOSE_TAB = 'close-tab',
START_BOT = 'start-bot',
STOP_BOT = 'stop-bot',
GET_COOKIES = 'get-cookies',
EXPORT_COOKIES_ZIP = 'export-cookies-zip',
RELAY_LOG = 'relay-log',
CREATE_BOT_TAB = 'create-bot-tab',
CLOSE_BOT_TAB = 'close-bot-tab',
+4 -22
View File
@@ -1,16 +1,9 @@
import { ipcMain, session } from 'electron';
import { ipcMain } 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,
DION_COOKIE_DOMAINS,
WBSTREAM_COOKIE_DOMAINS,
} from '../constants';
import { IPC } from '../constants';
import { TunnelMode, Platform, BotSettings, HeadlessStartArgs } from '../types';
export function registerIpcHandlers(tabManager: TabManager): void {
@@ -96,18 +89,7 @@ export function registerIpcHandlers(tabManager: TabManager): void {
tabManager.sendBotCallLink(tabId, link);
});
ipcMain.handle(IPC.GET_COOKIES, async (_e, domain: string) => {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
let domains: string[];
if (domain === 'yandex') domains = YANDEX_COOKIE_DOMAINS;
else if (domain === 'dion') domains = DION_COOKIE_DOMAINS;
else if (domain === 'wbstream') domains = WBSTREAM_COOKIE_DOMAINS;
else 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;
ipcMain.handle(IPC.EXPORT_COOKIES_ZIP, async () => {
return tabManager.buildCookiesZip();
});
}
+19 -42
View File
@@ -35,17 +35,8 @@ import {
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;
}
import { buildStoredZip } from './util/zip';
import { resolveResourcePath, binaryName } from './util/paths';
export class TabManager {
private tabs = new Map<string, TabState>();
@@ -248,7 +239,6 @@ export class TabManager {
cookieDomains: string[];
platformName: string;
binaryPath: string;
getCookies: () => Promise<{ name: string; value: string }[]>;
} | null {
switch (platform) {
case Platform.Telemost:
@@ -259,7 +249,6 @@ export class TabManager {
cookieDomains: YANDEX_COOKIE_DOMAINS,
platformName: 'Yandex',
binaryPath: this.headlessTelemostPath,
getCookies: () => this.getYandexCookies(),
};
case Platform.Dion:
return {
@@ -269,7 +258,6 @@ export class TabManager {
cookieDomains: DION_COOKIE_DOMAINS,
platformName: 'DION',
binaryPath: this.headlessDionPath,
getCookies: () => this.getDionCookies(),
};
case Platform.VK:
return {
@@ -279,7 +267,6 @@ export class TabManager {
cookieDomains: VK_COOKIE_DOMAINS,
platformName: 'VK',
binaryPath: this.headlessVKPath,
getCookies: () => this.getVKCookies(),
};
case Platform.WBStream:
return {
@@ -289,7 +276,6 @@ export class TabManager {
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
platformName: 'WB Stream',
binaryPath: this.headlessWBStreamPath,
getCookies: () => this.getWBStreamCookies(),
};
default:
return null;
@@ -325,7 +311,7 @@ export class TabManager {
return;
}
tab.tunnelMode = config.tunnelMode;
let cookies = await config.getCookies();
let cookies = await this.getCookiesForDomains(config.cookieDomains);
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
const needsLogin = !cookies.some((c) => c.name === refreshCookie);
if (needsLogin) {
@@ -343,7 +329,7 @@ export class TabManager {
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
}
this.sendLog(tabId, `${config.platformName} login captured.`);
cookies = await config.getCookies();
cookies = await this.getCookiesForDomains(config.cookieDomains);
}
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
this.killRelay(tabId, tab);
@@ -460,27 +446,11 @@ export class TabManager {
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
}
async getVKCookies(): Promise<{ name: string; value: string }[]> {
private async getCookiesForDomains(domains: string[]): Promise<{ name: string; value: string }[]> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
return all
.filter((c) => c.domain != null && VK_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
.map((c) => ({ name: c.name, value: c.value }));
}
async getYandexCookies(): Promise<{ name: string; value: string }[]> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
return all
.filter((c) => c.domain != null && YANDEX_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
.map((c) => ({ name: c.name, value: c.value }));
}
async getDionCookies(): Promise<{ name: string; value: string }[]> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
return all
.filter((c) => c.domain != null && DION_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
.filter((c) => c.domain != null && domains.some((d) => c.domain!.includes(d)))
.map((c) => ({ name: c.name, value: c.value }));
}
@@ -513,12 +483,19 @@ export class TabManager {
});
}
async getWBStreamCookies(): Promise<{ name: string; value: string }[]> {
const ses = session.fromPartition(SESSION_PARTITION);
const all = await ses.cookies.get({});
return all
.filter((c) => c.domain != null && WBSTREAM_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
.map((c) => ({ name: c.name, value: c.value }));
async buildCookiesZip(): Promise<Buffer> {
const platforms: { filename: string; domains: string[] }[] = [
{ filename: 'vk-cookies.json', domains: VK_COOKIE_DOMAINS },
{ filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS },
{ filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS },
{ filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS },
];
const cookies = await Promise.all(platforms.map((p) => this.getCookiesForDomains(p.domains)));
const entries = platforms.map((p, i) => ({
name: p.filename,
data: Buffer.from(JSON.stringify(cookies[i], null, 2), 'utf8'),
}));
return buildStoredZip(entries);
}
async setWBStreamDeviceId(id: string): Promise<void> {
+28
View File
@@ -0,0 +1,28 @@
import { CallStatus, Platform } from '../../types';
export 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,
};
}
export function extractTaggedCallLink(msg: string, platform: Platform): { tabId: string; link: string } | null {
const tag = platform === Platform.Telemost ? 'Telemost' : 'VKCalls';
const re = new RegExp('\\[BOT\\] ' + tag + '\\[([^\\]]*)\\]: call link:\\s*(.+)$');
const match = msg.match(re);
if (!match) return null;
return { tabId: match[1].trim(), link: match[2].trim() };
}
export function parseWBDeviceId(msg: string): string | null {
const match = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
return match ? match[1] : null;
}
+13
View File
@@ -0,0 +1,13 @@
import { app } from 'electron';
import * as path from 'path';
export function resolveResourcePath(devRelative: string, packedName: string): string {
if (app.isPackaged) {
return path.join(process.resourcesPath!, packedName);
}
return path.join(__dirname, '..', '..', '..', '..', devRelative);
}
export function binaryName(base: string): string {
return process.platform === 'win32' ? base + '.exe' : base;
}
+78
View File
@@ -0,0 +1,78 @@
export interface ZipEntry {
name: string;
data: Buffer;
}
const crc32Table = (() => {
const table = new Uint32Array(256);
for (let i = 0; i < 256; i++) {
let c = i;
for (let j = 0; j < 8; j++) c = (c & 1) ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
table[i] = c >>> 0;
}
return table;
})();
function crc32(buf: Buffer): number {
let c = 0xffffffff;
for (let i = 0; i < buf.length; i++) c = crc32Table[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
return (c ^ 0xffffffff) >>> 0;
}
export function buildStoredZip(entries: ZipEntry[]): Buffer {
const localChunks: Buffer[] = [];
const centralChunks: Buffer[] = [];
let offset = 0;
const dosTime = 0;
const dosDate = (1 << 5) | 1;
for (const entry of entries) {
const nameBytes = Buffer.from(entry.name, 'utf8');
const crc = crc32(entry.data);
const size = entry.data.length;
const lfh = Buffer.alloc(30);
lfh.writeUInt32LE(0x04034b50, 0);
lfh.writeUInt16LE(20, 4);
lfh.writeUInt16LE(0, 6);
lfh.writeUInt16LE(0, 8);
lfh.writeUInt16LE(dosTime, 10);
lfh.writeUInt16LE(dosDate, 12);
lfh.writeUInt32LE(crc, 14);
lfh.writeUInt32LE(size, 18);
lfh.writeUInt32LE(size, 22);
lfh.writeUInt16LE(nameBytes.length, 26);
lfh.writeUInt16LE(0, 28);
localChunks.push(lfh, nameBytes, entry.data);
const cdh = Buffer.alloc(46);
cdh.writeUInt32LE(0x02014b50, 0);
cdh.writeUInt16LE(20, 4);
cdh.writeUInt16LE(20, 6);
cdh.writeUInt16LE(0, 8);
cdh.writeUInt16LE(0, 10);
cdh.writeUInt16LE(dosTime, 12);
cdh.writeUInt16LE(dosDate, 14);
cdh.writeUInt32LE(crc, 16);
cdh.writeUInt32LE(size, 20);
cdh.writeUInt32LE(size, 24);
cdh.writeUInt16LE(nameBytes.length, 28);
cdh.writeUInt16LE(0, 30);
cdh.writeUInt16LE(0, 32);
cdh.writeUInt16LE(0, 34);
cdh.writeUInt16LE(0, 36);
cdh.writeUInt32LE(0, 38);
cdh.writeUInt32LE(offset, 42);
centralChunks.push(cdh, nameBytes);
offset += lfh.length + nameBytes.length + size;
}
const local = Buffer.concat(localChunks);
const central = Buffer.concat(centralChunks);
const eocd = Buffer.alloc(22);
eocd.writeUInt32LE(0x06054b50, 0);
eocd.writeUInt16LE(0, 4);
eocd.writeUInt16LE(0, 6);
eocd.writeUInt16LE(entries.length, 8);
eocd.writeUInt16LE(entries.length, 10);
eocd.writeUInt32LE(central.length, 12);
eocd.writeUInt32LE(local.length, 16);
eocd.writeUInt16LE(0, 20);
return Buffer.concat([local, central, eocd]);
}
+5 -26
View File
@@ -4,7 +4,8 @@ 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';
import { Platform } from '../types';
import { parseCallStatus, extractTaggedCallLink, parseWBDeviceId } from './util/log-tags';
function stripCSP(ses: Session): void {
ses.webRequest.onHeadersReceived((details, callback) => {
@@ -17,28 +18,6 @@ function stripCSP(ses: Session): void {
});
}
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 extractTaggedCallLink(msg: string, platform: Platform): { tabId: string; link: string } | null {
const tag = platform === Platform.Telemost ? 'Telemost' : 'VKCalls';
const re = new RegExp('\\[BOT\\] ' + tag + '\\[([^\\]]*)\\]: call link:\\s*(.+)$');
const match = msg.match(re);
if (!match) return null;
return { tabId: match[1].trim(), link: match[2].trim() };
}
export function createWindow(tabManager: TabManager): BrowserWindow {
const ses = session.fromPartition(SESSION_PARTITION);
stripCSP(ses);
@@ -130,9 +109,9 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
handleBotCallLink(tabManager, msg, Platform.VK);
handleBotCallLink(tabManager, msg, Platform.Telemost);
const deviceIdMatch = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
if (deviceIdMatch) {
tabManager.setWBStreamDeviceId(deviceIdMatch[1]).catch(() => {});
const deviceId = parseWBDeviceId(msg);
if (deviceId) {
tabManager.setWBStreamDeviceId(deviceId).catch(() => {});
}
const callStatus = parseCallStatus(msg);
+2 -2
View File
@@ -32,8 +32,8 @@ import { IPC } from '../constants';
onBotError(cb: (msg: string) => void) {
ipcRenderer.on(IPC.BOT_ERROR, (_e, msg) => cb(msg));
},
getCookies(domain: string) {
return ipcRenderer.invoke(IPC.GET_COOKIES, domain);
exportCookiesZip() {
return ipcRenderer.invoke(IPC.EXPORT_COOKIES_ZIP);
},
startHeadless(tabId: string, platform: string, args: any) {
return ipcRenderer.invoke(IPC.START_HEADLESS, tabId, platform, args);
+4 -9
View File
@@ -285,17 +285,12 @@ export function saveLogs(): void {
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' });
export function exportCookiesZip(): void {
window.bridge.exportCookiesZip().then((bytes) => {
const blob = new Blob([new Uint8Array(bytes)], { type: 'application/zip' });
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(blob);
anchor.download = filename;
anchor.download = 'cookies.zip';
anchor.click();
URL.revokeObjectURL(anchor.href);
});
+2 -25
View File
@@ -9,7 +9,7 @@ import {
closeError,
clearLog,
saveLogs,
exportCookies,
exportCookiesZip,
copyToClipboard,
renameTab,
attachLoginWebview,
@@ -66,30 +66,7 @@ function bindToolbarEvents(): void {
}
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('btnDionCookies')!.addEventListener('click', () => {
exportCookies(
'dion',
'cookies-dion.json',
'No DION cookies found.\nPlease log into DION (dion.vc) first.',
);
});
document.getElementById('btnWBStreamCookies')!.addEventListener('click', () => {
exportCookies(
'wbstream',
'cookies-wbstream.json',
'No WB Stream cookies found.\nPlease log into stream.wb.ru first.',
);
});
document.getElementById('btnExportCookies')!.addEventListener('click', exportCookiesZip);
document.getElementById('btnSettings')!.addEventListener('click', openSettings);
document.getElementById('tabBot')!.addEventListener('click', () => {
if (!tm.botSettings.token || !tm.botSettings.groupId) {
+1 -1
View File
@@ -141,7 +141,7 @@ export interface Bridge {
onCreateBotTab(cb: (data: BotTabData) => void): void;
getCallCreatorCode(scriptFile: string): Promise<string>;
onBotError(cb: (msg: string) => void): void;
getCookies(domain: string): Promise<Electron.Cookie[]>;
exportCookiesZip(): Promise<Uint8Array>;
startHeadless(tabId: string, platform: string, args: HeadlessStartArgs): Promise<void>;
sendBotCallLink(tabId: string, link: string): Promise<void>;
onCloseBotTab(cb: (data: { tabId: string }) => void): void;