2015-03-02 14:55:34 +01:00
( function ( ) {
'use strict' ;
var app = angular . module ( 'URLabuseApp' , [ 'ui.bootstrap' ] ) ;
2015-03-12 15:51:12 +01:00
app . factory ( "flash" , function ( $rootScope ) {
var queue = [ ] ;
var currentMessage = "" ;
$rootScope . $on ( "newFlashMessage" , function ( ) {
currentMessage = queue . shift ( ) || "" ;
} ) ;
return {
setMessage : function ( message ) {
queue . push ( message ) ;
} ,
getMessage : function ( ) {
return currentMessage ;
}
} ;
} ) ;
2015-03-02 14:55:34 +01:00
app . factory ( 'globFct' , [ '$log' , '$http' , '$timeout' , function ( $log , $http , $timeout ) {
return {
poller : function myself ( jobID , callback ) {
var timeout = "" ;
// fire another request
$http . get ( '_result/' + jobID ) .
success ( function ( data , status , headers , config ) {
if ( status === 202 ) {
$log . log ( data , status ) ;
} else if ( status === 200 ) {
$log . log ( data ) ;
$timeout . cancel ( timeout ) ;
callback ( angular . fromJson ( data ) ) ;
return ;
}
// continue to call the poller() function every 2 seconds
// until the timout is cancelled
timeout = $timeout ( function ( ) { myself ( jobID , callback ) ; } , 2000 ) ;
} ) ;
} ,
query : function ( path , data , callback ) {
$http . post ( path , data ) .
success ( callback ) .
error ( function ( error ) {
$log . log ( error ) ;
} ) ;
}
} ;
} ] ) ;
2015-03-12 15:51:12 +01:00
app . controller ( 'URLabuseController' , function ( $scope , $log , globFct , flash ) {
2015-03-02 14:55:34 +01:00
$scope . poller = globFct . poller ;
$scope . query = globFct . query ;
2015-03-12 15:51:12 +01:00
$scope . flash = flash ;
2015-03-02 14:55:34 +01:00
var get _redirects = function ( jobID ) {
$scope . poller ( jobID , function ( data ) {
$log . log ( data ) ;
$scope . urls = data ;
} ) ;
} ;
$scope . getResults = function ( ) {
// get the URL from the input
$scope . query _url = '' ;
$scope . urls = '' ;
2015-03-12 15:51:12 +01:00
// Reset the message
$scope . $emit ( 'newFlashMessage' , '' ) ;
2015-03-02 14:55:34 +01:00
var userInput = $scope . input _url ;
var check _validity = function ( jobID ) {
$scope . poller ( jobID , function ( data ) {
$scope . query _url = data [ 1 ] ;
if ( data [ 0 ] === false ) {
$scope . error = data [ 2 ] ;
} else {
$scope . query ( 'urls' , { "url" : data [ 1 ] } , get _redirects ) ;
}
} ) ;
} ;
$scope . query ( 'start' , { "url" : userInput } , check _validity ) ;
} ;
2015-03-11 18:14:25 +01:00
$scope . submit _email = function ( ) {
$scope . query ( 'submit' , { "url" : $scope . query _url } , function ( ) {
$scope . query _url = '' ;
$scope . urls = '' ;
$scope . input _url = '' ;
2015-03-12 15:51:12 +01:00
flash . setMessage ( "Mail sent to CIRCL" ) ;
$scope . $emit ( 'newFlashMessage' , '' ) ;
2015-03-11 18:14:25 +01:00
} ) ;
} ;
2015-03-02 14:55:34 +01:00
} ) ;
app . directive ( 'uqUrlreport' , function ( globFct ) {
return {
scope : {
url : '=uqUrlreport' ,
// status: {isFirstOpen: true, isFirstDisabled: false}
} ,
link : function ( scope , element , attrs ) {
var get _ips = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . ipv4 = data [ 0 ] ;
scope . ipv6 = data [ 1 ] ;
2015-04-30 10:54:39 +02:00
if ( ! scope . ipv4 ) {
2015-04-30 10:33:08 +02:00
scope . ipv4 = [ 'Unable to resolve in IPv4' ] ;
}
2015-04-30 10:54:39 +02:00
if ( ! scope . ipv6 ) {
2015-04-30 10:33:08 +02:00
scope . ipv6 = [ 'Unable to resolve in IPv6' ] ;
}
2015-03-02 14:55:34 +01:00
} ) ;
} ;
globFct . query ( 'resolve' , { "url" : scope . url } , get _ips ) ;
} ,
templateUrl : 'urlreport' ,
} ;
} ) ;
app . directive ( 'uqPhishtank' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . response = data ;
} ) ;
} ;
globFct . query ( 'phishtank' , { "query" : scope . query } , get _response ) ;
} ,
template : function ( elem , attr ) {
return '<div ng-show="response" class="animate-show"><alert type="danger">Known phishing website on Phishtank. <a target="_blank" ng-href="{{response}}">More details</a>.</alert></div>' ; }
} ;
} ) ;
app . directive ( 'uqVirustotal' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . message = data [ 0 ] ;
scope . link = data [ 1 ] ;
scope . positives = data [ 2 ] ;
scope . total = data [ 3 ] ;
if ( scope . link && scope . positives === null ) {
scope . alert _val = "info" ;
scope . message = "Scan request successfully queued, report available soon." ;
} else if ( scope . link && scope . positives === 0 ) {
scope . message = "None of the " + data [ 3 ] + " scanners know this URL as malicious." ;
scope . alert _val = "success" ;
} else if ( scope . link && scope . positives < scope . total / 3 ) {
scope . message = data [ 2 ] + " of the " + data [ 3 ] + " scanners know this URL as malicious." ;
scope . alert _val = "warning" ;
} else if ( scope . link && scope . positives >= scope . total / 3 ) {
scope . message = data [ 2 ] + " of the " + data [ 3 ] + " scanners know this URL as malicious." ;
scope . alert _val = "danger" ;
}
} ) ;
} ;
globFct . query ( 'virustotal_report' , { "query" : scope . query } , get _response ) ;
} ,
template : function ( elem , attr ) {
return '<div ng-show="message" class="animate-show"><alert type="{{alert_val}}">{{message}} <a ng-if="link" target="_blank" ng-href="{{link}}">More details</a>.</alert></div>' ; }
} ;
} ) ;
app . directive ( 'uqGooglesafebrowsing' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . response = data ;
} ) ;
} ;
globFct . query ( 'googlesafebrowsing' , { "query" : scope . query } , get _response ) ;
} ,
template : function ( elem , attr ) {
return '<div ng-show="response" class="animate-show"><alert type="danger">Known {{response}} website on Google Safe Browsing. <a target="_blank" ng-href="https://www.google.com/safebrowsing/diagnostic?site={{query}}">More details</a>.</alert></div>' ; }
} ;
} ) ;
2015-09-09 15:18:06 +02:00
app . directive ( 'uqEupi' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
2015-09-09 15:32:24 +02:00
if ( data === "inconnu" ) {
return ;
}
2015-09-09 15:18:06 +02:00
scope . response = data ;
if ( data === "clean" ) {
scope . alert _val = "success" ;
}
else {
ascope . alert _val = "danger" ;
}
} ) ;
} ;
globFct . query ( 'eupi' , { "query" : scope . query } , get _response ) ;
} ,
template : function ( elem , attr ) {
return '<div ng-show="response" class="animate-show"><alert type="{{alert_val}}">Known as {{response}} by the European Union antiphishing initiative.</alert></div>' ; }
} ;
} ) ;
2015-03-02 14:55:34 +01:00
app . directive ( 'uqUrlquery' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . response = data ;
} ) ;
} ;
globFct . query ( 'urlquery' , { "query" : scope . query } , get _response ) ;
} ,
template : function ( elem , attr ) {
return '<div ng-show="response" class="animate-show"><alert type="danger">The total alert count on URLquery is {{response}}.</alert></div>' ; }
} ;
} ) ;
app . directive ( 'uqTicket' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . response = data ;
} ) ;
} ;
globFct . query ( 'ticket' , { "query" : scope . query } , get _response ) ;
} ,
template : '<div ng-show="response.length > 0" class="animate-show">Tickets: <ul><div ng-repeat="ticket in response"><li><a target="_blank" ng-href={{ticket}}>{{ticket}}</a></li></div></ul></div>'
} ;
} ) ;
app . directive ( 'uqWhois' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . response = data . join ( ) ;
} ) ;
} ;
globFct . query ( 'whois' , { "query" : scope . query } , get _response ) ;
} ,
template : '<div ng-show="response" class="animate-show">Contact points from Whois: {{ response }}</div>'
} ;
} ) ;
app . directive ( 'uqPdnscircl' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . nbentries = data [ 0 ] ;
scope . lastentries = data [ 1 ] ;
} ) ;
} ;
globFct . query ( 'pdnscircl' , { "query" : scope . query } , get _response ) ;
} ,
2015-04-07 13:22:00 +02:00
template : '<div ng-show="nbentries" class="animate-show">Has {{nbentries}} unique entries in CIRCL Passive DNS. {{lastentries.length}} most recent one(s): <ul><div ng-repeat="domain in lastentries"><li>{{domain}}</li></div></ul></div>'
2015-03-02 14:55:34 +01:00
} ;
} ) ;
app . directive ( 'uqPsslcircl' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . entries = data ;
} ) ;
} ;
globFct . query ( 'psslcircl' , { "query" : scope . query } , get _response ) ;
} ,
2015-09-09 14:38:56 +02:00
template : '<div ng-show="entries" class="animate-show">SSL certificates related to this IP: <ul><div ng-repeat="(sha1, subject) in entries"><li><b>{{sha1}}</b>: {{subject[0]}}</li></div></ul></div>'
2015-03-02 14:55:34 +01:00
} ;
} ) ;
app . directive ( 'uqBgpranking' , function ( globFct ) {
return {
scope : {
query : '=data' ,
} ,
link : function ( scope , element , attrs ) {
var get _response = function ( jobID ) {
globFct . poller ( jobID , function ( data ) {
scope . ptr = data [ 0 ] ;
scope . asndesc = data [ 1 ] ;
scope . asn = data [ 2 ] ;
scope . position = data [ 3 ] ;
scope . total = data [ 4 ] ;
scope . value = data [ 5 ] ;
if ( scope . position < 100 ) {
scope . alert _val = "danger" ;
} else if ( scope . position < 1000 ) {
scope . alert _val = "warning" ;
} else {
scope . alert _val = "info" ;
}
} ) ;
} ;
globFct . query ( 'bgpranking' , { "query" : scope . query } , get _response ) ;
} ,
2015-04-07 13:22:00 +02:00
template : '<div ng-show="asn" class="animate-show"><alert type="{{alert_val}}">Information from BGP Ranking: <ul><li ng-show="ptr">PTR Resource Record: {{ptr}}</li><li>Announced by: {{asndesc}} (<a target="_blank" ng-href="http://bgpranking.circl.lu/asn_details?asn={{asn}}">{{asn}}</a>)</li><li>This ASN is at position {{position}} in the list of {{total}} known ASNs ({{value}}).</li></ul></alert></div>'
2015-03-02 14:55:34 +01:00
} ;
} ) ;
} ( ) ) ;