Ejemplo n.º 1
0
def do_appdata_init(store):
    try:
        appdata = store.find(models.ApplicationData).one()

        if not appdata:
            raise Exception

    except Exception as xxx:
        appdata = models.ApplicationData()
        source = opportunistic_appdata_init()
        appdata.version = source['version']
        appdata.fields = source['fields']
        store.add(appdata)
Ejemplo n.º 2
0
    def test_post(self):

        appdata_blob = opportunistic_appdata_init()

        handler = self.request(appdata_blob, role='admin')
        yield handler.post()

        appdata_blob['version'] = (appdata_blob['version'] + 1)

        handler = self.request(appdata_blob, role='admin')
        yield handler.post()

        yield handler.get()
        self.assertEqual(len(self.responses[2]), len(appdata_blob['fields']) )
        self.assertEqual(self.responses[2]['version'], appdata_blob['version'])
Ejemplo n.º 3
0
    def migrate_Node(self):
        print "%s Node migration assistant: (x_frame_options_mode, x_frame_options_allow_from, \
                                             disable_privacy_badge, disable_security_awareness_badge, \
                                             disable_security_awareness_questions, security_awareness_title, \
                                             security_awareness_text" % self.std_fancy

        appdata = opportunistic_appdata_init()

        old_node = self.store_old.find(self.get_right_model("Node", 13)).one()
        new_node = self.get_right_model("Node", 14)()

        for k, v in new_node._storm_columns.iteritems():

            if v.name == 'x_frame_options_mode':
                new_node.x_frame_options_mode = 'deny';
                continue

            if v.name == 'x_frame_options_allow_from':
                new_node.x_frame_options_allow_from = '';
                continue

            if v.name == 'disable_privacy_badge':
                new_node.disable_privacy_badge = False
                continue

            if v.name == 'disable_security_awareness_badge':
                new_node.disable_security_awareness_badge = False
                continue

            if v.name == 'disable_security_awareness_questions':
                new_node.disable_security_awareness_questions = False
                continue

            if v.name == 'security_awareness_title':
                new_node.security_awareness_title = appdata['node']['security_awareness_title']
                continue

            if v.name == 'security_awareness_text':
                new_node.security_awareness_text = appdata['node']['security_awareness_text']
                continue

            setattr(new_node, v.name, getattr(old_node, v.name))

        self.store_new.add(new_node)
        self.store_new.commit()
Ejemplo n.º 4
0
    def test_post(self):

        appdata_blob = opportunistic_appdata_init()

        # FIX currently wizard create contexts only with default fields
        # so only valid requests are the one with steps = []
        self.dummyContext['steps'] = []

        wizard_blob = {
            'receiver' : self.get_dummy_receiver("christianice"),
            'fields' : self.dummyFields,
            'context' : self.dummyContext,
            'node' : self.dummyNode,
            'appdata' : appdata_blob,
        }

        handler = self.request(wizard_blob, role='admin')
        yield handler.post()
Ejemplo n.º 5
0
    def migrate_Node(self):
        print "%s Node migration assistant: (terms_and_conditions)" % self.std_fancy

        appdata = opportunistic_appdata_init()

        old_node = self.store_old.find(self.get_right_model("Node", 12)).one()
        new_node = self.get_right_model("Node", 13)()

        for k, v in new_node._storm_columns.iteritems():

            if v.name == 'terms_and_conditions':
                new_node.terms_and_conditions = ''
                continue

            setattr(new_node, v.name, getattr(old_node, v.name))

        self.store_new.add(new_node)
        self.store_new.commit()
Ejemplo n.º 6
0
    def migrate_Node(self):
        print "%s Node migration assistant: added default_language and default_timezone" \
              "whistleblowing_question, whistleblowing_button" % self.std_fancy

        appdata = opportunistic_appdata_init()

        old_node = self.store_old.find(self.get_right_model("Node", 14)).one()
        new_node = self.get_right_model("Node", 15)()

        for k, v in new_node._storm_columns.iteritems():

            if v.name == 'default_timezone':
                new_node.default_timezone= 0;
                continue

            if v.name == 'whistleblowing_question':
                new_node.whistleblowing_question = appdata['node']['whistleblowing_question']
                continue

            if v.name == 'whistleblowing_button':
                new_node.whistleblowing_button = appdata['node']['whistleblowing_button']
                continue

            if v.name == 'enable_custom_privacy_badge':
                new_node.enable_custom_privacy_badge = False
                continue

            if v.name == 'custom_privacy_badge_tbb':
                new_node.custom_privacy_badge_tbb = {'en': ''}
                continue

            if v.name == 'custom_privacy_badge_tor':
                new_node.custom_privacy_badge_tor = {'en': ''}
                continue

            if v.name == 'custom_privacy_badge_none':
                new_node.custom_privacy_badge_none = {'en': ''}
                continue

            setattr(new_node, v.name, getattr(old_node, v.name))

        self.store_new.add(new_node)
        self.store_new.commit()
Ejemplo n.º 7
0
def do_appdata_init(store):

    try:
        appdata = store.find(models.ApplicationData).one()

        if not appdata:
            raise Exception

    except Exception as xxx:
        appdata = models.ApplicationData()
        source = opportunistic_appdata_init()
        appdata.version = source['version']
        appdata.fields = source['fields']
        store.add(appdata)

    fo = Fields()
    fo.noisy = True
    fo.default_fields(appdata.fields)
    (unique_fields, localized_fields) = fo.extensive_dump()

    return unique_fields, localized_fields
Ejemplo n.º 8
0
def do_appdata_init(store):

    try:
        appdata = store.find(models.ApplicationData).one()

        if not appdata:
            raise Exception

    except Exception as xxx:
        appdata = models.ApplicationData()
        source = opportunistic_appdata_init()
        appdata.version = source['version']
        appdata.fields = source['fields']
        store.add(appdata)

    fo = Fields()
    fo.noisy = True
    fo.default_fields(appdata.fields)
    (unique_fields, localized_fields) = fo.extensive_dump()

    return unique_fields, localized_fields
Ejemplo n.º 9
0
def default_context_fields():

    source = opportunistic_appdata_init()
    if not source.has_key('fields'):
        raise Exception("Invalid Application Data initialization")

    f = source['fields']
    fo = Fields()
    fo.noisy = True
    fo.default_fields(f)
    default_fields_unhappy = fo.dump_fields('en')

    ret_fields = []
    the_first_is_required = False

    for field in default_fields_unhappy:

        if not the_first_is_required:
            field['required'] = True
            the_first_is_required = True

        ret_fields.append(field)

    return ret_fields
Ejemplo n.º 10
0
def default_context_fields():

    source = opportunistic_appdata_init()
    if not source.has_key('fields'):
        raise Exception("Invalid Application Data initialization")

    f = source['fields']
    fo = Fields()
    fo.noisy = True
    fo.default_fields(f)
    default_fields_unhappy = fo.dump_fields('en')

    ret_fields = []
    the_first_is_required = False

    for field in default_fields_unhappy:

        if not the_first_is_required:
            field['required'] = True
            the_first_is_required = True

        ret_fields.append(field)

    return ret_fields
Ejemplo n.º 11
0
def create_tables(create_node=True):
    """
    Override transactor for testing.
    """
    if GLSetting.db_type == 'sqlite' and os.path.exists(GLSetting.db_uri.replace('sqlite:', '').split('?')[0]):
        # Here we instance every model so that __storm_table__ gets set via
        # __new__
        for model in models.models:
            model()
        return succeed(None)

    deferred = create_tables_transaction()
    if create_node:

        log.debug("Node initialization with defaults values")

        only_node = {
            'name':  u"",
            'description':  dict({ GLSetting.memory_copy.default_language: u"" }),
            'presentation':  dict({ GLSetting.memory_copy.default_language: u"" }),
            'footer':  dict({ GLSetting.memory_copy.default_language: u"" }),
            'subtitle':  dict({ GLSetting.memory_copy.default_language: u"" }),
            'hidden_service':  u"",
            'public_site':  u"",
            'email':  u"",
            'receipt_regexp': u"[0-9]{16}",
            'stats_update_time':  2, # hours,
            # advanced settings
            'maximum_filesize' : GLSetting.defaults.maximum_filesize,
            'maximum_namesize' : GLSetting.defaults.maximum_namesize,
            'maximum_textsize' : GLSetting.defaults.maximum_textsize,
            'tor2web_admin' : GLSetting.defaults.tor2web_admin,
            'tor2web_submission' : GLSetting.defaults.tor2web_submission,
            'tor2web_receiver' : GLSetting.defaults.tor2web_receiver,
            'tor2web_unauth' : GLSetting.defaults.tor2web_unauth,
            'postpone_superpower' : False, # disabled by default
            'can_delete_submission' : False, # disabled too
            'ahmia' : False, # disabled too
            'anomaly_checks' : False, # need to disabled in this stage as it need to be tuned
            'allow_unencrypted': GLSetting.memory_copy.allow_unencrypted,
            'exception_email' : GLSetting.defaults.exception_email,
            'default_language' : GLSetting.memory_copy.default_language,
        }

        templates = {}

        templates['encrypted_tip'] = acquire_email_templates('default_ETNT.txt',
            "default Encrypted Tip notification not available! %NodeName% configure this!")
        templates['plaintext_tip'] = acquire_email_templates('default_PTNT.txt',
            "default Plaintext Tip notification not available! %NodeName% configure this!")

        templates['encrypted_comment'] = acquire_email_templates('default_ECNT.txt',
            "default Encrypted Comment notification not available! %NodeName% configure this!")
        templates['plaintext_comment'] = acquire_email_templates('default_PCNT.txt',
            "default Plaintext Comment notification not available! %NodeName% configure this!")

        templates['encrypted_message'] = acquire_email_templates('default_EMNT.txt',
             "default Encrypted Message notification not available! %NodeName% configure this!")
        templates['plaintext_message'] = acquire_email_templates('default_PMNT.txt',
             "default Plaintext Message notification not available! %NodeName% configure this!")

        templates['encrypted_file'] = acquire_email_templates('default_EFNT.txt',
            "default Encrypted File notification not available! %NodeName% configure this!")
        templates['plaintext_file'] = acquire_email_templates('default_PFNT.txt',
            "default Plaintext File notification not available! %NodeName% configure this!")

        # This specific template do not need different threatment as it is used to write some
        # data inside zip files.  
        templates['zip_collection'] = acquire_email_templates('default_ZCT.txt',
            "default Zip Collection template not available! %NodeName% configure this!")

        appdata_dict = opportunistic_appdata_init()
        # here is ok!

        # Initialize the node + notification table
        deferred.addCallback(initialize_node, only_node, templates, appdata_dict)

    return deferred
Ejemplo n.º 12
0
def create_tables(create_node=True):
    """
    Override transactor for testing.
    """
    if GLSetting.db_type == 'sqlite':
        db_path = GLSetting.db_uri.replace('sqlite:', '').split('?', 1)[0]
        if os.path.exists(db_path):
            return succeed(None)

    deferred = create_tables_transaction()
    if create_node:

        log.debug("Node initialization with defaults values")

        only_node = {
            'name':  u"",
            'description': dict({ GLSetting.memory_copy.default_language: u"" }),
            'presentation': dict({ GLSetting.memory_copy.default_language: u"" }),
            'footer': dict({ GLSetting.memory_copy.default_language: u"" }),
            'subtitle': dict({ GLSetting.memory_copy.default_language: u"" }),
            'security_awareness_title': dict({ GLSetting.memory_copy.default_language: u"" }),
            'security_awareness_text': dict({ GLSetting.memory_copy.default_language: u"" }),
            'whistleblowing_question': dict({ GLSetting.memory_copy.default_language: u"" }),
            'whistleblowing_button': dict({ GLSetting.memory_copy.default_language: u"" }),
            'hidden_service': u"",
            'public_site': u"",
            'email': u"",
            'receipt_regexp': u"[0-9]{16}",
            'stats_update_time': 2, # hours,
            # advanced settings
            'maximum_filesize' : GLSetting.defaults.maximum_filesize,
            'maximum_namesize' : GLSetting.defaults.maximum_namesize,
            'maximum_textsize' : GLSetting.defaults.maximum_textsize,
            'tor2web_admin' : GLSetting.defaults.tor2web_admin,
            'tor2web_submission' : GLSetting.defaults.tor2web_submission,
            'tor2web_receiver' : GLSetting.defaults.tor2web_receiver,
            'tor2web_unauth' : GLSetting.defaults.tor2web_unauth,
            'postpone_superpower' : False, # disabled by default
            'can_delete_submission' : False, # disabled too
            'ahmia' : False, # disabled too
            'allow_unencrypted': GLSetting.memory_copy.allow_unencrypted,
            'exception_email' : GLSetting.defaults.exception_email,
            'default_language' : GLSetting.memory_copy.default_language,
            'default_timezone' : 0,
            'admin_language' : GLSetting.memory_copy.default_language,
            'admin_timezone' : 0,
            'disable_privacy_badge': False,
            'disable_security_awareness_badge': False,
            'disable_security_awareness_questions': False,
            'enable_custom_privacy_badge': False,
            'custom_privacy_badge_tbb': dict({ GLSetting.memory_copy.default_language: u"" }),
            'custom_privacy_badge_tor': dict({ GLSetting.memory_copy.default_language: u"" }),
            'custom_privacy_badge_none': dict({ GLSetting.memory_copy.default_language: u"" }),
        }

        appdata_dict = opportunistic_appdata_init()

        # Initialize the node + notification table
        deferred.addCallback(initialize_node, only_node, appdata_dict)

    return deferred
Ejemplo n.º 13
0
    def migrate_InternalTip(self):
        print "%s InternalTip migration assistant" % self.std_fancy
        steps = []

        steps.append(opportunistic_appdata_init()['fields'][0])

        i = 1
        for step in steps:
            step['number'] = i
            step['label'] = step['label']['en']
            step['hint'] = step['hint']['en']
            step['description'] = step['description']['en']
            step['children'] = []  # wipe out default fields

        old_itips = self.store_old.find(self.get_right_model("InternalTip", 14))
        context_model = self.get_right_model("Context", 14)
        for old_itip in old_itips:
            new_itip = self.get_right_model("InternalTip", 15)()
            try:
                wb_steps = copy.deepcopy(steps)
                wb_fields_copy = copy.deepcopy(old_itip.wb_fields)
                for wb_field in wb_fields_copy:
                    wb_fields_copy[wb_field]["id"] = ""
                    wb_fields_copy[wb_field]["step_id"] = ""
                    wb_fields_copy[wb_field]["fieldgroup_id"] = ""
                    wb_fields_copy[wb_field]["description"] = ""
                    wb_fields_copy[wb_field]["hint"] = ""
                    wb_fields_copy[wb_field]["multi_entry"] = False
                    wb_fields_copy[wb_field]["stats_enabled"] = False
                    wb_fields_copy[wb_field]["required"] = False
                    wb_fields_copy[wb_field]["is_template"] = False
                    wb_fields_copy[wb_field]["options"] = []
                    wb_fields_copy[wb_field]["y"] = wb_fields_copy[wb_field]['answer_order']
                    wb_fields_copy[wb_field]["x"] = 0
                    wb_fields_copy[wb_field]["preview"] = False
                    wb_fields_copy[wb_field]["children"] = []
                    wb_fields_copy[wb_field]["options"] = []
                    del wb_fields_copy[wb_field]['answer_order']
                    c = self.store_old.find(context_model, context_model.id == old_itip.context_id).one()
                    for f in c.unique_fields:
                        if f == wb_field:
                            wb_fields_copy[wb_field]['label'] = c.unique_fields[f]['name']
                            if c.unique_fields[f]['type'] in ['email',
                                                              'phone',
                                                              'url',
                                                              'number',
                                                              'text']:
                                wb_fields_copy[wb_field]['type'] = 'inputbox'
                            elif c.unique_fields[f]['type'] in ['radio', 'select']:
                                wb_fields_copy[wb_field]['type'] = 'selectbox'
                            elif c.unique_fields[f]['type'] in ['multiple', 'checkboxes']:
                                wb_fields_copy[wb_field]['type'] = 'checkbox'
                            else:
                                wb_fields_copy[wb_field]['type'] = c.unique_fields[f]['type']

                            if wb_fields_copy[wb_field]['type'] in ['selectbox', 'checkbox'] and \
                                    'options' in c.unique_fields[f]:

                                val = {}

                                j = 1
                                for o in c.unique_fields[f]['options']:
                                    opt_dict = {}
                                    opt_dict['id'] = uuid4()
                                    opt_dict['attrs'] = {}
                                    opt_dict['attrs']['name'] = o['name']
                                    opt_dict['value'] = ''

                                    wb_fields_copy[wb_field]['options'].append(opt_dict)

                                    if wb_fields_copy[wb_field]['type'] == 'checkbox':
                                        opt_name = o['name']
                                        if opt_name in wb_fields_copy[wb_field]["value"] and \
                                                wb_fields_copy[wb_field]["value"][opt_name]:
                                            opt_val = True
                                        else:
                                            opt_val = False

                                        val[opt_dict['id']] = {
                                            'order': j,
                                            'value': opt_val,
                                            'name': o['name']
                                        }
                                    j += 1

                                if wb_fields_copy[wb_field]['type'] == 'checkbox':
                                    wb_fields_copy[wb_field]["value"] = val
                                # else: it's already initialized with copy


                for f in wb_fields_copy:
                    wb_steps[0]['children'].append(wb_fields_copy[f])

                for k, v in new_itip._storm_columns.iteritems():
                    if v.name == 'wb_steps':
                        new_itip.wb_steps = wb_steps;
                        continue

                    setattr(new_itip, v.name, getattr(old_itip, v.name))
            except Exception as e:
                continue

            self.store_new.add(new_itip)

        self.store_new.commit()
Ejemplo n.º 14
0
    def migrate_Context(self):
        print "%s Context migration assistant" % self.std_fancy

        old_contexts = self.store_old.find(self.get_right_model("Context", 14))

        steps = opportunistic_appdata_init()['fields']
        tos_dict = copy.deepcopy(steps[1]['children'][0])
        tos_opt_dict = copy.deepcopy(tos_dict['options'][0])
        tos_opt_dict['number'] = 1
        print tos_opt_dict
        del tos_dict['children']
        del tos_dict['options']
        i = 1
        for step in steps:
            step['number'] = i
            del step['children']

            i += 1

        for old_context in old_contexts:

            new_context = self.get_right_model("Context", 15)()

            step1 = db_forge_obj(self.store_new, Step, steps[0])
            new_context.steps.add(step1)
            step2 = db_forge_obj(self.store_new, Step, steps[1])
            new_context.steps.add(step2)

            for k, v in new_context._storm_columns.iteritems():
                if v.name == 'steps':
                    continue

                setattr(new_context, v.name, getattr(old_context, v.name))

            for f in old_context.unique_fields:
                try:

                    field_dict = {}
                    field_dict['label'] = {}
                    field_dict['hint'] = {}
                    field_dict['description'] = {}
                    field_dict['multi_entry'] = False
                    field_dict['required'] = old_context.unique_fields[f]['required']
                    field_dict['preview'] = old_context.unique_fields[f]['preview']
                    field_dict['stats_enabled'] = False
                    field_dict['is_template'] = False
                    field_dict['x'] = 0
                    field_dict['y'] = old_context.unique_fields[f]['presentation_order']
                    if old_context.unique_fields[f]['type'] in ['email',
                                                                'phone',
                                                                'url',
                                                                'number',
                                                                'text']:
                        field_dict['type'] = 'inputbox'
                    elif old_context.unique_fields[f]['type'] in ['radio', 'select']:
                        field_dict['type'] = 'selectbox'
                    elif old_context.unique_fields[f]['type'] in ['multiple', 'checkboxes']:
                        field_dict['type'] = 'checkbox'
                    else:
                        field_dict['type'] = old_context.unique_fields[f]['type']

                    for l in old_context.localized_fields:
                        if f in old_context.localized_fields[l]:
                            field_dict['label'][l] = old_context.localized_fields[l][f]['name']
                            field_dict['hint'][l] = old_context.localized_fields[l][f]['hint']

                    field = db_forge_obj(self.store_new, Field, field_dict)

                    if field_dict['type'] in ['selectbox', 'checkbox'] and 'options' in old_context.unique_fields[f]:
                        j = 1
                        for o in old_context.unique_fields[f]['options']:
                            opt_dict = {}
                            opt_dict['number'] = j
                            opt_dict['field_id'] = field.id
                            opt_dict['attrs'] = {}
                            opt_dict['attrs']['name'] = {}
                            for lang in LANGUAGES_SUPPORTED_CODES:
                                opt_dict['attrs']['name'][lang] = o['name']
                            option = db_forge_obj(self.store_new, FieldOption, opt_dict)
                            field.options.add(option)
                            j += 1

                    step1.children.add(field)

                except:
                    continue

            tos_opt = db_forge_obj(self.store_new, FieldOption, tos_opt_dict)
            tos = db_forge_obj(self.store_new, Field, tos_dict)
            tos.options.add(tos_opt)
            step2.children.add(tos)

            self.store_new.add(new_context)

        self.store_new.commit()