(function () {
'use strict';
var app = angular.module('URLabuseApp', ['ui.bootstrap']);
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;
}
};
});
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);
});
}
};
}]);
app.controller('URLabuseController', function($scope, $log, globFct, flash) {
$scope.poller = globFct.poller;
$scope.query = globFct.query;
$scope.flash = flash;
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 = '';
// Reset the message
$scope.$emit('newFlashMessage', '');
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);
};
$scope.submit_email = function() {
$scope.query('submit', {"url": $scope.query_url}, function(){
$scope.query_url = '';
$scope.urls = '';
$scope.input_url = '';
flash.setMessage("Mail sent to CIRCL");
$scope.$emit('newFlashMessage', '');
});
};
});
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];
if (!scope.ipv4){
scope.ipv4 = ['Unable to resolve in IPv4'];
}
if (!scope.ipv6){
scope.ipv6 = ['Unable to resolve in IPv6'];
}
});
};
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 '
';}
};
});
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 '';}
};
});
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 'Known {{response}} website on Google Safe Browsing. More details. ';}
};
});
app.directive('uqEupi', function(globFct) {
return {
scope: {
query: '=data',
},
link: function(scope, element, attrs) {
var get_response = function(jobID) {
globFct.poller(jobID, function(data){
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 'Known as {{response}} by the European Union antiphishing initiative. ';}
};
});
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 'The total alert count on URLquery is {{response}}. ';}
};
});
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: ''
};
});
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: 'Contact points from Whois: {{ response }}
'
};
});
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);
},
template: 'Has {{nbentries}} unique entries in CIRCL Passive DNS. {{lastentries.length}} most recent one(s):
'
};
});
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);
},
template: 'SSL certificates related to this IP:
'
};
});
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);
},
template: 'Information from BGP Ranking: - PTR Resource Record: {{ptr}}
- Announced by: {{asndesc}} ({{asn}})
- This ASN is at position {{position}} in the list of {{total}} known ASNs ({{value}}).
'
};
});
}());