Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
import EventEmitter from "events"; import { AntiCaptcha } from "./common/services/captcha"; import ILAProxy, { IProxyData, ProxyType } from "./common/net/proxy"; import { IVKAccount, IVKPureAccount } from "./types"; import { initDataStorage, DataStorage, getRandomString, checkConnection } from "./utils"; import ILAServiceCompound from "./vk/services"; import { validateAccount } from "./vk/providers/validate_account"; import { Logger } from "@utils/logger"; import { ITask } from "./vk/services/listener"; type IlaEventType = "added-accounts" | "added-proxies" | "accounts-required" | "proxies-required" | "tasks-required" | "anticaptcha-required" | "auth-started" | "auth-stoped" | "auth-completed" | "auth-error" | "connection-failed" | "anticaptcha-updated"; class ILAEventEmitter extends EventEmitter { public on = (event: IlaEventType, fn: (...args: any[]) => void) => super.on(event, fn); public emit = (event: IlaEventType, ...args: any[]) => super.emit(event, ...args); } export class Application extends ILAEventEmitter { private inited = false; private serverConnected = false; private storage: DataStorage; private services: ILAServiceCompound; private authHandler = { error: (error) => { Logger.error("[auth_error]:", error); this.emit("auth-error", error); }, complete: (accounts) => { let invalidCount = 0; accounts.forEach(({ login, password, session }) => { const pure = { login, password }; if (!session?.valid) { invalidCount++; return this.deleteAccount(pure); } const account = this.findAccount(pure) as (IVKAccount | undefined); if (!account) return; account.session = session; }); this.storage.accounts.save(); this.emit("auth-completed", { invalid: invalidCount, total: accounts.length }); }, started: count => this.emit("auth-started", count), stoped: count => this.emit("auth-stoped", count) } private listenerHandler = { started: (...args) => { Logger.log("Listener started event:", ...args) }, stoped: (...args) => { Logger.log("Listener stoped event:", ...args) }, error: (error) => { Logger.error("Listener error:", error) }, "task-completed": (...args) => { Logger.log("Task completed:", ...args) } } public constructor() { super(); this.services = new ILAServiceCompound(); this.storage = initDataStorage(); this.services.authenticator.setHandler((type, payload) => { if (!this.authHandler[type]) return Logger.warn("Unhandled authorization response type:", type); this.authHandler[type](payload); }); this.services.listener.setHandler((type, payload) => { if (!this.listenerHandler[type]) return Logger.warn("Unhandled listener response type:", type); this.listenerHandler[type](payload); }) } public get isConnectionEstabilished() { return this.serverConnected; } public async init() { if (this.inited) return Promise.resolve(); await this.storage.read(); const { systemProxy } = this.storage.cache.data.settings; globalThis.SYSTEM_PROXY_DATA = systemProxy; this.storage.on("error", error => Logger.error("Storage error:", error)); this.storage.on("restored", (data: any) => Logger.log(`File "${data.file.name}" content restored.`)); this.on("added-accounts", () => this.startAuthenticator()); this.on("added-proxies", () => this.services.authenticator.setProxies(this.storage.proxies.data)) this.on("anticaptcha-updated", key => this.services.authenticator.setAntiCaptchaKey(key)); } public async start() { const { systemProxy } = this.getSettings(); const result = await checkConnection(systemProxy && ILAProxy.from(systemProxy)); if (!result) { this.serverConnected = false; Logger.warn("Failed connection to the vk.com, mail. System proxy required"); return this.emit("connection-failed"); } this.serverConnected = true; Logger.log("Success connection to the vk.com, mail.ru"); } public stop() { } public reset() { } public getAuthorizationStatus() { return this.services.authenticator.isRunning; } public async startAuthenticator() { const { antiCaptchaKey } = this.getSettings(); if (!this.serverConnected) { return this.emit("connection-failed"); } const accounts = this.getAccounts({ authorized: false }); if (!accounts.length) return; const proxies = this.storage.proxies.data; if (!proxies.length) { return this.emit("proxies-required"); } if (!antiCaptchaKey) { return this.emit("anticaptcha-required"); } Logger.log("Starting authenticator..."); this.services.authenticator.setAntiCaptchaKey(antiCaptchaKey); this.services.authenticator.setProxies(proxies); this.services.authenticator.setAccounts(accounts); this.services.authenticator.start() .catch(error => this.emit("auth-error", error)); return true; } public stopAuthenticator() { this.services.authenticator.stop(); } public startListener() { const { tasks } = this.storage.cache.data; const accounts = this.getAccounts({ authorized: true }); const proxies = this.storage.proxies.data; if (!this.serverConnected) { return this.emit("connection-failed"); } if (!accounts.length) { return this.emit("accounts-required"); } if (!tasks.length) { return this.emit("tasks-required"); } if (!proxies.length) { return this.emit("proxies-required"); } Logger.log("Listener starting..."); const { listener } = this.services; listener.setTasks(tasks); listener.setAccounts(accounts); return listener.start(); } public async stopListener() { const { listener } = this.services; await listener.stop(); } public getListenerTasks() { return this.storage.cache.data.tasks; } public getListenerStatus() { return this.services.listener.isRunning; } public addAccountsString(text: string) { const pattern = /(\S+):(\S+)/; const dirtAccounts = text.trim().split("\n").map(line => { const result = line.match(pattern); if (!result) return false; const [, login, password] = result!; return { login, password }; }) const pureAccounts = dirtAccounts.filter(a => a) as IVKPureAccount[]; this.addAccounts(pureAccounts); return { total: dirtAccounts.length, added: pureAccounts.length } } private addAccounts(elementOrArray: IVKPureAccount | IVKPureAccount[]) { const { accounts } = this.storage; let oldSize = accounts.data.length; (Array.isArray(elementOrArray)) ? elementOrArray.forEach(this.addUniqueAccount.bind(this)) : this.addUniqueAccount(elementOrArray); accounts.save(); const newAccounts = accounts.data.slice(oldSize, accounts.data.length); this.emit("added-accounts", newAccounts); return this; } private addUniqueAccount(account: IVKPureAccount) { const accountsFile = this.storage.accounts; const result = this.findAccount(account); if (result) return false; this.normalizeAccount(account); accountsFile.data.push(account); return true; } private findAccount(account: IVKPureAccount, returnIndex = false) { const { data } = this.storage.accounts; const predicate = a => a.login == account.login && a.password == account.password; return returnIndex ? data.findIndex(predicate) : data.find(predicate); } private normalizeAccount(account: IVKAccount) { account.session = { cookies: {}, valid: true } return account; } private deleteAccount(account: IVKPureAccount) { const index = this.findAccount(account, true) as number; if (index == -1) return false; this.storage.accounts.data.splice(index, 1); return true; } private deleteInvalidAccounts() { const invalidAccounts = this.getInvalidAccounts(); const invalidCount = invalidAccounts.length; if (!invalidAccounts.length) return null; const deletedCount = invalidAccounts .map(this.deleteAccount.bind(this)) .filter(status => status) .length; return Object.freeze({ invalidCount, deletedCount }); } public clearAccounts() { this.storage.accounts.data = []; return this.storage.accounts.save(); } public clearSessions() { const accountsFile = this.storage.accounts; const accounts = accountsFile.data; accounts.forEach(account => delete account.session); return accountsFile.save(); } public validateAccounts(accounts = this.getAuthorizedAccounts()) { const pure = accounts.filter(validateAccount); return Promise.all(pure); } public getAccounts(filter?: { authorized?: boolean }): IVKAccount[] { if (!filter) return this.storage.accounts.data; if (filter.authorized != undefined) { return !filter.authorized ? this.getUnauthorizedAccounts() : this.getAuthorizedAccounts(); } return this.storage.accounts.data; } private getUnauthorizedAccounts = (accounts = this.getAccounts()) => accounts.filter(account => this.isValidAccount(account) && !this.isAuthorizedAccount(account)); private getInvalidAccounts = (accounts = this.getAccounts()) => accounts.filter(account => !this.isValidAccount(account)); private getAuthorizedAccounts = (accounts = this.getAccounts()) => accounts.filter(this.isAuthorizedAccount); private isAuthorizedAccount = (account: IVKAccount) => account.session && account.session?.valid && account.session?.cookies?.base; private isValidAccount = (account: IVKAccount) => account.session?.valid; public addProxies(type: ProxyType, content: string) { const lines = content.trim().split("\n"); const proxies = lines.map(line => { const proxy = ILAProxy.fromString(type, line).getProxyData(); const finded = this.findProxy(proxy); return finded ? false : proxy; }).filter(proxy => proxy) as IProxyData[]; this.storage.proxies.data = [ ...this.getProxies(), ...proxies ]; this.storage.proxies.save(); this.emit("added-proxies"); return true; } private findProxy(proxy: IProxyData) { return this.storage.proxies.data.find(a => { return a.address == proxy.address && a.port == proxy.port && a.type == proxy.type; }); } public deleteProxy() { } public clearProxies() { } public getProxies() { return this.storage.proxies.data; } public validateProxy() { } public validateProxies() { } public addTask(data: any) { const task: ITask = { enable: true, id: getRandomString(16), monetize: true, performed: false, playlist: data.playlist, progress: { initial: data.playlist.listens, actual: data.playlist.listens, target: data.playlist.listens + data.totalCount }, speed: 0 } const cache = this.storage.cache.data; cache.tasks.push(task); this.storage.cache.save() .then(() => Logger.log("addTask(): cache saved...")) .catch(error => Logger.error("addTask(): cache saving error:", error)); this.startListener(); return; } public reloadTask() { } public reloadTasks() { } public deleteTask(id: string) { const { listener } = this.services; if (listener.isRunning) { return this.services.listener.deleteTask(id); } const cache = this.storage.cache.data const index = cache.tasks.findIndex(task => task.id == id); if (index == -1) { throw new Error("Task with specify id not found"); } cache.tasks.splice(index, 1); return this.storage.cache.save(); } public clearTasks() { } public getTasks() { return this.storage.cache.data.tasks } public validateTasks() { } public getHistory() { return this.storage.cache.data.tasksHistory; } public clearHistory() { } public async setAnticaptcha(key: string) { const { settings } = this.storage.cache.data; if (settings.antiCaptchaKey == key) return true; const valid = await AntiCaptcha.isValidKey(key); if (!valid) throw new Error("Key is invalid"); AntiCaptcha.setKey(key); settings.antiCaptchaKey = key; this.storage.cache.save(); this.emit("anticaptcha-updated", key); return true; } public getAnticaptcha() { return this.storage.cache.data.settings.antiCaptchaKey; } public getSettings() { const { cache } = this.storage; return cache.data.settings; } public async setSystemProxy(type: ProxyType, proxyString: string) { try { const { cache } = this.storage; const proxy = ILAProxy.fromString(type, proxyString); const connected = await checkConnection(proxy); if (!connected) return false; this.serverConnected = true; cache.data.settings.systemProxy = proxy.getProxyData(); globalThis.SYSTEM_PROXY_DATA = proxy.getProxyData(); return cache.save(); } catch (error) { this.serverConnected = false; return false; } } public save() { return this.storage.save(); } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
13 hours ago | 0.16 KB
settings
13 hours ago | 0.10 KB
IT & AI
22 hours ago | 1.62 KB
Stationeers - Sign Tags from Power Distributi...
HTML | 1 day ago | 2.00 KB
PM: Shopify Client Edits
1 day ago | 0.19 KB
PM: Shopify Assigning Design Task 2
1 day ago | 0.14 KB
PM: Shopify Assigning Design Task 1
1 day ago | 0.32 KB
Commodore Callback 8020
1 day ago | 0.18 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!