Use POST to send email and to get content the cache

travis
Raphaël Vinot 2015-03-12 15:51:12 +01:00
parent 89658c709b
commit 709ef400e4
6 changed files with 47 additions and 26 deletions

5
.gitignore vendored
View File

@ -14,3 +14,8 @@ sphinxapi.py
# JS libs # JS libs
angular.min.js angular.min.js
ui-bootstrap-tpls.min.js ui-bootstrap-tpls.min.js
# Packages stuff
build
dist
*egg-info

View File

@ -4,7 +4,6 @@
import json import json
import requests import requests
import time import time
from base64 import urlsafe_b64encode
class PyURLAbuse(object): 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) return {'info': 'New query, all the details may not be available.'}, self.get_cache(q)
def get_cache(self, q): def get_cache(self, q):
q = urlsafe_b64encode(q) query = {'query': q}
response = self.session.get('{}get_cache/{}'.format(self.url, q)) response = self.session.post('{}get_cache' .format(self.url), data=json.dumps(query))
return response.json() return response.json()

View File

@ -468,7 +468,7 @@ def get_url_data(url):
return {url: data} return {url: data}
def get_cached(url): def cached(url):
_cache_init() _cache_init()
if not enable_cache: if not enable_cache:
return [url] return [url]

View File

@ -1,8 +1,7 @@
import json import json
import os 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_mail import Mail, Message
from flask_bootstrap import Bootstrap from flask_bootstrap import Bootstrap
from flask_wtf import Form from flask_wtf import Form
@ -23,7 +22,7 @@ import ConfigParser
from proxied import ReverseProxied from proxied import ReverseProxied
from url_abuse_async import is_valid_url, url_list, dns_resolve, phish_query, psslcircl, \ 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, \ 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' config_path = 'config.ini'
@ -272,10 +271,11 @@ def create_app(configfile=None):
query,), result_ttl=500) query,), result_ttl=500)
return u.get_id() return u.get_id()
@app.route('/get_cache/<path:url>') @app.route('/get_cache', methods=['POST'])
def get_cache(url): def get_cache():
url = urlsafe_b64decode(url.encode('utf-8')) data = json.loads(request.data)
data = get_cached(url) url = data["query"]
data = cached(url)
dumped = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) dumped = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
return dumped return dumped
@ -283,7 +283,7 @@ def create_app(configfile=None):
if not get_mail_sent(url): if not get_mail_sent(url):
print 'Send mail' print 'Send mail'
set_mail_sent(url) set_mail_sent(url)
data = get_cached(url) data = cached(url)
if not autosend: if not autosend:
subject = 'URL Abuse report from ' + ip subject = 'URL Abuse report from ' + ip
else: else:
@ -296,12 +296,9 @@ def create_app(configfile=None):
def send_mail(): def send_mail():
data = json.loads(request.data) data = json.loads(request.data)
url = data["url"] url = data["url"]
if get_mail_sent(url): if not get_mail_sent(url):
flash('Mail already sent to CIRCL.')
else:
ip = _get_user_ip(request) ip = _get_user_ip(request)
send(url, ip) send(url, ip)
flash('Mail successfully sent to CIRCL.')
return redirect(url_for('index')) return redirect(url_for('index'))
return app return app

View File

@ -3,6 +3,24 @@
var app = angular.module('URLabuseApp', ['ui.bootstrap']); 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){ app.factory('globFct', [ '$log', '$http', '$timeout', function($log, $http, $timeout){
return { return {
poller: function myself(jobID, callback) { 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.poller = globFct.poller;
$scope.query = globFct.query; $scope.query = globFct.query;
$scope.flash = flash;
var get_redirects = function(jobID) { var get_redirects = function(jobID) {
$scope.poller(jobID, function(data){ $scope.poller(jobID, function(data){
@ -50,6 +69,9 @@
// get the URL from the input // get the URL from the input
$scope.query_url = ''; $scope.query_url = '';
$scope.urls = ''; $scope.urls = '';
// Reset the message
$scope.$emit('newFlashMessage', '');
var userInput = $scope.input_url; var userInput = $scope.input_url;
@ -72,6 +94,8 @@
$scope.query_url = ''; $scope.query_url = '';
$scope.urls = ''; $scope.urls = '';
$scope.input_url = ''; $scope.input_url = '';
flash.setMessage("Mail sent to CIRCL");
$scope.$emit('newFlashMessage', '');
}); });
}; };

View File

@ -19,15 +19,11 @@
<h1>URL Abuse testing form</h1> <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> <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/> <br/>
{% with messages = get_flashed_messages() %} {% raw %}
{% if messages %} <div class="alert alert-success" ng-show="flash.getMessage()">
<div class="flashes alert"> <center>{{ flash.getMessage() }}</center>
{% for message in messages %} </div>
<center><div class="alert alert-success">{{ message }}</div></center> {% endraw %}
{% endfor %}
</div>
{% endif %}
{% endwith %}
<br/> <br/>
<form class="form form-horizontal" method="post" role="form" ng-submit="getResults()"> <form class="form form-horizontal" method="post" role="form" ng-submit="getResults()">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}