From d89ae365f9792c63a13ab258b31594c3d5d040f9 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 24 Dec 2014 14:42:20 +0000 Subject: [PATCH] web: basic search functionality added --- var/www/Flask_server.py | 24 ++++++- var/www/templates/Queue_live_Monitoring.html | 2 +- var/www/templates/index.html | 9 +-- var/www/templates/search.html | 72 ++++++++++++++++++++ var/www/templates/searchbox.html | 11 +++ 5 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 var/www/templates/search.html create mode 100644 var/www/templates/searchbox.html diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 5171ba3b..7a1aa472 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -4,10 +4,11 @@ import redis import ConfigParser import json -from flask import Flask, render_template, jsonify +from flask import Flask, render_template, jsonify, request import flask import os + # CONFIG # configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg') if not os.path.exists(configfile): @@ -58,6 +59,27 @@ def stuff(): return jsonify(row1=get_queues(r_serv)) +@app.route("/search", methods=['POST']) +def search(): + query = request.form['query'] + q = [] + q.append(query) + r = [] + # Search + from whoosh import index + from whoosh.fields import Schema, TEXT, ID + schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) + + indexpath = os.path.join(os.environ['AIL_HOME'], cfg.get("Indexer", "path")) + ix = index.open_dir(indexpath) + from whoosh.qparser import QueryParser + with ix.searcher() as searcher: + query = QueryParser("content", ix.schema).parse(" ".join(q)) + results = searcher.search(query, limit=None) + for x in results: + r.append(x.items()[0][1]) + return render_template("search.html", r=r) + @app.route("/") def index(): return render_template("index.html") diff --git a/var/www/templates/Queue_live_Monitoring.html b/var/www/templates/Queue_live_Monitoring.html index b8e5791e..81b322b3 100644 --- a/var/www/templates/Queue_live_Monitoring.html +++ b/var/www/templates/Queue_live_Monitoring.html @@ -40,4 +40,4 @@ $(document).ready(function () {
- \ No newline at end of file + diff --git a/var/www/templates/index.html b/var/www/templates/index.html index aa01d968..e70afba8 100644 --- a/var/www/templates/index.html +++ b/var/www/templates/index.html @@ -43,14 +43,7 @@ diff --git a/var/www/templates/search.html b/var/www/templates/search.html new file mode 100644 index 00000000..04b82cda --- /dev/null +++ b/var/www/templates/search.html @@ -0,0 +1,72 @@ + + + + + + + + Analysis Information Leak framework Dashboard + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+
+ {{ r|length }} Results +
+ +
+
+ +
+ + {% for result in r %} + + {% endfor %} +
{{ result }}
+
+ +
+
+ +
+ +
+ + + + diff --git a/var/www/templates/searchbox.html b/var/www/templates/searchbox.html new file mode 100644 index 00000000..415ab15a --- /dev/null +++ b/var/www/templates/searchbox.html @@ -0,0 +1,11 @@ +
+
+ + + + +
+
+