Permalink
Browse files

Improve Web UI (#181)

* fix docker freezing

* make api server compatible

* limit sessions display to 15 on one page and add next & previous buttons

* add proper shutdown
  • Loading branch information...
rnehra01 authored and afeena committed Jul 29, 2017
1 parent 29da6bd commit 50b19e8bdf0ecf8f89b95e3e37992afc638c11e7
View
@@ -88,7 +88,7 @@ def __init__(self, redis_client):
return 'Invalid filter : %s' % filter_name
if match_count == len(filters):
matching_sessions.append(sess['sess_uuid'])
matching_sessions.append(sess)
return matching_sessions
View
@@ -57,7 +57,9 @@ def _make_response(msg):
self.logger.error('Filter error : %s' % e)
result = 'Invalid filter definition'
else:
result = await self.api.return_sessions(applied_filters)
sessions = await self.api.return_sessions(applied_filters)
sess_uuids = [sess['sess_uuid'] for sess in sessions]
result = sess_uuids
response_msg = self._make_response(result)
return web.json_response(response_msg)
@@ -71,7 +71,7 @@ def get_app(self):
async def mock_return_sessions(filters):
if type(filters) is dict and filters['peer_ip'] == "127.0.0.1" and \
filters['start_time'] == 1497890400 and filters['user_agent'] == 'ngnix':
return ["f387d46eaeb1454cadf0713a4a55be49", "e85ae767b0bb4b1f91b421b3a28082ef"]
return [{"sess_uuid":"f387d46eaeb1454cadf0713a4a55be49"}, {"sess_uuid":"e85ae767b0bb4b1f91b421b3a28082ef"}]
assert_content = {"version": 1, "response": {"message": ["f387d46eaeb1454cadf0713a4a55be49", "e85ae767b0bb4b1f91b421b3a28082ef"]}}
self.serv.api.return_sessions = mock_return_sessions
View
@@ -43,6 +43,7 @@ def __init__(self):
@aiohttp_jinja2.template('sessions.html')
async def handle_sessions(self, request):
snare_uuid = request.match_info['snare_uuid']
page_id = int(request.match_info['page_id'])
params = request.url.query
applied_filters = {'snare_uuid': snare_uuid}
try:
@@ -57,14 +58,27 @@ def __init__(self):
self.logger.error('Filter error : %s' % e)
result = 'Invalid filter definition'
else:
sess_uuids = await self.api.return_sessions(applied_filters)
sessions = []
for sess_uuid in sess_uuids:
sess = await self.api.return_session_info(sess_uuid)
sessions.append(sess)
result = sessions
sessions = await self.api.return_sessions(applied_filters)
result = sessions[15*(page_id-1):15*page_id]
next_val = None
pre_val = None
if(page_id*15 <= len(sessions)):
next_val = '/{snare_uuid}/sessions/page/{page_id}'.format(snare_uuid=snare_uuid,
page_id=str(page_id + 1)
)
if len(applied_filters) > 1:
next_val += '?filters={filters}'.format(filters=params['filters'])
if(page_id > 1):
pre_val = '/{snare_uuid}/sessions/page/{page_id}'.format(snare_uuid=snare_uuid,
page_id=str(page_id - 1)
)
if len(applied_filters) > 1:
pre_val += '?filters={filters}'.format(filters=params['filters'])
return {
'sessions' : result
'sessions' : result,
'next_val' : next_val,
'pre_val' : pre_val
}
@aiohttp_jinja2.template('session.html')
@@ -75,19 +89,23 @@ def __init__(self):
'session' : session
}
async def on_shutdown(self, app):
self.redis_client.close()
def setup_routes(self, app):
app.router.add_get('/', self.handle_index)
app.router.add_get('/snares', self.handle_snares)
app.router.add_resource('/snare/{snare_uuid}').add_route('GET', self.handle_snare)
app.router.add_resource('/snare-stats/{snare_uuid}').add_route('GET', self.handle_snare_stats)
app.router.add_resource('/session/{sess_uuid}').add_route('GET', self.handle_session_info)
app.router.add_resource('/{snare_uuid}/sessions').add_route('GET', self.handle_sessions)
app.router.add_resource('/{snare_uuid}/sessions/page/{page_id}').add_route('GET', self.handle_sessions)
app.router.add_static('/static/', path='tanner/web/static')
def create_app(self, loop):
app = web.Application(loop= loop)
aiohttp_jinja2.setup(app,
loader= jinja2.FileSystemLoader('tanner/web/templates'))
app.on_shutdown.append(self.on_shutdown)
self.setup_routes(app)
return app
@@ -14,7 +14,7 @@ <h3 align="center">SESSION INFO</h3>
</tr>
<tr>
<td><b>IP</b></td>
<td><a href="/{{session.snare_uuid}}/sessions?filters=peer_ip:{{session.peer_ip}}">{{session.peer_ip}}</a></td>
<td><a href="/{{session.snare_uuid}}/sessions/page/1?filters=peer_ip:{{session.peer_ip}}">{{session.peer_ip}}</a></td>
</tr>
<tr>
<td><b>Port</b></td>
@@ -30,11 +30,11 @@ <h3 align="center">SESSION INFO</h3>
</tr>
<tr>
<td><b>Start time</b></td>
<td><a href="/{{session.snare_uuid}}/sessions?filters=start_time:{{session.start_time}}">{{session.start_time}}</a></td>
<td><a href="/{{session.snare_uuid}}/sessions/page/1?filters=start_time:{{session.start_time}}">{{session.start_time}}</a></td>
</tr>
<tr>
<td><b>End time</b></td>
<td><a href="/{{session.snare_uuid}}/sessions?filters=end_time:{{session.end_time}}">{{session.end_time}}</a></td>
<td><a href="/{{session.snare_uuid}}/sessions/page/1?filters=end_time:{{session.end_time}}">{{session.end_time}}</a></td>
</tr>
<tr>
<td><b>Requests/sec</b></td>
@@ -60,7 +60,7 @@ <h3 align="center">SESSION INFO</h3>
<td><b>Attack types</b></td>
<td>
{% for attack in session.attack_types %}
<a href="/{{session.snare_uuid}}/sessions?filters=attack_types:{{attack}}">{{attack}}</a><br>
<a href="/{{session.snare_uuid}}/sessions/page/1?filters=attack_types:{{attack}}">{{attack}}</a><br>
{% endfor %}
</td>
</tr>
@@ -84,7 +84,7 @@ <h3 align="center">SESSION INFO</h3>
<td><b>Possible Owners</b></td>
<td>
{% for owner in session.possible_owners %}
<a href="/{{session.snare_uuid}}/sessions?filters=possible_owners:{{owner}}">{{owner}}</a><br>
<a href="/{{session.snare_uuid}}/sessions/page/1?filters=possible_owners:{{owner}}">{{owner}}</a><br>
{% endfor %}
</td>
</tr>
@@ -25,6 +25,11 @@ <h3 align="center">SNARE-SESSIONS</h3>
</tr>
{% endfor %}
</table>
<br>
<div align="center">
{% if pre_val %}<a href="{{pre_val if pre_val}}">Previous</a>{% endif %}
{% if next_val %}<a href="{{next_val}}">Next</a>{% endif %}
</div>
<script src="/static/js/site.js"></script>
</script>
{% endblock %}
@@ -3,5 +3,5 @@
{% block content %}
<h3 align="center">{{snare}}</h3>
<h4 align="center"><a href="/snare-stats/{{snare}}">Snare-Stats</a></h4>
<h4 align="center"><a href="/{{snare}}/sessions">Sessions</a></h4>
<h4 align="center"><a href="/{{snare}}/sessions/page/1">Sessions</a></h4>
{% endblock %}

0 comments on commit 50b19e8

Please sign in to comment.