chg: [Tracker] add optionnal description field

pull/396/head
Terrtia 2019-09-13 16:33:34 +02:00
parent 5734205828
commit fed04e8e5a
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
6 changed files with 84 additions and 59 deletions

View File

@ -109,17 +109,18 @@ Redis and ARDB overview
| **uuid**:ltags | **tag** | | **uuid**:ltags | **tag** |
| **uuid**:ltagsgalaxies | **tag** | | **uuid**:ltagsgalaxies | **tag** |
## DB2 - Leak Hunter: ## DB3 - Leak Hunter:
##### Tracker metadata: ##### Tracker metadata:
| Hset - Key | Field | Value | | Hset - Key | Field | Value |
| ------ | ------ | ------ | | ------ | ------ | ------ |
| tracker:**uuid** | tracked | **tacked word/set/regex** | | tracker:**uuid** | tracker | **tacked word/set/regex** |
| | type | **word/set/regex** | | | type | **word/set/regex** |
| | date | **date added** | | | date | **date added** |
| | user_id | **created by user_id** | | | user_id | **created by user_id** |
| | dashboard | **0/1 Display alert on dashboard** | | | dashboard | **0/1 Display alert on dashboard** |
| | level | **0/1 Tracker visibility** | | | description | **Tracker description** |
| | level | **0/1 Tracker visibility** |
##### Tracker by user_id (visibility level: user only): ##### Tracker by user_id (visibility level: user only):
| Set - Key | Value | | Set - Key | Value |
@ -180,51 +181,6 @@ Redis and ARDB overview
| ------ | ------ | | ------ | ------ |
| stat_token_history | **date** | | stat_token_history | **date** |
## DB2 - TermFreq:
##### Set:
##### Set:
| Key | Value |
| ------ | ------ |
| TrackedSetTermSet | **tracked_term** |
| TrackedSetSet | **tracked_set** |
| TrackedRegexSet | **tracked_regex** |
| | |
| | |
| tracked_**tracked_term** | **item_path** |
| set_**tracked_set** | **item_path** |
| regex_**tracked_regex** | **item_path** |
| | |
| TrackedNotifications | **tracked_trem / set / regex** |
| | |
| TrackedNotificationTags_**tracked_trem / set / regex** | **tag** |
| | |
| TrackedNotificationEmails_**tracked_trem / set / regex** | **email** |
##### Zset:
| Key | Field | Value |
| ------ | ------ | ------ |
| per_paste_TopTermFreq_set_month | **term** | **nb_seen** |
| per_paste_TopTermFreq_set_week | **term** | **nb_seen** |
| per_paste_TopTermFreq_set_day_**epoch** | **term** | **nb_seen** |
| | | |
| TopTermFreq_set_month | **term** | **nb_seen** |
| TopTermFreq_set_week | **term** | **nb_seen** |
| TopTermFreq_set_day_**epoch** | **term** | **nb_seen** |
##### Hset:
| Key | Field | Value |
| ------ | ------ | ------ |
| TrackedTermDate | **tracked_term** | **epoch** |
| TrackedSetDate | **tracked_set** | **epoch** |
| TrackedRegexDate | **tracked_regex** | **epoch** |
| | | |
| BlackListTermDate | **blacklisted_term** | **epoch** |
| | | |
| **epoch** | **term** | **nb_seen** |
## DB6 - Tags: ## DB6 - Tags:
##### Hset: ##### Hset:

View File

@ -144,6 +144,8 @@ def parse_json_term_to_add(dict_input, user_id):
if not term_type: if not term_type:
return ({"status": "error", "reason": "Term type not provided"}, 400) return ({"status": "error", "reason": "Term type not provided"}, 400)
nb_words = dict_input.get('nb_words', 1) nb_words = dict_input.get('nb_words', 1)
description = dict_input.get('description', '')
description = escape(description)
res = parse_tracked_term_to_add(term , term_type, nb_words=nb_words) res = parse_tracked_term_to_add(term , term_type, nb_words=nb_words)
if res[1]!=200: if res[1]!=200:
@ -174,7 +176,7 @@ def parse_json_term_to_add(dict_input, user_id):
if is_term_tracked_in_user_level(term, term_type, user_id): if is_term_tracked_in_user_level(term, term_type, user_id):
return ({"status": "error", "reason": "Term already tracked"}, 409) return ({"status": "error", "reason": "Term already tracked"}, 409)
term_uuid = add_tracked_term(term , term_type, user_id, level, tags, mails) term_uuid = add_tracked_term(term , term_type, user_id, level, tags, mails, description)
return ({'term': term, 'type': term_type, 'uuid': term_uuid}, 200) return ({'term': term, 'type': term_type, 'uuid': term_uuid}, 200)
@ -217,7 +219,7 @@ def parse_tracked_term_to_add(term , term_type, nb_words=1):
return ({"status": "error", "reason": "Incorrect type"}, 400) return ({"status": "error", "reason": "Incorrect type"}, 400)
return ({"status": "success", "term": term, "type": term_type}, 200) return ({"status": "success", "term": term, "type": term_type}, 200)
def add_tracked_term(term , term_type, user_id, level, tags, mails, dashboard=0): def add_tracked_term(term , term_type, user_id, level, tags, mails, description, dashboard=0):
term_uuid = str(uuid.uuid4()) term_uuid = str(uuid.uuid4())
@ -229,6 +231,9 @@ def add_tracked_term(term , term_type, user_id, level, tags, mails, dashboard=0)
r_serv_term.hset('tracker:{}'.format(term_uuid), 'level', level) r_serv_term.hset('tracker:{}'.format(term_uuid), 'level', level)
r_serv_term.hset('tracker:{}'.format(term_uuid), 'dashboard', dashboard) r_serv_term.hset('tracker:{}'.format(term_uuid), 'dashboard', dashboard)
if description:
r_serv_term.hset('tracker:{}'.format(term_uuid), 'description', description)
# create all term set # create all term set
r_serv_term.sadd('all:tracker:{}'.format(term_type), term) r_serv_term.sadd('all:tracker:{}'.format(term_type), term)
@ -300,9 +305,14 @@ def delete_term(term_uuid):
r_serv_term.delete('tracker:item:{}:{}'.format(term_uuid, date)) r_serv_term.delete('tracker:item:{}:{}'.format(term_uuid, date))
r_serv_term.delete('tracker:stat:{}'.format(term_uuid)) r_serv_term.delete('tracker:stat:{}'.format(term_uuid))
def replace_tracker_description(term_uuid, description):
description = escape(description)
r_serv_term.hset('tracker:{}'.format(term_uuid), 'description', description)
def replace_tracked_term_tags(term_uuid, tags): def replace_tracked_term_tags(term_uuid, tags):
r_serv_term.delete('tracker:tags:{}'.format(term_uuid)) r_serv_term.delete('tracker:tags:{}'.format(term_uuid))
for tag in tags: for tag in tags:
tag = escape(tag)
r_serv_term.sadd('tracker:tags:{}'.format(term_uuid), tag) r_serv_term.sadd('tracker:tags:{}'.format(term_uuid), tag)
def replace_tracked_term_mails(term_uuid, mails): def replace_tracked_term_mails(term_uuid, mails):
@ -312,6 +322,7 @@ def replace_tracked_term_mails(term_uuid, mails):
else: else:
r_serv_term.delete('tracker:mail:{}'.format(term_uuid)) r_serv_term.delete('tracker:mail:{}'.format(term_uuid))
for mail in mails: for mail in mails:
mail = escape(mail)
r_serv_term.sadd('tracker:mail:{}'.format(term_uuid), mail) r_serv_term.sadd('tracker:mail:{}'.format(term_uuid), mail)
def get_term_uuid_list(term, term_type): def get_term_uuid_list(term, term_type):
@ -394,11 +405,12 @@ def get_tracked_term_last_seen(term_uuid):
else: else:
return None return None
def get_term_metedata(term_uuid, user_id=False, level=False, tags=False, mails=False, sparkline=False): def get_term_metedata(term_uuid, user_id=False, description=False, level=False, tags=False, mails=False, sparkline=False):
dict_uuid = {} dict_uuid = {}
dict_uuid['term'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'tracked') dict_uuid['term'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'tracked')
dict_uuid['type'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'type') dict_uuid['type'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'type')
dict_uuid['date'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'date') dict_uuid['date'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'date')
dict_uuid['description'] = r_serv_term.hget('tracker:{}'.format(term_uuid), 'description')
dict_uuid['first_seen'] = get_tracked_term_first_seen(term_uuid) dict_uuid['first_seen'] = get_tracked_term_first_seen(term_uuid)
dict_uuid['last_seen'] = get_tracked_term_last_seen(term_uuid) dict_uuid['last_seen'] = get_tracked_term_last_seen(term_uuid)
if user_id: if user_id:

View File

@ -783,6 +783,9 @@ You need to use a regex if you want to use one of the following special characte
- tracker visibility - tracker visibility
- *int - 0: user only, 1: all users* - *int - 0: user only, 1: all users*
- default: `1` - default: `1`
- `description`
- tracker description
- *str*
#### JSON response #### JSON response
- `uuid` - `uuid`

View File

@ -9,7 +9,7 @@ import redis
import datetime import datetime
import calendar import calendar
import flask import flask
from flask import Flask, render_template, jsonify, request, Blueprint, url_for, redirect, Response from flask import Flask, render_template, jsonify, request, Blueprint, url_for, redirect, Response, escape
from Role_Manager import login_admin, login_analyst from Role_Manager import login_admin, login_analyst
from flask_login import login_required, current_user from flask_login import login_required, current_user
@ -88,6 +88,7 @@ def add_tracked_menu():
term = request.form.get("term") term = request.form.get("term")
term_type = request.form.get("tracker_type") term_type = request.form.get("tracker_type")
nb_words = request.form.get("nb_word", 1) nb_words = request.form.get("nb_word", 1)
description = request.form.get("description", '')
level = request.form.get("level", 0) level = request.form.get("level", 0)
tags = request.form.get("tags", []) tags = request.form.get("tags", [])
mails = request.form.get("mails", []) mails = request.form.get("mails", [])
@ -100,7 +101,7 @@ def add_tracked_menu():
if tags: if tags:
tags = tags.split() tags = tags.split()
input_dict = {"term": term, "type": term_type, "nb_words": nb_words, "tags": tags, "mails": mails, "level": level} input_dict = {"term": term, "type": term_type, "nb_words": nb_words, "tags": tags, "mails": mails, "level": level, "description": description}
user_id = current_user.get_id() user_id = current_user.get_id()
res = Term.parse_json_term_to_add(input_dict, user_id) res = Term.parse_json_term_to_add(input_dict, user_id)
if res[1] == 200: if res[1] == 200:
@ -129,7 +130,7 @@ def show_tracker():
if date_to: if date_to:
date_to = date_to.replace('-', '') date_to = date_to.replace('-', '')
tracker_metadata = Term.get_term_metedata(term_uuid, user_id=True, level=True, tags=True, mails=True, sparkline=True) tracker_metadata = Term.get_term_metedata(term_uuid, user_id=True, level=True, description=True, tags=True, mails=True, sparkline=True)
if date_from: if date_from:
res = Term.parse_get_tracker_term_item({'uuid': term_uuid, 'date_from': date_from, 'date_to': date_to}, user_id) res = Term.parse_get_tracker_term_item({'uuid': term_uuid, 'date_from': date_from, 'date_to': date_to}, user_id)
@ -145,6 +146,19 @@ def show_tracker():
return render_template("showTracker.html", tracker_metadata=tracker_metadata, bootstrap_label=bootstrap_label) return render_template("showTracker.html", tracker_metadata=tracker_metadata, bootstrap_label=bootstrap_label)
@hunter.route("/tracker/update_tracker_description", methods=['POST'])
@login_required
@login_analyst
def update_tracker_description():
user_id = current_user.get_id()
term_uuid = request.form.get('uuid')
res = Term.check_term_uuid_valid_access(term_uuid, user_id)
if res: # invalid access
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
description = escape( str(request.form.get('description', '')) )
Term.replace_tracker_description(term_uuid, description)
return redirect(url_for('hunter.show_tracker', uuid=term_uuid))
@hunter.route("/tracker/update_tracker_tags", methods=['POST']) @hunter.route("/tracker/update_tracker_tags", methods=['POST'])
@login_required @login_required
@login_analyst @login_analyst

View File

@ -49,6 +49,12 @@
<div class="input-group-text"><i class="fas fa-at"></i></div> <div class="input-group-text"><i class="fas fa-at"></i></div>
</div> </div>
<input id="mails" name="mails" class="form-control" placeholder="E-Mails Notification (optional, space separated)" type="text"> <input id="mails" name="mails" class="form-control" placeholder="E-Mails Notification (optional, space separated)" type="text">
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-pencil-alt"></i></div>
</div>
<input id="description" name="description" class="form-control" placeholder="Tracker Description (optional)" type="text">
</div> </div>
</div> </div>
<div class="col-12 col-xl-3"> <div class="col-12 col-xl-3">

View File

@ -49,6 +49,12 @@
<div class="card my-3"> <div class="card my-3">
<div class="card-header" style="background-color:#d9edf7;font-size: 15px"> <div class="card-header" style="background-color:#d9edf7;font-size: 15px">
<h4 class="text-secondary">{{ tracker_metadata['uuid'] }} </h4> <h4 class="text-secondary">{{ tracker_metadata['uuid'] }} </h4>
<div class="text-info">
{%if tracker_metadata['description']%}
{{ tracker_metadata['description'] }}
{%endif%}
<span class="btn-link btn-interaction mouse_pointer" title="Edit Tracker description" onclick="edit_description();"><i class="fas fa-pencil-alt" style="color:Red;"></i></span></th>
</div>
<ul class="list-group mb-2"> <ul class="list-group mb-2">
<li class="list-group-item py-0"> <li class="list-group-item py-0">
<div class="row"> <div class="row">
@ -108,6 +114,25 @@
</li> </li>
</ul> </ul>
<div id="div_edit_description">
<form action="{{ url_for('hunter.update_tracker_description') }}" method='post'>
<input name="uuid" type="text" value="{{tracker_metadata['uuid']}}" hidden>
<div>Update this tracker description: </div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-pencil-alt"></i></div>
</div>
<input id="description" name="description" class="form-control" placeholder="Tracker Description" type="text"
value="{%if tracker_metadata['description']%}{{tracker_metadata['description']}}{%endif%}">
</div>
<button class="btn btn-info">
<i class="fas fa-pencil-alt"></i> Edit Description
</button>
</form>
</div>
<div id="div_edit_tags"> <div id="div_edit_tags">
<form action="{{ url_for('hunter.update_tracker_tags') }}" method='post'> <form action="{{ url_for('hunter.update_tracker_tags') }}" method='post'>
<input name="uuid" type="text" value="{{tracker_metadata['uuid']}}" hidden> <input name="uuid" type="text" value="{{tracker_metadata['uuid']}}" hidden>
@ -223,7 +248,8 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('#div_edit_mails').hide(); $('#div_edit_mails').hide();
$('#div_edit_tags').hide(); $('#div_edit_tags').hide();edit_description
$('#div_edit_description').hide();
$("#page-Decoded").addClass("active"); $("#page-Decoded").addClass("active");
$('#date-range-from').dateRangePicker({ $('#date-range-from').dateRangePicker({
@ -283,14 +309,22 @@ function toggle_sidebar(){
function edit_tags(){ function edit_tags(){
$('#div_edit_mails').hide(); $('#div_edit_mails').hide();
$('#div_edit_description').hide();
$('#div_edit_tags').show(); $('#div_edit_tags').show();
} }
function edit_mails(){ function edit_mails(){
$('#div_edit_tags').hide(); $('#div_edit_tags').hide();
$('#div_edit_description').hide();
$('#div_edit_mails').show(); $('#div_edit_mails').show();
} }
function edit_description(){
$('#div_edit_tags').hide();
$('#div_edit_mails').hide();
$('#div_edit_description').show();
}
function getItems() { function getItems() {
var date_from = $('#date-range-from-input').val(); var date_from = $('#date-range-from-input').val();
var date_to =$('#date-range-to-input').val(); var date_to =$('#date-range-to-input').val();