mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
web: basic search functionality added
This commit is contained in:
parent
9b7e329888
commit
d89ae365f9
5 changed files with 108 additions and 10 deletions
|
@ -4,10 +4,11 @@
|
||||||
import redis
|
import redis
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import json
|
import json
|
||||||
from flask import Flask, render_template, jsonify
|
from flask import Flask, render_template, jsonify, request
|
||||||
import flask
|
import flask
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
# CONFIG #
|
# CONFIG #
|
||||||
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
||||||
if not os.path.exists(configfile):
|
if not os.path.exists(configfile):
|
||||||
|
@ -58,6 +59,27 @@ def stuff():
|
||||||
return jsonify(row1=get_queues(r_serv))
|
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("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
|
@ -43,14 +43,7 @@
|
||||||
<ul class="nav" id="side-menu">
|
<ul class="nav" id="side-menu">
|
||||||
<li class="sidebar-search">
|
<li class="sidebar-search">
|
||||||
<a href="{{ url_for('index') }}"><img src="{{ url_for('static', filename='image/AIL.png') }}" /></a>
|
<a href="{{ url_for('index') }}"><img src="{{ url_for('static', filename='image/AIL.png') }}" /></a>
|
||||||
<div class="input-group custom-search-form">
|
{% include 'searchbox.html' %}
|
||||||
<input type="text" class="form-control" placeholder="Search Paste">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button class="btn btn-default" type="button">
|
|
||||||
<i class="fa fa-search"></i>
|
|
||||||
</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<!-- /input-group -->
|
<!-- /input-group -->
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
72
var/www/templates/search.html
Normal file
72
var/www/templates/search.html
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
<title>Analysis Information Leak framework Dashboard</title>
|
||||||
|
|
||||||
|
<!-- Core CSS -->
|
||||||
|
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
|
||||||
|
<link href="{{ url_for('static', filename='css/dygraph_gallery.css') }}" rel="stylesheet" type="text/css" />
|
||||||
|
<!-- JS -->
|
||||||
|
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/jquery-1.4.2.js') }}"></script>
|
||||||
|
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="wrapper">
|
||||||
|
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a href="{{ url_for('index') }}"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a></li><li><a href="{{ url_for('wordstrending') }}"><i class="glyphicon glyphicon-stats"></i> WordsTrendings</a><li></ul>
|
||||||
|
</div>
|
||||||
|
<!-- /.navbar-top-links -->
|
||||||
|
<div class="navbar-default sidebar" role="navigation">
|
||||||
|
<div class="sidebar-collapse">
|
||||||
|
<ul class="nav" id="side-menu">
|
||||||
|
{% include 'searchbox.html' %}
|
||||||
|
</ul>
|
||||||
|
<!-- /#side-menu -->
|
||||||
|
</div>
|
||||||
|
<!-- /.sidebar-collapse -->
|
||||||
|
<a href="{{ url_for('index') }}"><img src="{{ url_for('static', filename='image/AIL.png') }}" /></a>
|
||||||
|
</div>
|
||||||
|
<!-- /.navbar-static-side -->
|
||||||
|
</nav>
|
||||||
|
<div id="page-wrapper">
|
||||||
|
<!-- /.row -->
|
||||||
|
<div class="row"> </div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<i class="glyphicon glyphicon-search"></i> {{ r|length }} Results
|
||||||
|
<div class="pull-right">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- /.panel-heading -->
|
||||||
|
<div class="panel-body">
|
||||||
|
<table class="table">
|
||||||
|
{% for result in r %}
|
||||||
|
<tr><td>{{ result }}</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!-- /.panel-body -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- /.row -->
|
||||||
|
</div>
|
||||||
|
<!-- /#page-wrapper -->
|
||||||
|
</div>
|
||||||
|
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
11
var/www/templates/searchbox.html
Normal file
11
var/www/templates/searchbox.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="input-group custom-search-form">
|
||||||
|
<form action="/search" method=POST>
|
||||||
|
<input type="text" name="query" class="form-control" placeholder="Search Paste">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-default" type="submit">
|
||||||
|
<i class="fa fa-search"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue