diff --git a/bin/update-background.py b/bin/update-background.py index 4b2ac197..6ca990e7 100755 --- a/bin/update-background.py +++ b/bin/update-background.py @@ -31,23 +31,27 @@ if __name__ == "__main__": db=cfg.getint("ARDB_DB", "db"), decode_responses=True) - if r_serv.exists('ail:update_v1.5'): - onions_update_status = r_serv.get('v1.5:onions') - if onions_update_status is None: + if r_serv.scard('ail:update_v1.5') != 4: + r_serv.delete('ail:update_error') + r_serv.set('ail:update_in_progress', 'v1.5') + r_serv.set('ail:current_background_update', 'v1.5') + if not r_serv.sismember('ail:update_v1.5', 'onions'): update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.4', 'Update-ARDB_Onions.py') process = subprocess.run(['python' ,update_file]) - metadata_update_status = r_serv.get('v1.5:metadata') - if metadata_update_status is None: + if not r_serv.sismember('ail:update_v1.5', 'metadata'): update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.4', 'Update-ARDB_Metadata.py') process = subprocess.run(['python' ,update_file]) - tags_update_status = r_serv.get('v1.5:tags') - if tags_update_status is None: + if not r_serv.sismember('ail:update_v1.5', 'tags'): update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.4', 'Update-ARDB_Tags.py') process = subprocess.run(['python' ,update_file]) - tags_background_update_status = r_serv.get('v1.5:tags_background') - if tags_background_update_status is None: + if if not r_serv.sismember('ail:update_v1.5', 'tags_background'): update_file = os.path.join(os.environ['AIL_HOME'], 'update', 'v1.4', 'Update-ARDB_Tags_background.py') process = subprocess.run(['python' ,update_file]) + if r_serv.scard('ail:update_v1.5') != 4: + r_serv.set('ail:update_error', 'Update v1.5 Failed, please relaunch the bin/update-background.py script') + else: + r_serv.delete('ail:update_in_progress') + r_serv.delete('ail:current_background_update', 'v1.5') diff --git a/update/v1.4/Update-ARDB_Metadata.py b/update/v1.4/Update-ARDB_Metadata.py index a4edb0f7..128b9bdf 100755 --- a/update/v1.4/Update-ARDB_Metadata.py +++ b/update/v1.4/Update-ARDB_Metadata.py @@ -143,7 +143,7 @@ if __name__ == '__main__': print('Updating ARDB_Metadata Done => {} paths: {} s'.format(index, end - start)) print() - r_serv.set('v1.5:metadata', 1) + r_serv.sadd('ail:update_v1.5', 'metadata') ## #Key, Dynamic Update diff --git a/update/v1.4/Update-ARDB_Onions.py b/update/v1.4/Update-ARDB_Onions.py index 5c249ba9..dec17961 100755 --- a/update/v1.4/Update-ARDB_Onions.py +++ b/update/v1.4/Update-ARDB_Onions.py @@ -134,4 +134,4 @@ if __name__ == '__main__': print() print('Done in {} s'.format(end - start_deb)) - r_serv.set('v1.5:onions', 1) + r_serv.sadd('ail:update_v1.5', 'onions') diff --git a/update/v1.4/Update-ARDB_Tags.py b/update/v1.4/Update-ARDB_Tags.py index e76e9ab5..50c9ead3 100755 --- a/update/v1.4/Update-ARDB_Tags.py +++ b/update/v1.4/Update-ARDB_Tags.py @@ -130,4 +130,4 @@ if __name__ == '__main__': print('Updating ARDB_Tags Done => {} paths: {} s'.format(index, end - start)) - r_serv.set('v1.5:tags', 1) + r_serv.sadd('ail:update_v1.5', 'tags') diff --git a/update/v1.4/Update-ARDB_Tags_background.py b/update/v1.4/Update-ARDB_Tags_background.py index ecd356ca..700d9022 100755 --- a/update/v1.4/Update-ARDB_Tags_background.py +++ b/update/v1.4/Update-ARDB_Tags_background.py @@ -76,4 +76,4 @@ if __name__ == '__main__': print('Updating ARDB_Tags Done: {} s'.format(end - start)) - r_serv.set('v1.5:tags_background', 1) + r_serv.sadd('ail:update_v1.5', 'tags_background') diff --git a/update/v1.4/Update.py b/update/v1.4/Update.py index 126b30a0..af8800cf 100755 --- a/update/v1.4/Update.py +++ b/update/v1.4/Update.py @@ -57,7 +57,10 @@ if __name__ == '__main__': #Set current ail version r_serv.set('ail:version', 'v1.5') - r_serv.set('ail:update_v1.5', 1) + + #Set current update_in_progress + r_serv.set('ail:update_in_progress', 'v1.5') + r_serv.set('ail:current_background_update', 'v1.5') #Set current ail version r_serv.set('ail:update_date_v1.5', datetime.datetime.now().strftime("%Y%m%d")) diff --git a/var/www/modules/Flask_config.py b/var/www/modules/Flask_config.py index 0f7b0e3f..d16aeaad 100644 --- a/var/www/modules/Flask_config.py +++ b/var/www/modules/Flask_config.py @@ -165,6 +165,8 @@ UPLOAD_FOLDER = os.path.join(os.environ['AIL_FLASK'], 'submitted') PASTES_FOLDER = os.path.join(os.environ['AIL_HOME'], cfg.get("Directories", "pastes")) + '/' SCREENSHOT_FOLDER = os.path.join(os.environ['AIL_HOME'], cfg.get("Directories", "crawled_screenshot")) +REPO_ORIGIN = 'https://github.com/CIRCL/AIL-framework.git' + max_dashboard_logs = int(cfg.get("Flask", "max_dashboard_logs")) # VT diff --git a/var/www/modules/settings/Flask_settings.py b/var/www/modules/settings/Flask_settings.py new file mode 100644 index 00000000..0e735979 --- /dev/null +++ b/var/www/modules/settings/Flask_settings.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*-coding:UTF-8 -* + +''' + Flask functions and routes for the settings modules page +''' +from flask import Flask, render_template, jsonify, request, Blueprint, redirect, url_for + +import json +import datetime + +import git_status + +# ============ VARIABLES ============ +import Flask_config + +app = Flask_config.app +cfg = Flask_config.cfg +baseUrl = Flask_config.baseUrl +r_serv_db = Flask_config.r_serv_db +max_preview_char = Flask_config.max_preview_char +max_preview_modal = Flask_config.max_preview_modal +REPO_ORIGIN = Flask_config.REPO_ORIGIN + +settings = Blueprint('settings', __name__, template_folder='templates') + + + +# ============ FUNCTIONS ============ +def one(): + return 1 + +#def get_v1.5_update_tags_backgroud_status(): +# return '38%' + +def get_git_metadata(): + dict_git = {} + dict_git['current_branch'] = git_status.get_current_branch() + dict_git['is_clone'] = git_status.is_not_fork(REPO_ORIGIN) + dict_git['is_working_directory_clean'] = git_status.is_working_directory_clean() + dict_git['current_commit'] = git_status.get_last_commit_id_from_local() + dict_git['last_remote_commit'] = git_status.get_last_commit_id_from_remote() + dict_git['last_local_tag'] = git_status.get_last_tag_from_local() + dict_git['last_remote_tag'] = git_status.get_last_tag_from_remote() + + # # DEBUG: + dict_git['last_local_tag'] = 'v1.3' + dict_git['last_remote_commit'] = '234328439828943843839' + + if dict_git['current_commit'] != dict_git['last_remote_commit']: + dict_git['new_git_update_available'] = True + else: + dict_git['new_git_update_available'] = False + + if dict_git['last_local_tag'] != dict_git['last_remote_tag']: + dict_git['new_git_version_available'] = True + else: + dict_git['new_git_version_available'] = False + + return dict_git + +def get_update_metadata(): + dict_update = {} + dict_update['current_version'] = r_serv_db.get('ail:version') + dict_update['current_background_update'] = r_serv_db.get('ail:current_background_update') + dict_update['update_in_progress'] = r_serv_db.get('ail:update_in_progress') + dict_update['update_error'] = r_serv_db.get('ail:update_error') + + dict_update['update_in_progress']='v1.5' + + return dict_update +# ============= ROUTES ============== + +@settings.route("/settings/", methods=['GET']) +def settings_page(): + git_metadata = get_git_metadata() + update_metadata = get_update_metadata() + + + return render_template("settings_index.html", git_metadata=git_metadata, + update_metadata=update_metadata) + +# ========= REGISTRATION ========= +app.register_blueprint(settings, url_prefix=baseUrl) diff --git a/var/www/modules/settings/templates/settings_index.html b/var/www/modules/settings/templates/settings_index.html new file mode 100644 index 00000000..9f5707a8 --- /dev/null +++ b/var/www/modules/settings/templates/settings_index.html @@ -0,0 +1,172 @@ + + + +
+AIL Version | +{{update_metadata['current_version']}} (release note) | +
Current Branch | ++ {%if git_metadata['current_branch'] != 'master'%} + + {%endif%} + {{git_metadata['current_branch']}} + | +
Update in progress | +{{update_metadata['update_in_progress']}} | +
Current Commit ID | ++ {%if git_metadata['new_git_update_available']%} + + {%endif%} + {{git_metadata['current_commit']}} + | +
Current Tag | ++ {%if git_metadata['new_git_version_available']%} + + {%endif%} + {{git_metadata['last_local_tag']}} + | +
This working directory is a fork | +
{{update_metadata['update_error']}}
+A new version is available, new version: {{git_metadata['last_remote_tag']}}
+ Check last release note. +A new update is available, new commit ID: {{git_metadata['last_remote_commit']}}
+ Check last commit content. +