From 66b3ad535f8d04f2201e1285cd9f6ba5e8ad0449 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 19 Aug 2024 22:51:43 +0200 Subject: [PATCH 1/2] api template display on list fix --- src/app/settings/settings.component.ts | 530 +++++++++--------- .../templates-list.component.html | 4 +- .../templates-list.component.ts | 55 +- 3 files changed, 322 insertions(+), 267 deletions(-) diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index e26905aac..e6edca3b0 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -4,8 +4,8 @@ import { Router } from '@angular/router'; import { ApiService } from '../api.service'; import { DialogApikeyComponent } from '../dialog-apikey/dialog-apikey.component'; import { DialogApiaddComponent } from '../dialog-apiadd/dialog-apiadd.component'; -import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator'; -import {MatSort, MatSortModule} from '@angular/material/sort'; +import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator'; +import { MatSort, MatSortModule } from '@angular/material/sort'; import { MatDialog } from '@angular/material/dialog'; import { MatTableDataSource } from '@angular/material/table'; import { DialogAddreportprofileComponent } from '../dialog-addreportprofile/dialog-addreportprofile.component'; @@ -72,7 +72,7 @@ export class SettingsComponent implements OnInit { ReportProfilesdataSource = new MatTableDataSource([]); ReportTemplatesdataSource = new MatTableDataSource([]); - ReportTemplatesdisplayedColumns: string[] = ['source','title', 'template_settings']; + ReportTemplatesdisplayedColumns: string[] = ['source', 'title', 'template_settings']; vaultListdataSource = new MatTableDataSource([]); vaultListdisplayedColumns: string[] = ['vault_name', 'vault_settings']; @@ -95,13 +95,13 @@ export class SettingsComponent implements OnInit { } - + foundvault(bool: boolean): boolean { this.listkey = bool; - if(bool) { - this.vaultListdataSource = new MatTableDataSource([{"vault_name": "Main Vault"}]); + if (bool) { + this.vaultListdataSource = new MatTableDataSource([{ "vault_name": "Main Vault" }]); this.vaultList = this.vaultListdataSource.data; } else { this.vaultList = []; @@ -140,17 +140,17 @@ export class SettingsComponent implements OnInit { } else { - + this.indexeddbService.retrieveAPIkey().then(ret => { if (ret) { this.tryconnectdb = true; this.foundvault(true); - this.vaultListdataSource = new MatTableDataSource([{"vault_name": "Main Vault"}]); + this.vaultListdataSource = new MatTableDataSource([{ "vault_name": "Main Vault" }]); this.vaultList = this.vaultListdataSource.data; this.showregapi = false; - + if (this.sessionsub.getSessionStorageItem('hidedialog') !== 'true') { setTimeout(_ => this.openDialog(ret)); } @@ -164,7 +164,7 @@ export class SettingsComponent implements OnInit { } -getProfiles(): void { + getProfiles(): void { //get report profiles from local at init this.indexeddbService.retrieveReportProfile().then(ret => { if (ret) { @@ -174,18 +174,18 @@ getProfiles(): void { this.ReportProfilesdataSource.sort = this.sort; } }); -} + } -getTemplates(): void { - this.indexeddbService.retrieveReportTemplates().then(ret => { - if (ret) { - this.ReportTemplatesdataSource = new MatTableDataSource(ret); - this.reportTemplateList = this.ReportTemplatesdataSource.data; - this.ReportTemplatesdataSource.paginator = this.paginator2; - this.ReportTemplatesdataSource.sort = this.sort2; - } - }); -} + getTemplates(): void { + this.indexeddbService.retrieveReportTemplates().then(ret => { + if (ret) { + this.ReportTemplatesdataSource = new MatTableDataSource(ret); + this.reportTemplateList = this.ReportTemplatesdataSource.data; + this.ReportTemplatesdataSource.paginator = this.paginator2; + this.ReportTemplatesdataSource.sort = this.sort2; + } + }); + } wipeDatachanged() { @@ -210,7 +210,7 @@ getTemplates(): void { } - getdumps(){ + getdumps() { let pro, tem, rep, vau: any; @@ -269,40 +269,40 @@ getTemplates(): void { parseMyBackupfile(array) { const parsed = JSON.parse(array); - if(parsed.vault !== undefined && parsed.vault.length > 0) { - this.indexeddbService.saveKEYinDB(parsed.vault); - this.foundvault(true); - this.showregapi = true; - this.tryconnectdb = true; + if (parsed.vault !== undefined && parsed.vault.length > 0) { + this.indexeddbService.saveKEYinDB(parsed.vault); + this.foundvault(true); + this.showregapi = true; + this.tryconnectdb = true; } - if(parsed.reports.length > 0) { + if (parsed.reports.length > 0) { for (let _i = 0; _i < parsed.reports.length; _i++) { const num = parsed.reports[_i]; this.indexeddbService.importReportfromfileSettings(num); } } - if(parsed.templates.length > 0) { + if (parsed.templates.length > 0) { for (let _i = 0; _i < parsed.templates.length; _i++) { const num = parsed.templates[_i]; this.reportTemplateList = this.reportProfileList.concat(num); this.ReportTemplatesdataSource.data = this.reportTemplateList; - + for (let item of this.reportTemplateList) { this.indexeddbService.saveReportTemplateinDB(item); - } + } } } - if(parsed.profiles.length > 0) { + if (parsed.profiles.length > 0) { for (let _i = 0; _i < parsed.profiles.length; _i++) { const num = parsed.profiles[_i]; this.reportProfileList = this.reportProfileList.concat(num); this.ReportProfilesdataSource.data = this.reportProfileList; - this.indexeddbService.saveReportProfileinDB(this.reportProfileList).then(ret => {}); + this.indexeddbService.saveReportProfileinDB(this.reportProfileList).then(ret => { }); } } } @@ -315,7 +315,7 @@ getTemplates(): void { const fileToRead = files[0]; const fileReader = new FileReader(); fileReader.onload = (e) => { - this.parseMyBackupfile(fileReader.result); + this.parseMyBackupfile(fileReader.result); }; fileReader.readAsText(fileToRead, 'UTF-8'); @@ -340,55 +340,55 @@ getTemplates(): void { const elementlist: ApiList[] = []; const vaultobj = JSON.parse(vault); - vaultobj.forEach( (element) => { + vaultobj.forEach((element) => { if (element.apikey !== undefined && element.apikey !== '') { this.apiService.APISend(element.value, element.apikey, 'apiconnect', '').then(resp => { - if (resp !== undefined && resp !== null && resp.AUTH === 'OK') { - this.apiconneted = true; - this.foundvault(false); - this.createdate = resp.CREATEDATE; - this.expirydate = resp.EXPIRYDATE; - this.remain = this.gettimebetweendates(this.today, this.expirydate); - this.user = resp.WELCOME; - this.max_storage = resp.MAX_STORAGE; - this.current_storage = resp.CURRENT_STORAGE; - const stor = this.current_storage / this.max_storage * 100; - + if (resp !== undefined && resp !== null && resp.AUTH === 'OK') { + this.apiconneted = true; + this.foundvault(false); + this.createdate = resp.CREATEDATE; + this.expirydate = resp.EXPIRYDATE; + this.remain = this.gettimebetweendates(this.today, this.expirydate); + this.user = resp.WELCOME; + this.max_storage = resp.MAX_STORAGE; + this.current_storage = resp.CURRENT_STORAGE; + const stor = this.current_storage / this.max_storage * 100; + + // tslint:disable-next-line:max-line-length + const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: this.user, status: 'Connected', created: resp.CREATEDATE, expires: resp.EXPIRYDATE + ' (' + this.remain + ' days left)', current_storage: stor }; + elementlist.push(elementdata); + this.dataSource.data = elementlist; + this.tryconnectdb = false; + } else { + + if (resp === null) { // tslint:disable-next-line:max-line-length - const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: this.user, status: 'Connected', created: resp.CREATEDATE, expires: resp.EXPIRYDATE + ' (' + this.remain + ' days left)', current_storage: stor }; + const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: '', status: 'Not connected: wrong API key?', created: '', expires: '', current_storage: 0 }; elementlist.push(elementdata); this.dataSource.data = elementlist; - this.tryconnectdb = false; } else { - - if (resp === null) { - // tslint:disable-next-line:max-line-length - const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: '', status: 'Not connected: wrong API key?', created: '', expires: '', current_storage: 0 }; - elementlist.push(elementdata); - this.dataSource.data = elementlist; - } else { - // tslint:disable-next-line:max-line-length - const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: '', status: 'Not connected', created: '', expires: '', current_storage: 0 }; - elementlist.push(elementdata); - this.dataSource.data = elementlist; - } - + // tslint:disable-next-line:max-line-length + const elementdata = { apikey: element.apikey, apiname: element.viewValue, apiurl: element.value, organisation: '', status: 'Not connected', created: '', expires: '', current_storage: 0 }; + elementlist.push(elementdata); + this.dataSource.data = elementlist; } + } + }).catch(error => { console.log('API error: ', error); }); } - }); + }); + + this.sessionsub.setSessionStorageItem('VULNREPO-API', JSON.stringify(vaultobj)); - this.sessionsub.setSessionStorageItem('VULNREPO-API', JSON.stringify(vaultobj)); - - this.getReportProfiles(); - this.getReportTemplates(); + this.getReportProfiles(); + this.getReportTemplates(); } removeapikey() { @@ -437,7 +437,7 @@ getTemplates(): void { if (result) { this.apiconnect(result); if (data) { - this.indexeddbService.saveKEYinDB(data).then(ret => {}); + this.indexeddbService.saveKEYinDB(data).then(ret => { }); } this.tryconnectdb = false; this.showregapi = false; @@ -518,9 +518,9 @@ getTemplates(): void { dialogRef.afterClosed().subscribe(result => { if (result) { - this.sessionsub.setSessionStorageItem('VULNREPO-API', JSON.stringify(drem)); - this.saveAPIKEY(drem, result); - this.apiconnect(JSON.stringify(drem)); + this.sessionsub.setSessionStorageItem('VULNREPO-API', JSON.stringify(drem)); + this.saveAPIKEY(drem, result); + this.apiconnect(JSON.stringify(drem)); } }); @@ -532,12 +532,12 @@ getTemplates(): void { if (data) { let today = ''; if (navigator.language) { - today = new Date(this.currentdateService.getcurrentDate()).toLocaleDateString(navigator.language); + today = new Date(this.currentdateService.getcurrentDate()).toLocaleDateString(navigator.language); } else { - today = String(Date.now()); + today = String(Date.now()); } - - + + // download dump const blob = new Blob([JSON.stringify(data)], { type: 'application/json;charset=utf-8' }); const link = document.createElement('a'); @@ -587,7 +587,7 @@ getTemplates(): void { const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); if (localkey) { const result = JSON.parse(localkey); - const index = result.map(function(e) { return e.apikey; }).indexOf(element); + const index = result.map(function (e) { return e.apikey; }).indexOf(element); if (index !== -1) { this.openDialogAPIremove(result); result.splice(index, 1); @@ -601,64 +601,64 @@ getTemplates(): void { this.indexeddbService.encryptKEY(JSON.stringify(key), pass).then(data => { if (data) { - this.indexeddbService.saveKEYinDB(data).then(ret => {}); + this.indexeddbService.saveKEYinDB(data).then(ret => { }); } }); } -getReportProfiles() { - this.indexeddbService.retrieveReportProfile().then(ret => { - if (ret) { - this.ReportProfilesdataSource = new MatTableDataSource(ret); - this.reportProfileList = this.ReportProfilesdataSource.data; - } - this.getAPIReportProfiles(); - }); -} - - -getAPIReportProfiles() { - - const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); - if (localkey) { - this.msg = 'API connection please wait...'; + getReportProfiles() { + this.indexeddbService.retrieveReportProfile().then(ret => { + if (ret) { + this.ReportProfilesdataSource = new MatTableDataSource(ret); + this.reportProfileList = this.ReportProfilesdataSource.data; + } + this.getAPIReportProfiles(); + }); + } - const vaultobj = JSON.parse(localkey); - vaultobj.forEach( (element) => { + getAPIReportProfiles() { - this.apiService.APISend(element.value, element.apikey, 'getreportprofiles', '').then(resp => { - this.reportProfileList_int = []; - if (resp.length > 0) { - resp.forEach((ele) => { - ele.api = 'remote'; - ele.apiurl = element.value; - ele.apikey = element.apikey; - ele.apiname = element.viewValue; - }); - this.reportProfileList_int.push(...resp); - } + const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); + if (localkey) { + this.msg = 'API connection please wait...'; + + const vaultobj = JSON.parse(localkey); + + vaultobj.forEach((element) => { + + this.apiService.APISend(element.value, element.apikey, 'getreportprofiles', '').then(resp => { + this.reportProfileList_int = []; + if (resp.length > 0) { + resp.forEach((ele) => { + ele.api = 'remote'; + ele.apiurl = element.value; + ele.apikey = element.apikey; + ele.apiname = element.viewValue; + }); + this.reportProfileList_int.push(...resp); + } - }).then(() => { + }).then(() => { - this.ReportProfilesdataSource.data = [...this.reportProfileList, ...this.reportProfileList_int]; - this.ReportProfilesdataSource.paginator = this.paginator; - this.ReportProfilesdataSource.sort = this.sort; - this.msg = ''; - }).catch(() => {}); + this.ReportProfilesdataSource.data = [...this.reportProfileList, ...this.reportProfileList_int]; + this.ReportProfilesdataSource.paginator = this.paginator; + this.ReportProfilesdataSource.sort = this.sort; + this.msg = ''; + }).catch(() => { }); - setTimeout(() => { - // console.log('hide progress timeout'); - this.msg = ''; - }, 10000); + setTimeout(() => { + // console.log('hide progress timeout'); + this.msg = ''; + }, 10000); - }); + }); + } } -} openDialogReportProfiles(data: any): void { @@ -704,7 +704,7 @@ getAPIReportProfiles() { console.log("custom template added"); } }); - + } this.getTemplates(); @@ -722,7 +722,7 @@ getAPIReportProfiles() { this.indexeddbService.deleteTemplate(item).then(ret => { this.getTemplates(); }); - + } } @@ -737,7 +737,7 @@ getAPIReportProfiles() { this.indexeddbService.deleteProfile(item).then(ret => { this.getReportProfiles(); }); - + } } @@ -780,7 +780,7 @@ getAPIReportProfiles() { report_custom_content: result.report_custom_content }; this.ReportProfilesdataSource.data = this.reportProfileList; - this.indexeddbService.updateProfile(this.reportProfileList[index], result.original[0]._key).then(ret => {}); + this.indexeddbService.updateProfile(this.reportProfileList[index], result.original[0]._key).then(ret => { }); this.getReportProfiles(); } } @@ -819,7 +819,7 @@ getAPIReportProfiles() { fileReader.onload = (e) => { this.parseprofile(fileReader.result); - + }; fileReader.readAsText(fileToRead, 'UTF-8'); @@ -827,186 +827,186 @@ getAPIReportProfiles() { } -parseprofile(profile){ - const parsed = JSON.parse(profile); - - if(Array.isArray(parsed)){ - parsed.forEach((item) => { - this.indexeddbService.saveReportProfileinDB(item).then(ret => {}); - }); - } else { - this.indexeddbService.saveReportProfileinDB(parsed).then(ret => {}); - } - - this.getReportProfiles(); -} + parseprofile(profile) { + const parsed = JSON.parse(profile); -downloadProfileItem(element) { - - delete element.api; - delete element.apikey; - delete element.apiname; - delete element._key; - delete element.apiurl; - - const blob = new Blob([JSON.stringify(element)], { type: 'application/json' }); - const link = document.createElement('a'); - const url = window.URL.createObjectURL(blob); - link.setAttribute('href', url); - link.setAttribute('download', '' + element.profile_name + ' settings profile (vulnrepo.com).vulnrepo-profiles'); - link.style.visibility = 'hidden'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -} + if (Array.isArray(parsed)) { + parsed.forEach((item) => { + this.indexeddbService.saveReportProfileinDB(item).then(ret => { }); + }); + } else { + this.indexeddbService.saveReportProfileinDB(parsed).then(ret => { }); + } -downloadTemplateItem(element) { - - delete element.api; - delete element._key; - delete element.apikey; - delete element.apiname; - delete element.apiurl; - - const blob = new Blob([JSON.stringify(element)], { type: 'application/json' }); - const link = document.createElement('a'); - const url = window.URL.createObjectURL(blob); - link.setAttribute('href', url); - link.setAttribute('download', '' + element.title + ' template (vulnrepo.com).vulnrepo-templates'); - link.style.visibility = 'hidden'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -} + this.getReportProfiles(); + } -exporttemplates() { - - this.indexeddbService.retrieveReportTemplates().then(ret => { - if (ret) { - const blob = new Blob([JSON.stringify(ret)], { type: 'application/json' }); - const link = document.createElement('a'); - const url = window.URL.createObjectURL(blob); - link.setAttribute('href', url); - link.setAttribute('download', 'Backup Report Templates (vulnrepo.com).vulnrepo-templates'); - link.style.visibility = 'hidden'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } - }); -} + downloadProfileItem(element) { -importReportTemplates(input: HTMLInputElement) { - console.log('import templates'); + delete element.api; + delete element.apikey; + delete element.apiname; + delete element._key; + delete element.apiurl; - const files = input.files; - if (files && files.length) { + const blob = new Blob([JSON.stringify(element)], { type: 'application/json' }); + const link = document.createElement('a'); + const url = window.URL.createObjectURL(blob); + link.setAttribute('href', url); + link.setAttribute('download', '' + element.profile_name + ' settings profile (vulnrepo.com).vulnrepo-profiles'); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } - const fileToRead = files[0]; - const fileReader = new FileReader(); + downloadTemplateItem(element) { - fileReader.onload = (e) => { - this.parsetemplate(fileReader.result); - - }; + delete element.api; + delete element._key; + delete element.apikey; + delete element.apiname; + delete element.apiurl; - fileReader.readAsText(fileToRead, 'UTF-8'); + const blob = new Blob([JSON.stringify(element)], { type: 'application/json' }); + const link = document.createElement('a'); + const url = window.URL.createObjectURL(blob); + link.setAttribute('href', url); + link.setAttribute('download', '' + element.title + ' template (vulnrepo.com).vulnrepo-templates'); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } -} - -parsetemplate(template){ - const parsed = JSON.parse(template); + exporttemplates() { - if(Array.isArray(parsed)){ - parsed.forEach((item) => { - this.indexeddbService.saveReportTemplateinDB(item).then(ret => {}); + this.indexeddbService.retrieveReportTemplates().then(ret => { + if (ret) { + const blob = new Blob([JSON.stringify(ret)], { type: 'application/json' }); + const link = document.createElement('a'); + const url = window.URL.createObjectURL(blob); + link.setAttribute('href', url); + link.setAttribute('download', 'Backup Report Templates (vulnrepo.com).vulnrepo-templates'); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } }); - } else { - this.indexeddbService.saveReportTemplateinDB(parsed).then(ret => {}); } - this.getTemplates(); -} + importReportTemplates(input: HTMLInputElement) { + console.log('import templates'); + const files = input.files; + if (files && files.length) { + const fileToRead = files[0]; + const fileReader = new FileReader(); -editTemplateItem(item: any): void { - const dialogRef = this.dialog.open(DialogAddCustomTemplateComponent, { - width: '600px', - disableClose: true, - data: [item,{edit: true}] - }); + fileReader.onload = (e) => { + this.parsetemplate(fileReader.result); + }; - dialogRef.afterClosed().subscribe(result => { - console.log('Report Settings Templates edit dialog was closed'); - if (result) { + fileReader.readAsText(fileToRead, 'UTF-8'); + } - const index: number = this.reportTemplateList.indexOf(result[1].original[0]); - if (index !== -1) { - const ndd = {"title": result[0].title,"poc": "","desc": result[0].desc,"severity": result[0].severity,"ref": result[0].ref,"cvss": result[0].cvss,"cvss_vector": result[0].cvss_vector,"cve": result[0].cve, "tags": result[0].tags}; - this.reportTemplateList[index] = ndd; - - this.indexeddbService.updateTemplate(ndd, result[1].original[0]._key).then(ret => {}); - this.ReportTemplatesdataSource.data = this.reportTemplateList; + } - } + parsetemplate(template) { + const parsed = JSON.parse(template); + if (Array.isArray(parsed)) { + parsed.forEach((item) => { + this.indexeddbService.saveReportTemplateinDB(item).then(ret => { }); + }); + } else { + this.indexeddbService.saveReportTemplateinDB(parsed).then(ret => { }); } + this.getTemplates(); - }); + } -} -getReportTemplates() { - this.indexeddbService.retrieveReportTemplates().then(ret => { - if (ret) { - this.ReportTemplatesdataSource = new MatTableDataSource(ret); - this.reportTemplateList = this.ReportTemplatesdataSource.data; - } - this.getAPITemplates(); - }); -} -getAPITemplates() { + editTemplateItem(item: any): void { + const dialogRef = this.dialog.open(DialogAddCustomTemplateComponent, { + width: '600px', + disableClose: true, + data: [item, { edit: true }] + }); - const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); - if (localkey) { - this.msg = 'API connection please wait...'; - const vaultobj = JSON.parse(localkey); + dialogRef.afterClosed().subscribe(result => { + console.log('Report Settings Templates edit dialog was closed'); + if (result) { + + const index: number = this.reportTemplateList.indexOf(result[1].original[0]); + if (index !== -1) { + const ndd = { "title": result[0].title, "poc": "", "desc": result[0].desc, "severity": result[0].severity, "ref": result[0].ref, "cvss": result[0].cvss, "cvss_vector": result[0].cvss_vector, "cve": result[0].cve, "tags": result[0].tags }; + this.reportTemplateList[index] = ndd; - vaultobj.forEach( (element) => { + this.indexeddbService.updateTemplate(ndd, result[1].original[0]._key).then(ret => { }); + this.ReportTemplatesdataSource.data = this.reportTemplateList; - this.apiService.APISend(element.value, element.apikey, 'getreporttemplates', '').then(resp => { - this.reportTemplateList_int = []; - if (resp.length > 0) { - resp.forEach((ele) => { - ele.api = 'remote'; - ele.apiurl = element.value; - ele.apikey = element.apikey; - ele.apiname = element.viewValue; - }); - this.reportTemplateList_int.push(...resp); } - }).then(() => { - this.ReportTemplatesdataSource.data = [...this.reportTemplateList, ...this.reportTemplateList_int]; + } + + }); + + } + + getReportTemplates() { + this.indexeddbService.retrieveReportTemplates().then(ret => { + if (ret) { + this.ReportTemplatesdataSource = new MatTableDataSource(ret); this.reportTemplateList = this.ReportTemplatesdataSource.data; - this.ReportTemplatesdataSource.paginator = this.paginator2; - this.ReportTemplatesdataSource.sort = this.sort2; - this.msg = ''; - }).catch(() => {}); + } + this.getAPITemplates(); + }); + } + + getAPITemplates() { - setTimeout(() => { - // console.log('hide progress timeout'); - this.msg = ''; - }, 10000); + const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); + if (localkey) { + this.msg = 'API connection please wait...'; + + const vaultobj = JSON.parse(localkey); + + vaultobj.forEach((element) => { + + this.apiService.APISend(element.value, element.apikey, 'getreporttemplates', '').then(resp => { + this.reportTemplateList_int = []; + if (resp.length > 0) { + resp.forEach((ele) => { + ele.api = 'remote'; + ele.apiurl = element.value; + ele.apikey = element.apikey; + ele.apiname = element.viewValue; + }); + this.reportTemplateList_int.push(...resp); + } + + }).then(() => { + this.ReportTemplatesdataSource.data = [...this.reportTemplateList, ...this.reportTemplateList_int]; + this.reportTemplateList = this.ReportTemplatesdataSource.data; + this.ReportTemplatesdataSource.paginator = this.paginator2; + this.ReportTemplatesdataSource.sort = this.sort2; + this.msg = ''; + }).catch(() => { }); - }); + setTimeout(() => { + // console.log('hide progress timeout'); + this.msg = ''; + }, 10000); + }); + + } } -} } diff --git a/src/app/templates-list/templates-list.component.html b/src/app/templates-list/templates-list.component.html index bbb86102c..b36840240 100644 --- a/src/app/templates-list/templates-list.component.html +++ b/src/app/templates-list/templates-list.component.html @@ -47,7 +47,9 @@

matSortDirection="desc"> Title - {{element.title}} + + public {{element.title}} diff --git a/src/app/templates-list/templates-list.component.ts b/src/app/templates-list/templates-list.component.ts index 0c36f4157..8c1006fc0 100644 --- a/src/app/templates-list/templates-list.component.ts +++ b/src/app/templates-list/templates-list.component.ts @@ -13,6 +13,8 @@ import { } from '@angular/animations'; import { DialogAddCustomTemplateComponent } from '../dialog-add-custom-template/dialog-add-custom-template.component'; import { MatDialog, MatDialogRef } from '@angular/material/dialog'; +import { SessionstorageserviceService } from "../sessionstorageservice.service" +import { ApiService } from '../api.service'; export interface VulnsList { title: string; @@ -50,11 +52,13 @@ export class TemplatesListComponent implements OnInit { countvulns = []; expandedElement: VulnsList | null; sourceSelect = 'VULNREPO'; + reportTemplateList_int = []; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - constructor(private http: HttpClient,public dialog: MatDialog,private indexeddbService: IndexeddbService) { } + constructor(private http: HttpClient,public dialog: MatDialog,private indexeddbService: IndexeddbService, + private apiService: ApiService, public sessionsub: SessionstorageserviceService) { } ngOnInit() { this.getvulnlistStatus = 'Loading...'; @@ -76,9 +80,58 @@ export class TemplatesListComponent implements OnInit { this.getvulnlistStatus = ''; }); } + this.getAPITemplates(); }); } + getAPITemplates() { + + const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); + if (localkey) { + //this.msg = 'API connection please wait...'; + + const vaultobj = JSON.parse(localkey); + + vaultobj.forEach( (element) => { + + this.apiService.APISend(element.value, element.apikey, 'getreporttemplates', '').then(resp => { + this.reportTemplateList_int = []; + if (resp.length > 0) { + resp.forEach((ele) => { + ele.api = 'remote'; + ele.apiurl = element.value; + ele.apikey = element.apikey; + ele.apiname = element.viewValue; + }); + this.reportTemplateList_int.push(...resp); + } + + }).then(() => { + + this.http.get('/assets/vulns.json?v=' + + new Date()).subscribe(res => { + let xxx = [...res,...this.reportTemplateList_int]; + + this.dataSource = new MatTableDataSource(xxx); + this.countvulns = xxx; + this.dataSource.sort = this.sort; + this.dataSource.paginator = this.paginator; + this.getvulnlistStatus = ''; + }); + + + //this.msg = ''; + }).catch(() => {}); + + setTimeout(() => { + // console.log('hide progress timeout'); + //this.msg = ''; + }, 10000); + + }); + + } + } + changeselect() { if (this.sourceSelect === "VULNREPO") { From aaf1dab0672dbda8283c6976d72c230b42466649 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 19 Aug 2024 22:58:33 +0200 Subject: [PATCH 2/2] api template add issue fix --- .../dialog-addissue.component.ts | 48 ++++++++++++++++++- .../templates-list.component.ts | 4 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/app/dialog-addissue/dialog-addissue.component.ts b/src/app/dialog-addissue/dialog-addissue.component.ts index 1016f5b84..b99e7e011 100644 --- a/src/app/dialog-addissue/dialog-addissue.component.ts +++ b/src/app/dialog-addissue/dialog-addissue.component.ts @@ -4,7 +4,6 @@ import { HttpClient } from '@angular/common/http'; import { UntypedFormControl } from '@angular/forms'; import { Observable } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; -import { DatePipe } from '@angular/common'; import { Router } from '@angular/router'; import { ApiService } from '../api.service'; import {COMMA, ENTER} from '@angular/cdk/keycodes'; @@ -13,6 +12,8 @@ import {LiveAnnouncer} from '@angular/cdk/a11y'; import {MatAutocompleteSelectedEvent, MatAutocompleteModule} from '@angular/material/autocomplete'; import { CurrentdateService } from '../currentdate.service'; import { IndexeddbService } from '../indexeddb.service'; +import { SessionstorageserviceService } from "../sessionstorageservice.service" + export interface Tags { name: string; @@ -88,11 +89,12 @@ export class DialogAddissueComponent implements OnInit { separatorKeysCodes: number[] = [ENTER, COMMA]; announcer = inject(LiveAnnouncer); chipsissue: string[] = []; + reportTemplateList_int = []; constructor(public router: Router, public dialogRef: MatDialogRef, private http: HttpClient, private currentdateService: CurrentdateService, - private apiService: ApiService, private datePipe: DatePipe, + private apiService: ApiService, public sessionsub: SessionstorageserviceService, private indexeddbService: IndexeddbService) { this.filteredOptions = this.customissueform.valueChanges @@ -221,6 +223,7 @@ export class DialogAddissueComponent implements OnInit { this.options = [...res,...ret]; }); } + this.getAPITemplates(); }); this.http.get('/assets/CWE_V.4.3.json?v=' + + new Date()).subscribe(res => { @@ -265,6 +268,47 @@ export class DialogAddissueComponent implements OnInit { return this.currentdateService.getcurrentDate(); } + getAPITemplates() { + + const localkey = this.sessionsub.getSessionStorageItem('VULNREPO-API'); + if (localkey) { + //this.msg = 'API connection please wait...'; + + const vaultobj = JSON.parse(localkey); + + vaultobj.forEach( (element) => { + + this.apiService.APISend(element.value, element.apikey, 'getreporttemplates', '').then(resp => { + this.reportTemplateList_int = []; + if (resp.length > 0) { + resp.forEach((ele) => { + ele.api = 'remote'; + ele.apiurl = element.value; + ele.apikey = element.apikey; + ele.apiname = element.viewValue; + }); + this.reportTemplateList_int.push(...resp); + } + + }).then(() => { + + this.http.get('/assets/vulns.json?v=' + + new Date()).subscribe(res => { + this.options = [...this.options,...this.reportTemplateList_int]; + }); + + //this.msg = ''; + }).catch(() => {}); + + //setTimeout(() => { + // console.log('hide progress timeout'); + //this.msg = ''; + //}, 10000); + + }); + + } + } + addIssue() { if (this.customissueform.value !== "" && this.customissueform.value !== null) { diff --git a/src/app/templates-list/templates-list.component.ts b/src/app/templates-list/templates-list.component.ts index 8c1006fc0..c0ec9d141 100644 --- a/src/app/templates-list/templates-list.component.ts +++ b/src/app/templates-list/templates-list.component.ts @@ -122,10 +122,10 @@ export class TemplatesListComponent implements OnInit { //this.msg = ''; }).catch(() => {}); - setTimeout(() => { + //setTimeout(() => { // console.log('hide progress timeout'); //this.msg = ''; - }, 10000); + //}, 10000); });