mirror of https://github.com/CIRCL/AIL-framework
Added comments and renamed variables and separeted chunks of codes into function
parent
f846255d84
commit
f475f18f06
|
@ -21,9 +21,8 @@ if not os.path.exists(configfile):
|
||||||
cfg = ConfigParser.ConfigParser()
|
cfg = ConfigParser.ConfigParser()
|
||||||
cfg.read(configfile)
|
cfg.read(configfile)
|
||||||
|
|
||||||
max_preview_char = int(cfg.get("Flask", "max_preview_char"))
|
max_preview_char = int(cfg.get("Flask", "max_preview_char")) # Maximum number of character to display in the tooltip
|
||||||
max_preview_modal = int(cfg.get("Flask", "max_preview_modal"))
|
max_preview_modal = int(cfg.get("Flask", "max_preview_modal")) # Maximum number of character to display in the modal
|
||||||
index_prev = 0 # used if the user want to load more paste content
|
|
||||||
|
|
||||||
# REDIS #
|
# REDIS #
|
||||||
r_serv = redis.StrictRedis(
|
r_serv = redis.StrictRedis(
|
||||||
|
@ -59,6 +58,25 @@ def list_len(s):
|
||||||
return len(s)
|
return len(s)
|
||||||
app.jinja_env.filters['list_len'] = list_len
|
app.jinja_env.filters['list_len'] = list_len
|
||||||
|
|
||||||
|
|
||||||
|
def showpaste(content_range):
|
||||||
|
requested_path = request.args.get('paste', '')
|
||||||
|
paste = Paste.Paste(requested_path)
|
||||||
|
p_date = str(paste._get_p_date())
|
||||||
|
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
|
||||||
|
p_source = paste.p_source
|
||||||
|
p_encoding = paste._get_p_encoding()
|
||||||
|
p_language = paste._get_p_language()
|
||||||
|
p_size = paste.p_size
|
||||||
|
p_mime = paste.p_mime
|
||||||
|
p_lineinfo = paste.get_lines_info()
|
||||||
|
p_content = paste.get_p_content().decode('utf-8', 'ignore')
|
||||||
|
if content_range != 0:
|
||||||
|
p_content = p_content[0:content_range]
|
||||||
|
|
||||||
|
return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content, initsize=len(p_content))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/_logs")
|
@app.route("/_logs")
|
||||||
def logs():
|
def logs():
|
||||||
return flask.Response(event_stream(), mimetype="text/event-stream")
|
return flask.Response(event_stream(), mimetype="text/event-stream")
|
||||||
|
@ -74,8 +92,8 @@ def search():
|
||||||
query = request.form['query']
|
query = request.form['query']
|
||||||
q = []
|
q = []
|
||||||
q.append(query)
|
q.append(query)
|
||||||
r = []
|
r = [] #complete path
|
||||||
c = []
|
c = [] #preview of the paste content
|
||||||
paste_date = []
|
paste_date = []
|
||||||
paste_size = []
|
paste_size = []
|
||||||
# Search
|
# Search
|
||||||
|
@ -101,6 +119,7 @@ def search():
|
||||||
paste_size.append(paste._get_p_size())
|
paste_size.append(paste._get_p_size())
|
||||||
return render_template("search.html", r=r, c=c, query=request.form['query'], paste_date=paste_date, paste_size=paste_size, char_to_display=max_preview_modal)
|
return render_template("search.html", r=r, c=c, query=request.form['query'], paste_date=paste_date, paste_size=paste_size, char_to_display=max_preview_modal)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
@ -121,42 +140,21 @@ def wordstrending():
|
||||||
def protocolstrending():
|
def protocolstrending():
|
||||||
return render_template("Protocolstrending.html")
|
return render_template("Protocolstrending.html")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/tldstrending/")
|
@app.route("/tldstrending/")
|
||||||
def tldstrending():
|
def tldstrending():
|
||||||
return render_template("Tldstrending.html")
|
return render_template("Tldstrending.html")
|
||||||
|
|
||||||
@app.route("/showsavedpaste/")
|
|
||||||
|
@app.route("/showsavedpaste/") #completely shows the paste in a new tab
|
||||||
def showsavedpaste():
|
def showsavedpaste():
|
||||||
requested_path = request.args.get('paste', '')
|
return showpaste(0)
|
||||||
paste = Paste.Paste(requested_path)
|
|
||||||
p_date = str(paste._get_p_date())
|
|
||||||
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
|
|
||||||
p_source = paste.p_source
|
|
||||||
p_encoding = paste._get_p_encoding()
|
|
||||||
p_language = paste._get_p_language()
|
|
||||||
p_size = paste.p_size
|
|
||||||
p_mime = paste.p_mime
|
|
||||||
p_lineinfo = paste.get_lines_info()
|
|
||||||
p_content = paste.get_p_content().decode('utf-8', 'ignore')
|
|
||||||
return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content)
|
|
||||||
|
|
||||||
@app.route("/showpreviewpaste/")
|
@app.route("/showpreviewpaste/")
|
||||||
def showpreviewpaste():
|
def showpreviewpaste():
|
||||||
requested_path = request.args.get('paste', '')
|
return showpaste(max_preview_modal)
|
||||||
paste = Paste.Paste(requested_path)
|
|
||||||
p_date = str(paste._get_p_date())
|
|
||||||
p_date = p_date[0:4]+'/'+p_date[4:6]+'/'+p_date[6:]
|
|
||||||
p_source = paste.p_source
|
|
||||||
p_encoding = paste._get_p_encoding()
|
|
||||||
p_language = paste._get_p_language()
|
|
||||||
p_size = paste.p_size
|
|
||||||
p_mime = paste.p_mime
|
|
||||||
p_lineinfo = paste.get_lines_info()
|
|
||||||
#p_content = paste.get_p_content()[0:max_preview_modal].decode('utf-8', 'ignore')
|
|
||||||
p_content = paste.get_p_content().decode('utf-8', 'ignore')
|
|
||||||
p_content = p_content[0:max_preview_modal]
|
|
||||||
p_initsize = len(p_content)
|
|
||||||
return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content, initsize=p_initsize)
|
|
||||||
|
|
||||||
@app.route("/getmoredata/")
|
@app.route("/getmoredata/")
|
||||||
def getmoredata():
|
def getmoredata():
|
||||||
|
@ -166,5 +164,6 @@ def getmoredata():
|
||||||
to_return = p_content[max_preview_modal:]
|
to_return = p_content[max_preview_modal:]
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0', port=7000, threaded=True)
|
app.run(host='0.0.0.0', port=7000, threaded=True)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.js') }}"></script>
|
||||||
|
<!-- Custom style -->
|
||||||
<style>
|
<style>
|
||||||
.tooltip-inner {
|
.tooltip-inner {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
@ -108,13 +108,12 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% set i = 0 %}
|
{% set i = 0 %}
|
||||||
{% for path in r %}
|
{% for path in r %}
|
||||||
{% set prev_content = c[i] %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i + 1 }}</td>
|
<td>{{ i + 1 }}</td>
|
||||||
<td><a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ path }}"> {{ path }}</a></td>
|
<td><a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ path }}&num={{ i+1 }}"> {{ path }}</a></td>
|
||||||
<td>{{ paste_date[i] }}</td>
|
<td>{{ paste_date[i] }}</td>
|
||||||
<td>{{ paste_size[i] }}</td>
|
<td>{{ paste_size[i] }}</td>
|
||||||
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ prev_content }}"></span> <button type="button" class="btn-link" data-num="{{ i + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpaste') }}?paste={{ path }}&num={{ i+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
|
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ c[i] }}"></span> <button type="button" class="btn-link" data-num="{{ i + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpaste') }}?paste={{ path }}&num={{ i+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% set i = i + 1 %}
|
{% set i = i + 1 %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -131,7 +130,7 @@
|
||||||
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<!-- enable tooltip -->
|
<!-- enable tooltip and dataTable -->
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
@ -146,7 +145,7 @@
|
||||||
var alert_message = '<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>No more data.</strong> Full paste displayed.</div>';
|
var alert_message = '<div class="alert alert-info alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>No more data.</strong> Full paste displayed.</div>';
|
||||||
var complete_paste = null;
|
var complete_paste = null;
|
||||||
var char_to_display = {{ char_to_display }};
|
var char_to_display = {{ char_to_display }};
|
||||||
var current_index = 0;
|
var start_index = 0;
|
||||||
|
|
||||||
// On click, get html content from url and update the corresponding modal
|
// On click, get html content from url and update the corresponding modal
|
||||||
$("[data-toggle='modal']").on("click", function (event) {
|
$("[data-toggle='modal']").on("click", function (event) {
|
||||||
|
@ -161,12 +160,12 @@
|
||||||
|
|
||||||
$("#button_show_path").attr('href', $(modal).attr('data-url'));
|
$("#button_show_path").attr('href', $(modal).attr('data-url'));
|
||||||
$("#button_show_path").show('fast');
|
$("#button_show_path").show('fast');
|
||||||
if ($("[data-initsize]").attr('data-initsize') < char_to_display) {
|
if ($("[data-initsize]").attr('data-initsize') < char_to_display) { // All the content is displayed
|
||||||
nothing_to_display();
|
nothing_to_display();
|
||||||
}
|
}
|
||||||
// On load more content click, replace paste content
|
// On click, donwload all paste's content
|
||||||
$("#load-more-button").on("click", function (event) {
|
$("#load-more-button").on("click", function (event) {
|
||||||
if (complete_paste == null) {
|
if (complete_paste == null) { //Donwload only once
|
||||||
$.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){
|
$.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){
|
||||||
complete_paste = data;
|
complete_paste = data;
|
||||||
update_preview();
|
update_preview();
|
||||||
|
@ -184,20 +183,21 @@
|
||||||
$("#button_show_path").attr('href', '');
|
$("#button_show_path").attr('href', '');
|
||||||
$("#button_show_path").hide();
|
$("#button_show_path").hide();
|
||||||
complete_paste = null;
|
complete_paste = null;
|
||||||
current_index = 0;
|
start_index = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the paste preview in the modal
|
// Update the paste preview in the modal
|
||||||
function update_preview() {
|
function update_preview() {
|
||||||
if (current_index + char_to_display > complete_paste.length-1){
|
if (start_index + char_to_display > complete_paste.length-1){ // end of paste reached
|
||||||
var final_index = complete_paste.length-1;
|
var final_index = complete_paste.length-1;
|
||||||
var flag_stop = true; // if there is no more data.
|
var flag_stop = true;
|
||||||
} else {
|
} else {
|
||||||
var final_index = current_index + char_to_display;
|
var final_index = start_index + char_to_display;
|
||||||
}
|
}
|
||||||
if (final_index != current_index){
|
|
||||||
$("#mymodalbody").find("#paste-holder").append(complete_paste.substring(current_index+1, final_index+1));
|
if (final_index != start_index){ // still have data to display
|
||||||
current_index = final_index;
|
$("#mymodalbody").find("#paste-holder").append(complete_paste.substring(start_index+1, final_index+1)); // Append the new content
|
||||||
|
start_index = final_index;
|
||||||
if (flag_stop)
|
if (flag_stop)
|
||||||
nothing_to_display();
|
nothing_to_display();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue