Esempio n. 1
0
def file_delivery_planning(session):
    """
    This function roll over the InternalFile uploaded, extract a path, id and
    receivers associated, one entry for each combination. representing the
    ReceiverFile that need to be created.
    """
    receiverfiles_maps = {}
    whistleblowerfiles_maps = {}

    for ifile, itip in session.query(models.InternalFile, models.InternalTip)\
                              .filter(models.InternalFile.new == True,
                                      models.InternalTip.id == models.InternalFile.internaltip_id):
        ifile.new = False
        for rtip, user in session.query(models.ReceiverTip, models.User) \
                                 .filter(models.ReceiverTip.internaltip_id == ifile.internaltip_id,
                                         models.User.id == models.ReceiverTip.receiver_id):
            receiverfile = models.ReceiverFile()
            receiverfile.internalfile_id = ifile.id
            receiverfile.receivertip_id = rtip.id
            receiverfile.filename = ifile.filename
            receiverfile.status = u'processing'

            # https://github.com/globaleaks/GlobaLeaks/issues/444
            # avoid to mark the receiverfile as new if it is part of a submission
            # this way we avoid to send unuseful messages
            receiverfile.new = not ifile.submission

            session.add(receiverfile)

            session.flush()

            if ifile.id not in receiverfiles_maps:
                receiverfiles_maps[ifile.id] = {
                    'tid': user.tid,
                    'crypto_tip_pub_key': itip.crypto_tip_pub_key,
                    'id': ifile.id,
                    'filename': ifile.filename,
                    'plaintext_file_needed': False,
                    'rfiles': [],
                }

            receiverfiles_maps[ifile.id]['rfiles'].append({
                'id':
                receiverfile.id,
                'status':
                receiverfile.status,
                'filename':
                ifile.filename,
                'size':
                ifile.size,
                'receiver': {
                    'name': user.name,
                    'pgp_key_public': user.pgp_key_public,
                    'pgp_key_fingerprint': user.pgp_key_fingerprint,
                },
            })

    for wbfile, itip in session.query(models.WhistleblowerFile, models.InternalTip)\
                                .filter(models.WhistleblowerFile.new == True,
                                        models.ReceiverTip.id == models.WhistleblowerFile.receivertip_id,
                                        models.InternalTip.id == models.ReceiverTip.internaltip_id):

        wbfile.new = False
        whistleblowerfiles_maps[wbfile.id] = {
            'crypto_tip_pub_key': itip.crypto_tip_pub_key,
            'id': wbfile.id,
            'filename': wbfile.filename,
        }

    return receiverfiles_maps, whistleblowerfiles_maps
Esempio n. 2
0
def receiverfile_planning(store):
    """
    This function roll over the InternalFile uploaded, extract a path, id and
    receivers associated, one entry for each combination. representing the
    ReceiverFile that need to be created.
    """
    receiverfiles_maps = {}

    for ifile in store.find(models.InternalFile, new=True):
        if ifile.processing_attempts >= INTERNALFILES_HANDLE_RETRY_MAX:
            ifile.new = False
            log.err(
                "Failed to handle receiverfiles creation for ifile %s (%d retries)",
                ifile.id, INTERNALFILES_HANDLE_RETRY_MAX)
            continue

        elif ifile.processing_attempts >= 1:
            log.err(
                "Failed to handle receiverfiles creation for ifile %s (retry %d/%d)",
                ifile.id, ifile.processing_attempts,
                INTERNALFILES_HANDLE_RETRY_MAX)

        if ifile.processing_attempts:
            log.debug(
                "Starting handling receiverfiles creation for ifile %s retry %d/%d",
                ifile.id, ifile.processing_attempts,
                INTERNALFILES_HANDLE_RETRY_MAX)

        ifile.processing_attempts += 1

        for rtip, user in store.find(
            (models.ReceiverTip, models.User),
                models.ReceiverTip.internaltip_id == ifile.internaltip_id,
                models.User.id == models.ReceiverTip.receiver_id):
            receiverfile = models.ReceiverFile()
            receiverfile.internalfile_id = ifile.id
            receiverfile.receivertip_id = rtip.id
            receiverfile.file_path = ifile.file_path
            receiverfile.size = ifile.size
            receiverfile.status = u'processing'

            # https://github.com/globaleaks/GlobaLeaks/issues/444
            # avoid to mark the receiverfile as new if it is part of a submission
            # this way we avoid to send unuseful messages
            receiverfile.new = False if ifile.submission else True

            store.add(receiverfile)

            if ifile.id not in receiverfiles_maps:
                receiverfiles_maps[ifile.id] = {
                    'plaintext_file_needed': False,
                    'ifile_id': ifile.id,
                    'ifile_path': ifile.file_path,
                    'ifile_size': ifile.size,
                    'rfiles': []
                }

            receiverfiles_maps[ifile.id]['rfiles'].append({
                'id': receiverfile.id,
                'status': u'processing',
                'path': ifile.file_path,
                'size': ifile.size,
                'receiver': {
                    'name': user.name,
                    'pgp_key_public': user.pgp_key_public,
                    'pgp_key_fingerprint': user.pgp_key_fingerprint,
                },
            })

    return receiverfiles_maps
Esempio n. 3
0
def file_delivery(session):
    """
    This function roll over the InternalFile uploaded, extract a path, id and
    receivers associated, one entry for each combination. representing the
    ReceiverFile that need to be created.
    """
    receiverfiles_maps = {}
    whistleblowerfiles_maps = {}

    for ifile, itip in session.query(models.InternalFile, models.InternalTip) \
                              .filter(models.InternalFile.new.is_(True),
                                      models.InternalTip.id == models.InternalFile.internaltip_id):
        ifile.new = False
        src = ifile.filename
        filecode = src.split('.')[0]

        if itip.crypto_tip_pub_key:
            itip.filename = "%s.encrypted" % filecode
        else:
            itip.filename = "%s.plain" % filecode

        for rtip, user in session.query(models.ReceiverTip, models.User) \
                                 .filter(models.ReceiverTip.internaltip_id == ifile.internaltip_id,
                                         models.User.id == models.ReceiverTip.receiver_id):
            receiverfile = models.ReceiverFile()
            receiverfile.internalfile_id = ifile.id
            receiverfile.receivertip_id = rtip.id

            # https://github.com/globaleaks/GlobaLeaks/issues/444
            # avoid to mark the receiverfile as new if it is part of a submission
            # this way we avoid to send unuseful messages
            receiverfile.new = not ifile.submission

            session.add(receiverfile)

            if ifile.id not in receiverfiles_maps:
                receiverfiles_maps[ifile.id] = {
                    'src': src,
                    'key': itip.crypto_tip_pub_key,
                    'pgp_encrypted_for_everybody': True,
                    'rfiles': []
                }

            if user.pgp_key_public:
                receiverfile.filename = "%s.pgp" % filecode
                receiverfile.status = 'encrypted'
            else:
                receiverfiles_maps[
                    ifile.id]['pgp_encrypted_for_everybody'] = False
                receiverfile.filename = itip.filename
                receiverfile.status = 'reference'

            receiverfiles_maps[ifile.id]['rfiles'].append({
                'dst':
                os.path.abspath(
                    os.path.join(Settings.attachments_path,
                                 receiverfile.filename)),
                'pgp_key_public':
                user.pgp_key_public,
                'pgp_key_fingerprint':
                user.pgp_key_fingerprint
            })

    for wbfile, itip in session.query(models.WhistleblowerFile, models.InternalTip)\
                               .filter(models.WhistleblowerFile.new.is_(True),
                                       models.ReceiverTip.id == models.WhistleblowerFile.receivertip_id,
                                       models.InternalTip.id == models.ReceiverTip.internaltip_id):
        wbfile.new = False
        src = wbfile.filename
        filecode = src.split('.')[0]

        if itip.crypto_tip_pub_key:
            wbfile.filename = "%s.encrypted" % filecode
        else:
            wbfile.filename = "%s.plain" % filecode

        whistleblowerfiles_maps[wbfile.id] = {
            'key':
            itip.crypto_tip_pub_key,
            'src':
            src,
            'dst':
            os.path.abspath(
                os.path.join(Settings.attachments_path, wbfile.filename)),
        }

    return receiverfiles_maps, whistleblowerfiles_maps