import { NodeDetailCredentialsInfoController } from './credentials.controller' ; import { INodeDetailResolverService } from '../../app/services/nodedetailresolver' ; import { IMinemeldConfigService } from '../../app/services/config' ; import { IMinemeldStatusService } from '../../app/services/status' ; import { IThrottleService } from '../../app/services/throttle' ; import { IConfirmService } from '../../app/services/confirm' ; import { IMineMeldRunningConfigStatusService , IMineMeldRunningConfigStatus , IMinemeldResolvedConfigNode } from '../../app/services/runningconfigstatus' ; ngInject function taxiiClientConfig ( $stateProvider ) { $stateProvider . state ( 'nodedetail.taxiiclientinfo' , { templateUrl : 'app/nodedetail/taxiiclient.info.html' , controller : TAXIIClientInfoController , controllerAs : 'nodedetailinfo' } ) ; } ngInject function taxiiClientRegisterClasses ( NodeDetailResolver ) { NodeDetailResolver . registerClass ( 'minemeld.ft.taxii.TaxiiClient' , { tabs : [ { icon : 'fa fa-circle-o' , tooltip : 'INFO' , state : 'nodedetail.taxiiclientinfo' , active : false } , { icon : 'fa fa-area-chart' , tooltip : 'STATS' , state : 'nodedetail.stats' , active : false } , { icon : 'fa fa-asterisk' , tooltip : 'GRAPH' , state : 'nodedetail.graph' , active : false } ] } ) ; } interface ITAXIIClientSideConfig { username ? : string ; password ? : string ; } class TAXIIClientInfoController extends NodeDetailCredentialsInfoController { ConfirmService : IConfirmService ; MineMeldRunningConfigStatusService : IMineMeldRunningConfigStatusService ; clientCertEnabled : boolean ; clientCertSet : boolean ; serverCAEnabled : boolean ; serverCASet : boolean ; subscriptionIdEnabled : boolean ; subscriptionId : string ; constructor ( toastr , $interval , MinemeldStatusService , moment , $scope , $compile , $state , $stateParams , MinemeldConfigService , $modal , $rootScope , ThrottleService , MineMeldRunningConfigStatusService , ConfirmService ) { this . MineMeldRunningConfigStatusService = MineMeldRunningConfigStatusService ; this . clientCertEnabled = false ; this . clientCertSet = false ; this . serverCAEnabled = false ; this . serverCASet = false ; this . subscriptionIdEnabled = false ; super ( toastr , $interval , MinemeldStatusService , moment , $scope , $compile , $state , $stateParams , MinemeldConfigService , $modal , $rootScope , ThrottleService ) ; this . ConfirmService = ConfirmService ; } updateMinemeldConfig ( ) { var vm = this ; vm . MineMeldRunningConfigStatusService . getStatus ( ) . then ( function ( result ) { var tnodeConfig ; tnodeConfig = result . nodes [ vm . nodename ] ; vm . nodeConfig = tnodeConfig ; if ( vm . nodeConfig . config && ( Object . keys ( vm . nodeConfig . config ) . length === 0 ) ) { vm . nodeConfig . config = null ; } if ( tnodeConfig . resolvedPrototype ) { var pconfig = tnodeConfig . resolvedPrototype . config ; if ( typeof ( pconfig . client_credentials_required ) == 'boolean' && ! pconfig . client_credentials_required ) { vm . usernameField = null ; } else { if ( typeof ( pconfig . username ) === 'undefined' && typeof ( pconfig . password ) === 'undefined' ) { vm . usernameField = 'username' ; } } if ( pconfig . client_cert_required ) { vm . clientCertEnabled = true ; vm . MinemeldConfigService . getDataFile ( vm . nodename , 'cert' ) . then ( ( result ) => { if ( result == null ) { vm . clientCertSet = false ; return ; } vm . MinemeldConfigService . getDataFile ( vm . nodename , 'pkey' ) . then ( ( result ) => { if ( result == null ) { vm . clientCertSet = false ; return ; } vm . clientCertSet = true ; } , ( error ) => { vm . clientCertSet = false ; } ) ; } , ( error ) => { vm . clientCertSet = false ; } ) ; } if ( pconfig . subscription_id_required ) { vm . subscriptionIdEnabled = true ; } if ( pconfig . discovery_service . startsWith ( 'https://' ) ) { vm . serverCAEnabled = true ; vm . MinemeldConfigService . getDataFile ( vm . nodename + '-ca' , 'cert' ) . then ( ( result ) => { if ( result == null ) { vm . serverCASet = false ; return ; } vm . serverCASet = true ; } , ( error ) => { vm . serverCASet = false ; } ) ; } } } , function ( error ) { if ( ! error . cancelled ) { vm . toastr . error ( 'ERROR RETRIEVING MINEMELD CONFIG: ' + error . status ) ; } } ) . finally ( function ( ) { vm . updateMinemeldConfigPromise = vm . $interval ( vm . updateMinemeldConfig . bind ( vm ) , vm . updateMinemeldConfigInterval , 1 ) ; } ) ; } uploadClientCertificate ( ) { var mi ; mi = this . $modal . open ( { templateUrl : 'app/nodedetail/taxiiclient.uploadcert.modal.html' , controller : UploadClientCertController , controllerAs : 'vm' , bindToController : true , backdrop : 'static' , animation : false , resolve : { nodeName : ( ) => { return this . nodename ; } } } ) ; mi . result . then ( ( result ) => { this . $interval . cancel ( this . updateMinemeldConfigPromise ) ; this . updateMinemeldConfig ( ) ; } ) ; } uploadServerCA ( ) { var mi ; mi = this . $modal . open ( { templateUrl : 'app/nodedetail/taxiiclient.uploadserverca.modal.html' , controller : UploadServerCACertController , controllerAs : 'vm' , bindToController : true , backdrop : 'static' , animation : false , resolve : { nodeName : ( ) => { return this . nodename ; } } } ) ; mi . result . then ( ( result ) => { this . $interval . cancel ( this . updateMinemeldConfigPromise ) ; this . updateMinemeldConfig ( ) ; } ) ; } setSubscriptionId ( ) { var mi ; if ( ! this . subscriptionIdEnabled ) { return ; } mi = this . $modal . open ( { templateUrl : 'app/nodedetail/taxiiclient.sid.modal.html' , controller : SetSubscriptionIdController , controllerAs : 'vm' , bindToController : true , backdrop : 'static' , animation : false , resolve : { subscriptionId : ( ) => { return this . subscriptionId ; } } } ) ; mi . result . then ( ( result ) => { this . subscriptionId = result . subscriptionId ; return this . saveSideConfig ( ) . then ( ( result ) => { this . toastr . success ( 'SUBSCRIPTION ID SET' ) ; } , ( error ) => { this . toastr . error ( 'ERROR SETTING SUBSCRIPTION ID: ' + error . statusText ) ; } ) ; } ) ; } protected restoreSideConfig ( result ) { super . restoreSideConfig ( result ) ; if ( ! result ) { this . subscriptionId = undefined ; } else { if ( result . subscription_id ) { this . subscriptionId = result . subscription_id ; } } } protected prepareSideConfig ( ) { var side_config = super . prepareSideConfig ( ) ; if ( this . subscriptionId ) { side_config . subscription_id = this . subscriptionId ; } return side_config ; } } class UploadClientCertController { $modalInstance : angular . ui . bootstrap . IModalServiceInstance ; toastr : any ; uploading : boolean = false ; certUploader : any ; keyUploader : any ; ngInject constructor ( $modalInstance , FileUploader , toastr , nodeName ) { this . $modalInstance = $modalInstance ; this . toastr = toastr ; this . certUploader = new FileUploader ( { url : '/config/data/' + nodeName + '?t=cert' , method : 'PUT' , queueLimit : 1 , removeAfterUpload : true } ) ; this . keyUploader = new FileUploader ( { url : '/config/data/' + nodeName + '?t=pkey' , method : 'PUT' , queueLimit : 1 , removeAfterUpload : true } ) ; this . certUploader . onErrorItem = this . onErrorItem ; this . keyUploader . onErrorItem = this . onErrorItem ; this . certUploader . onSuccessItem = ( item ) => { this . keyUploader . uploadAll ( ) ; } ; this . keyUploader . onSuccessItem = ( item ) => { this . uploading = false ; this . toastr . success ( 'CLIENT CERT SET' ) ; this . $modalInstance . close ( 'ok' ) ; } ; } uploadAll ( ) { this . uploading = true ; this . certUploader . uploadAll ( ) ; } cancel ( ) { this . $modalInstance . dismiss ( 'cancel' ) ; } private onErrorItem ( item , response , status ) { this . uploading = false ; if ( status === 400 ) { this . toastr . error ( 'ERROR UPLOADING: ' + response . error . message ) ; return ; } this . toastr . error ( 'ERROR UPLOADING: ' + status ) ; } ; } class UploadServerCACertController { $modalInstance : angular . ui . bootstrap . IModalServiceInstance ; toastr : any ; uploading : boolean = false ; certUploader : any ; ngInject constructor ( $modalInstance , FileUploader , toastr , nodeName ) { this . $modalInstance = $modalInstance ; this . toastr = toastr ; this . certUploader = new FileUploader ( { url : '/config/data/' + nodeName + '-ca?t=cert' , method : 'PUT' , queueLimit : 1 , removeAfterUpload : true } ) ; this . certUploader . onErrorItem = this . onErrorItem ; this . certUploader . onSuccessItem = ( item ) => { this . uploading = false ; this . toastr . success ( 'SERVER CA SET' ) ; this . $modalInstance . close ( 'ok' ) ; } ; } uploadAll ( ) { this . uploading = true ; this . certUploader . uploadAll ( ) ; } cancel ( ) { this . $modalInstance . dismiss ( 'cancel' ) ; } private onErrorItem ( item , response , status ) { this . uploading = false ; if ( status === 400 ) { this . toastr . error ( 'ERROR UPLOADING: ' + response . error . message ) ; return ; } this . toastr . error ( 'ERROR UPLOADING: ' + status ) ; } ; } class SetSubscriptionIdController { $modalInstance : angular . ui . bootstrap . IModalServiceInstance ; subscriptionId : string ; ngInject constructor ( $modalInstance , subscriptionId ) { this . $modalInstance = $modalInstance ; this . subscriptionId = subscriptionId ; } valid ( ) { if ( ! this . subscriptionId ) { return false ; } return true ; } save ( ) { var result = { } ; result . subscriptionId = this . subscriptionId ; this . $modalInstance . close ( result ) ; } cancel ( ) { this . $modalInstance . dismiss ( ) ; } } ; console . log ( 'Loading TAXII Client' ) ; angular . module ( 'minemeldWebui' ) . config ( taxiiClientConfig ) . run ( taxiiClientRegisterClasses ) ;