From 5eadc2755f79e30eda5fade54e7d96bd19d228ac Mon Sep 17 00:00:00 2001 From: Terrtia Date: Thu, 20 Sep 2018 10:38:19 +0200 Subject: [PATCH] chg: [Flask] add prefix in config to flask routes --- bin/packages/config.cfg.sample | 2 ++ var/www/Flask_base_template.py | 3 ++- var/www/Flask_server.py | 6 +++++- var/www/modules/Flask_config.py | 5 +++++ var/www/modules/PasteSubmit/Flask_PasteSubmit.py | 3 ++- var/www/modules/Tags/Flask_Tags.py | 3 ++- var/www/modules/browsepastes/Flask_browsepastes.py | 3 ++- var/www/modules/dashboard/Flask_dashboard.py | 3 ++- var/www/modules/search/Flask_search.py | 3 ++- var/www/modules/sentiment/Flask_sentiment.py | 3 ++- var/www/modules/showpaste/Flask_showpaste.py | 3 ++- var/www/modules/terms/Flask_terms.py | 3 ++- var/www/modules/trendingcharts/Flask_trendingcharts.py | 3 ++- var/www/modules/trendingmodules/Flask_trendingmodules.py | 3 ++- 14 files changed, 34 insertions(+), 12 deletions(-) diff --git a/bin/packages/config.cfg.sample b/bin/packages/config.cfg.sample index eead0357..7c2cff55 100644 --- a/bin/packages/config.cfg.sample +++ b/bin/packages/config.cfg.sample @@ -32,6 +32,8 @@ sender_port = 1337 ##### Flask ##### [Flask] +#Proxying requests to the app +baseUrl = / #Number of logs to display in the dashboard max_dashboard_logs = 15 #Maximum number of character to display in the toolip diff --git a/var/www/Flask_base_template.py b/var/www/Flask_base_template.py index e9b65cda..df85d9d9 100644 --- a/var/www/Flask_base_template.py +++ b/var/www/Flask_base_template.py @@ -12,6 +12,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl MODULENAME = Blueprint('MODULENAME', __name__, template_folder='templates') @@ -27,4 +28,4 @@ def MODULENAME_page(): # ========= REGISTRATION ========= -app.register_blueprint(MODULENAME) +app.register_blueprint(MODULENAME, url_prefix=baseUrl) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 068bee65..51b492d7 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -25,8 +25,12 @@ import Flask_config # CONFIG # cfg = Flask_config.cfg +baseUrl = cfg.get("Flask", "baseurl") +baseUrl = baseUrl.replace('/', '') +if baseUrl != '': + baseUrl = '/'+baseUrl -Flask_config.app = Flask(__name__, static_url_path='/static/') +Flask_config.app = Flask(__name__, static_url_path=baseUrl+'/static/') app = Flask_config.app app.config['MAX_CONTENT_LENGTH'] = 900 * 1024 * 1024 diff --git a/var/www/modules/Flask_config.py b/var/www/modules/Flask_config.py index 2b32f5ab..364a15df 100644 --- a/var/www/modules/Flask_config.py +++ b/var/www/modules/Flask_config.py @@ -135,6 +135,11 @@ if HiveApi != False: print('The Hive not connected') # VARIABLES # +baseUrl = cfg.get("Flask", "baseurl") +baseUrl = baseUrl.replace('/', '') +if baseUrl != '': + baseUrl = '/'+baseUrl + 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 diff --git a/var/www/modules/PasteSubmit/Flask_PasteSubmit.py b/var/www/modules/PasteSubmit/Flask_PasteSubmit.py index cb404d2f..122fc74c 100644 --- a/var/www/modules/PasteSubmit/Flask_PasteSubmit.py +++ b/var/www/modules/PasteSubmit/Flask_PasteSubmit.py @@ -39,6 +39,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_tags = Flask_config.r_serv_tags r_serv_metadata = Flask_config.r_serv_metadata r_serv_db = Flask_config.r_serv_db @@ -585,4 +586,4 @@ def disable_hive_auto_alert(): return edit_tag_export() # ========= REGISTRATION ========= -app.register_blueprint(PasteSubmit) +app.register_blueprint(PasteSubmit, url_prefix=baseUrl) diff --git a/var/www/modules/Tags/Flask_Tags.py b/var/www/modules/Tags/Flask_Tags.py index 91b07435..e79d56fc 100644 --- a/var/www/modules/Tags/Flask_Tags.py +++ b/var/www/modules/Tags/Flask_Tags.py @@ -21,6 +21,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_tags = Flask_config.r_serv_tags r_serv_metadata = Flask_config.r_serv_metadata r_serv_statistics = Flask_config.r_serv_statistics @@ -865,4 +866,4 @@ def tag_galaxy_info(): return 'INVALID INPUT' # ========= REGISTRATION ========= -app.register_blueprint(Tags) +app.register_blueprint(Tags, url_prefix=baseUrl) diff --git a/var/www/modules/browsepastes/Flask_browsepastes.py b/var/www/modules/browsepastes/Flask_browsepastes.py index 2a73d9b8..eb962ffe 100644 --- a/var/www/modules/browsepastes/Flask_browsepastes.py +++ b/var/www/modules/browsepastes/Flask_browsepastes.py @@ -18,6 +18,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl max_preview_char = Flask_config.max_preview_char max_preview_modal = Flask_config.max_preview_modal r_serv_metadata = Flask_config.r_serv_metadata @@ -177,4 +178,4 @@ def getImportantPasteByModule(): # ========= REGISTRATION ========= -app.register_blueprint(browsepastes) +app.register_blueprint(browsepastes, url_prefix=baseUrl) diff --git a/var/www/modules/dashboard/Flask_dashboard.py b/var/www/modules/dashboard/Flask_dashboard.py index 6d7992d7..fb59e96f 100644 --- a/var/www/modules/dashboard/Flask_dashboard.py +++ b/var/www/modules/dashboard/Flask_dashboard.py @@ -19,6 +19,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv = Flask_config.r_serv r_serv_log = Flask_config.r_serv_log @@ -167,4 +168,4 @@ def index(): log_select=log_select, selected=max_dashboard_logs) # ========= REGISTRATION ========= -app.register_blueprint(dashboard) +app.register_blueprint(dashboard, url_prefix=baseUrl) diff --git a/var/www/modules/search/Flask_search.py b/var/www/modules/search/Flask_search.py index 9ff9343d..5b458589 100644 --- a/var/www/modules/search/Flask_search.py +++ b/var/www/modules/search/Flask_search.py @@ -21,6 +21,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_pasteName = Flask_config.r_serv_pasteName r_serv_metadata = Flask_config.r_serv_metadata max_preview_char = Flask_config.max_preview_char @@ -241,4 +242,4 @@ def get_more_search_result(): # ========= REGISTRATION ========= -app.register_blueprint(searches) +app.register_blueprint(searches, url_prefix=baseUrl) diff --git a/var/www/modules/sentiment/Flask_sentiment.py b/var/www/modules/sentiment/Flask_sentiment.py index fbf09f55..9a86eaa4 100644 --- a/var/www/modules/sentiment/Flask_sentiment.py +++ b/var/www/modules/sentiment/Flask_sentiment.py @@ -18,6 +18,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_charts = Flask_config.r_serv_charts r_serv_sentiment = Flask_config.r_serv_sentiment @@ -142,4 +143,4 @@ def sentiment_analysis_plot_tool_getdata(): return jsonify(to_return) # ========= REGISTRATION ========= -app.register_blueprint(sentiments) +app.register_blueprint(sentiments, url_prefix=baseUrl) diff --git a/var/www/modules/showpaste/Flask_showpaste.py b/var/www/modules/showpaste/Flask_showpaste.py index 09ff8ba7..cd7319c3 100644 --- a/var/www/modules/showpaste/Flask_showpaste.py +++ b/var/www/modules/showpaste/Flask_showpaste.py @@ -20,6 +20,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_pasteName = Flask_config.r_serv_pasteName r_serv_metadata = Flask_config.r_serv_metadata r_serv_tags = Flask_config.r_serv_tags @@ -271,4 +272,4 @@ def send_file_to_vt(): return redirect(url_for('showsavedpastes.showsavedpaste', paste=paste)) # ========= REGISTRATION ========= -app.register_blueprint(showsavedpastes) +app.register_blueprint(showsavedpastes, url_prefix=baseUrl) diff --git a/var/www/modules/terms/Flask_terms.py b/var/www/modules/terms/Flask_terms.py index cca6b713..b0794593 100644 --- a/var/www/modules/terms/Flask_terms.py +++ b/var/www/modules/terms/Flask_terms.py @@ -21,6 +21,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_term = Flask_config.r_serv_term r_serv_cred = Flask_config.r_serv_cred @@ -605,4 +606,4 @@ def cred_management_action(): # ========= REGISTRATION ========= -app.register_blueprint(terms) +app.register_blueprint(terms, url_prefix=baseUrl) diff --git a/var/www/modules/trendingcharts/Flask_trendingcharts.py b/var/www/modules/trendingcharts/Flask_trendingcharts.py index d0c2e8f1..ad2e5b76 100644 --- a/var/www/modules/trendingcharts/Flask_trendingcharts.py +++ b/var/www/modules/trendingcharts/Flask_trendingcharts.py @@ -15,6 +15,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_charts = Flask_config.r_serv_charts trendings = Blueprint('trendings', __name__, template_folder='templates') @@ -78,4 +79,4 @@ def trending(): # ========= REGISTRATION ========= -app.register_blueprint(trendings) +app.register_blueprint(trendings, url_prefix=baseUrl) diff --git a/var/www/modules/trendingmodules/Flask_trendingmodules.py b/var/www/modules/trendingmodules/Flask_trendingmodules.py index 373d08bc..aeec0eb9 100644 --- a/var/www/modules/trendingmodules/Flask_trendingmodules.py +++ b/var/www/modules/trendingmodules/Flask_trendingmodules.py @@ -15,6 +15,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl r_serv_charts = Flask_config.r_serv_charts trendingmodules = Blueprint('trendingmodules', __name__, template_folder='templates') @@ -125,4 +126,4 @@ def moduletrending(): # ========= REGISTRATION ========= -app.register_blueprint(trendingmodules) +app.register_blueprint(trendingmodules, url_prefix=baseUrl)