コード例 #1
0
ファイル: node.py プロジェクト: Taipo/GlobaLeaks
def enable_disable_languages(store, request):
    cur_enabled_langs = EnabledLanguage.list(store)
    new_enabled_langs = [unicode(y) for y in request['languages_enabled']]

    if len(new_enabled_langs) < 1:
        raise errors.InvalidInputFormat("No languages enabled!")

    if request['default_language'] not in new_enabled_langs:
        raise errors.InvalidInputFormat("Invalid lang code for chosen default_language")

    appdata = None
    for lang_code in new_enabled_langs:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InvalidInputFormat("Invalid lang code: %s" % lang_code)
        if lang_code not in cur_enabled_langs:
            if appdata is None:
              appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            EnabledLanguage.add_new_lang(store, lang_code, appdata)

    to_remove = []
    for lang_code in cur_enabled_langs:
        if lang_code not in new_enabled_langs:
            to_remove.append(lang_code)

    if len(to_remove):
        EnabledLanguage.remove_old_langs(store, to_remove)
コード例 #2
0
ファイル: node.py プロジェクト: CreativeOthman/GlobaLeaks
def db_update_enabled_languages(session, tid, languages_enabled,
                                default_language):
    cur_enabled_langs = models.EnabledLanguage.list(session, tid)
    new_enabled_langs = [text_type(y) for y in languages_enabled]

    if len(new_enabled_langs) < 1:
        raise errors.InputValidationError("No languages enabled!")

    if default_language not in new_enabled_langs:
        raise errors.InputValidationError(
            "Invalid lang code for chosen default_language")

    appdata = None
    for lang_code in new_enabled_langs:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InputValidationError("Invalid lang code: %s" %
                                              lang_code)

        if lang_code not in cur_enabled_langs:
            if appdata is None:
                appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            models.config.add_new_lang(session, tid, lang_code, appdata)

    to_remove = list(set(cur_enabled_langs) - set(new_enabled_langs))
    if to_remove:
        session.query(
            models.User).filter(models.User.tid == tid,
                                models.User.language.in_(to_remove)).update(
                                    {'language': default_language},
                                    synchronize_session='fetch')
        session.query(models.EnabledLanguage).filter(
            models.EnabledLanguage.tid == tid,
            models.EnabledLanguage.name.in_(to_remove)).delete(
                synchronize_session='fetch')
コード例 #3
0
def enable_disable_languages(store, request):
    cur_enabled_langs = EnabledLanguage.list(store)
    new_enabled_langs = [unicode(y) for y in request['languages_enabled']]

    if len(new_enabled_langs) < 1:
        raise errors.InvalidInputFormat("No languages enabled!")

    if request['default_language'] not in new_enabled_langs:
        raise errors.InvalidInputFormat(
            "Invalid lang code for chosen default_language")

    appdata = None
    for lang_code in new_enabled_langs:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InvalidInputFormat("Invalid lang code: %s" %
                                            lang_code)
        if lang_code not in cur_enabled_langs:
            if appdata is None:
                appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            EnabledLanguage.add_new_lang(store, lang_code, appdata)

    to_remove = list(set(cur_enabled_langs) - set(new_enabled_langs))

    if len(to_remove):
        users = store.find(models.User, In(models.User.language, to_remove))
        for user in users:
            user.language = request['default_language']

        EnabledLanguage.remove_old_langs(store, to_remove)
コード例 #4
0
    def setUp(self):
        self.test_reactor = task.Clock()
        jobs.base.test_reactor = self.test_reactor
        token.TokenList.reactor = self.test_reactor
        runner.test_reactor = self.test_reactor
        tempdict.test_reactor = self.test_reactor
        GLSessions.reactor = self.test_reactor

        init_glsettings_for_unit_tests()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', GLSettings.db_file_name),
                os.path.join(GLSettings.working_path, 'db',
                             GLSettings.db_file_name))
        else:
            yield db.init_db(use_single_lang=True)

        allow_unencrypted = self.encryption_scenario in ['PLAINTEXT', 'MIXED']

        yield update_node_setting('allow_unencrypted', allow_unencrypted)

        yield db.refresh_memory_variables()

        Alarm.reset()
        event.EventTrackQueue.clear()
        jobs.statistics_sched.StatisticsSchedule.reset()

        self.internationalized_text = load_appdata(
        )['node']['whistleblowing_button']
コード例 #5
0
ファイル: node.py プロジェクト: globaleaks/GlobaLeaks
def enable_disable_languages(store, request):
    cur_enabled_langs = EnabledLanguage.list(store)
    new_enabled_langs = [unicode(y) for y in request["languages_enabled"]]

    if len(new_enabled_langs) < 1:
        raise errors.InvalidInputFormat("No languages enabled!")

    if request["default_language"] not in new_enabled_langs:
        raise errors.InvalidInputFormat("Invalid lang code for chosen default_language")

    appdata = None
    for lang_code in new_enabled_langs:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InvalidInputFormat("Invalid lang code: %s" % lang_code)
        if lang_code not in cur_enabled_langs:
            if appdata is None:
                appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            EnabledLanguage.add_new_lang(store, lang_code, appdata)

    to_remove = list(set(cur_enabled_langs) - set(new_enabled_langs))

    if len(to_remove):
        users = store.find(models.User, In(models.User.language, to_remove))
        for user in users:
            user.language = request["default_language"]

        EnabledLanguage.remove_old_langs(store, to_remove)
コード例 #6
0
def db_create(session, desc):
    t = models.Tenant()

    session.add(t)

    # required to generate the tenant id
    session.flush()

    appdata = load_appdata()

    db_load_defaults(session)

    models.config.initialize_config(session, t.id, desc['mode'])

    for var in ['mode', 'name', 'subdomain']:
        db_set_config_variable(session, t.id, var, desc[var])

    models.config.add_new_lang(session, t.id, 'en', appdata)

    db_initialize_tenant_submission_statuses(session, t.id)

    if desc['mode'] == 'default':
        file_descs = [('favicon', 'data/favicon.ico')]

        for file_desc in file_descs:
            with open(os.path.join(Settings.client_path, file_desc[1]),
                      'rb') as f:
                data = base64.b64encode(f.read()).decode()
                file.db_add_file(session, t.id, file_desc[0], '', data)

    return t
コード例 #7
0
ファイル: helpers.py プロジェクト: nyimbi/GlobaLeaks
    def setUp(self):
        init_glsettings_for_unit_tests()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', GLSettings.db_file_name),
                os.path.join(GLSettings.working_path, 'db',
                             GLSettings.db_file_name))
        else:
            yield db.init_db()

        yield db.refresh_memory_variables()

        for fixture in getattr(self, 'fixtures', []):
            yield import_fixture(fixture)

        # override of imported memory variables
        GLSettings.memory_copy.allow_unencrypted = True

        anomaly.Alarm.reset()
        event.EventTrackQueue.reset()
        statistics_sched.StatisticsSchedule.reset()

        self.internationalized_text = load_appdata(
        )['node']['whistleblowing_button']
コード例 #8
0
ファイル: tenant.py プロジェクト: prateekj117/GlobaLeaks
def db_create(session, desc):
    t = models.Tenant()

    t.active = desc['active']

    session.add(t)

    # required to generate the tenant id
    session.flush()

    appdata = load_appdata()

    if t.id == 1:
        db_load_defaults(session)

    models.config.initialize_config(session, t.id, desc['mode'])

    for var in ['mode', 'name', 'subdomain']:
        db_set_config_variable(session, t.id, var, desc[var])

    models.config.add_new_lang(session, t.id, 'en', appdata)

    db_initialize_tenant_submission_statuses(session, t.id)

    db_refresh_memory_variables(session, [t.id])

    return t
コード例 #9
0
ファイル: helpers.py プロジェクト: jpobley/GlobaLeaks
    def setUp(self):
        self.test_reactor = task.Clock()
        jobs.base.test_reactor = self.test_reactor
        token.TokenList.reactor = self.test_reactor
        runner.test_reactor = self.test_reactor
        tempdict.test_reactor = self.test_reactor
        GLSettings.sessions.reactor = self.test_reactor

        init_glsettings_for_unit_tests()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', GLSettings.db_file_name),
                os.path.join(GLSettings.working_path, 'db', GLSettings.db_file_name)
            )
        else:
            yield db.init_db()

        yield db.refresh_memory_variables()

        for fixture in getattr(self, 'fixtures', []):
            yield import_fixture(fixture)

        # override of imported memory variables
        GLSettings.memory_copy.allow_unencrypted = True

        Alarm.reset()
        event.EventTrackQueue.reset()
        jobs.statistics_sched.StatisticsSchedule.reset()

        self.internationalized_text = load_appdata()['node']['whistleblowing_button']
コード例 #10
0
ファイル: helpers.py プロジェクト: Taipo/GlobaLeaks
    def setUp(self):
        self.test_reactor = task.Clock()

        jobs.base.test_reactor = self.test_reactor
        tempdict.test_reactor = self.test_reactor
        token.TokenList.reactor = self.test_reactor
        runner.test_reactor = self.test_reactor
        GLSessions.reactor = self.test_reactor

        init_glsettings_for_unit_tests()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', GLSettings.db_file_name),
                os.path.join(GLSettings.working_path, 'db', GLSettings.db_file_name)
            )
        else:
            yield db.init_db(use_single_lang=True)

        allow_unencrypted = self.encryption_scenario in ['PLAINTEXT', 'MIXED']

        yield update_node_setting('allow_unencrypted', allow_unencrypted)
        yield update_node_setting('submission_minimum_delay', 0)

        yield db.refresh_memory_variables()

        Alarm.reset()
        event.EventTrackQueue.clear()
        jobs.statistics_sched.StatisticsSchedule.reset()

        self.internationalized_text = load_appdata()['node']['whistleblowing_button']
コード例 #11
0
ファイル: node.py プロジェクト: prateekj117/GlobaLeaks
def db_update_enabled_languages(session, tid, languages, default_language):
    """
    Transaction for updating the enabled languages for a tenant

    :param session: An ORM session
    :param tid: A tenant id
    :param languages_enabled: The list of enabled languages
    :param default_language: The language to be set as default
    """
    cur_enabled_langs = db_get_languages(session, tid)

    if len(languages) < 1:
        raise errors.InputValidationError("No languages enabled!")

    # get sure that the default language is included in the enabled languages
    languages = set(languages + [default_language])

    appdata = None
    for lang_code in languages:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InputValidationError("Invalid lang code: %s" % lang_code)

        if lang_code not in cur_enabled_langs:
            if appdata is None:
                appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            models.config.add_new_lang(session, tid, lang_code, appdata)

    to_remove = list(set(cur_enabled_langs) - set(languages))
    if to_remove:
        session.query(models.User).filter(models.User.tid == tid, models.User.language.in_(to_remove)).update({'language': default_language}, synchronize_session=False)
        db_del(session, models.EnabledLanguage, (models.EnabledLanguage.tid == tid, models.EnabledLanguage.name.in_(to_remove)))
コード例 #12
0
ファイル: node.py プロジェクト: sshyran/GlobaLeaks
def enable_disable_languages(store, request):
    cur_enabled_langs = EnabledLanguage.get_all_strings(store)
    new_enabled_langs = [unicode(y) for y in request['languages_enabled']]

    if len(new_enabled_langs) < 1:
        raise errors.InvalidInputFormat("No languages enabled!")

    if request['default_language'] not in new_enabled_langs:
        raise errors.InvalidInputFormat(
            "Invalid lang code for chosen default_language")

    appdata = None
    for lang_code in new_enabled_langs:
        if lang_code not in LANGUAGES_SUPPORTED_CODES:
            raise errors.InvalidInputFormat("Invalid lang code: %s" %
                                            lang_code)
        if lang_code not in cur_enabled_langs:
            if appdata is None:
                appdata = load_appdata()
            log.debug("Adding a new lang %s" % lang_code)
            EnabledLanguage.add_new_lang(store, lang_code, appdata)

    for lang_code in cur_enabled_langs:
        if lang_code not in new_enabled_langs:
            EnabledLanguage.remove_old_lang(store, lang_code)
コード例 #13
0
ファイル: tenant.py プロジェクト: Stiv/GlobaLeaks
def db_create(session, desc):
    appdata = load_appdata()

    t = models.db_forge_obj(session, models.Tenant, desc)

    # required to generate/retrive the id
    session.flush()

    db_update_defaults(session)

    models.config.system_cfg_init(session, tid=t.id)

    models.config.add_new_lang(session, t.id, u'en', appdata)

    file_descs = [
      (u'logo', 'data/logo.png'),
      (u'favicon', 'data/favicon.ico')
    ]

    for file_desc in file_descs:
        with open(os.path.join(Settings.client_path, file_desc[1]), 'r') as f:
            data = base64.b64encode(f.read())
            file.db_add_file(session, t.id, file_desc[0], u'', data)

    db_refresh_memory_variables(session, [t.id])

    return t
コード例 #14
0
ファイル: update.py プロジェクト: chojar/GlobaLeaks
    def __init__(self, migration_mapping, start_version, session_old, session_new):
        self.appdata = load_appdata()

        self.migration_mapping = migration_mapping
        self.start_version = start_version

        self.session_old = session_old
        self.session_new = session_new

        self.model_from = {}
        self.model_to = {}
        self.entries_count = {}
        self.fail_on_count_mismatch = {}

        expected = DATABASE_VERSION + 1 - FIRST_DATABASE_VERSION_SUPPORTED
        for model_name, model_history in migration_mapping.items():
            length = len(model_history)
            if length != expected:
                raise TypeError('Number of status mismatch for table {}, expected:{} actual:{}'.format(model_name, expected, length))

            self.fail_on_count_mismatch[model_name] = True

            self.model_from[model_name] = migration_mapping[model_name][start_version - FIRST_DATABASE_VERSION_SUPPORTED]
            self.model_to[model_name] = migration_mapping[model_name][start_version + 1 - FIRST_DATABASE_VERSION_SUPPORTED]

            self.entries_count[model_name] = 0
            if self.model_from[model_name] is not None and self.model_to[model_name] is not None:
                self.entries_count[model_name] = self.session_old.query(self.model_from[model_name]).count()

        self.session_new.commit()
コード例 #15
0
    def __init__(self, migration_mapping, start_version, session_old,
                 session_new):
        self.appdata = load_appdata()

        self.migration_mapping = migration_mapping
        self.start_version = start_version

        self.session_old = session_old
        self.session_new = session_new

        self.model_from = {}
        self.model_to = {}
        self.entries_count = {}

        expected = DATABASE_VERSION + 1 - FIRST_DATABASE_VERSION_SUPPORTED
        for model_name, model_history in migration_mapping.items():
            length = len(model_history)
            if length != expected:
                raise TypeError(
                    'Number of status mismatch for table {}, expected:{} actual:{}'
                    .format(model_name, expected, length))

            self.model_from[model_name] = migration_mapping[model_name][
                start_version - FIRST_DATABASE_VERSION_SUPPORTED]
            self.model_to[model_name] = migration_mapping[model_name][
                start_version + 1 - FIRST_DATABASE_VERSION_SUPPORTED]

            if self.model_from[model_name] is None or self.model_to[
                    model_name] is None:
                self.entries_count[model_name] = 0
            else:
                self.entries_count[model_name] = self.session_old.query(
                    self.model_from[model_name]).count()

        self.session_new.commit()
コード例 #16
0
    def setUp(self):
        self.test_reactor = task.Clock()

        jobs.job.reactor = self.test_reactor
        tempdict.TempDict.reactor = self.test_reactor

        self.state = State

        init_state()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', 'glbackend-%d.db' % DATABASE_VERSION),
                os.path.join(Settings.db_file_path)
            )
        else:
            yield db.create_db()
            yield db.init_db()

        yield self.set_hostnames(1)

        yield db.refresh_memory_variables()

        self.state.reset_hourly()

        Settings.submission_minimum_delay = 0

        self.internationalized_text = load_appdata()['node']['whistleblowing_button']
コード例 #17
0
    def __init__(self, migration_mapping, start_version, store_old, store_new):
        self.appdata = load_appdata()

        self.migration_mapping = migration_mapping
        self.start_version = start_version

        self.store_old = store_old
        self.store_new = store_new

        self.model_from = {}
        self.model_to = {}
        self.entries_count = {}
        self.fail_on_count_mismatch = {}

        for model_name, model_history in migration_mapping.iteritems():
            length = DATABASE_VERSION + 1 - FIRST_DATABASE_VERSION_SUPPORTED
            if len(model_history) != length:
                raise TypeError(
                    'Expecting a table with {} statuses ({})'.format(
                        length, model_name))

            self.fail_on_count_mismatch[model_name] = True

            self.model_from[model_name] = self.get_right_model(
                model_name, start_version)
            self.model_to[model_name] = self.get_right_model(
                model_name, start_version + 1)

            if self.model_from[model_name] is not None and self.model_to[
                    model_name] is not None:
                self.entries_count[model_name] = self.store_old.find(
                    self.model_from[model_name]).count()
            else:
                self.entries_count[model_name] = 0

        if self.start_version + 1 == DATABASE_VERSION:
            # we are there!
            if not os.access(GLSettings.db_schema, os.R_OK):
                GLSettings.print_msg(
                    "Unable to access %s ' % GLSettings.db_schema")
                raise IOError('Unable to access db schema file')
            with open(GLSettings.db_schema) as f:
                queries = ''.join(f).split(';')
                for query in queries:
                    self.execute_query(query)

        else:  # manage the migrantion here
            for k, _ in self.migration_mapping.iteritems():
                query = self.get_right_sql_version(k, self.start_version + 1)
                if not query:
                    # the table has been removed
                    continue

                self.execute_query(query)

        self.store_new.commit()
コード例 #18
0
ファイル: test_notification.py プロジェクト: br1n0/GlobaLeaks
    def test_put_reset_templates(self):
        handler = self.request(role='admin')
        yield handler.get()

        self.responses[0]['reset_templates'] = True

        handler = self.request(self.responses[0], role='admin')
        yield handler.put()

        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            self.assertEqual(self.responses[1][k], appdata_dict['templates'][k]['en'])
コード例 #19
0
ファイル: helpers.py プロジェクト: nyimbi/GlobaLeaks
def do_appdata_init(store):
    try:
        appdata = store.find(models.ApplicationData).one()

        if not appdata:
            raise Exception

    except Exception:
        appdata = models.ApplicationData()
        source = load_appdata()
        appdata.version = source['version']
        appdata.fields = source['fields']
        store.add(appdata)
コード例 #20
0
ファイル: helpers.py プロジェクト: br1n0/GlobaLeaks
def do_appdata_init(store):
    try:
        appdata = store.find(models.ApplicationData).one()

        if not appdata:
            raise Exception

    except Exception:
        appdata = models.ApplicationData()
        source = load_appdata()
        appdata.version = source['version']
        appdata.fields = source['fields']
        store.add(appdata)
コード例 #21
0
    def test_put_reset_templates(self):
        handler = self.request(role='admin')
        notif_desc = yield handler.get()

        notif_desc['reset_templates'] = True
        notif_desc['password'] = u'widdlyscuds'

        handler = self.request(notif_desc, role='admin')
        response = yield handler.put()

        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            self.assertEqual(response[k], appdata_dict['templates'][k]['en'])
コード例 #22
0
    def test_put_reset_templates(self):
        handler = self.request(role='admin')
        yield handler.get()

        self.responses[0]['reset_templates'] = True

        handler = self.request(self.responses[0], role='admin')
        yield handler.put()

        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            self.assertEqual(self.responses[1][k],
                             appdata_dict['templates'][k]['en'])
コード例 #23
0
ファイル: update.py プロジェクト: tempbottle/GlobaLeaks
    def __init__(self, migration_mapping, start_version, store_old, store_new):
        self.appdata = load_appdata()

        self.migration_mapping = migration_mapping
        self.start_version = start_version

        self.store_old = store_old
        self.store_new = store_new

        self.model_from = {}
        self.model_to = {}
        self.entries_count = {}
        self.fail_on_count_mismatch = {}

        for model_name, model_history in migration_mapping.iteritems():
            length = DATABASE_VERSION + 1 - FIRST_DATABASE_VERSION_SUPPORTED
            if len(model_history) != length:
                raise TypeError('Expecting a table with {} statuses ({})'.format(length, model_name))

            self.fail_on_count_mismatch[model_name] = True

            self.model_from[model_name] = self.get_right_model(model_name, start_version)
            self.model_to[model_name] = self.get_right_model(model_name, start_version + 1)

            if self.model_from[model_name] is not None and self.model_to[model_name] is not None:
                self.entries_count[model_name] = self.store_old.find(self.model_from[model_name]).count()
            else:
                self.entries_count[model_name] = 0

        if self.start_version + 1 == DATABASE_VERSION:
            # we are there!
            if not os.access(GLSettings.db_schema, os.R_OK):
                print 'Unable to access %s ' % GLSettings.db_schema
                raise IOError('Unable to access db schema file')
            with open(GLSettings.db_schema) as f:
                queries = ''.join(f).split(';')
                for query in queries:
                    self.execute_query(query)

        else: # manage the migrantion here
            for k, _ in self.migration_mapping.iteritems():
                query = self.get_right_sql_version(k, self.start_version + 1)
                if not query:
                    # the table has been removed
                    continue

                self.execute_query(query)

        self.store_new.commit()
コード例 #24
0
ファイル: __init__.py プロジェクト: Taipo/GlobaLeaks
    def prologue(self):
        appdata = load_appdata()

        steps = appdata['default_questionnaire']['steps']
        del appdata['default_questionnaire']['steps']

        questionnaire = db_forge_obj(self.store_new, Questionnaire, appdata['default_questionnaire'])

        for step in steps:
            f_children = step['children']
            del step['children']
            s = db_forge_obj(self.store_new, Step, step)
            db_import_fields(self.store_new, s, None, f_children)
            s.questionnaire_id = questionnaire.id

        self.store_new.commit()
コード例 #25
0
def update_notification(session, tid, request, language):
    config = ConfigFactory(session, tid)
    if request['smtp_password'] == '':
        del request['smtp_password']

    config.update('notification', request)

    config_l10n = ConfigL10NFactory(session, tid)
    config_l10n.update('notification', request, language)

    if request.pop('reset_templates'):
        config_l10n.reset('notification', load_appdata())

    db_refresh_memory_variables(session, [tid])

    return db_get_notification(session, tid, language)
コード例 #26
0
def update_notification(session, tid, request, language):
    notif = ConfigFactory(session, tid, 'notification')
    if request['smtp_password'] == '':
        del request['smtp_password']

    notif.update(request)

    notif_l10n = NotificationL10NFactory(session, tid)
    notif_l10n.update(request, language)

    if request.pop('reset_templates'):
        notif_l10n.reset_templates(load_appdata())

    db_refresh_memory_variables(session, [tid])

    return admin_serialize_notification(session, tid, language)
コード例 #27
0
ファイル: migration.py プロジェクト: prateekj117/GlobaLeaks
def perform_data_update(db_file):
    """
    Update the database including up-to-date application data
    :param db_file: The database file path
    """
    now = datetime_now()

    appdata = load_appdata()

    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            % removed_languages)

    try:
        if config.ConfigFactory(session, 1).get_val('version') != __version__:
            session.query(models.Config).filter_by(var_name = 'version') \
                   .update({'value': __version__, 'update_date': now})

            session.query(models.Config).filter_by(var_name = 'latest_version') \
                   .update({'value': __version__, 'update_date': now})

            session.query(models.Config).filter_by(var_name = 'version_db') \
                   .update({'value': DATABASE_VERSION, 'update_date': now})

            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                config.update_defaults(session, tid, appdata)

            db_load_defaults(session)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
コード例 #28
0
ファイル: migration.py プロジェクト: MrMEEE/GlobaLeaks
def perform_data_update(db_file):
    """
    Update the database including up-to-date application data
    :param db_file: The database file path
    """
    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop"
            % removed_languages)

    try:
        cfg = config.ConfigFactory(session, 1)

        stored_ver = cfg.get_val('version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_load_defaults(session)

            cfg.set_val('version', __version__)
            cfg.set_val('latest_version', __version__)
            cfg.set_val('version_db', DATABASE_VERSION)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
コード例 #29
0
    def prologue(self):
        appdata = load_appdata()

        steps = appdata['default_questionnaire']['steps']
        del appdata['default_questionnaire']['steps']

        questionnaire = db_forge_obj(self.store_new, Questionnaire,
                                     appdata['default_questionnaire'])

        for step in steps:
            f_children = step['children']
            del step['children']
            s = db_forge_obj(self.store_new, Step, step)
            db_import_fields(self.store_new, s, None, f_children)
            s.questionnaire_id = questionnaire.id

        self.store_new.commit()
コード例 #30
0
def update_notification(store, request, language):
    notif = store.find(Notification).one()

    fill_localized_keys(request, Notification.localized_keys, language)

    if request['reset_templates']:
        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            request[k] = appdata_dict['templates'][k]

    notif.update(request)

    parse_pgp_options(notif, request)

    db_refresh_memory_variables(store)

    return admin_serialize_notification(notif, language)
コード例 #31
0
def update_notification(store, request, language):
    notif = store.find(Notification).one()

    fill_localized_keys(request, Notification.localized_keys, language)

    if request['reset_templates']:
        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            request[k] = appdata_dict['templates'][k]

    notif.update(request)

    parse_pgp_options(notif, request)

    db_refresh_memory_variables(store)

    return admin_serialize_notification(notif, language)
コード例 #32
0
    def __init__(self, migration_mapping, start_version, store_old, store_new):
        self.appdata = load_appdata()

        self.migration_mapping = migration_mapping
        self.start_version = start_version

        self.store_old = store_old
        self.store_new = store_new

        self.model_from = {}
        self.model_to = {}
        self.entries_count = {}
        self.fail_on_count_mismatch = {}

        expected = DATABASE_VERSION + 1 - FIRST_DATABASE_VERSION_SUPPORTED
        for model_name, model_history in migration_mapping.items():
            length = len(model_history)
            if length != expected:
                raise TypeError(
                    'Number of status mismatch for table {}, expected:{} actual:{}'
                    .format(model_name, expected, length))

            self.fail_on_count_mismatch[model_name] = True

            self.model_from[model_name] = self.get_right_model(
                model_name, start_version)
            self.model_to[model_name] = self.get_right_model(
                model_name, start_version + 1)

            self.entries_count[model_name] = 0
            if self.model_from[model_name] is not None and self.model_to[
                    model_name] is not None:
                self.entries_count[model_name] = self.store_old.find(
                    self.model_from[model_name]).count()

        if start_version + 1 < DATABASE_VERSION:
            for k, _ in self.migration_mapping.items():
                query = self.get_right_sql_version(k, self.start_version + 1)
                if query:  # the query is missing when the table has been removed
                    self.execute_query(query)

        else:  # the last commit is the only one that use the actual sqlite.sql file
            db_create_tables(self.store_new)

        self.store_new.commit()
コード例 #33
0
def init_db(store):
    appdata = load_appdata()

    db_create_tables(store)

    db_update_defaults(store)

    log.debug("Performing database initialization...")

    models.config.system_cfg_init(store)

    models.l10n.EnabledLanguage.add_all_supported_langs(store, appdata)

    file_descs = [(u'logo', 'data/logo.png'), (u'favicon', 'data/favicon.ico')]

    for file_desc in file_descs:
        with open(os.path.join(Settings.client_path, file_desc[1]), 'r') as f:
            files.db_add_file(store, f.read(), file_desc[0])
コード例 #34
0
def db_initialize(session, tid):
    appdata = load_appdata()

    models.config.system_cfg_init(session, tid=tid)

    models.config.add_new_lang(session, tid, u'en', appdata)

    initialize_submission_statuses(session, tid)

    file_descs = [
      (u'logo', 'data/logo.png'),
      (u'favicon', 'data/favicon.ico')
    ]

    for file_desc in file_descs:
        with open(os.path.join(Settings.client_path, file_desc[1]), 'rb') as f:
            data = base64.b64encode(f.read())
            file.db_add_file(session, tid, file_desc[0], u'', data)
コード例 #35
0
ファイル: notification.py プロジェクト: vondrakk/GlobaLeaks
def update_notification(store, request, language):
    notif = NotificationFactory(store)
    notif.update(request)

    smtp_pw = request.pop('smtp_password', u'')
    if smtp_pw != u'':
        PrivateFactory(store).set_val(u'smtp_password', smtp_pw)

    notif_l10n = NotificationL10NFactory(store)
    notif_l10n.update(request, language)

    if request.pop('reset_templates'):
        notif_l10n.reset_templates(load_appdata())

    # Since the Notification object has been changed refresh the global copy.
    db_refresh_memory_variables(store)

    return admin_serialize_notification(store, language)
コード例 #36
0
ファイル: migration.py プロジェクト: Stiv/GlobaLeaks
def perform_data_update(db_file):
    engine = get_engine(make_db_uri(db_file), foreign_keys=False)
    session = sessionmaker(bind=engine)()

    enabled_languages = [
        lang.name for lang in session.query(models.EnabledLanguage)
    ]

    removed_languages = list(
        set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception(
            "FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
            "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop"
            % removed_languages)

    try:
        prv = ConfigFactory(session, 1, 'node')

        stored_ver = prv.get_val(u'version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_update_defaults(session)
            db_fix_fields_attrs(session)

            prv.set_val(u'version', __version__)
            prv.set_val(u'latest_version', __version__)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()
コード例 #37
0
ファイル: tenant.py プロジェクト: og3niuz/GlobaLeaks
def db_initialize(session, tenant, mode):
    tenant.active = True

    appdata = load_appdata()

    models.config.initialize_config(session, tenant.id, mode)

    models.config.add_new_lang(session, tenant.id, u'en', appdata)

    initialize_submission_statuses(session, tenant.id)

    if tenant.id == 1:
        file_descs = [(u'logo', 'data/logo.png'),
                      (u'favicon', 'data/favicon.ico')]

        for file_desc in file_descs:
            with open(os.path.join(Settings.client_path, file_desc[1]),
                      'rb') as f:
                data = base64.b64encode(f.read()).decode()
                file.db_add_file(session, tenant.id, file_desc[0], u'', data)
コード例 #38
0
ファイル: migration.py プロジェクト: vondrakk/GlobaLeaks
def db_perform_data_update(store):
    prv = PrivateFactory(store)

    stored_ver = prv.get_val(u'version')
    t = (stored_ver, __version__)

    if stored_ver != __version__:
        prv.set_val(u'version', __version__)

        # The below commands can change the current store based on the what is
        # currently stored in the DB.
        appdata = load_appdata()
        db_update_defaults(store)
        l10n.update_defaults(store, appdata)
        config.update_defaults(store)

    ok = config.is_cfg_valid(store)
    if not ok:
        m = 'Error: the system is not stable, update failed from %s to %s' % t
        raise Exception(m)
コード例 #39
0
    def setUp(self):
        self.test_reactor = task.Clock()

        jobs.job.reactor = self.test_reactor
        tempdict.reactor = self.test_reactor
        token.TokenList.reactor = self.test_reactor
        Sessions.reactor = self.test_reactor

        self.state = State

        init_state()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty',
                             'glbackend-%d.db' % DATABASE_VERSION),
                os.path.join(Settings.db_file_path))
        else:
            yield db.create_db()
            yield db.init_db()

        allow_unencrypted = self.encryption_scenario in ['PLAINTEXT', 'MIXED']

        yield tw(db_set_config_variable, 1, u'allow_unencrypted',
                 allow_unencrypted)

        yield self.set_hostnames(1)

        yield db.refresh_memory_variables()

        sup = ProcessSupervisor([], '127.0.0.1', 8082)
        self.state.process_supervisor = sup

        self.state.reset_hourly()

        Settings.submission_minimum_delay = 0

        self.internationalized_text = load_appdata(
        )['node']['whistleblowing_button']
コード例 #40
0
ファイル: tenant.py プロジェクト: svendber/GlobaLeaks
def db_initialize_tenant(session, tenant, mode):
    tenant.active = True

    appdata = load_appdata()

    db_load_defaults(session)

    models.config.initialize_config(session, tenant.id, mode)

    models.config.add_new_lang(session, tenant.id, 'en', appdata)

    db_initialize_tenant_submission_statuses(session, tenant.id)

    if mode == 'default':
        file_descs = [('favicon', 'data/favicon.ico')]

        for file_desc in file_descs:
            with open(os.path.join(Settings.client_path, file_desc[1]),
                      'rb') as f:
                data = base64.b64encode(f.read()).decode()
                file.db_add_file(session, tenant.id, file_desc[0], '', data)
コード例 #41
0
ファイル: notification.py プロジェクト: Taipo/GlobaLeaks
def update_notification(store, request, language):
    notif_l10n = NotificationL10NFactory(store)
    notif_l10n.update(request, language)

    if request.pop('reset_templates'):
        appdata = load_appdata()
        notif_l10n.reset_templates(appdata)

    smtp_pw = request.pop('smtp_password', u'')
    if smtp_pw != u'':
        PrivateFactory(store).set_val('smtp_password', smtp_pw)

    notif = NotificationFactory(store)
    notif.update(request)

    parse_pgp_options(notif, request)

    # Since the Notification object has been changed refresh the global copy.
    db_refresh_memory_variables(store)

    return admin_serialize_notification(store, language)
コード例 #42
0
def update_notification(store, request, language):
    notif = store.find(Notification).one()

    fill_localized_keys(request, Notification.localized_keys, language)

    if request['reset_templates']:
        appdata_dict = load_appdata()
        for k in appdata_dict['templates']:
            request[k] = appdata_dict['templates'][k]

    if request['password'] == u'':
      log.debug('No password set. Using pw already in the DB.')
      request['password'] = notif.password

    notif.update(request)

    parse_pgp_options(notif, request)
    # Since the Notification object has been changed refresh the global copy.
    db_refresh_memory_variables(store)

    return admin_serialize_notification(notif, language)
コード例 #43
0
ファイル: tenant.py プロジェクト: chojar/GlobaLeaks
def db_initialize(session, tenant, mode):
    tenant.active = True

    appdata = load_appdata()

    models.config.initialize_config(session, tenant.id, mode)

    models.config.add_new_lang(session, tenant.id, u'en', appdata)

    initialize_submission_statuses(session, tenant.id)

    if mode == 'default':
        file_descs = [
          (u'logo', 'data/logo.png'),
          (u'favicon', 'data/favicon.ico')
        ]

        for file_desc in file_descs:
            with open(os.path.join(Settings.client_path, file_desc[1]), 'rb') as f:
                data = base64.b64encode(f.read()).decode()
                file.db_add_file(session, tenant.id, file_desc[0], u'', data)
コード例 #44
0
ファイル: helpers.py プロジェクト: globaleaks/GlobaLeaks
    def setUp(self):
        self.test_reactor = task.Clock()

        jobs.job.reactor = self.test_reactor
        tempdict.reactor = self.test_reactor
        token.TokenList.reactor = self.test_reactor
        Sessions.reactor = self.test_reactor

        self.state = State

        init_state()

        self.setUp_dummy()

        if self.initialize_test_database_using_archived_db:
            shutil.copy(
                os.path.join(TEST_DIR, 'db', 'empty', 'glbackend-%d.db' % DATABASE_VERSION),
                os.path.join(Settings.db_file_path)
            )
        else:
            yield db.create_db()
            yield db.init_db()

        allow_unencrypted = self.encryption_scenario in ['PLAINTEXT', 'MIXED']

        yield tw(db_set_config_variable, 1, u'allow_unencrypted', allow_unencrypted)

        yield self.set_hostnames(1)

        yield db.refresh_memory_variables()

        sup = ProcessSupervisor([], '127.0.0.1', 8082)
        self.state.process_supervisor = sup

        self.state.reset_hourly()

        Settings.submission_minimum_delay = 0

        self.internationalized_text = load_appdata()['node']['whistleblowing_button']
コード例 #45
0
ファイル: migration.py プロジェクト: globaleaks/GlobaLeaks
def perform_data_update(db_file):
    session = get_session(make_db_uri(db_file), foreign_keys=False)

    enabled_languages = [lang.name for lang in session.query(models.EnabledLanguage)]

    removed_languages = list(set(enabled_languages) - set(LANGUAGES_SUPPORTED_CODES))

    if removed_languages:
        removed_languages.sort()
        removed_languages = ', '.join(removed_languages)
        raise Exception("FATAL: cannot complete the upgrade because the support for some of the enabled languages is currently incomplete (%s)\n"
                        "Read about how to handle this condition at: https://github.com/globaleaks/GlobaLeaks/wiki/Upgrade-Guide#lang-drop" % removed_languages)

    try:
        cfg = ConfigFactory(session, 1)

        stored_ver = cfg.get_val(u'version')

        if stored_ver != __version__:
            # The below commands can change the current store based on the what is
            # currently stored in the DB.
            for tid in [t[0] for t in session.query(models.Tenant.id)]:
                appdata = load_appdata()
                config.update_defaults(session, tid, appdata)

            db_update_defaults(session)

            db_fix(session)

            cfg.set_val(u'version', __version__)
            cfg.set_val(u'latest_version', __version__)
            cfg.set_val(u'version_db', DATABASE_VERSION)

        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()