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' ; ngInject function CIFConfig ( $stateProvider ) { $stateProvider . state ( 'nodedetail.cifinfo' , { templateUrl : 'app/nodedetail/cif.info.html' , controller : NodeDetailCIFInfoController , controllerAs : 'nodedetailinfo' , params : { usernameEnabled : { value : false } , secretName : { value : 'TOKEN' } , secretField : { value : 'token' } } } ) ; } ngInject function CIFRegisterClasses ( NodeDetailResolver ) { NodeDetailResolver . registerClass ( 'minemeld.ft.cif.Feed' , { tabs : [ { icon : 'fa fa-circle-o' , tooltip : 'INFO' , state : 'nodedetail.cifinfo' , 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 ICIFSideConfigFilters { tags ? : string [ ] ; otype ? : string ; confidence ? : number ; [ key ] : any ; } interface ICIFSideConfig { verify_cert ? : boolean ; remote ? : string ; filters ? : ICIFSideConfigFilters ; } class NodeDetailCIFInfoController extends NodeDetailCredentialsInfoController { MinemeldConfigService : IMinemeldConfigService ; $modal : angular . ui . bootstrap . IModalService ; ConfirmService : IConfirmService ; remote : string ; flattenedFilters : string ; verify_cert : boolean ; private _filters : ICIFSideConfigFilters ; constructor ( toastr , $interval , MinemeldStatusService , moment , $scope , $compile , $state , $stateParams , MinemeldConfigService , $modal , $rootScope , ThrottleService , ConfirmService ) { super ( toastr , $interval , MinemeldStatusService , moment , $scope , $compile , $state , $stateParams , MinemeldConfigService , $modal , $rootScope , ThrottleService ) ; this . ConfirmService = ConfirmService ; } setRemote ( ) { var mi ; mi = this . $modal . open ( { templateUrl : 'app/nodedetail/cif.remote.modal.html' , controller : CIFSetRemoteController , controllerAs : 'vm' , bindToController : true , backdrop : 'static' , animation : false , resolve : { remote : ( ) => { return this . remote ; } } } ) ; mi . result . then ( ( result ) => { this . remote = result . remote ; return this . saveSideConfig ( ) . then ( ( result ) => { this . toastr . success ( 'REMOTE SET' ) ; } , ( error ) => { this . toastr . error ( 'ERROR SETTING REMOTE: ' + error . statusText ) ; } ) ; } ) ; } toggleCertificateVerification ( ) { var p ; var new_value ; if ( typeof this . verify_cert === 'undefined' || this . verify_cert ) { new_value = false ; p = this . ConfirmService . show ( 'CIF REMOTE CERT VERIFICATION' , 'Are you sure you want to disable certificate verification ?' ) ; } else { new_value = true ; p = this . ConfirmService . show ( 'CIF REMOTE CERT VERIFICATION' , 'Are you sure you want to enable certificate verification ?' ) ; } p . then ( ( result ) => { this . verify_cert = new_value ; return this . saveSideConfig ( ) . then ( ( result ) => { this . toastr . success ( 'CERT VERIFICATION TOGGLED' ) ; } , ( error ) => { this . toastr . error ( 'ERROR TOGGLING CERT VERIFICATION: ' + error . statusText ) ; } ) ; } ) ; } setFilters ( ) { var mi ; mi = this . $modal . open ( { templateUrl : 'app/nodedetail/cif.filters.modal.html' , controller : CIFSetFiltersController , controllerAs : 'vm' , bindToController : true , backdrop : 'static' , animation : false , resolve : { filters : ( ) => { return this . filters ; } } } ) ; mi . result . then ( ( result ) => { this . filters = result . filters ; return this . saveSideConfig ( ) . then ( ( result ) => { this . toastr . success ( 'FILTERS SET' ) ; } , ( error ) => { this . toastr . error ( 'ERROR SETTING FILTERS: ' + error . statusText ) ; } ) ; } ) ; } protected restoreSideConfig ( result ) { let side_config = < ICIFSideConfig > result ; super . restoreSideConfig ( result ) ; this . remote = undefined ; this . filters = undefined ; this . verify_cert = undefined ; if ( ! result ) { return ; } if ( side_config . remote ) { this . remote = side_config . remote ; } if ( side_config . filters ) { this . filters = side_config . filters ; } if ( typeof side_config . verify_cert !== 'undefined' ) { this . verify_cert = side_config . verify_cert ; } } protected prepareSideConfig ( ) { var side_config = super . prepareSideConfig ( ) ; if ( this . remote ) { side_config . remote = this . remote ; } if ( this . filters ) { side_config . filters = this . filters ; } if ( typeof this . verify_cert !== 'undefined' ) { side_config . verify_cert = this . verify_cert ; } return side_config ; } get filters ( ) : ICIFSideConfigFilters { return this . _filters ; } set filters ( newfilters ) { this . _filters = newfilters ; this . flattenFilters ( ) ; } private flattenFilters ( ) { var filter = [ ] ; if ( ! this . filters ) { this . flattenedFilters = undefined ; return ; } Object . keys ( this . filters ) . forEach ( ( key ) => { var value ; var kv ; kv = key + ': ' ; value = this . filters [ key ] ; if ( value instanceof Array ) { kv += value . join ( ', ' ) ; } else { kv += value ; } filter . push ( kv ) ; } ) ; this . flattenedFilters = filter . join ( ' ' ) ; } } class CIFSetRemoteController { $modalInstance : angular . ui . bootstrap . IModalServiceInstance ; remote : string ; ngInject constructor ( $modalInstance , remote ) { this . $modalInstance = $modalInstance ; this . remote = remote ; } valid ( ) { if ( ! this . remote ) { return false ; } return true ; } save ( ) { var result = { } ; result . remote = this . remote ; this . $modalInstance . close ( result ) ; } cancel ( ) { this . $modalInstance . dismiss ( ) ; } } ; class CIFSetFiltersController { $modalInstance : angular . ui . bootstrap . IModalServiceInstance ; otypes : string [ ] = [ 'ipv4' , 'ipv6' , 'fqdn' , 'url' ] ; defaultTags : string [ ] = [ 'whitelist' , 'spam' , 'malware' , 'scanner' , 'hijacked' , 'botnet' , 'exploit' , 'phishing' ] ; filters : ICIFSideConfigFilters ; otype : string ; confidence : string ; confidenceValid : boolean = true ; tags : string [ ] ; changed : boolean ; ngInject constructor ( $modalInstance , filters ) { this . $modalInstance = $modalInstance ; this . filters = filters ; if ( this . filters ) { if ( this . filters . otype ) { this . otype = this . filters . otype ; } if ( typeof this . filters . confidence !== 'undefined' ) { this . confidence = '' + this . filters . confidence ; } if ( typeof this . filters . tags !== 'undefined' ) { this . tags = this . filters . tags ; } } } tagging ( value ) { return value ; } valid ( ) { var result = true ; var nconfidence ; if ( ! this . changed ) { result = false ; } angular . element ( '#fgConfidence' ) . removeClass ( 'has-error' ) ; if ( typeof this . confidence !== 'undefined' && this . confidence . length !== 0 ) { if ( ! /^\s*[0-9]+\s*$/ . test ( this . confidence ) ) { result = false ; angular . element ( '#fgConfidence' ) . addClass ( 'has-error' ) ; } else { nconfidence = + this . confidence ; if ( nconfidence < 0 || nconfidence > 100 || isNaN ( nconfidence ) ) { result = false ; angular . element ( '#fgConfidence' ) . addClass ( 'has-error' ) ; } } } return result ; } save ( ) { var result = { } ; result . filters = this . filters ; if ( typeof this . confidence !== 'undefined' && this . confidence . length !== 0 ) { if ( ! result . filters ) { result . filters = { } ; } result . filters . confidence = + this . confidence ; } else { if ( result . filters ) { delete result . filters . confidence ; } } if ( typeof this . tags !== 'undefined' && this . tags . length !== 0 ) { if ( ! result . filters ) { result . filters = { } ; } result . filters . tags = this . tags ; } else { if ( result . filters ) { delete result . filters . tags ; } } if ( typeof this . otype !== 'undefined' && this . otype . length !== 0 ) { if ( ! result . filters ) { result . filters = { } ; } result . filters . otype = this . otype ; } else { if ( result . filters ) { delete result . filters . otype ; } } if ( Object . keys ( result . filters ) . length === 0 ) { result . filters = undefined ; } this . $modalInstance . close ( result ) ; } cancel ( ) { this . $modalInstance . dismiss ( ) ; } } ; console . log ( 'Loading CIF' ) ; angular . module ( 'minemeldWebui' ) . config ( CIFConfig ) . run ( CIFRegisterClasses ) ;