Exemple #1
0
def wizard(store, request, language):
    node = NodeFactory(store)

    if node.get_val('wizard_done'):
        # TODO report as anomaly
        log.err("DANGER: Wizard already initialized!")
        raise errors.ForbiddenOperation

    try:
        node._query_group()

        node.set_val('name', request['node']['name'])
        node.set_val('default_language', language)
        node.set_val('wizard_done', True)

        if GLSettings.onionservice is not None:
            node.set_val('onionservice', GLSettings.onionservice)

        node_l10n = NodeL10NFactory(store)

        node_l10n.set_val('description', language,
                          request['node']['description'])
        node_l10n.set_val('header_title_homepage', language,
                          request['node']['name'])

        context = db_create_context(store, request['context'], language)

        langs_to_drop = EnabledLanguage.list(store)
        langs_to_drop.remove(language)
        if len(langs_to_drop):
            EnabledLanguage.remove_old_langs(store, langs_to_drop)

        request['receiver']['contexts'] = [context.id]
        request['receiver']['language'] = language
        db_create_receiver(store, request['receiver'], language)

        admin_dict = {
            'username': u'admin',
            'password': request['admin']['password'],
            'role': u'admin',
            'state': u'enabled',
            'deletable': False,
            'name': u'Admin',
            'public_name': u'Admin',
            'description': u'',
            'mail_address': request['admin']['mail_address'],
            'language': language,
            'password_change_needed': False,
            'pgp_key_remove': False,
            'pgp_key_fingerprint': '',
            'pgp_key_public': '',
            'pgp_key_expiration': datetime_null()
        }

        db_create_admin_user(store, admin_dict, language)

    except Exception as excep:
        log.err("Failed wizard initialization %s" % excep)
        raise excep
Exemple #2
0
def wizard(store, request, language):
    node = NodeFactory(store)

    if node.get_val('wizard_done'):
        # TODO report as anomaly
        log.err("DANGER: Wizard already initialized!")
        raise errors.ForbiddenOperation

    try:
        node._query_group()

        nn = unicode(request['node']['name'])
        node.set_val('name', nn)
        node.set_val('default_language', language)
        node.set_val('wizard_done', True)

        node_l10n = NodeL10NFactory(store)

        node_l10n.set_val('description', language, nn)
        node_l10n.set_val('header_title_homepage', language, nn)
        node_l10n.set_val('presentation', language, nn)

        context = db_create_context(store, request['context'], language)

        langs_to_drop = EnabledLanguage.list(store)
        langs_to_drop.remove(language)
        if len(langs_to_drop):
            EnabledLanguage.remove_old_langs(store, langs_to_drop)

        request['receiver']['contexts'] = [context.id]
        request['receiver']['language'] = language
        db_create_receiver(store, request['receiver'], language)

        admin_dict = {
            'username': u'admin',
            'password': request['admin']['password'],
            'role': u'admin',
            'state': u'enabled',
            'deletable': False,
            'name': u'Admin',
            'public_name': u'Admin',
            'description': u'',
            'mail_address': request['admin']['mail_address'],
            'language': language,
            'password_change_needed': False,
            'pgp_key_remove': False,
            'pgp_key_fingerprint': '',
            'pgp_key_public': '',
            'pgp_key_expiration': datetime_null()
        }

        db_create_admin_user(store, admin_dict, language)

    except Exception as excep:
        log.err("Failed wizard initialization %s" % excep)
        raise excep
Exemple #3
0
def wizard(store, request, language):
    models.db_delete(store, l10n.EnabledLanguage,
                     l10n.EnabledLanguage.name != language)

    node = config.NodeFactory(store)

    if node.get_val(u'wizard_done'):
        log.err("DANGER: Wizard already initialized!")
        raise errors.ForbiddenOperation

    node._query_group()

    node.set_val(u'name', request['node']['name'])
    node.set_val(u'default_language', language)
    node.set_val(u'wizard_done', True)

    node_l10n = l10n.NodeL10NFactory(store)

    node_l10n.set_val(u'description', language, request['node']['description'])
    node_l10n.set_val(u'header_title_homepage', language,
                      request['node']['name'])

    profiles.load_profile(store, request['profile'])

    context = db_create_context(store, request['context'], language)

    request['receiver']['username'] = u'recipient'
    request['receiver']['contexts'] = [context.id]
    request['receiver']['language'] = language
    db_create_receiver_user(store, request['receiver'], language)

    admin_dict = {
        'username': u'admin',
        'password': request['admin']['password'],
        'role': u'admin',
        'state': u'enabled',
        'deletable': False,
        'name': u'Admin',
        'public_name': u'Admin',
        'description': u'',
        'mail_address': request['admin']['mail_address'],
        'language': language,
        'password_change_needed': False,
        'pgp_key_remove': False,
        'pgp_key_fingerprint': '',
        'pgp_key_public': '',
        'pgp_key_expiration': datetime_null()
    }

    db_create_admin_user(store, admin_dict, language)

    db_refresh_memory_variables(store)
Exemple #4
0
def wizard(store, request, language):
    models.db_delete(store, l10n.EnabledLanguage, l10n.EnabledLanguage.name != language)

    node = config.NodeFactory(store)

    if node.get_val(u'wizard_done'):
        log.err("DANGER: Wizard already initialized!")
        raise errors.ForbiddenOperation

    node._query_group()

    node.set_val(u'name', request['node_name'])
    node.set_val(u'default_language', language)
    node.set_val(u'wizard_done', True)

    node_l10n = l10n.NodeL10NFactory(store)

    node_l10n.set_val(u'header_title_homepage', language, request['node_name'])

    profiles.load_profile(store, request['profile'])

    receiver_desc = models.User().dict(language)
    receiver_desc['username'] = u'recipient'
    receiver_desc['name'] = receiver_desc['public_name'] = request['receiver_name']
    receiver_desc['mail_address'] = request['receiver_mail_address']
    receiver_desc['language'] = language
    receiver_desc['role'] =u'receiver'
    receiver_desc['deletable'] = True
    receiver_desc['pgp_key_remove'] = False

    _, receiver = db_create_receiver_user(store, receiver_desc, language)

    context_desc = models.Context().dict(language)
    context_desc['name'] = u'Default'
    context_desc['receivers'] = [receiver.id]

    context = db_create_context(store, context_desc, language)

    admin_desc = models.User().dict(language)
    admin_desc['username'] = u'admin'
    admin_desc['password'] = request['admin_password']
    admin_desc['name'] = admin_desc['public_name'] = request['admin_name']
    admin_desc['mail_address'] = request['admin_mail_address']
    admin_desc['language'] = language
    admin_desc['role'] =u'admin'
    admin_desc['deletable'] = False
    admin_desc['pgp_key_remove'] = False
    admin_desc['password_change_needed'] = False

    db_create_admin_user(store, admin_desc, language)

    db_refresh_memory_variables(store)
Exemple #5
0
def init_db(store):
    db_create_tables(store)
    appdata_dict = db_update_appdata(store)

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

    node = models.Node()
    node.wizard_done = GLSettings.skip_wizard
    node.receipt_salt = generateRandomSalt()

    for k in appdata_dict['node']:
        setattr(node, k, appdata_dict['node'][k])

    notification = models.Notification()
    for k in appdata_dict['templates']:
        setattr(notification, k, appdata_dict['templates'][k])

    logo = ''
    with open(os.path.join(GLSettings.client_path, 'logo.png'), 'r') as logo_file:
        logo = logo_file.read()

    node.logo = models.File()
    node.logo.data = base64.b64encode(logo)

    store.add(node)
    store.add(notification)

    admin_dict = {
        'username': u'admin',
        'password': u'globaleaks',
        'deeletable': False,
        'role': u'admin',
        'state': u'enabled',
        'deletable': False,
        'name': u'Admin',
        'description': u'',
        'mail_address': u'',
        'language': node.default_language,
        'timezone': node.default_timezone,
        'password_change_needed': False,
        'pgp_key_remove': False,
        'pgp_key_status': 'disabled',
        'pgp_key_info': '',
        'pgp_key_fingerprint': '',
        'pgp_key_public': '',
        'pgp_key_expiration': datetime_null()
    }

    admin = db_create_admin_user(store, admin_dict, node.default_language)
    admin.password_change_needed = False