From 709ef400e40ff48f4dd6c638acb38fb1cb390cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 12 Mar 2015 15:51:12 +0100 Subject: [PATCH] Use POST to send email and to get content the cache --- .gitignore | 5 +++++ pyurlabuse/pyurlabuse/api.py | 5 ++--- url_abuse_async.py | 2 +- web/__init__.py | 21 +++++++++------------ web/static/main.js | 26 +++++++++++++++++++++++++- web/templates/index.html | 14 +++++--------- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 679fb36..14f1d62 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ sphinxapi.py # JS libs angular.min.js ui-bootstrap-tpls.min.js + +# Packages stuff +build +dist +*egg-info diff --git a/pyurlabuse/pyurlabuse/api.py b/pyurlabuse/pyurlabuse/api.py index 55f4b16..cc477c6 100644 --- a/pyurlabuse/pyurlabuse/api.py +++ b/pyurlabuse/pyurlabuse/api.py @@ -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() diff --git a/url_abuse_async.py b/url_abuse_async.py index 2dba39e..6210135 100644 --- a/url_abuse_async.py +++ b/url_abuse_async.py @@ -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] diff --git a/web/__init__.py b/web/__init__.py index 65763ef..4201fdd 100644 --- a/web/__init__.py +++ b/web/__init__.py @@ -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/') - 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 diff --git a/web/static/main.js b/web/static/main.js index 4cc291d..5c67552 100644 --- a/web/static/main.js +++ b/web/static/main.js @@ -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', ''); }); }; diff --git a/web/templates/index.html b/web/templates/index.html index eb788ab..6a56485 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -19,15 +19,11 @@

URL Abuse testing form

URL Abuse is a public CIRCL service to review URL.
For more information about the service


- {% with messages = get_flashed_messages() %} - {% if messages %} -
- {% for message in messages %} -
{{ message }}
- {% endfor %} -
- {% endif %} - {% endwith %} + {% raw %} +
+
{{ flash.getMessage() }}
+
+ {% endraw %}
{{ form.hidden_tag() }}