Skip to content
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

Added frontend components for benchmarkcache #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/app/agents/agent.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { DirectivesModule } from "../shared/directives.module";
import { ComponentsModule } from "../shared/components.module";
import { AgentsRoutingModule } from "./agents-routing.module";
import { PipesModule } from "../shared/pipes.module";
import { BenchmarkComponent } from './benchmarks/benchmarks.component';

@NgModule({
declarations:[
AgentStatusComponent,
ShowAgentsComponent,
EditAgentComponent,
NewAgentComponent
NewAgentComponent,
BenchmarkComponent
],
imports:[
ReactiveFormsModule,
Expand Down
8 changes: 8 additions & 0 deletions src/app/agents/agents-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Routes, RouterModule } from '@angular/router';
import { AgentStatusComponent } from "./agent-status/agent-status.component";
import { PendingChangesGuard } from "../core/_guards/pendingchanges.guard";
import { ShowAgentsComponent } from "./show-agents/show-agents.component";
import { BenchmarkComponent } from "./benchmarks/benchmarks.component"
import { EditAgentComponent } from "./edit-agent/edit-agent.component";
import { NewAgentComponent } from "./new-agent/new-agent.component";
import { AgentGuard } from "../core/_guards/agent.guard";
Expand Down Expand Up @@ -41,6 +42,13 @@ const routes: Routes = [
breadcrumb: 'Edit Agent'
},
canActivate: [AuthGuard,AgentGuard]},
{
path: 'benchmarks', component: BenchmarkComponent,
data: {
kind: 'edit-agent',
breadcrumb: 'Edit Agent'
},
canActivate: [AuthGuard,AgentGuard]},
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has change, so pull the new code and change should be sth like this.

    {
      path: 'benchmarks', component: BenchmarkComponent,
      data: {
        kind: 'benchmark',
        breadcrumb: 'Benchmark'
    },
    canActivate: [IsAuth,CheckPerm]},

},
];
Expand Down
48 changes: 48 additions & 0 deletions src/app/agents/benchmarks/benchmarks.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center py-4">
<div class="d-block mb-4 mb-md-0">
<h2 class="h4">Benchmarks</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change this block for this template

<app-page-title [title]="Benchmarks'" [subbutton]="false">

<p class="mb-0">Section to view and manage cached benchmarks.</p>
</div>

</div>
<!-- Body -->
<div class="card border-0 shadow mb-4">
<div class="card-body">
<div class="table-responsive">
<table class="table table-centered table-nowrap mb-0 rounded" #benchmark datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" id="benchmarks">
<thead class="thead-light">
<tr>
<th class="border-0 rounded-start"><input type="checkbox" (click)="setCheckAll()"> ID</th>
<th class="border-0">CMD</th>
<th class="border-0">Hashmode</th>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class="border-0" is not needed

<th class="border-0">Cracker Binary</th>
<th class="border-0">GPU/CPU</th>
<th class="border-0">Benchmark Value</th>
<th class="border-0">TTL</th>
<th class="border-0 rounded-end">Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let benchmark of benchmarks">
<td>{{ benchmark.benchmarkId }}</td>
<td>{{ benchmark.attackParameters }}</td>
<td>{{ benchmark.hashMode }}</td>
<td>{{ benchmark.crackerBinary.binaryName }} {{benchmark.crackerBinary.version}}</td>
<td class="pre">{{ benchmark.hardwareGroup.devices }}</td>
<td>{{ benchmark.benchmarkValue }}</td>
<td>{{ benchmark.ttl *1000 | date: uidateformat}}</td>
<td>
<a>
<a class='btn-outline-gray-600 float-right' data-toggle="tooltip" data-placement="top" title="Delete" (click)="onDelete(benchmark.benchmarkId)">
<fa-icon [icon]="faTrash" aria-hidden="true"></fa-icon></a>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>


<!-- Bulk Actions Modal -->
Empty file.
238 changes: 238 additions & 0 deletions src/app/agents/benchmarks/benchmarks.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
import { faRefresh, faPauseCircle, faEdit, faTrash, faLock, faFileImport, faFileExport, faPlus, faHomeAlt, faArchive, faCopy, faBookmark, faEye } from '@fortawesome/free-solid-svg-icons';
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
import { environment } from './../../../environments/environment';
import { ActivatedRoute, Router } from '@angular/router';
import { DataTableDirective } from 'angular-datatables';
import Swal from 'sweetalert2/dist/sweetalert2.js';
import { interval, Subject, Subscription } from 'rxjs';
import { UIConfigService } from 'src/app/core/_services/shared/storage.service';


import { CookieService } from 'src/app/core/_services/shared/cookies.service';
import { ChunkService } from 'src/app/core/_services/tasks/chunks.service';
import { UsersService } from 'src/app/core/_services/users/users.service';
import { TasksService } from '../../core/_services/tasks/tasks.sevice';

import { BenchmarkService } from 'src/app/core/_services/agents/benchmark.service';

@Component({
selector: 'app-benchmark',
templateUrl: './benchmarks.component.html'
})

export class BenchmarkComponent implements OnInit {
faPauseCircle=faPauseCircle;
faFileImport=faFileImport;
faFileExport=faFileExport;
faBookmark=faBookmark;
faArchive=faArchive;
faRefresh=faRefresh;
faHome=faHomeAlt;
faTrash=faTrash;
faEdit=faEdit;
faLock=faLock;
faPlus=faPlus;
faCopy=faCopy;
faEye=faEye;

storedAutorefresh: any =[]

@ViewChild(DataTableDirective)
dtElement: DataTableDirective;

dtTrigger: Subject<any> = new Subject<any>();
dtOptions: any = {};

benchmarks: any = []; //Change to Interface

uidateformat:any;

isChecked:boolean =false;
private maxResults = environment.config.prodApiMaxResults

constructor(
private benchmarkService: BenchmarkService,
private route: ActivatedRoute,
private users: UsersService,
private uiService: UIConfigService,
) { }

ngOnInit(): void {

this.getBenchmarks();
this.setAccessPermissions();

this.uidateformat = this.uiService.getUIsettings('timefmt').value;

this.dtOptions = {
dom: 'Bfrtip',
scrollY: true,
bDestroy: true,
columnDefs: [
{
targets: 0,
className: 'noVis'
}
],
order: [[0, 'desc']],
bStateSave:true,
select: {
style: 'multi',
},
buttons: {
dom: {
button: {
className: 'dt-button buttons-collection btn btn-sm-dt btn-outline-gray-600-dt',
}
},
buttons: [
{
extend: 'collection',
text: 'Export',
buttons: [
{
extend: 'excelHtml5',
exportOptions: {
columns: [0, 1, 2, 3, 4]
},
},
{
extend: 'print',
exportOptions: {
columns: [0, 1, 2, 3, 4]
},
customize: function ( win ) {
$(win.document.body)
.css( 'font-size', '10pt' )
$(win.document.body).find( 'table' )
.addClass( 'compact' )
.css( 'font-size', 'inherit' );
}
},
{
extend: 'csvHtml5',
exportOptions: {modifier: {selected: true}},
select: true,
customize: function (dt, csv) {
var data = "";
for (var i = 0; i < dt.length; i++) {
data = "Benchmark\n\n"+ dt;
}
return data;
}
},
'copy'
]
},
{
extend: 'colvis',
text: 'Column View',
columns: [ 1,2,3,4,5,6 ],
},
{
extend: "pageLength",
className: "btn-sm"
},
],
}
}
}

rerender(): void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
// Destroy the table first
dtInstance.destroy();
// Call the dtTrigger to rerender again
setTimeout(() => {
this.dtTrigger['new'].next();
});
});
}

getBenchmarks():void {
let params = {'maxResults': this.maxResults, 'expand': 'crackerBinary,hardwareGroup'}
this.benchmarks = [];

this.benchmarkService.getAllbenchmarks(params).subscribe((benchmarks: any) => {
this.benchmarks = benchmarks.values;
this.dtTrigger.next(void 0);
});
}

setCheckAll(){
let chkBoxlength = $(".checkboxCls:checked").length;
if (this.isChecked == true) {
$(".checkboxCls").prop("checked", false);
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.rows( ).deselect();
this.isChecked = false;
});
} else {
$(".checkboxCls").prop("checked", true);
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.rows( ).select();
this.isChecked = true;
});
}
}

// Set permissions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont need this code anymore as we have now guards and we leave the backend handle the permissions

manageBenchmarkAccess: any;

setAccessPermissions(){
this.users.getUser(this.users.userId,{'expand':'globalPermissionGroup'}).subscribe((perm: any) => {
this.manageBenchmarkAccess = perm.globalPermissionGroup.permissions.manageTaskAccess;
});
}

onDelete(id: number){
if(this.manageBenchmarkAccess || typeof this.manageBenchmarkAccess == 'undefined'){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, leave it to the back end hadling error

const swalWithBootstrapButtons = Swal.mixin({
customClass: {
confirmButton: 'btn btn-success',
cancelButton: 'btn btn-danger'
},
buttonsStyling: false
})
Swal.fire({
title: "Are you sure?",
text: "Once deleted, it can not be recovered!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: '#4B5563',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
})
.then((result) => {
if (result.isConfirmed) {
this.benchmarkService.deleteBenchmark(id).subscribe(() => {
Swal.fire(
"Benchmark has been deleted!",
{
icon: "success",
showConfirmButton: false,
timer: 1500
});
this.ngOnInit();
this.rerender(); // rerender datatables
});
} else {
swalWithBootstrapButtons.fire(
'Cancelled',
'No worries, your Task is safe!',
'error'
)
}
});
}else{
Swal.fire({
title: "ACTION DENIED",
text: "Please contact your Administrator.",
icon: "error",
showConfirmButton: false,
timer: 2000
})
}
}

}
2 changes: 1 addition & 1 deletion src/app/agents/edit-agent/edit-agent.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ <h4 class="display-col">Agent Detailed Information</h4>
<label class="form-label display-col" for="getdevices">Graphic cards</label>
<span class="pre input-group-text input-group-lg w-70 mx-auto">
<td>
{{ showagent['devices'] }}
{{ showagent['hardwareGroup']['devices'] }}
</td>
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/agents/show-agents/show-agents.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 class="h4">Show Agents</h2>
<a style="display: none;">notes</a>
</span>
</td>
<td class="pre">{{ agent.devices }}</td>
<td class="pre">{{ agent.hardwareGroup.devices }}</td>
<td>{{ agent.cpuOnly == true ? "Yes" : "No" }}</td>
<td>
<code>{{ agent.lastAct }}</code> at <br>
Expand Down
2 changes: 1 addition & 1 deletion src/app/agents/show-agents/show-agents.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ShowAgentsComponent implements OnInit, OnDestroy {

this.setAccessPermissions();

let params = {'maxResults': this.maxResults}
let params = {'maxResults': this.maxResults, 'expand': 'hardwareGroup'}

this.agentsService.getAgents(params).subscribe((agents: any) => {
this.showagents = agents.values;
Expand Down
10 changes: 10 additions & 0 deletions src/app/core/_models/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IBenchmark {
benchmarkId: number;
benchmarkValue: string;
hardwareGroupId: number;
crackerBinaryId: number;
attackParameters: string;
ttl: number;
hashMode: number;
benchmarkType: string;
}
2 changes: 1 addition & 1 deletion src/app/core/_services/agents/agents.service.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use instead the service _services/main.service.ts instead

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AgentsService {
* @returns Object
**/
getAgent(id: number):Observable<any> {
return this.http.get(`${this.endpoint}/${id}`)
return this.http.get(`${this.endpoint}/${id}?expand=hardwareGroup`)
}

/**
Expand Down
Loading