Commit 98c0d23d authored by Ondřej Borýsek's avatar Ondřej Borýsek
Browse files

Import public Scan2Report during init

parent 0361043d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ def import_scan2report_templates_to_pwndoc():


def upload_scan2report_templates(locale_to_import: str, saved_filepaths: List[str]):
    # note: requires app or request context
    PwndocTemplateManager.update_template_db_from_pwndoc()  # necessary for mapping new uploads to existing templates
    bundled_templates: Dict[str, Dict[str, TNSTemplatePwndoc]] = defaultdict(dict)

+5 −0
Original line number Diff line number Diff line
@@ -52,6 +52,11 @@ def create_app(skip_pwndoc: bool = False):
    with app.app_context():
        db.create_all()

    if not skip_pwndoc:
        # todo: ensure only one thread does this?
        with app.app_context():
            pwndoc_db_init.PwnDocUpdate.upload_templates_from_scan2report_repository()

    app.config['UPLOAD_FOLDER'] = config.FLASK_UPLOAD_FOLDER
    app.config['MAX_CONTENT_LENGTH'] = 100 * 1000 * 1000
    app.config["JSONIFY_PRETTYPRINT_REGULAR"] = True
+15 −3
Original line number Diff line number Diff line
import base64
import glob
import os
import random
import shutil
@@ -9,6 +10,7 @@ import time
import json
from typing import Dict, Optional, List

import api_templates
import config
from helpers.file_utils import relative_path
from pathlib import Path
@@ -50,10 +52,8 @@ class InitialData:
        self._upload_universal('_api_data_audit-types.json')  # requires: templates, languages, sections
        self._upload_universal('_api_data_custom-fields.json')  # requires: everything

        # api_templates.import_scan2report_templates_to_pwndoc()

        self._save_new_id_mapping(self.__INIT_INDICATOR_NAME, self.__INIT_FINISHED)
        logger.info("DB Init completed")
        logger.info("PwnDoc Init completed")

    @staticmethod
    def wait_until_pwndoc_setup(wait_max_x_seconds=30):
@@ -218,3 +218,15 @@ class PwnDocUpdate:
        shutil.copytree(os.path.join(config.SCAN2REPORT_ORIGINAL_FOLDER, 'plugins'), os.path.join(config.SCAN2REPORT_ALTERNATIVE_FOLDER, 'plugins'))
        shutil.copytree(os.path.join(config.SCAN2REPORT_ORIGINAL_FOLDER, 'templates'), os.path.join(config.SCAN2REPORT_ALTERNATIVE_FOLDER, 'templates'))

    @staticmethod
    def upload_templates_from_scan2report_repository():
        # This requires app context because it needs access to sqlite db.
        for locale in config.LOCALES:
            if locale == 'og':
                return
            try:
                template_filepaths = glob.glob(os.path.join(config.SCAN2REPORT_ORIGINAL_FOLDER, 'plugins', locale, '*.json'))
                api_templates.upload_scan2report_templates(locale, template_filepaths)
            except Exception as e:
                logger.warning(f"Upload of initial templates failed for locale {locale}. Skipping. Reason: {e}")
                raise
 No newline at end of file