diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 80eecbc9..142671fb 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -21,9 +21,8 @@ if not os.path.exists(configfile): cfg = ConfigParser.ConfigParser() cfg.read(configfile) -max_preview_char = int(cfg.get("Flask", "max_preview_char")) -max_preview_modal = int(cfg.get("Flask", "max_preview_modal")) -index_prev = 0 # used if the user want to load more paste content +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")) # Maximum number of character to display in the modal # REDIS # r_serv = redis.StrictRedis( @@ -59,6 +58,25 @@ def list_len(s): return len(s) 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") def logs(): return flask.Response(event_stream(), mimetype="text/event-stream") @@ -74,8 +92,8 @@ def search(): query = request.form['query'] q = [] q.append(query) - r = [] - c = [] + r = [] #complete path + c = [] #preview of the paste content paste_date = [] paste_size = [] # Search @@ -101,6 +119,7 @@ def search(): 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) + @app.route("/") def index(): return render_template("index.html") @@ -121,42 +140,21 @@ def wordstrending(): def protocolstrending(): return render_template("Protocolstrending.html") + @app.route("/tldstrending/") def tldstrending(): return render_template("Tldstrending.html") -@app.route("/showsavedpaste/") + +@app.route("/showsavedpaste/") #completely shows the paste in a new tab def showsavedpaste(): - 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') - 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) + return showpaste(0) + @app.route("/showpreviewpaste/") def showpreviewpaste(): - requested_path = request.args.get('paste', '') - 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) + return showpaste(max_preview_modal) + @app.route("/getmoredata/") def getmoredata(): @@ -166,5 +164,6 @@ def getmoredata(): to_return = p_content[max_preview_modal:] return to_return + if __name__ == "__main__": app.run(host='0.0.0.0', port=7000, threaded=True) diff --git a/var/www/templates/search.html b/var/www/templates/search.html index 3f0c7bd4..0bafa147 100644 --- a/var/www/templates/search.html +++ b/var/www/templates/search.html @@ -19,7 +19,7 @@ - +