From 2bddb4f21197ec026441f66b046c80d5cdcd5d5f Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:57:50 +0200 Subject: [PATCH 1/3] Refactor task and taskwrapper model to one file and add enum for TaskType (task or supertask) --- .../tasks-table/tasks-table.component.ts | 36 +-- .../core/_datasources/hashes.datasource.ts | 2 +- .../tasks-supertasks.datasource.ts | 3 +- src/app/core/_datasources/tasks.datasource.ts | 3 +- src/app/core/_models/task-wrapper.model.ts | 28 -- src/app/core/_models/task.model.ts | 32 ++ src/app/home/home.component.ts | 8 +- src/app/shared/graphs/graphs.module.ts | 6 +- .../task-visual/task-visual.component.ts | 298 ++++++++---------- 9 files changed, 184 insertions(+), 232 deletions(-) delete mode 100644 src/app/core/_models/task-wrapper.model.ts diff --git a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts index 41fce4927..afc7eda11 100644 --- a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts +++ b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts @@ -1,12 +1,11 @@ -import { Observable, catchError, of } from 'rxjs'; +import { catchError, Observable, of } from 'rxjs'; import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { SafeHtml } from '@angular/platform-browser'; import { ChunkData } from '@models/chunk.model'; import { JHashlist } from '@models/hashlist.model'; -import { JTaskWrapper } from '@models/task-wrapper.model'; -import { JTask } from '@models/task.model'; +import { JTask, JTaskWrapper, TaskType } from '@models/task.model'; import { TaskContextMenuService } from '@services/context-menu/tasks/task-menu.service'; import { SERV } from '@services/main.config'; @@ -32,7 +31,6 @@ import { import { TasksDataSource } from '@datasources/tasks.datasource'; -import { TaskWrapper } from '@src/app/core/_constants/userpermissions.config'; import { convertCrackingSpeed, convertToLocale } from '@src/app/shared/utils/util'; import { ModalSubtasksComponent } from '@src/app/tasks/show-tasks/modal-subtasks/modal-subtasks.component'; @@ -108,7 +106,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O return item.tasks?.some((task: JTask) => task.taskName?.toLowerCase().includes(filterValue)); case 'taskType': { - const typeText = item.taskType === 0 ? 'task' : 'supertask'; + const typeText = item.taskType === TaskType.TASK ? 'task' : 'supertask'; return typeText.includes(filterValue); } @@ -150,8 +148,8 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O { id: TaskTableCol.TASK_TYPE, dataKey: 'taskType', - render: (wrapper: JTaskWrapper) => (wrapper.taskType === 0 ? 'Task' : 'SuperTask'), - export: async (wrapper: JTaskWrapper) => (wrapper.taskType === 0 ? 'Task' : 'Supertask' + '') + render: (wrapper: JTaskWrapper) => (wrapper.taskType === TaskType.TASK ? 'Task' : 'SuperTask'), + export: async (wrapper: JTaskWrapper) => (wrapper.taskType === TaskType.TASK ? 'Task' : 'Supertask' + '') }, { id: TaskTableCol.NAME, @@ -265,10 +263,10 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O id: TaskTableCol.PREPROCESSOR, dataKey: 'preprocessorId', render: (wrapper: JTaskWrapper) => - wrapper.taskType === 0 && wrapper.tasks[0].preprocessorId === 1 ? 'Prince' : '', + wrapper.taskType === TaskType.TASK && wrapper.tasks[0].preprocessorId === 1 ? 'Prince' : '', isSortable: false, export: async (wrapper: JTaskWrapper) => - wrapper.taskType === 0 && wrapper.tasks[0].preprocessorId === 1 ? 'Prince' : '' + wrapper.taskType === TaskType.TASK && wrapper.tasks[0].preprocessorId === 1 ? 'Prince' : '' }, { id: TaskTableCol.IS_SMALL, @@ -276,7 +274,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O icon: (wrapper: JTaskWrapper) => this.renderIsSmallIcon(wrapper), isSortable: false, export: async (wrapper: JTaskWrapper) => - wrapper.taskType === 0 ? (wrapper.tasks[0].isSmall ? 'Yes' : 'No') : '' + wrapper.taskType === TaskType.TASK ? (wrapper.tasks[0].isSmall ? 'Yes' : 'No') : '' }, { id: TaskTableCol.IS_CPU_TASK, @@ -284,7 +282,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O icon: (wrapper: JTaskWrapper) => this.renderIsCpuTaskIcon(wrapper), isSortable: false, export: async (wrapper: JTaskWrapper) => - wrapper.taskType === 0 ? (wrapper.tasks[0].isCpuTask ? 'Yes' : 'No') : '' + wrapper.taskType === TaskType.TASK ? (wrapper.tasks[0].isCpuTask ? 'Yes' : 'No') : '' } ]; } @@ -328,7 +326,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O getRowDeleteLabel(data: JTaskWrapper): JTaskWrapper { return { ...data, - taskName: data.taskType === 1 ? data.taskWrapperName : data.tasks[0].taskName + taskName: data.taskType === TaskType.SUPERTASK ? data.taskWrapperName : data.tasks[0].taskName }; } @@ -338,7 +336,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O // Preprocess the data and count the occurrences of each type const updatedData: JTaskWrapper[] = event.data.map((taskWrapper: JTaskWrapper) => { - if (taskWrapper.taskType === 1) { + if (taskWrapper.taskType === TaskType.SUPERTASK) { superTasksCount++; return { ...taskWrapper, taskName: taskWrapper.taskWrapperName }; } else { @@ -426,7 +424,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O } getDispatchedSearchedString(wrapper: JTaskWrapper): string { - if (wrapper.taskType === 0) { + if (wrapper.taskType === TaskType.TASK) { const task: JTask = wrapper.tasks[0]; if (task.keyspace > 0) { return `${convertToLocale(Number(task.dispatched))}% / ${convertToLocale(Number(task.searched))}%`; @@ -480,7 +478,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O } getNumAgents(wrapper: JTaskWrapper): number { - return wrapper.taskType === 0 && wrapper.chunkData ? wrapper.chunkData.agents.length : 0; + return wrapper.taskType === TaskType.TASK && wrapper.chunkData ? wrapper.chunkData.agents.length : 0; } renderAgents(wrapper: JTaskWrapper): SafeHtml { @@ -490,7 +488,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O renderSpeed(wrapper: JTaskWrapper): SafeHtml { let html = ''; - if (wrapper.taskType === 0) { + if (wrapper.taskType === TaskType.TASK) { const chunkData: ChunkData = wrapper.chunkData; if (chunkData && 'speed' in chunkData && chunkData.speed > 0) { html = `${convertCrackingSpeed(chunkData.speed)}`; @@ -522,7 +520,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O } private getTaskStatus(wrapper: JTaskWrapper): TaskStatus { - if (wrapper.taskType === 0 && wrapper.tasks.length > 0) { + if (wrapper.taskType === TaskType.TASK && wrapper.tasks.length > 0) { const chunkData: ChunkData = wrapper.chunkData; if (chunkData) { const speed = chunkData.speed; @@ -560,7 +558,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O private renderBoolIcon(wrapper: JTaskWrapper, key: string, equals: string = ''): HTTableIcon { let icon: HTTableIcon = { name: '' }; - if (wrapper.taskType === 0) { + if (wrapper.taskType === TaskType.TASK) { const task: JTask = wrapper.tasks[0]; if (equals === '') { if (task[key] === true) { @@ -744,7 +742,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O */ private renderCrackedLinkFromWrapper(wrapper: JTaskWrapper): Observable { const links: HTTableRouterLink[] = []; - if (wrapper.taskType === 0) { + if (wrapper.taskType === TaskType.TASK) { links.push({ label: wrapper.cracked.toLocaleString(), routerLink: ['/hashlists', 'hashes', 'tasks', wrapper.id] diff --git a/src/app/core/_datasources/hashes.datasource.ts b/src/app/core/_datasources/hashes.datasource.ts index ecda25d76..4ea13b28f 100644 --- a/src/app/core/_datasources/hashes.datasource.ts +++ b/src/app/core/_datasources/hashes.datasource.ts @@ -3,11 +3,11 @@ import { catchError, finalize, of } from 'rxjs'; import { BaseDataSource } from '@datasources/base.datasource'; import { FilterType } from '@models/request-params.model'; import { JHash } from '@models/hash.model'; -import { JTaskWrapper } from '@models/task-wrapper.model'; import { JsonAPISerializer } from '@services/api/serializer-service'; import { RequestParamBuilder } from '@services/params/builder-implementation.service'; import { ResponseWrapper } from '@models/response.model'; import { SERV } from '@services/main.config'; +import { JTaskWrapper } from '@models/task.model'; export class HashesDataSource extends BaseDataSource { private _id = 0; diff --git a/src/app/core/_datasources/tasks-supertasks.datasource.ts b/src/app/core/_datasources/tasks-supertasks.datasource.ts index 14d301f15..2d3639b00 100644 --- a/src/app/core/_datasources/tasks-supertasks.datasource.ts +++ b/src/app/core/_datasources/tasks-supertasks.datasource.ts @@ -3,8 +3,7 @@ import { catchError, finalize, of } from 'rxjs'; import { JChunk } from '@models/chunk.model'; import { FilterType } from '@models/request-params.model'; import { ResponseWrapper } from '@models/response.model'; -import { JTaskWrapper } from '@models/task-wrapper.model'; -import { JTask } from '@models/task.model'; +import { JTask, JTaskWrapper } from '@models/task.model'; import { JsonAPISerializer } from '@services/api/serializer-service'; import { SERV } from '@services/main.config'; diff --git a/src/app/core/_datasources/tasks.datasource.ts b/src/app/core/_datasources/tasks.datasource.ts index 730f685d8..ac37a651e 100644 --- a/src/app/core/_datasources/tasks.datasource.ts +++ b/src/app/core/_datasources/tasks.datasource.ts @@ -4,8 +4,7 @@ import { finalize } from 'rxjs/operators'; import { JChunk } from '@models/chunk.model'; import { FilterType } from '@models/request-params.model'; import { ResponseWrapper } from '@models/response.model'; -import { JTaskWrapper } from '@models/task-wrapper.model'; -import { JTask } from '@models/task.model'; +import { JTask, JTaskWrapper } from '@models/task.model'; import { SERV } from '@services/main.config'; import { RequestParamBuilder } from '@services/params/builder-implementation.service'; diff --git a/src/app/core/_models/task-wrapper.model.ts b/src/app/core/_models/task-wrapper.model.ts deleted file mode 100644 index dc7daed9d..000000000 --- a/src/app/core/_models/task-wrapper.model.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { JAccessGroup } from '@models/access-group.model'; -import { BaseModel } from '@models/base.model'; -import { ChunkData } from '@models/chunk.model'; -import { JHashlist } from '@models/hashlist.model'; -import { JHashtype } from '@models/hashtype.model'; -import { JTask } from '@models/task.model'; - -/** - * Interface definition for a task wrapper (wrapper object for tasks and supertasks) - */ -export interface JTaskWrapper extends BaseModel { - accessGroupId: number; - accessGroup?: JAccessGroup; - accessGroupName?: string; - cracked: number; - hashlistId: number; - hashlist?: JHashlist; - hashType?: JHashtype; - isArchived: boolean; - maxAgents: number; - priority: number; - taskType: number; - taskWrapperId: number; - taskWrapperName: string; - tasks?: JTask[]; - taskName?: string; - chunkData?: ChunkData; -} diff --git a/src/app/core/_models/task.model.ts b/src/app/core/_models/task.model.ts index 13957e5e6..072f93cfd 100644 --- a/src/app/core/_models/task.model.ts +++ b/src/app/core/_models/task.model.ts @@ -1,11 +1,21 @@ +import { JAccessGroup } from '@models/access-group.model'; import { JAgent } from '@models/agent.model'; import { BaseModel } from '@models/base.model'; import { ChunkData } from '@models/chunk.model'; import { JCrackerBinary, JCrackerBinaryType } from '@models/cracker-binary.model'; import { JFile } from '@models/file.model'; import { JHashlist } from '@models/hashlist.model'; +import { JHashtype } from '@models/hashtype.model'; import { SpeedStat } from '@models/speed-stat.model'; +/** + * Enum definition for taskType (task or supertask) + */ +export enum TaskType { + TASK = 0, + SUPERTASK = 1 +} + /** * Interface definition for a cracking task */ @@ -43,3 +53,25 @@ export interface JTask extends BaseModel { speeds: SpeedStat[]; chunkData?: ChunkData; } + +/** + * Interface definition for a task wrapper (wrapper object for cracking tasks and supertasks) + */ +export interface JTaskWrapper extends BaseModel { + accessGroupId: number; + accessGroup?: JAccessGroup; + accessGroupName?: string; + cracked: number; + hashlistId: number; + hashlist?: JHashlist; + hashType?: JHashtype; + isArchived: boolean; + maxAgents: number; + priority: number; + taskType: TaskType; + taskWrapperId: number; + taskWrapperName: string; + tasks?: JTask[]; + taskName?: string; + chunkData?: ChunkData; +} diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index fa6b1ce3c..b5b17b167 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -5,7 +5,9 @@ import { CanvasRenderer } from 'echarts/renderers'; import { Subscription } from 'rxjs'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; -import { Component, OnDestroy, OnInit, AfterViewInit } from '@angular/core'; +import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'; + +import { TaskType } from '@models/task.model'; import { PermissionService } from '@services/permission/permission.service'; import { AlertService } from '@services/shared/alert.service'; @@ -363,7 +365,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { */ private getSuperTasks(): void { const paramsTotalTasks = new RequestParamBuilder() - .addFilter({ field: 'taskType', operator: FilterType.EQUAL, value: 1 }) + .addFilter({ field: 'taskType', operator: FilterType.EQUAL, value: TaskType.SUPERTASK }) .create(); this.subscriptions.push( @@ -375,7 +377,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit { const paramsCompletedTasks = new RequestParamBuilder() .addFilter({ field: 'keyspace', operator: FilterType.EQUAL, value: 'keyspaceProgress' }) .addFilter({ field: 'keyspace', operator: FilterType.GREATER, value: 0 }) - .addFilter({ field: 'taskType', operator: FilterType.EQUAL, value: 1 }) + .addFilter({ field: 'taskType', operator: FilterType.EQUAL, value: TaskType.SUPERTASK }) .addInclude('tasks') .create(); diff --git a/src/app/shared/graphs/graphs.module.ts b/src/app/shared/graphs/graphs.module.ts index 7904f7fcb..c8f299451 100644 --- a/src/app/shared/graphs/graphs.module.ts +++ b/src/app/shared/graphs/graphs.module.ts @@ -1,16 +1,16 @@ -import { TaskVisualomponent } from "./task-visual/task-visual.component"; +import { TaskVisualComponent } from "./task-visual/task-visual.component"; import { CommonModule } from "@angular/common"; import { NgModule } from "@angular/core"; @NgModule({ declarations:[ - TaskVisualomponent, + TaskVisualComponent, ], imports:[ CommonModule ], exports:[ - TaskVisualomponent + TaskVisualComponent ] }) export class GraphsModule {} diff --git a/src/app/shared/graphs/task-visual/task-visual.component.ts b/src/app/shared/graphs/task-visual/task-visual.component.ts index 8f748c7d0..c6d9a9fc8 100644 --- a/src/app/shared/graphs/task-visual/task-visual.component.ts +++ b/src/app/shared/graphs/task-visual/task-visual.component.ts @@ -1,33 +1,29 @@ -import { Component, ElementRef, Input, ViewChild } from '@angular/core'; -import { GlobalService } from '../../../core/_services/main.service'; -import { SERV } from '../../../core/_services/main.config'; import { FilterType } from 'src/app/core/_models/request-params.model'; -import { RequestParamBuilder } from '@services/params/builder-implementation.service'; -import { JTask } from '@models/task.model'; + +import { AfterViewInit, Component, ElementRef, Input, ViewChild } from '@angular/core'; + +import { JChunk } from '@models/chunk.model'; import { ResponseWrapper } from '@models/response.model'; +import { JTask, JTaskWrapper, TaskType } from '@models/task.model'; + import { JsonAPISerializer } from '@services/api/serializer-service'; -import { JTaskWrapper } from '@models/task-wrapper.model'; -import { JChunk } from '@models/chunk.model'; +import { SERV } from '@services/main.config'; +import { GlobalService } from '@services/main.service'; +import { RequestParamBuilder } from '@services/params/builder-implementation.service'; @Component({ - selector: 'task-visual', - template: ` - + selector: 'task-visual', + template: ` + Fallback content `, - host: { - '(window:resize)': 'onWindowResize($event)' - }, - standalone: false + host: { + '(window:resize)': 'onWindowResize($event)' + }, + standalone: false }) -export class TaskVisualomponent { +export class TaskVisualComponent implements AfterViewInit { @ViewChild('myCanvas') canvasRef: ElementRef; @Input() view: any; @Input() tkeyspace: any; @@ -40,7 +36,7 @@ export class TaskVisualomponent { public x: number = window.innerWidth; // Dynamic width public y = 32; - getWidth(){ + getWidth() { if (document.body.className.includes('fixed-width-layout')) { this.x = 1467; } else if (document.body.className.includes('full-width-layout')) { @@ -52,7 +48,7 @@ export class TaskVisualomponent { this.getWidth(); } - onWindowResize(event) { + onWindowResize() { this.getWidth(); } @@ -62,170 +58,124 @@ export class TaskVisualomponent { this.drawPoint(); } - drawBorder(xPos, yPos, width, height, thickness = 1) { - this.ctx.fillStyle = '#000'; - this.ctx.rect( - xPos - thickness, - yPos - thickness, - width + thickness * 2, - height + thickness * 2 - ); - this.ctx.fill(); - } - drawPoint() { const maxResults = 10000; - const paramsTasks = new RequestParamBuilder() + const paramsTasks = new RequestParamBuilder() .addFilter({ field: 'taskId', operator: FilterType.EQUAL, value: this.taskid }) .setPageSize(maxResults) .create(); - this.gs - .getAll(SERV.TASKS, paramsTasks) - .subscribe((response: ResponseWrapper) => { + this.gs.getAll(SERV.TASKS, paramsTasks).subscribe((response: ResponseWrapper) => { + const responseBody = { data: response.data, included: response.included }; + const tasks = new JsonAPISerializer().deserialize(responseBody); + + const paramsTaskWrapper = new RequestParamBuilder() + .addFilter({ field: 'taskWrapperId', operator: FilterType.EQUAL, value: tasks[0].taskWrapperId }) + .setPageSize(maxResults) + .create(); + + this.gs.getAll(SERV.TASKS_WRAPPER, paramsTaskWrapper).subscribe((response: ResponseWrapper) => { const responseBody = { data: response.data, included: response.included }; - const tasks = new JsonAPISerializer().deserialize(responseBody); + const taskWrappers = new JsonAPISerializer().deserialize(responseBody); + if (taskWrappers[0].taskType === TaskType.SUPERTASK && this.view === 'supertask') { + for (let i = 0; i < taskWrappers.length; i++) { + this.gs.getAll(SERV.CHUNKS, paramsTasks).subscribe((res: ResponseWrapper) => { + const responseBody = { data: response.data, included: response.included }; + const chunks = new JsonAPISerializer().deserialize(responseBody); + + let progress = []; + let cracked = []; + for (let i = 0; i < chunks.length; i++) { + progress.push(chunks[i].progress); + cracked.push(chunks[i].cracked); + } + progress = progress.reduce((a, i) => a + i, 0); + cracked = cracked.reduce((a, i) => a + i, 0); + + if (cracked.length > 0) { + this.ctx.fillStyle = '#00ff00'; + this.ctx.fillRect( + (i * this.x) / taskWrappers.length, + 0, + ((i + 1) * this.x) / taskWrappers.length, + this.y - 1 + ); + } + //ToDo need to get the task keypace + // if(){ + // this.ctx.fillStyle = "#0000FF"; + // this.ctx.strokeRect(i*this.x/taskWrappers.length, 0, (i+1)*this.x/taskWrappers.length, (this.y-1)); + // } + // if(){ + // this.ctx.fillStyle = "#00ff00"; + // this.ctx.strokeRect(i*this.x/taskWrappers.length, 0, (i+1)*this.x/taskWrappers.length, (this.y-1)); + // } + else { + this.ctx.fillStyle = '#c0c0c0'; + this.ctx.fillRect( + (i * this.x) / taskWrappers.length, + 0, + ((i + 1) * this.x) / taskWrappers.length, + this.y - 1 + ); + } + }); + } + } else { + this.gs.getAll(SERV.CHUNKS, paramsTasks).subscribe((response: ResponseWrapper) => { + const responseBody = { data: response.data, included: response.included }; + const ch = new JsonAPISerializer().deserialize(responseBody); // Get chunks by id + // Getting variables + const keyspace = Number(this.tkeyspace); // Get Keyspace Progress + const progress = Number(this.cprogress); // Get Progress - const paramsTaskWrapper = new RequestParamBuilder() - .addFilter({ field: 'taskWrapperId', operator: FilterType.EQUAL, value: tasks[0].taskWrapperId }) - .setPageSize(maxResults) - .create(); + // this.ctx.beginPath(); + for (let i = 0; i < ch.length; i++) { + if (this.tusepreprocessor === 1 && this.tkeyspace <= 0) { + break; + } + const start = Math.floor(((this.x - 1) * ch[i]['skip']) / keyspace); + const end = Math.floor(((this.x - 1) * (ch[i]['skip'] + ch[i]['length'])) / keyspace) - 1; + let current = + Math.floor(((this.x - 1) * (ch[i]['skip'] + (ch[i]['length'] * progress) / 10000)) / keyspace) - 1; - this.gs - .getAll(SERV.TASKS_WRAPPER, paramsTaskWrapper) - .subscribe((response: ResponseWrapper) => { - const responseBody = { data: response.data, included: response.included }; - const taskwrapper = new JsonAPISerializer().deserialize(responseBody); - - const ch = taskwrapper; - if (ch[0].taskType === 1 && this.view === 'supertask') { - for (let i = 0; i < ch.length; i++) { - this.gs - .getAll(SERV.CHUNKS, paramsTasks) - .subscribe((res: ResponseWrapper) => { - - const responseBody = { data: response.data, included: response.included }; - const chunks = new JsonAPISerializer().deserialize(responseBody); - - let progress; - let cracked; - for (let i = 0; i < chunks.length; i++) { - progress.push(chunks[i].progress); - cracked.push(chunks[i].cracked); - } - progress = progress.reduce((a, i) => a + i, 0); - cracked = cracked.reduce((a, i) => a + i, 0); - - if (cracked > 0) { - this.ctx.fillStyle = '#00ff00'; - this.ctx.fillRect( - (i * this.x) / ch.length, - 0, - ((i + 1) * this.x) / ch.length, - this.y - 1 - ); - } - //ToDo need to get the task keypace - // if(){ - // this.ctx.fillStyle = "#0000FF"; - // this.ctx.strokeRect(i*this.x/ch.length, 0, (i+1)*this.x/ch.length, (this.y-1)); - // } - // if(){ - // this.ctx.fillStyle = "#00ff00"; - // this.ctx.strokeRect(i*this.x/ch.length, 0, (i+1)*this.x/ch.length, (this.y-1)); - // } - else { - this.ctx.fillStyle = '#c0c0c0'; - this.ctx.fillRect( - (i * this.x) / ch.length, - 0, - ((i + 1) * this.x) / ch.length, - this.y - 1 - ); - } - }); + if (current > end) { + current = end; + } + + if (end - start < 3) { + if (ch[i]['state'] >= 6) { + this.ctx.fillStyle = '#ff0000'; //Red + this.ctx.fillRect(start, 0, end, this.y - 1); + } + if (ch[i]['cracked'] > 0) { + this.ctx.fillStyle = '#00ff00'; //Green + this.ctx.fillRect(start, 0, end, this.y - 1); + } else { + this.ctx.fillStyle = '#ffff00'; //Yellow + this.ctx.fillRect(start, 0, end, this.y - 1); + } + } else { + if (ch[i]['state'] >= 6) { + this.ctx.fillStyle = '#ff0000'; //Red + this.ctx.fillRect(start, 0, end, this.y - 1); + } else { + this.ctx.fillStyle = '#c0c0c0'; //Gray + this.ctx.fillRect(start, 1, end, this.y); + } + if (ch[i]['cracked'] > 0) { + this.ctx.fillStyle = '#00ff00'; //Green + this.ctx.fillRect(start + 1, 1, current - 1, this.y - 2); + } else { + this.ctx.fillStyle = '#ffff00'; //Yellow + this.ctx.fillRect(start + 1, 1, current - 1, this.y - 2); + } } - } else { - this.gs - .getAll(SERV.CHUNKS, paramsTasks) - .subscribe((response: ResponseWrapper) => { - - const responseBody = { data: response.data, included: response.included }; - const chunks = new JsonAPISerializer().deserialize(responseBody); - const ch = chunks; // Get chunks by id - - // Getting variables - const keyspace = Number(this.tkeyspace); // Get Keyspace Progress - const progress = Number(this.cprogress); // Get Progress - - // this.ctx.beginPath(); - for (let i = 0; i < ch.length; i++) { - if (this.tusepreprocessor === 1 && this.tkeyspace <= 0) { - break; - } - const start = Math.floor( - ((this.x - 1) * ch[i]['skip']) / keyspace - ); - const end = - Math.floor( - ((this.x - 1) * (ch[i]['skip'] + ch[i]['length'])) / - keyspace - ) - 1; - let current = - Math.floor( - ((this.x - 1) * - (ch[i]['skip'] + - (ch[i]['length'] * progress) / 10000)) / - keyspace - ) - 1; - - if (current > end) { - current = end; - } - - if (end - start < 3) { - if (ch[i]['state'] >= 6) { - this.ctx.fillStyle = '#ff0000'; //Red - this.ctx.fillRect(start, 0, end, this.y - 1); - } - if (ch[i]['cracked'] > 0) { - this.ctx.fillStyle = '#00ff00'; //Green - this.ctx.fillRect(start, 0, end, this.y - 1); - } else { - this.ctx.fillStyle = '#ffff00'; //Yellow - this.ctx.fillRect(start, 0, end, this.y - 1); - } - } else { - if (ch[i]['state'] >= 6) { - this.ctx.fillStyle = '#ff0000'; //Red - this.ctx.fillRect(start, 0, end, this.y - 1); - } else { - this.ctx.fillStyle = '#c0c0c0'; //Gray - this.ctx.fillRect(start, 1, end, this.y); - } - if (ch[i]['cracked'] > 0) { - this.ctx.fillStyle = '#00ff00'; //Green - this.ctx.fillRect( - start + 1, - 1, - current - 1, - this.y - 2 - ); - } else { - this.ctx.fillStyle = '#ffff00'; //Yellow - this.ctx.fillRect( - start + 1, - 1, - current - 1, - this.y - 2 - ); - } - } - } - }); } }); + } }); + }); } } From 699fde471c8b4fc118406c67af111e9995e8986b Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Mon, 7 Jul 2025 14:01:52 +0200 Subject: [PATCH 2/3] Fix ESLint errors --- .../_components/tables/tasks-table/tasks-table.component.ts | 2 +- src/app/shared/graphs/task-visual/task-visual.component.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts index afc7eda11..e23ef230f 100644 --- a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts +++ b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts @@ -1,4 +1,4 @@ -import { catchError, Observable, of } from 'rxjs'; +import { Observable, catchError, of } from 'rxjs'; import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { SafeHtml } from '@angular/platform-browser'; diff --git a/src/app/shared/graphs/task-visual/task-visual.component.ts b/src/app/shared/graphs/task-visual/task-visual.component.ts index c6d9a9fc8..418aad4c6 100644 --- a/src/app/shared/graphs/task-visual/task-visual.component.ts +++ b/src/app/shared/graphs/task-visual/task-visual.component.ts @@ -79,17 +79,17 @@ export class TaskVisualComponent implements AfterViewInit { const taskWrappers = new JsonAPISerializer().deserialize(responseBody); if (taskWrappers[0].taskType === TaskType.SUPERTASK && this.view === 'supertask') { for (let i = 0; i < taskWrappers.length; i++) { - this.gs.getAll(SERV.CHUNKS, paramsTasks).subscribe((res: ResponseWrapper) => { + this.gs.getAll(SERV.CHUNKS, paramsTasks).subscribe((response: ResponseWrapper) => { const responseBody = { data: response.data, included: response.included }; const chunks = new JsonAPISerializer().deserialize(responseBody); - let progress = []; + const progress = []; let cracked = []; for (let i = 0; i < chunks.length; i++) { progress.push(chunks[i].progress); cracked.push(chunks[i].cracked); } - progress = progress.reduce((a, i) => a + i, 0); + progress.reduce((a, i) => a + i, 0); cracked = cracked.reduce((a, i) => a + i, 0); if (cracked.length > 0) { From 3d12e100300cb84c4fdf4e592c72a29826a0f686 Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Tue, 8 Jul 2025 10:22:54 +0200 Subject: [PATCH 3/3] -Now use taskID instead of taskWrapperID for cracked links - Render supertask cracked as plain text --- .../link/ht-table-type-link.component.html | 57 ++++++++++-------- .../tasks-table/tasks-table.component.ts | 60 +++++++++++-------- 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/src/app/core/_components/tables/ht-table/type/link/ht-table-type-link.component.html b/src/app/core/_components/tables/ht-table/type/link/ht-table-type-link.component.html index bd2565703..5865efae4 100644 --- a/src/app/core/_components/tables/ht-table/type/link/ht-table-type-link.component.html +++ b/src/app/core/_components/tables/ht-table/type/link/ht-table-type-link.component.html @@ -1,27 +1,36 @@ - - - - - {{ link.label }} - - - {{ element[tableColumn.dataKey] }} - - + + + + + + + + {{ link.label }} + + + {{ element[tableColumn.dataKey] }} + + + + + + + + + + + + {{ link.label }} + + + {{ element[tableColumn.dataKey] }} + + + + + + - - - - {{ link.label }} - - - {{ element[tableColumn.dataKey] }} - - - - - - - + diff --git a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts index e23ef230f..d103356a0 100644 --- a/src/app/core/_components/tables/tasks-table/tasks-table.component.ts +++ b/src/app/core/_components/tables/tasks-table/tasks-table.component.ts @@ -100,8 +100,7 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O ); case 'id': - return item.id?.toString().toLowerCase().includes(filterValue); - + return item.tasks?.some((task: JTask) => task.id?.toString().toLowerCase().includes(filterValue)); case 'taskName': return item.tasks?.some((task: JTask) => task.taskName?.toLowerCase().includes(filterValue)); @@ -143,7 +142,12 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O dataKey: 'id', isSortable: true, isSearchable: true, - export: async (wrapper: JTaskWrapper) => wrapper.id + '' + export: async (wrapper: JTaskWrapper) => { + return wrapper.taskType === TaskType.TASK ? wrapper.tasks[0]?.id + '' : ''; + }, + render: (wrapper: JTaskWrapper) => { + return wrapper.taskType === TaskType.TASK ? wrapper.tasks[0]?.id + '' : ''; + } }, { id: TaskTableCol.TASK_TYPE, @@ -156,7 +160,6 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O dataKey: 'taskName', routerLink: (wrapper: JTaskWrapper) => this.renderTaskWrapperLink(wrapper), isSearchable: true, - isSortable: false, export: async (wrapper: JTaskWrapper) => wrapper.tasks[0]?.taskName }, @@ -735,21 +738,21 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O } /** - * Render router link to show cracked hashes for a task + * Render router link to show cracked hashes for a task if any. + * For supertasks only the cracked number as text is shown * @param wrapper - the task wrapper object to render the link for * @return observable containing an array of router links to be rendered in HTML * @private */ private renderCrackedLinkFromWrapper(wrapper: JTaskWrapper): Observable { - const links: HTTableRouterLink[] = []; - if (wrapper.taskType === TaskType.TASK) { - links.push({ - label: wrapper.cracked.toLocaleString(), - routerLink: ['/hashlists', 'hashes', 'tasks', wrapper.id] - }); + if (wrapper.cracked === 0) { + return of([{ label: null, routerLink: null }]); } - - return of(links); + const link: HTTableRouterLink = { + label: wrapper.cracked.toLocaleString(), + routerLink: wrapper.taskType === TaskType.TASK ? ['/hashlists', 'hashes', 'tasks', wrapper.tasks[0].id] : null + }; + return of([link]); } /** @@ -759,18 +762,27 @@ export class TasksTableComponent extends BaseTableComponent implements OnInit, O * @private */ private renderTaskWrapperLink(wrapper: JTaskWrapper): Observable { - const links: HTTableRouterLink[] = []; - for (const task of wrapper.tasks) { - const taskName = task.taskName?.length > 40 ? `${task.taskName.substring(40)}...` : task.taskName; - - links.push({ - label: taskName, - routerLink: ['/tasks', 'show-tasks', task.id, 'edit'], - tooltip: task.attackCmd - }); + if (wrapper.taskType === TaskType.TASK) { + const task = wrapper.tasks?.[0]; + const taskName = task?.taskName?.length > 40 ? `${task.taskName.substring(0, 40)}...` : task?.taskName; + + return of([ + { + label: taskName, + routerLink: ['/tasks', 'show-tasks', task?.id, 'edit'], + tooltip: task?.attackCmd ?? '' + } + ]); + } else { + // Supertask: No link + return of([ + { + label: wrapper.taskWrapperName, + routerLink: null, + tooltip: '' + } + ]); } - - return of(links); } /**