Esempio n. 1
0
def update_receiver_settings(store, receiver_id, request, language=GLSetting.memory_copy.default_language):
    receiver = store.find(Receiver, Receiver.id == unicode(receiver_id)).one()
    receiver.description[language] = request['description']

    if not receiver:
        raise errors.ReceiverIdNotFound

    new_password = request['password']
    old_password = request['old_password']

    if len(new_password) and len(old_password):
        receiver.user.password = change_password(receiver.user.password,
                                                 old_password,
                                                 new_password,
                                                 receiver.user.salt)

    mail_address = request['mail_address']

    if mail_address != receiver.mail_address:
        log.info("Email change %s => %s" % (receiver.mail_address, mail_address))
        receiver.mail_address = mail_address

    receiver.tip_notification = acquire_bool(request['tip_notification'])
    receiver.message_notification = acquire_bool(request['message_notification'])
    receiver.comment_notification = acquire_bool(request['comment_notification'])
    receiver.file_notification = acquire_bool(request['file_notification'])

    gpg_options_parse(receiver, request)

    return receiver_serialize_receiver(receiver, language)
Esempio n. 2
0
def update_receiver_settings(store,
                             receiver_id,
                             request,
                             language=GLSetting.memory_copy.default_language):
    receiver = store.find(Receiver, Receiver.id == unicode(receiver_id)).one()
    receiver.description[language] = request['description']

    if not receiver:
        raise errors.ReceiverIdNotFound

    new_password = request['password']
    old_password = request['old_password']

    if len(new_password) and len(old_password):
        receiver.user.password = change_password(receiver.user.password,
                                                 old_password, new_password,
                                                 receiver.user.salt)

    mail_address = request['mail_address']

    if mail_address != receiver.mail_address:
        log.info("Email change %s => %s" %
                 (receiver.mail_address, mail_address))
        receiver.mail_address = mail_address

    receiver.tip_notification = acquire_bool(request['tip_notification'])
    receiver.message_notification = acquire_bool(
        request['message_notification'])
    receiver.comment_notification = acquire_bool(
        request['comment_notification'])
    receiver.file_notification = acquire_bool(request['file_notification'])

    gpg_options_parse(receiver, request)

    return receiver_serialize_receiver(receiver, language)
Esempio n. 3
0
def update_receiver_settings(store, user_id, request, language=GLSetting.memory_copy.default_language):
    receiver = store.find(Receiver, Receiver.id == unicode(user_id)).one()
    receiver.description[language] = request.get('description')

    if not receiver:
        raise errors.ReceiverGusNotFound

    new_password = request.get('password')
    old_password = request.get('old_password')

    if len(new_password) and len(old_password):
        receiver.user.password = change_password(receiver.user.password,
                                                 old_password,
                                                 new_password,
                                                 receiver.user.salt)

    mail_address = acquire_mail_address(request)
    if not mail_address:
        raise errors.NoEmailSpecified

    # receiver.notification_fields is not update until GLClient supports them
    receiver.tip_notification = acquire_bool(request['tip_notification'])
    receiver.comment_notification = acquire_bool(request['comment_notification'])
    receiver.file_notification = acquire_bool(request['file_notification'])

    gpg_options_parse(receiver, request)

    return receiver_serialize_receiver(receiver, language)
Esempio n. 4
0
def update_receiver_settings(store, receiver_id, request, language):
    """
    TODO: remind that 'description' is imported, but is not permitted
        by UI to be modified right now.
    """
    receiver = store.find(Receiver, Receiver.id == receiver_id).one()
    receiver.description[language] = request['description']

    if not receiver:
        raise errors.ReceiverIdNotFound

    receiver.user.language = request.get('language', GLSetting.memory_copy.language)
    receiver.user.timezone = request.get('timezone', GLSetting.memory_copy.default_timezone)

    new_password = request['password']
    old_password = request['old_password']

    if len(new_password) and len(old_password):
        receiver.user.password = change_password(receiver.user.password,
                                                 old_password,
                                                 new_password,
                                                 receiver.user.salt)

        if receiver.user.password_change_needed:
            receiver.user.password_change_needed = False

        receiver.user.password_change_date = datetime_now()

    mail_address = request['mail_address']
    ping_mail_address = request['ping_mail_address']

    if mail_address != receiver.mail_address:
        log.err("Email cannot be change by receiver, only by admin " \
                "%s rejected. Kept %s" % (receiver.mail_address, mail_address))

    if ping_mail_address != receiver.ping_mail_address:
        log.info("Ping email going to be update, %s => %s" % (
            receiver.ping_mail_address, ping_mail_address))
        receiver.ping_mail_address = ping_mail_address

    receiver.tip_notification = acquire_bool(request['tip_notification'])
    receiver.message_notification = acquire_bool(request['message_notification'])
    receiver.comment_notification = acquire_bool(request['comment_notification'])
    receiver.file_notification = acquire_bool(request['file_notification'])
    receiver.ping_notification = acquire_bool(request['ping_notification'])

    gpg_options_parse(receiver, request)

    return receiver_serialize_receiver(receiver, language)
Esempio n. 5
0
 def test_acquire_bool(self):
     self.assertTrue(utility.acquire_bool('true'))
     self.assertTrue(utility.acquire_bool(u'true'))
     self.assertTrue(utility.acquire_bool(True))
     self.assertFalse(utility.acquire_bool('false'))
     self.assertFalse(utility.acquire_bool(None))
     self.assertFalse(utility.acquire_bool('antani'))
Esempio n. 6
0
 def test_017_acquire_bool(self):
     self.assertTrue(utility.acquire_bool('true'))
     self.assertTrue(utility.acquire_bool(u'true'))
     self.assertTrue(utility.acquire_bool(True))
     self.assertFalse(utility.acquire_bool('false'))
     self.assertFalse(utility.acquire_bool(None))
     self.assertFalse(utility.acquire_bool('antani'))
Esempio n. 7
0
def update_receiver_settings(store, receiver_id, request, language):
    """
    TODO: remind that 'description' is imported, but is not permitted
        by UI to be modified right now.
    """
    receiver = store.find(Receiver, Receiver.id == receiver_id).one()
    receiver.description[language] = request['description']

    if not receiver:
        raise errors.ReceiverIdNotFound

    receiver.user.language = request.get('language', GLSetting.memory_copy.language)
    receiver.user.timezone = request.get('timezone', GLSetting.memory_copy.default_timezone)

    new_password = request['password']
    old_password = request['old_password']

    if len(new_password) and len(old_password):
        receiver.user.password = change_password(receiver.user.password,
                                                 old_password,
                                                 new_password,
                                                 receiver.user.salt)

        if receiver.user.password_change_needed:
            receiver.user.password_change_needed = False

        receiver.user.password_change_date = datetime_now()

    mail_address = request['mail_address']
    ping_mail_address = request['ping_mail_address']

    if mail_address != receiver.mail_address:
        log.err("Email cannot be change by receiver, only by admin " \
                "%s rejected. Kept %s" % (receiver.mail_address, mail_address))

    if ping_mail_address != receiver.ping_mail_address:
        log.info("Ping email going to be update, %s => %s" % (
            receiver.ping_mail_address, ping_mail_address))
        receiver.ping_mail_address = ping_mail_address

    receiver.tip_notification = acquire_bool(request['tip_notification'])

    pgp_options_parse(receiver, request)

    return receiver_serialize_receiver(receiver, language)
Esempio n. 8
0
def gpg_options_parse(receiver, request):
    """
    This is called in a @transact, when receiver update prefs and
    when admin configure a new key (at the moment, Admin GUI do not
    permit to sets preferences, but still the same function is
    used.

    @param receiver: the Storm object
    @param request: the Dict receiver by the Internets
    @return: None

    This function is called in create_recever and update_receiver
    and is used to manage the GPG options forced by the administrator

    This is needed also because no one of these fields are
    *enforced* by unicode_keys or bool_keys in models.Receiver

    GPG management, here are check'd these actions:
    1) Proposed a new GPG key, is imported to check validity, and
       stored in Storm DB if not error raise
    2) Removal of the present key

    Further improvement: update the keys using keyserver
    """

    new_gpg_key = request.get('gpg_key_armor', None)
    remove_key = request.get('gpg_key_remove', False)

    encrypt_notification = acquire_bool(
        request.get('gpg_enable_notification', False))

    # set a default status
    receiver.gpg_key_status = Receiver._gpg_types[0]

    if remove_key:
        log.debug("User %s %s request to remove GPG key (%s)" %
                  (receiver.name, receiver.user.username,
                   receiver.gpg_key_fingerprint))

        # In all the cases below, the key is marked disabled as request
        receiver.gpg_key_status = Receiver._gpg_types[0]  # Disabled
        receiver.gpg_key_info = None
        receiver.gpg_key_armor = None
        receiver.gpg_key_fingerprint = None
        receiver.gpg_enable_notification = False

    if receiver.gpg_key_status == Receiver._gpg_types[1]:
        receiver.gpg_enable_notification = encrypt_notification
        log.debug(
            "Receiver %s sets GPG usage: notification %s, file %s" %
            (receiver.user.username, "YES" if encrypt_notification else "NO",
             "YES" if encrypt_file else "NO"))

    if new_gpg_key:

        fake_receiver_dict = {'username': receiver.user.username}
        gnob = GLBGPG(fake_receiver_dict)
        if not gnob.validate_key(new_gpg_key):
            raise errors.GPGKeyInvalid

        log.debug("GPG Key imported and enabled in file and notification: %s" %
                  gnob.keyinfo)

        receiver.gpg_key_info = gnob.keyinfo
        receiver.gpg_key_fingerprint = gnob.fingerprint
        receiver.gpg_key_status = Receiver._gpg_types[1]  # Enabled
        receiver.gpg_key_armor = new_gpg_key
        # default enabled https://github.com/globaleaks/GlobaLeaks/issues/620
        receiver.gpg_enable_notification = True

        gnob.destroy_environment()
Esempio n. 9
0
def gpg_options_parse(receiver, request):
    """
    This is called in a @transact, when receiver update prefs and
    when admin configure a new key (at the moment, Admin GUI do not
    permit to sets preferences, but still the same function is
    used.

    @param receiver: the Storm object
    @param request: the Dict receiver by the Internets
    @return: None

    This function is called in create_recever and update_receiver
    and is used to manage the GPG options forced by the administrator

    This is needed also because no one of these fields are
    *enforced* by unicode_keys or bool_keys in models.Receiver

    GPG management, here are check'd these actions:
    1) Proposed a new GPG key, is imported to check validity, and
       stored in Storm DB if not error raise
    2) Removal of the present key

    Further improvement: update the keys using keyserver
    """

    new_gpg_key = request.get('gpg_key_armor', None)
    remove_key = request.get('gpg_key_remove', False)

    encrypt_notification = acquire_bool(request.get('gpg_enable_notification', False))
    encrypt_file = acquire_bool(request.get('gpg_enable_files', False))

    # set a default status
    receiver.gpg_key_status = Receiver._gpg_types[0]

    if remove_key:
        log.debug("User %s %s request to remove GPG key (%s)" %
                  (receiver.name, receiver.user.username, receiver.gpg_key_fingerprint))

        # In all the cases below, the key is marked disabled as request
        receiver.gpg_key_status = Receiver._gpg_types[0] # Disabled
        receiver.gpg_key_info = None
        receiver.gpg_key_armor = None
        receiver.gpg_key_fingerprint = None
        receiver.gpg_enable_files = False
        receiver.gpg_enable_notification = False

    if receiver.gpg_key_status == Receiver._gpg_types[1]:
        receiver.gpg_enable_files = encrypt_file
        receiver.gpg_enable_notification = encrypt_notification
        log.debug("Receiver %s sets GPG usage: notification %s, file %s" %
                  (receiver.user.username,
                   "YES" if encrypt_notification else "NO",
                   "YES" if encrypt_file else "NO") )

    if new_gpg_key:

        fake_receiver_dict = { 'username' : receiver.user.username }
        gnob = GLBGPG(fake_receiver_dict)
        if not gnob.validate_key(new_gpg_key):
            raise errors.GPGKeyInvalid

        log.debug("GPG Key imported and enabled in file and notification: %s" % gnob.keyinfo)

        receiver.gpg_key_info = gnob.keyinfo
        receiver.gpg_key_fingerprint = gnob.fingerprint
        receiver.gpg_key_status = Receiver._gpg_types[1] # Enabled
        receiver.gpg_key_armor = new_gpg_key
        # default enabled https://github.com/globaleaks/GlobaLeaks/issues/620
        receiver.gpg_enable_files = True
        receiver.gpg_enable_notification = True

        gnob.destroy_environment()