mirror of
https://github.com/MikroWizard/mikrofront.git
synced 2025-08-31 15:19:31 +02:00
Add device scan results for admins
This commit is contained in:
parent
f4c785f7f1
commit
d83fb7a575
4 changed files with 168 additions and 29 deletions
|
@ -85,7 +85,7 @@ export class dataProvider {
|
|||
|
||||
return this.MikroWizardRPC.sendJsonRequest("/api/monitoring/devs/get", data);
|
||||
}
|
||||
|
||||
|
||||
monitoring_events_fix(event_id:number){
|
||||
var data={
|
||||
'event_id':event_id
|
||||
|
@ -206,7 +206,7 @@ export class dataProvider {
|
|||
'devid':devid
|
||||
}
|
||||
return this.MikroWizardRPC.sendJsonRequest("/api/devlogs/details/list", data);
|
||||
}
|
||||
}
|
||||
|
||||
scan_devs(type:string,info:any){
|
||||
var data: any={
|
||||
|
@ -218,6 +218,10 @@ export class dataProvider {
|
|||
return this.MikroWizardRPC.sendJsonRequest("/api/scanner/scan", data);
|
||||
}
|
||||
|
||||
scan_results(){
|
||||
return this.MikroWizardRPC.sendJsonRequest("/api/scanner/results", {});
|
||||
}
|
||||
|
||||
get_groups(searchstr:string=""){
|
||||
var data={
|
||||
'searchstr':searchstr
|
||||
|
|
|
@ -166,6 +166,7 @@
|
|||
</c-row>
|
||||
|
||||
|
||||
|
||||
<c-modal #ScannerModal [visible]="scanwizard_modal" (visibleChange)="handleScanwizard_modal($event)" backdrop="static"
|
||||
id="ScannerModal">
|
||||
<c-modal-header>
|
||||
|
@ -255,12 +256,59 @@
|
|||
</div>
|
||||
</c-modal-body>
|
||||
<c-modal-footer>
|
||||
<small *ngIf="scan_type=='ip'" style="margin: 0 auto;">Empty username and password means system default
|
||||
<h6 style="margin: 0 auto;" *ngIf="scanwizard_step==1" ><button cButton color="primary" (click)="show_exec()" style="margin: 0 auto;" variant="outline">Device scan logs</button></h6>
|
||||
<small *ngIf="scan_type=='ip'" >Empty username and password means system default
|
||||
configuration</small>
|
||||
</c-modal-footer>
|
||||
</c-modal>
|
||||
|
||||
|
||||
<c-modal #ExecutedDataModal backdrop="static" size="xl" [(visible)]="ExecutedDataModalVisible" id="ExecutedDataModal">
|
||||
<c-modal-header>
|
||||
<h5 cModalTitle>Editing Group </h5>
|
||||
<button (click)="ExecutedDataModalVisible=!ExecutedDataModalVisible" cButtonClose></button>
|
||||
</c-modal-header>
|
||||
<c-modal-body>
|
||||
<c-input-group class="mb-3">
|
||||
<h5>Group Members :</h5>
|
||||
<gui-grid [autoResizeWidth]="true" *ngIf="ExecutedDataModalVisible" [searching]="searching"
|
||||
[source]="ExecutedData" [columnMenu]="columnMenu" [sorting]="sorting" [infoPanel]="infoPanel"
|
||||
[autoResizeWidth]=true
|
||||
[paging]="paging">
|
||||
<gui-grid-column header="Start time" field="start">
|
||||
<ng-template let-value="item['started']" let-item="item" let-index="index">
|
||||
{{value}} </ng-template>
|
||||
</gui-grid-column>
|
||||
<gui-grid-column header="Start ip" field="start_ip">
|
||||
<ng-template let-value="item['start_ip']" let-item="item" let-index="index">
|
||||
{{value}} </ng-template>
|
||||
</gui-grid-column>
|
||||
<gui-grid-column header="End ip" field="start_ip">
|
||||
<ng-template let-value="item['start_ip']" let-item="item" let-index="index">
|
||||
{{value}} </ng-template>
|
||||
</gui-grid-column>
|
||||
<gui-grid-column header="End time" field="end">
|
||||
<ng-template let-value="item['ended']" let-item="item" let-index="index">
|
||||
{{value}}
|
||||
</ng-template>
|
||||
</gui-grid-column>
|
||||
<gui-grid-column header="Logs" field="mac" align="center">
|
||||
<ng-template let-value="item['result']" let-item="item" let-index="index">
|
||||
<button (click)="exportToCsv(value)" color="primary" cButton>download</button>
|
||||
</ng-template>
|
||||
</gui-grid-column>
|
||||
</gui-grid>
|
||||
<br/>
|
||||
</c-input-group>
|
||||
<hr />
|
||||
</c-modal-body>
|
||||
<c-modal-footer>
|
||||
<button (click)="ExecutedDataModalVisible=!ExecutedDataModalVisible" cButton color="secondary">
|
||||
Close
|
||||
</button>
|
||||
</c-modal-footer>
|
||||
</c-modal>
|
||||
|
||||
<c-modal #ConfirmModal backdrop="static" [(visible)]="ConfirmModalVisible" id="runConfirmModal">
|
||||
<c-modal-header>
|
||||
<h6 cModalTitle>Please Confirm Action </h6>
|
||||
|
|
|
@ -26,20 +26,9 @@ import {
|
|||
} from "@generic-ui/ngx-grid";
|
||||
import { ToasterComponent } from "@coreui/angular";
|
||||
import { AppToastComponent } from "../toast-simple/toast.component";
|
||||
import { formatInTimeZone } from "date-fns-tz";
|
||||
|
||||
|
||||
interface IUser {
|
||||
name: string;
|
||||
state: string;
|
||||
registered: string;
|
||||
country: string;
|
||||
usage: number;
|
||||
period: string;
|
||||
payment: string;
|
||||
activity: string;
|
||||
avatar: string;
|
||||
status: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
templateUrl: "devices.component.html",
|
||||
|
@ -47,6 +36,7 @@ interface IUser {
|
|||
export class DevicesComponent implements OnInit, OnDestroy {
|
||||
public uid: number;
|
||||
public uname: string;
|
||||
public tz: string;
|
||||
|
||||
constructor(
|
||||
private data_provider: dataProvider,
|
||||
|
@ -63,6 +53,7 @@ export class DevicesComponent implements OnInit, OnDestroy {
|
|||
this.data_provider.getSessionInfo().then((res) => {
|
||||
_self.uid = res.uid;
|
||||
_self.uname = res.name;
|
||||
_self.tz = res.tz;
|
||||
const userId = _self.uid;
|
||||
|
||||
if (res.role != "admin") {
|
||||
|
@ -99,6 +90,9 @@ export class DevicesComponent implements OnInit, OnDestroy {
|
|||
public selected_devices: any = {};
|
||||
public selected_device: any = {};
|
||||
public show_pass: boolean = false;
|
||||
public ExecutedDataModalVisible: boolean = false;
|
||||
public ExecutedData: any = [];
|
||||
|
||||
toasterForm = {
|
||||
autohide: true,
|
||||
delay: 3000,
|
||||
|
@ -192,6 +186,7 @@ export class DevicesComponent implements OnInit, OnDestroy {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
edit_device_form(dev: any) {
|
||||
var _self = this;
|
||||
this.selected_device = dev;
|
||||
|
@ -210,6 +205,7 @@ export class DevicesComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
save_device() {
|
||||
var _self = this;
|
||||
this.data_provider
|
||||
|
@ -452,6 +448,108 @@ export class DevicesComponent implements OnInit, OnDestroy {
|
|||
if (_self.Selectedrows && _self.Selectedrows.length < 1) _self.initGridTable();
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
sanitizeString(desc:string) {
|
||||
var itemDesc:string='';
|
||||
if (desc) {
|
||||
itemDesc = desc.toString().replace(/"/g, '\"');
|
||||
itemDesc = itemDesc.replace(/'/g, '\'');
|
||||
} else {
|
||||
itemDesc = '';
|
||||
}
|
||||
return itemDesc;
|
||||
}
|
||||
|
||||
exportToCsv(jsonResponse:any) {
|
||||
const data = jsonResponse;
|
||||
const columns = this.getColumns(data);
|
||||
const csvData = this.convertToCsv(data, columns);
|
||||
this.downloadFile(csvData, 'data.csv', 'text/csv');
|
||||
}
|
||||
|
||||
getColumns(data: any[]): string[] {
|
||||
const columns : any = [];
|
||||
data.forEach(row => {
|
||||
Object.keys(row).forEach((col) => {
|
||||
if (!columns.includes(col)) {
|
||||
columns.push(col);
|
||||
}
|
||||
});
|
||||
});
|
||||
return columns;
|
||||
}
|
||||
|
||||
convertToCsv(data: any[], columns: string[]): string {
|
||||
var _self=this;
|
||||
let csv = '';
|
||||
csv += columns.join(',') + '\n';
|
||||
data.forEach(row => {
|
||||
const values : any = [];
|
||||
columns.forEach((col:any) => {
|
||||
values.push('"'+_self.sanitizeString(row[col])+'"');
|
||||
});
|
||||
csv += values.join(',') + '\n';
|
||||
});
|
||||
return csv;
|
||||
}
|
||||
|
||||
downloadFile(data: string, filename: string, type: string) {
|
||||
const blob = new Blob([data], { type: type });
|
||||
const nav = (window.navigator as any);
|
||||
|
||||
if (nav.msSaveOrOpenBlob) {
|
||||
nav.msSaveBlob(blob, filename);
|
||||
} else {
|
||||
const link = document.createElement('a');
|
||||
link.setAttribute('href', URL.createObjectURL(blob));
|
||||
link.setAttribute('download', filename);
|
||||
link.style.visibility = 'hidden';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
show_exec(){
|
||||
var _self=this;
|
||||
this.ExecutedDataModalVisible = true;
|
||||
this.data_provider
|
||||
.scan_results()
|
||||
.then((res) => {
|
||||
console.dir(res);
|
||||
let index = 1;
|
||||
_self.ExecutedData= res.data.map((d: any) => {
|
||||
d.index = index;
|
||||
d.ended = formatInTimeZone(
|
||||
d.created.split(".")[0] + ".000Z",
|
||||
_self.tz,
|
||||
"yyyy-MM-dd HH:mm:ss XXX"
|
||||
);
|
||||
d.info=JSON.parse(d.info);
|
||||
d.started = formatInTimeZone(
|
||||
d.info.created.split(".")[0] + ".000Z",
|
||||
_self.tz,
|
||||
"yyyy-MM-dd HH:mm:ss XXX"
|
||||
);
|
||||
d.start_ip=d.info.start_ip;
|
||||
d.end_ip=d.info.end_ip;
|
||||
d.result=JSON.parse(d.result);
|
||||
index += 1;
|
||||
return d;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ngOnDestroy(): void {
|
||||
clearTimeout(this.scan_timer);
|
||||
|
|
|
@ -56,7 +56,7 @@ export class SnippetsComponent implements OnInit, OnDestroy {
|
|||
// console.dir("res",res)
|
||||
_self.uid = res.uid;
|
||||
_self.uname = res.name;
|
||||
_self.tz = res.tz;
|
||||
_self.tz = res.tz;
|
||||
// console.dir("role",res.role);
|
||||
const userId = _self.uid;
|
||||
|
||||
|
@ -205,17 +205,6 @@ export class SnippetsComponent implements OnInit, OnDestroy {
|
|||
index += 1;
|
||||
return d;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_self.DeleteConfirmModalVisible = false;
|
||||
});
|
||||
}
|
||||
|
@ -298,7 +287,7 @@ export class SnippetsComponent implements OnInit, OnDestroy {
|
|||
this.current_snippet = item;
|
||||
this.current_snippet["task_type"] = "snipet_exec";
|
||||
this.current_snippet["selection_type"] = "devices";
|
||||
this.form_changed();
|
||||
this.form_changed();
|
||||
this.ExecSnipetModalVisible = true;
|
||||
this.ModalAction = "exec";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue