示例#1
0
    def migrate_Node(self):
        print "%s Node migration assistant: disable_key_code_hint" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 19)).one()
        new_node = self.get_right_model("Node", 20)()

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

            if v.name == 'can_postpone_expiration':
                old_attr = 'postpone_superpower'
                setattr(new_node, v.name, getattr(old_node, old_attr))
                continue

            if v.name == 'context_selector_label':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.context_selector_label = appdata_dict['node']['context_selector_label']
                else:
                    new_node.context_selector_label = every_language("")
                continue

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

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

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#2
0
    def migrate_Node(self):
        print "%s Node migration assistant: header_titles and landing_page configuration" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 16)).one()
        new_node = self.get_right_model("Node", 17)()

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

            if v.name == 'header_title_homepage':
                new_node.header_title_homepage = {
                    old_node.default_language: old_node.name
                }
                continue

            if v.name == 'header_title_submissionpage':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.header_title_submissionpage = appdata_dict[
                        'node']['header_title_submissionpage']
                else:
                    new_node.header_title_submissionpage = every_language("")
                continue

            if v.name == 'landing_page':
                new_node.landing_page = u'homepage'
                continue

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#3
0
    def migrate_Node(self):
        print "%s Node migration assistant: header_titles and landing_page configuration" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 16)).one()
        new_node = self.get_right_model("Node", 17)()

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

            if v.name == 'header_title_homepage':
                new_node.header_title_homepage = {old_node.default_language: old_node.name}
                continue

            if v.name == 'header_title_submissionpage':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.header_title_submissionpage = appdata_dict['node']['header_title_submissionpage']
                else:
                    new_node.header_title_submissionpage = every_language("")
                continue

            if v.name == 'landing_page':
                new_node.landing_page = u'homepage'
                continue

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#4
0
    def setUp(self):
        GLSettings.set_devel_mode()
        GLSettings.logging = None
        GLSettings.scheduler_threadpool = FakeThreadPool()
        GLSettings.sessions = {}
        GLSettings.failed_login_attempts = 0

        if os.path.isdir('/dev/shm'):
            GLSettings.working_path = '/dev/shm/globaleaks'
            GLSettings.ramdisk_path = '/dev/shm/globaleaks/ramdisk'
        else:
            GLSettings.working_path = './working_path'
            GLSettings.ramdisk_path = './working_path/ramdisk'

        GLSettings.eval_paths()
        GLSettings.remove_directories()
        GLSettings.create_directories()

        self.setUp_dummy()

        yield db.create_tables(self.create_node)

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

        yield import_memory_variables()

        # 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']
示例#5
0
    def migrate_Notification(self):
        print "%s Notification migration assistant: (pgp_expiration_alert templates)" % self.std_fancy

        appdata_dict = load_appdata()

        old_notification = self.store_old.find(
            self.get_right_model("Notification", 16)).one()
        new_notification = self.get_right_model("Notification", 17)()

        for _, v in new_notification._storm_columns.iteritems():

            if v.name == 'admin_pgp_alert_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_pgp_alert_mail_template = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.admin_pgp_alert_mail_template = every_language(
                        "")
                continue

            if v.name == 'admin_pgp_alert_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_pgp_alert_mail_title = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.admin_pgp_alert_mail_title = every_language(
                        "")
                continue

            if v.name == 'pgp_alert_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.pgp_alert_mail_template = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.pgp_alert_mail_template = every_language(
                        "")
                continue

            if v.name == 'pgp_alert_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.pgp_alert_mail_title = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.pgp_alert_mail_title = every_language("")
                continue

            setattr(new_notification, v.name, getattr(old_notification,
                                                      v.name))

        self.store_new.add(new_notification)
        self.store_new.commit()
示例#6
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'])
示例#7
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'])
示例#8
0
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)
示例#9
0
def update_notification(store, request, language):
    notif = store.find(Notification).one()

    fill_localized_keys(request, Notification.localized_strings, language)

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

    notif.update(request)

    db_update_memory_variables(store)

    return admin_serialize_notification(notif, language)
示例#10
0
def update_notification(store, request, language):
    notif = store.find(Notification).one()

    fill_localized_keys(request, Notification.localized_strings, language)

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

    notif.update(request)

    db_update_memory_variables(store)

    return admin_serialize_notification(notif, language)
示例#11
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 = load_appdata()

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

        for _, 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()
示例#12
0
    def migrate_Notification(self):
        print "%s Notification migration assistant: (pgp_expiration_alert templates)" % self.std_fancy

        appdata_dict = load_appdata()

        old_notification = self.store_old.find(self.get_right_model("Notification", 16)).one()
        new_notification = self.get_right_model("Notification", 17)()

        for _, v in new_notification._storm_columns.iteritems():

            if v.name == 'admin_pgp_alert_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_pgp_alert_mail_template = appdata_dict['templates'][v.name]
                else:
                    new_notification.admin_pgp_alert_mail_template = every_language("")
                continue

            if v.name == 'admin_pgp_alert_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_pgp_alert_mail_title = appdata_dict['templates'][v.name]
                else:
                    new_notification.admin_pgp_alert_mail_title = every_language("")
                continue

            if v.name == 'pgp_alert_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.pgp_alert_mail_template = appdata_dict['templates'][v.name]
                else:
                    new_notification.pgp_alert_mail_template = every_language("")
                continue

            if v.name == 'pgp_alert_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.pgp_alert_mail_title = appdata_dict['templates'][v.name]
                else:
                    new_notification.pgp_alert_mail_title = every_language("")
                continue

            setattr(new_notification, v.name, getattr(old_notification, v.name))

        self.store_new.add(new_notification)
        self.store_new.commit()
示例#13
0
    def migrate_Node(self):
        print "%s Node migration assistant: added default_language and default_timezone" \
              "whistleblowing_question, whistleblowing_button" % self.std_fancy

        appdata = load_appdata()

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

        for _, 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()
示例#14
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 = load_appdata()

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

        for _, 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()
示例#15
0
    def migrate_Node(self):
        print "%s Node migration assistant: added default_language and default_timezone" \
              "whistleblowing_question, whistleblowing_button" % self.std_fancy

        appdata = load_appdata()

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

        for _, 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()
示例#16
0
    def migrate_Node(self):
        print "%s Node migration assistant: header_title_receiptpage" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 18)).one()
        new_node = self.get_right_model("Node", 19)()

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

            if v.name == 'header_title_receiptpage':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.header_title_receiptpage = appdata_dict['node']['header_title_receiptpage']
                else:
                    new_node.header_title_receiptpage = every_language("")
                continue

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#17
0
    def migrate_Node(self):
        print "%s Node migration assistant: header_title_receiptpage" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 18)).one()
        new_node = self.get_right_model("Node", 19)()

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

            if v.name == 'header_title_receiptpage':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.header_title_receiptpage = appdata_dict['node'][
                        'header_title_receiptpage']
                else:
                    new_node.header_title_receiptpage = every_language("")
                continue

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#18
0
    def migrate_Notification(self):
        print "%s Notification migration assistant:" % self.std_fancy

        appdata_dict = load_appdata()

        old_notification = self.store_old.find(self.get_right_model("Notification", 20)).one()
        new_notification = self.get_right_model("Notification", 21)()

        for _, v in new_notification._storm_columns.iteritems():
            # In this release we enforce reloading all the updated templates due to the
            # semplification applied and the fact that we are not aware of any adopter
            # that has customized them.
            if v.name in templates_list:
                if v.name in appdata_dict['templates']:
                    value = appdata_dict['templates'][v.name]
                else:
                    value = every_language("")

                setattr(new_notification, v.name, value)
                continue

            if v.name == 'notification_threshold_per_hour':
                setattr(new_notification, v.name, 20)
                continue

            if v.name == 'notification_suspension_time':
                setattr(new_notification, v.name, 7200)
                continue

            if v.name == 'tip_expiration_threshold':
                setattr(new_notification, v.name, 72)
                continue

            setattr(new_notification, v.name, getattr(old_notification, v.name))

        self.store_new.add(new_notification)
        self.store_new.commit()
示例#19
0
    def migrate_Node(self):
        print "%s Node migration assistant: disable_key_code_hint" % self.std_fancy

        appdata_dict = load_appdata()

        old_node = self.store_old.find(self.get_right_model("Node", 19)).one()
        new_node = self.get_right_model("Node", 20)()

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

            if v.name == 'can_postpone_expiration':
                old_attr = 'postpone_superpower'
                setattr(new_node, v.name, getattr(old_node, old_attr))
                continue

            if v.name == 'context_selector_label':
                # check needed to preserve funtionality if appdata will be altered in the future
                if v.name in appdata_dict['node']:
                    new_node.context_selector_label = appdata_dict['node'][
                        'context_selector_label']
                else:
                    new_node.context_selector_label = every_language("")
                continue

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

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

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

        self.store_new.add(new_node)
        self.store_new.commit()
示例#20
0
    def migrate_InternalTip(self):
        print "%s InternalTip migration assistant" % self.std_fancy
        steps = []

        steps.append(load_appdata()['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 _, 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:
                continue

            self.store_new.add(new_itip)

        self.store_new.commit()
示例#21
0
def create_tables(create_node=True):
    appdata_dict = load_appdata()

    db_exists = False
    if GLSettings.db_type == 'sqlite':
        db_path = GLSettings.db_uri.replace('sqlite:', '').split('?', 1)[0]
        if os.path.exists(db_path):
            db_exists = True

    if db_exists:
        ret = succeed(None)
        ret.addCallback(init_appdata, appdata_dict)
        return ret

    deferred = create_tables_transaction()
    deferred.addCallback(init_appdata, appdata_dict)

    if create_node:
        log.debug("Node initialization with defaults values")

        node_dict = {
            'name':
            u"",
            'description':
            dict({GLSettings.defaults.language: u""}),
            'presentation':
            dict({GLSettings.defaults.language: u""}),
            'footer':
            dict({GLSettings.defaults.language: u""}),
            'context_selector_label':
            dict({GLSettings.defaults.language: u""}),
            'security_awareness_title':
            dict({GLSettings.defaults.language: u""}),
            'security_awareness_text':
            dict({GLSettings.defaults.language: u""}),
            'whistleblowing_question':
            dict({GLSettings.defaults.language: u""}),
            'whistleblowing_button':
            dict({GLSettings.defaults.language: u""}),
            'hidden_service':
            u"",
            'public_site':
            u"",
            'email':
            u"",
            'receipt_regexp':
            u"[0-9]{16}",
            # advanced settings
            'maximum_filesize':
            GLSettings.defaults.maximum_filesize,
            'maximum_namesize':
            GLSettings.defaults.maximum_namesize,
            'maximum_textsize':
            GLSettings.defaults.maximum_textsize,
            'tor2web_admin':
            GLSettings.defaults.tor2web_admin,
            'tor2web_submission':
            GLSettings.defaults.tor2web_submission,
            'tor2web_receiver':
            GLSettings.defaults.tor2web_receiver,
            'tor2web_unauth':
            GLSettings.defaults.tor2web_unauth,
            'submission_minimum_delay':
            GLSettings.defaults.submission_minimum_delay,
            'submission_maximum_ttl':
            GLSettings.defaults.submission_maximum_ttl,
            'can_postpone_expiration':
            False,  # disabled by default
            'can_delete_submission':
            False,  # disabled too
            'ahmia':
            False,  # disabled too
            'allow_unencrypted':
            GLSettings.defaults.allow_unencrypted,
            'allow_iframes_inclusion':
            GLSettings.defaults.allow_iframes_inclusion,
            'exception_email':
            GLSettings.defaults.exception_email,
            'default_language':
            GLSettings.defaults.language,
            'default_timezone':
            GLSettings.defaults.timezone,
            'admin_language':
            GLSettings.defaults.language,
            'admin_timezone':
            GLSettings.defaults.timezone,
            'disable_privacy_badge':
            False,
            'disable_security_awareness_badge':
            False,
            'disable_security_awareness_questions':
            False,
            'enable_custom_privacy_badge':
            False,
            'disable_key_code_hint':
            False,
            'custom_privacy_badge_tor':
            dict({GLSettings.defaults.language: u""}),
            'custom_privacy_badge_none':
            dict({GLSettings.defaults.language: u""}),
            'header_title_homepage':
            dict({GLSettings.defaults.language: u""}),
            'header_title_submissionpage':
            dict({GLSettings.defaults.language: u""}),
            'header_title_receiptpage':
            dict({GLSettings.defaults.language: u""}),
            'landing_page':
            GLSettings.defaults.landing_page,
            'show_contexts_in_alphabetical_order':
            False
        }

        # Initialize the node and notification tables
        deferred.addCallback(init_db, node_dict, appdata_dict)

    return deferred
示例#22
0
    def migrate_InternalTip(self):
        print "%s InternalTip migration assistant" % self.std_fancy
        steps = []

        steps.append(load_appdata()['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 _, 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:
                continue

            self.store_new.add(new_itip)

        self.store_new.commit()
示例#23
0
def create_tables(create_node=True):
    appdata_dict = load_appdata()

    db_exists = False
    if GLSetting.db_type == 'sqlite':
        db_path = GLSetting.db_uri.replace('sqlite:', '').split('?', 1)[0]
        if os.path.exists(db_path):
            db_exists = True

    if db_exists:
        ret = succeed(None)
        ret.addCallback(init_appdata, appdata_dict)
        return ret

    deferred = create_tables_transaction()
    deferred.addCallback(init_appdata, appdata_dict)

    if create_node:
        log.debug("Node initialization with defaults values")

        node_dict = {
            'name': u"",
            'description': dict({GLSetting.defaults.language: u""}),
            'presentation': dict({GLSetting.defaults.language: u""}),
            'footer': dict({GLSetting.defaults.language: u""}),
            'context_selector_label': dict({GLSetting.defaults.language: u""}),
            'security_awareness_title': dict({GLSetting.defaults.language: u""}),
            'security_awareness_text': dict({GLSetting.defaults.language: u""}),
            'whistleblowing_question': dict({GLSetting.defaults.language: u""}),
            'whistleblowing_button': dict({GLSetting.defaults.language: u""}),
            'hidden_service': u"",
            'public_site': u"",
            'email': u"",
            'receipt_regexp': u"[0-9]{16}",
            # 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,
            'can_postpone_expiration': False,  # disabled by default
            'can_delete_submission': False,  # disabled too
            'ahmia': False,  # disabled too
            'allow_unencrypted': GLSetting.defaults.allow_unencrypted,
            'allow_iframes_inclusion': GLSetting.defaults.allow_iframes_inclusion,
            'exception_email': GLSetting.defaults.exception_email,
            'default_language': GLSetting.defaults.language,
            'default_timezone': GLSetting.defaults.timezone,
            'admin_language': GLSetting.defaults.language,
            'admin_timezone': GLSetting.defaults.timezone,
            'disable_privacy_badge': False,
            'disable_security_awareness_badge': False,
            'disable_security_awareness_questions': False,
            'enable_custom_privacy_badge': False,
            'disable_key_code_hint': False,
            'custom_privacy_badge_tor': dict({GLSetting.defaults.language: u""}),
            'custom_privacy_badge_none': dict({GLSetting.defaults.language: u""}),
            'header_title_homepage': dict({GLSetting.defaults.language: u""}),
            'header_title_submissionpage': dict({GLSetting.defaults.language: u""}),
            'header_title_receiptpage': dict({GLSetting.defaults.language: u""}),
            'landing_page': GLSetting.defaults.landing_page,
            'show_contexts_in_alphabetical_order': False
        }

        # Initialize the node and notification tables
        deferred.addCallback(init_db, node_dict, appdata_dict)

    return deferred
示例#24
0
    def migrate_Notification(self):
        print "%s Notification migration assistant: various templates addeed" % self.std_fancy

        appdata_dict = load_appdata()

        old_notification = self.store_old.find(
            self.get_right_model("Notification", 19)).one()
        new_notification = self.get_right_model("Notification", 20)()

        for _, v in new_notification._storm_columns.iteritems():

            if v.name == 'send_email_for_every_event':
                new_notification.send_email_for_every_event = True
                continue

            if v.name == 'torify':
                new_notification.torify = True
                continue

            if v.name == 'admin_anomaly_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_anomaly_mail_title = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.admin_anomaly_mail_title = every_language(
                        "")
                continue

            if v.name == 'admin_anomaly_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_anomaly_mail_template = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.admin_anomaly_mail_template = every_language(
                        "")
                continue

            if v.name == 'notification_digest_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.notification_digest_mail_title = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.notification_digest_mail_title = every_language(
                        "")
                continue

            if v.name == 'tip_expiration_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.tip_expiration_mail_title = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.tip_expiration_mail_title = every_language(
                        "")
                continue

            if v.name == 'tip_expiration_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.tip_expiration_template = appdata_dict[
                        'templates'][v.name]
                else:
                    new_notification.tip_expiration_template = every_language(
                        "")
                continue

            setattr(new_notification, v.name, getattr(old_notification,
                                                      v.name))

        self.store_new.add(new_notification)
        self.store_new.commit()
示例#25
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 = load_appdata()['fields']
        tos_dict = copy.deepcopy(steps[1]['children'][0])
        tos_opt_dict = copy.deepcopy(tos_dict['options'][0])
        tos_opt_dict['number'] = 1
        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 _, 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 Exception:
                    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()
示例#26
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 = load_appdata()['fields']
        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, self.get_right_model("Step", 15), steps[0])
            step1.context_id = new_context.id
            step2 = db_forge_obj(self.store_new, self.get_right_model("Step", 15), steps[1])
            step2.context_id = new_context.id

            for _, 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']

                    continue
                    field = db_forge_obj(self.store_new, self.get_right_model("Field", 15), 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, self.get_right_model("FieldOption", 15), opt_dict)
                            field.options.add(option)
                            j += 1

                    step1.children.add(field)

                except Exception:
                    continue

            self.store_new.add(new_context)

        self.store_new.commit()
示例#27
0
    def migrate_Notification(self):
        print "%s Notification migration assistant: various templates addeed" % self.std_fancy

        appdata_dict = load_appdata()

        old_notification = self.store_old.find(self.get_right_model("Notification", 19)).one()
        new_notification = self.get_right_model("Notification", 20)()

        for _, v in new_notification._storm_columns.iteritems():

            if v.name == 'send_email_for_every_event':
                new_notification.send_email_for_every_event = True
                continue

            if v.name == 'torify':
                new_notification.torify = True
                continue

            if v.name == 'admin_anomaly_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_anomaly_mail_title = appdata_dict['templates'][v.name]
                else:
                    new_notification.admin_anomaly_mail_title = every_language("")
                continue

            if v.name == 'admin_anomaly_mail_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.admin_anomaly_mail_template = appdata_dict['templates'][v.name]
                else:
                    new_notification.admin_anomaly_mail_template = every_language("")
                continue

            if v.name == 'notification_digest_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.notification_digest_mail_title = appdata_dict['templates'][v.name]
                else:
                    new_notification.notification_digest_mail_title = every_language("")
                continue

            if v.name == 'tip_expiration_mail_title':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.tip_expiration_mail_title = appdata_dict['templates'][v.name]
                else:
                    new_notification.tip_expiration_mail_title = every_language("")
                continue

            if v.name == 'tip_expiration_template':
                # check needed to preserve funtionality if templates will be altered in the future
                if v.name in appdata_dict['templates']:
                    new_notification.tip_expiration_template = appdata_dict['templates'][v.name]
                else:
                    new_notification.tip_expiration_template = every_language("")
                continue

            setattr(new_notification, v.name, getattr(old_notification, v.name))

        self.store_new.add(new_notification)
        self.store_new.commit()