Skip to content

Commit

Permalink
Fix for empty DDOS config after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
opengs committed Apr 6, 2024
1 parent 3f092b8 commit c9fdcdd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@quasar/extras": "^1.16.4",
"apexcharts": "^3.42.0",
"async-lock": "^1.4.1",
"async-mutex": "^0.5.0",
"decompress": "^4.2.1",
"electron-fetch": "^1.9.1",
"electron-updater": "^6.1.4",
Expand Down Expand Up @@ -59,4 +59,4 @@
"npm": ">= 6.13.4",
"yarn": ">= 1.21.1"
}
}
}
6 changes: 3 additions & 3 deletions package.winxp.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"private": false,
"license": "GPL-3.0",
"repository": "https://github.com/opengs/itarmykit",
"repository": "https://github.com/opengs/itarmykit-xp",
"homepage": "https://itarmy.com.ua",
"scripts": {
"lint": "eslint --ext .js,.ts,.vue ./",
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"@quasar/extras": "^1.16.4",
"apexcharts": "^3.42.0",
"async-lock": "^1.4.1",
"async-mutex": "^0.5.0",
"decompress": "^4.2.1",
"electron-fetch": "^1.9.1",
"electron-updater": "^6.1.4",
Expand All @@ -43,7 +43,7 @@
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"autoprefixer": "^10.4.2",
"electron": "^26.2.0",
"electron": "^22.3.25",
"electron-builder": "^24.3.0",
"electron-packager": "^17.1.1",
"eslint": "^8.10.0",
Expand Down
89 changes: 53 additions & 36 deletions src-electron/handlers/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs'
import path from 'path'
import { WebContents, app, ipcMain } from 'electron'
import { Mutex } from 'async-mutex'


import { Distress } from "app/lib/module/distress";
import { DB1000N } from "app/lib/module/db1000n";
Expand Down Expand Up @@ -37,42 +39,51 @@ export class ExecutionEngine {
private modules: Array<Distress | DB1000N | MHDDOSProxy> = []
private runningModule: Distress | DB1000N | MHDDOSProxy | null
private state?: State
private stateLock: Mutex = new Mutex()

private async appendToExecutionLog(entry: ExecutionLogEntry) {
const state = await this.getState()
state.executionLog.push(entry)
if (state.executionLog.length > 100) {
state.executionLog.shift()
}
await this.setState(state)
await this.stateLock.runExclusive(async () => {
const state = await this.getState()
state.executionLog.push(entry)
if (state.executionLog.length > 100) {
state.executionLog.shift()
}
await this.setState(state)
})
}

private async appendToStdOut(data: string) {
const state = await this.getState()
state.stdOut.push(data)
if (state.stdOut.length > 100) {
state.stdOut.shift()
}
await this.setState(state)
await this.stateLock.runExclusive(async () => {
const state = await this.getState()
state.stdOut.push(data)
if (state.stdOut.length > 100) {
state.stdOut.shift()
}
await this.setState(state)
})
}

private async appendToStdErr(data: string) {
const state = await this.getState()
state.stdErr.push(data)
if (state.stdErr.length > 100) {
state.stdErr.shift()
}
await this.setState(state)
await this.stateLock.runExclusive(async () => {
const state = await this.getState()
state.stdErr.push(data)
if (state.stdErr.length > 100) {
state.stdErr.shift()
}
await this.setState(state)
})
}

private async appendToStatistics(data: ModuleExecutionStatisticsEventData) {
const state = await this.getState()
state.statistics.push(data)
if (state.statistics.length > 100) {
state.statistics.shift()
}
state.statisticsTotals.totalBytesSent += data.bytesSend
await this.setState(state)
await this.stateLock.runExclusive(async () => {
const state = await this.getState()
state.statistics.push(data)
if (state.statistics.length > 100) {
state.statistics.shift()
}
state.statisticsTotals.totalBytesSent += data.bytesSend
await this.setState(state)
})
}

constructor(modules: Array<Distress | DB1000N | MHDDOSProxy>) {
Expand Down Expand Up @@ -188,12 +199,16 @@ export class ExecutionEngine {
throw new Error(`Module ${this.runningModule.name} is already running`)
}

const config = await this.getState()
const moduleName = config.moduleToRun
config.run = true
config.stdOut = []
config.stdErr = []
await this.setState(config)
let moduleName = undefined as ModuleName | undefined

await this.stateLock.runExclusive(async () => {
const config = await this.getState()
moduleName = config.moduleToRun
config.run = true
config.stdOut = []
config.stdErr = []
await this.setState(config)
})

const module = this.modules.find(m => m.name === moduleName)
if (!module) {
Expand All @@ -209,9 +224,11 @@ export class ExecutionEngine {
await this.runningModule.stop()
this.runningModule = null

const config = await this.getState()
config.run = false
await this.setState(config)
await this.stateLock.runExclusive(async () => {
const config = await this.getState()
config.run = false
await this.setState(config)
})
}
}

Expand All @@ -229,7 +246,7 @@ export class ExecutionEngine {
this.state = JSON.parse(configString) as State
} catch {
this.state = { run: false, executionLog: [] ,statistics: [], stdErr: [], stdOut: [], statisticsTotals: { totalBytesSent: 0 } } // To enable TS types
this.setState(this.state)
await this.setState(this.state)
}
}

Expand All @@ -241,7 +258,7 @@ export class ExecutionEngine {
return this.state
}

public async setState(config: State) {
private async setState(config: State) {
this.state = config
await fs.promises.mkdir(path.dirname(ExecutionEngine.stateFilePath), { recursive: true })
await fs.promises.writeFile(ExecutionEngine.stateFilePath, JSON.stringify(config))
Expand Down
12 changes: 7 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,12 @@ async-exit-hook@^2.0.1:
resolved "https://registry.yarnpkg.com/async-exit-hook/-/async-exit-hook-2.0.1.tgz#8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3"
integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==

async-lock@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/async-lock/-/async-lock-1.4.1.tgz#56b8718915a9b68b10fce2f2a9a3dddf765ef53f"
integrity sha512-Az2ZTpuytrtqENulXwO3GGv1Bztugx6TT37NIo7imr/Qo0gsYiGtSdBa2B6fsXhTpVZDNfu1Qn3pk531e3q+nQ==
async-mutex@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.5.0.tgz#353c69a0b9e75250971a64ac203b0ebfddd75482"
integrity sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==
dependencies:
tslib "^2.4.0"

async@^3.2.3, async@^3.2.4:
version "3.2.5"
Expand Down Expand Up @@ -5282,7 +5284,7 @@ tslib@^1.8.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.1.0:
tslib@^2.1.0, tslib@^2.4.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
Expand Down

0 comments on commit c9fdcdd

Please sign in to comment.