mirror of https://github.com/CIRCL/url-abuse
Use POST to send email and to get content the cache
parent
89658c709b
commit
709ef400e4
|
@ -14,3 +14,8 @@ sphinxapi.py
|
|||
# JS libs
|
||||
angular.min.js
|
||||
ui-bootstrap-tpls.min.js
|
||||
|
||||
# Packages stuff
|
||||
build
|
||||
dist
|
||||
*egg-info
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import json
|
||||
import requests
|
||||
import time
|
||||
from base64 import urlsafe_b64encode
|
||||
|
||||
|
||||
class PyURLAbuse(object):
|
||||
|
@ -132,6 +131,6 @@ class PyURLAbuse(object):
|
|||
return {'info': 'New query, all the details may not be available.'}, self.get_cache(q)
|
||||
|
||||
def get_cache(self, q):
|
||||
q = urlsafe_b64encode(q)
|
||||
response = self.session.get('{}get_cache/{}'.format(self.url, q))
|
||||
query = {'query': q}
|
||||
response = self.session.post('{}get_cache' .format(self.url), data=json.dumps(query))
|
||||
return response.json()
|
||||
|
|
|
@ -468,7 +468,7 @@ def get_url_data(url):
|
|||
return {url: data}
|
||||
|
||||
|
||||
def get_cached(url):
|
||||
def cached(url):
|
||||
_cache_init()
|
||||
if not enable_cache:
|
||||
return [url]
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import json
|
||||
import os
|
||||
from base64 import urlsafe_b64decode
|
||||
|
||||
from flask import Flask, render_template, request, Response, redirect, url_for, flash
|
||||
from flask import Flask, render_template, request, Response, redirect, url_for, jsonify
|
||||
from flask_mail import Mail, Message
|
||||
from flask_bootstrap import Bootstrap
|
||||
from flask_wtf import Form
|
||||
|
@ -23,7 +22,7 @@ import ConfigParser
|
|||
from proxied import ReverseProxied
|
||||
from url_abuse_async import is_valid_url, url_list, dns_resolve, phish_query, psslcircl, \
|
||||
vt_query_url, gsb_query, urlquery_query, sphinxsearch, whois, pdnscircl, bgpranking, \
|
||||
get_cached, get_mail_sent, set_mail_sent, get_submissions
|
||||
cached, get_mail_sent, set_mail_sent, get_submissions
|
||||
|
||||
config_path = 'config.ini'
|
||||
|
||||
|
@ -272,10 +271,11 @@ def create_app(configfile=None):
|
|||
query,), result_ttl=500)
|
||||
return u.get_id()
|
||||
|
||||
@app.route('/get_cache/<path:url>')
|
||||
def get_cache(url):
|
||||
url = urlsafe_b64decode(url.encode('utf-8'))
|
||||
data = get_cached(url)
|
||||
@app.route('/get_cache', methods=['POST'])
|
||||
def get_cache():
|
||||
data = json.loads(request.data)
|
||||
url = data["query"]
|
||||
data = cached(url)
|
||||
dumped = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
|
||||
return dumped
|
||||
|
||||
|
@ -283,7 +283,7 @@ def create_app(configfile=None):
|
|||
if not get_mail_sent(url):
|
||||
print 'Send mail'
|
||||
set_mail_sent(url)
|
||||
data = get_cached(url)
|
||||
data = cached(url)
|
||||
if not autosend:
|
||||
subject = 'URL Abuse report from ' + ip
|
||||
else:
|
||||
|
@ -296,12 +296,9 @@ def create_app(configfile=None):
|
|||
def send_mail():
|
||||
data = json.loads(request.data)
|
||||
url = data["url"]
|
||||
if get_mail_sent(url):
|
||||
flash('Mail already sent to CIRCL.')
|
||||
else:
|
||||
if not get_mail_sent(url):
|
||||
ip = _get_user_ip(request)
|
||||
send(url, ip)
|
||||
flash('Mail successfully sent to CIRCL.')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
return app
|
||||
|
|
|
@ -3,6 +3,24 @@
|
|||
|
||||
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) {
|
||||
|
@ -33,10 +51,11 @@
|
|||
};
|
||||
}]);
|
||||
|
||||
app.controller('URLabuseController', function($scope, $log, globFct) {
|
||||
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){
|
||||
|
@ -50,6 +69,9 @@
|
|||
// get the URL from the input
|
||||
$scope.query_url = '';
|
||||
$scope.urls = '';
|
||||
// Reset the message
|
||||
$scope.$emit('newFlashMessage', '');
|
||||
|
||||
var userInput = $scope.input_url;
|
||||
|
||||
|
||||
|
@ -72,6 +94,8 @@
|
|||
$scope.query_url = '';
|
||||
$scope.urls = '';
|
||||
$scope.input_url = '';
|
||||
flash.setMessage("Mail sent to CIRCL");
|
||||
$scope.$emit('newFlashMessage', '');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -19,15 +19,11 @@
|
|||
<h1>URL Abuse testing form</h1>
|
||||
<h3><div align="center">URL Abuse is a public CIRCL service to review URL.<br /><a target="_blank" href="https://www.circl.lu/services/urlabuse/">For more information about the service</a></div></h3>
|
||||
<br/>
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
<div class="flashes alert">
|
||||
{% for message in messages %}
|
||||
<center><div class="alert alert-success">{{ message }}</div></center>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% raw %}
|
||||
<div class="alert alert-success" ng-show="flash.getMessage()">
|
||||
<center>{{ flash.getMessage() }}</center>
|
||||
</div>
|
||||
{% endraw %}
|
||||
<br/>
|
||||
<form class="form form-horizontal" method="post" role="form" ng-submit="getResults()">
|
||||
{{ form.hidden_tag() }}
|
||||
|
|
Loading…
Reference in New Issue