-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 --> |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}) | ||
} | ||
} | ||
|
||
} |
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; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use instead the service _services/main.service.ts instead |
There was a problem hiding this comment.
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.