Skip to content

Add types to edit-tasks and remove "disabled" property from HTML #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/app/tasks/edit-tasks/edit-tasks.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<app-page-subtitle [subtitle]="'Edit Task'"></app-page-subtitle>
<form [formGroup]="updateForm">

<input-text title="ID" formControlName="taskId" [disabled]="true"></input-text>
<input-text title="ID" formControlName="taskId"></input-text>

<div formGroupName="updateData" fxLayout="row wrap" fxLayoutAlign="start center" fxLayoutGap="10px">

Expand Down Expand Up @@ -48,11 +48,11 @@
</mat-expansion-panel-header>
<form [formGroup]="updateForm" fxLayout="row wrap" fxLayoutAlign="start center" fxLayoutGap="10px">

<input-text title="No. of Chunks" formControlName="chunkSize" [disabled]="true"></input-text>
<input-text title="Enforce Piping" formControlName="forcePipe" [disabled]="true"></input-text>
<input-text title="Skipping keyspace" formControlName="skipKeyspace" [disabled]="true"></input-text>
<input-text title="Keyspace size" formControlName="keyspace" [disabled]="true"></input-text>
<input-text title="Keyspace dispatched" formControlName="keyspaceProgress" [disabled]="true"></input-text>
<input-text title="No. of Chunks" formControlName="chunkSize"></input-text>
<input-text title="Enforce Piping" formControlName="forcePipe"></input-text>
<input-text title="Skipping keyspace" formControlName="skipKeyspace"></input-text>
<input-text title="Keyspace size" formControlName="keyspace"></input-text>
<input-text title="Keyspace dispatched" formControlName="keyspaceProgress"></input-text>

<simulate-form-field *ngIf=" tkeyspace > 0 || (tusepreprocessor && cprogress > 0); else templatekeysearch" label="Keyspace Searched" message="{{ cprogress / tkeyspace | percent: '1.2-2' }}"></simulate-form-field>
<ng-template #templatekeysearch>
Expand Down Expand Up @@ -148,7 +148,7 @@
<!-- Dispatched Chunks -->
<app-table>
<app-page-subtitle [subtitle]="'Dispatched chunks - ' + chunktitle + ''"></app-page-subtitle>
<mat-slide-toggle #slideToggle (change)="toggleIsAll($event)">
<mat-slide-toggle #slideToggle (change)="toggleIsAll()">
{{ chunkview === 1 ? 'Live Chunks' : 'Show All' }}
</mat-slide-toggle>
<br /><br />
Expand Down
161 changes: 65 additions & 96 deletions src/app/tasks/edit-tasks/edit-tasks.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LineChart, LineSeriesOption } from 'echarts/charts';
import {
DataZoomComponent,
DataZoomComponentOption,
Expand All @@ -14,76 +15,78 @@ import {
VisualMapComponent,
VisualMapComponentOption
} from 'echarts/components';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { LineChart, LineSeriesOption } from 'echarts/charts';
import { FormControl, FormGroup } from '@angular/forms';
import * as echarts from 'echarts/core';
import { UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
import { finalize } from 'rxjs';
import Swal from 'sweetalert2/dist/sweetalert2.js';
import * as echarts from 'echarts/core';

import { AgentsTableComponent } from 'src/app/core/_components/tables/agents-table/agents-table.component';
import { UIConfigService } from 'src/app/core/_services/shared/storage.service';
import { AlertService } from 'src/app/core/_services/shared/alert.service';
import { GlobalService } from 'src/app/core/_services/main.service';
import { FileSizePipe } from 'src/app/core/_pipes/file-size.pipe';
import { SERV } from '../../core/_services/main.config';
import { MatSnackBar } from '@angular/material/snack-bar';
import { AutoTitleService } from 'src/app/core/_services/shared/autotitle.service';
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { finalize } from 'rxjs';
import { FilterType } from 'src/app/core/_models/request-params.model';
import { JsonAPISerializer } from '@services/api/serializer-service';
import { ResponseWrapper } from '@models/response.model';
import { JTask } from '@models/task.model';
import { RequestParamBuilder } from '@services/params/builder-implementation.service';
import { JHashtype } from '@models/hashtype.model';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActivatedRoute, Params, Router } from '@angular/router';

import { JAgentAssignment } from '@models/agent-assignment.model';
import { JAgent } from '@models/agent.model';
import { JChunk } from '@models/chunk.model';
import { JCrackerBinary } from '@models/cracker-binary.model';
import { JHashlist } from '@models/hashlist.model';
import { JHashtype } from '@models/hashtype.model';
import { FilterType } from '@models/request-params.model';
import { ResponseWrapper } from '@models/response.model';
import { JTask } from '@models/task.model';

import { JsonAPISerializer } from '@services/api/serializer-service';
import { SERV } from '@services/main.config';
import { GlobalService } from '@services/main.service';
import { RequestParamBuilder } from '@services/params/builder-implementation.service';
import { AlertService } from '@services/shared/alert.service';
import { AutoTitleService } from '@services/shared/autotitle.service';
import { UIConfigService } from '@services/shared/storage.service';

import { AgentsTableComponent } from '@components/tables/agents-table/agents-table.component';

import { FileSizePipe } from '@src/app/core/_pipes/file-size.pipe';

@Component({
selector: 'app-edit-tasks',
templateUrl: './edit-tasks.component.html',
providers: [FileSizePipe],
standalone: false
selector: 'app-edit-tasks',
templateUrl: './edit-tasks.component.html',
providers: [FileSizePipe],
standalone: false
})
export class EditTasksComponent implements OnInit {
editMode = false;
editedTaskIndex: number;
taskWrapperId: number;
editedTask: any; // Change to Model
originalValue: any; // Change to Model
originalValue: JTask;

updateForm: FormGroup;
createForm: FormGroup; // Assign Agent
/** On form update show a spinner loading */
isUpdatingLoading = false;

color = '';
tusepreprocessor: any;
hashlistDescrip: any;
hashlistinform: any;
assigAgents: any;
availAgents = [];
crackerinfo: any;
tkeyspace: any;
tusepreprocessor: number;
hashlistDescrip: string;
hashlistinform: JHashlist;
availAgents: JAgent[] = [];
crackerinfo: JCrackerBinary;
tkeyspace: number;

@ViewChild('agentsTable') agentsTable: AgentsTableComponent;
@ViewChild('slideToggle', { static: false }) slideToggle: MatSlideToggle;

//Time calculation
cprogress: any; // Keyspace searched
ctimespent: any; // Time Spent
cprogress; // Keyspace searched
ctimespent; // Time Spent

// Chunk View
chunkview: number;
chunktitle: string;
isactive = 0;
currenspeed = 0;
chunkresults: number;
activechunks: Object;

constructor(
private titleService: AutoTitleService,
Expand All @@ -103,7 +106,7 @@ export class EditTasksComponent implements OnInit {
this.onInitialize();
this.buildForm();
this.initForm();
this.assignChunksInit(this.editedTaskIndex);
this.assignChunksInit();
}

onInitialize() {
Expand Down Expand Up @@ -140,12 +143,6 @@ export class EditTasksComponent implements OnInit {
});
}

OnChangeValue(value) {
this.updateForm.patchValue({
updateData: { color: value }
});
}

onSubmit() {
if (this.updateForm.valid) {
// Check if attackCmd has been modified
Expand Down Expand Up @@ -194,13 +191,12 @@ export class EditTasksComponent implements OnInit {
this.originalValue = task;
this.color = task.color;
this.crackerinfo = task.crackerBinary;
this.taskWrapperId - task.taskWrapperId;
this.taskWrapperId = task.taskWrapperId;
// Graph Speed
this.initTaskSpeed(task.speeds);
// Assigned Agents init
this.assingAgentInit();
// Hashlist Description and Type
this.hashlistinform = '';
if (task.hashlist) {
this.hashlistinform = task.hashlist;
if (this.hashlistinform) {
Expand All @@ -217,44 +213,26 @@ export class EditTasksComponent implements OnInit {
}
this.tkeyspace = task.keyspace;
this.tusepreprocessor = task.preprocessorId;
this.updateForm = new FormGroup({
taskId: new FormControl({
value: task.id,
disabled: true
}),
forcePipe: new FormControl({
value: task.forcePipe == true ? 'Yes' : 'No',
disabled: true
}),
skipKeyspace: new FormControl({
value: task.skipKeyspace > 0 ? task.skipKeyspace : 'N/A',
disabled: true
}),
keyspace: new FormControl({
value: task.keyspace,
disabled: true
}),
keyspaceProgress: new FormControl({
value: task.keyspaceProgress,
disabled: true
}),
crackerBinaryId: new FormControl(task.crackerBinaryId),
chunkSize: new FormControl({
value: task.chunkSize,
disabled: true
}),
updateData: new FormGroup({
taskName: new FormControl(task.taskName),
attackCmd: new FormControl(task.attackCmd),
notes: new FormControl(task.notes),
color: new FormControl(task.color),
chunkTime: new FormControl(Number(task.chunkTime)),
statusTimer: new FormControl(task.statusTimer),
priority: new FormControl(task.priority),
maxAgents: new FormControl(task.maxAgents),
isCpuTask: new FormControl(task.isCpuTask),
isSmall: new FormControl(task.isSmall)
})
this.updateForm.setValue({
taskId: task.id,
forcePipe: task.forcePipe === true ? 'Yes' : 'No',
skipKeyspace: task.skipKeyspace > 0 ? task.skipKeyspace : 'N/A',
keyspace: task.keyspace,
keyspaceProgress: task.keyspaceProgress,
crackerBinaryId: task.crackerBinaryId,
chunkSize: task.chunkSize,
updateData: {
taskName: task.taskName,
attackCmd: task.attackCmd,
notes: task.notes,
color: task.color,
chunkTime: Number(task.chunkTime),
statusTimer: task.statusTimer,
priority: task.priority,
maxAgents: task.maxAgents,
isCpuTask: task.isCpuTask,
isSmall: task.isSmall
}
});
});
}
Expand All @@ -279,13 +257,7 @@ export class EditTasksComponent implements OnInit {

this.gs.getAll(SERV.AGENTS, params.create()).subscribe((responseAgents: ResponseWrapper) => {
const responseBodyAgents = { data: responseAgents.data, included: responseAgents.included };
const agents = this.serializer.deserialize<JAgent[]>(responseBodyAgents);
this.availAgents = agents;

// this.assigAgents = res.values.map((mainObject) => {
// const matchObject = agents.values.find((element) => element.agentId === mainObject.agentId);
// return { ...mainObject, ...matchObject };
// });
this.availAgents = this.serializer.deserialize<JAgent[]>(responseBodyAgents);
});
});
}
Expand Down Expand Up @@ -331,7 +303,7 @@ export class EditTasksComponent implements OnInit {
this.ctimespent = timespent.reduce((a, i) => a + i);
}

assignChunksInit(id: number) {
assignChunksInit() {
this.route.data.subscribe((data) => {
switch (data['kind']) {
case 'edit-task':
Expand All @@ -350,8 +322,6 @@ export class EditTasksComponent implements OnInit {
});

//TODO. It is repeting code to get the speed
const page = { size: this.chunkresults };

const paramsChunks = new RequestParamBuilder()
.addFilter({ field: 'taskId', operator: FilterType.EQUAL, value: this.editedTaskIndex })
.create();
Expand Down Expand Up @@ -394,7 +364,7 @@ export class EditTasksComponent implements OnInit {
});
}

toggleIsAll(event) {
toggleIsAll() {
if (this.chunkview === 0) {
this.router.navigate(['/tasks/show-tasks', this.editedTaskIndex, 'edit', 'show-all-chunks']);
} else {
Expand Down Expand Up @@ -504,11 +474,10 @@ export class EditTasksComponent implements OnInit {

const chartDom = document.getElementById('tspeed');
const myChart = echarts.init(chartDom);
let option: EChartsOption;

const self = this;

option = {
const option: EChartsOption = {
title: {
subtext: 'Last record: ' + datelabel
},
Expand Down