Пример #1
0
 def tip_total_delete(self):
     """
     function called when a receiver choose to remove a submission
     and all the derived tips. is called by scheduler when
     timeoftheday is >= expired_date, or is called by ReceiverTip.total_delete
     """
     log.debug("[D] %s %s " % (__file__, __name__), "InternalTip", "tip_total_delete")
Пример #2
0
    def update(self, context_gus, context_dict):
        """
        @param context_gus: the universal unique identifier
        @param context_dict: the information fields that need to be update, here is
            supported to be already validated, sanitized and logically verified
            by handlers
        @return: None or Exception on error
        """
        log.debug("[D] %s %s " % (__file__, __name__), "Context update of", context_gus)
        store = self.getStore('context update')

        try:
            requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one()
        except NotOneError:
            store.close()
            raise ContextGusNotFound
        if requested_c is None:
            store.close()
            raise ContextGusNotFound

        try:
            requested_c._import_dict(context_dict)
        except KeyError:
            store.rollback()
            store.close()
            raise InvalidInputFormat("Import failed near the Storm")

        requested_c.update_date = gltime.utcDateNow()

        store.commit()
        log.msg("Updated context %s in %s, created in %s" %
                (requested_c.name, requested_c.update_date, requested_c.creation_date) )

        store.close()
Пример #3
0
 def acceptedFileType(self, type):
     log.debug("[D] %s %s " % (__file__, __name__), "FilesHandler", "acceptedFileType", "type", type)
     regexp = None
     if regexp and regexp.match(type):
         return True
     else:
         return False
Пример #4
0
    def receiver_align(self, receiver_gus, context_selected):
        """
        Called by Receiver handler, (PUT|POST), just take the receiver and update the
        associated contexts
        """
        store = self.getStore('receiver_align')

        try:
            requested_r = store.find(Receiver, Receiver.receiver_gus == unicode(receiver_gus)).one()
        except NotOneError:
            store.close()
            raise ReceiverGusNotFound
        if requested_r is None:
            store.close()
            raise ReceiverGusNotFound

        requested_r.contexts = []
        for c in context_selected:
            requested_r.contexts.append(str(c))

        log.debug("    ++++   receiver_align in receiver %s with contexts %s" %
                  ( receiver_gus, str(context_selected) ) )

        store.commit()
        store.close()
Пример #5
0
 def delete(self, receiver_token_auth, plugin_gus, *uriargs):
     """
     Request: receiverProfileDesc
     Response: None
     Errors: InvalidInputFormat, ProfileGusNotFound
     """
     log.debug("[D] %s %s " % (__file__, __name__), "Class AdminPlugin -- NOT YET IMPLEMENTED -- ", "DELETE")
Пример #6
0
    def add_file(self, submission_gus, file_name, content_type, file_size):

        store = self.getStore('add_file')

        try:
            submission_r = store.find(Submission, Submission.submission_gus==submission_gus).one()
        except NotOneError:
            store.close()
            raise SubmissionGusNotFound
        if not submission_r:
            store.close()
            raise SubmissionGusNotFound

        new_file = File()
        new_file.file_gus = ret_file_gus = unicode(idops.random_file_gus())
        new_file.name = file_name
        new_file.content_type = content_type
        new_file.size = file_size

        submission_r.files.update({ new_file.file_gus : file_name })

        log.debug("Added file %s in submission %s with name %s" % (ret_file_gus, submission_gus, file_name))

        store.add(new_file)
        store.commit()
        store.close()

        return ret_file_gus
Пример #7
0
    def receiver_align(self, receiver_gus, context_selected):
        """
        Called by Receiver handler, (PUT|POST), just take the receiver and update the
        associated contexts
        """
        from globaleaks.models.context import Context
        from globaleaks.rest.errors import ContextGusNotFound

        store = self.getStore()

        try:
            requested_r = store.find(Receiver, Receiver.receiver_gus == unicode(receiver_gus)).one()
        except NotOneError:
            raise ReceiverGusNotFound
        if requested_r is None:
            raise ReceiverGusNotFound

        requested_r.contexts = []
        for c in context_selected:

            try:
                selected = store.find(Context, Context.context_gus == unicode(c)).one()
            except NotOneError:
                raise ContextGusNotFound
            if selected is None:
                raise ContextGusNotFound

            requested_r.contexts.append(str(c))
            requested_r.update_date = gltime.utcTimeNow()

        log.debug("    ++++   receiver_align in receiver %s with contexts %s" %
                  ( receiver_gus, str(context_selected) ) )
Пример #8
0
    def new(self, context_dict):
        """
        @param context_dict: a dictionary containing the expected field of a context,
                is called and define as contextDescriptionDict
        @return: context_gus, the universally unique identifier of the context
        """
        log.debug("[D] %s %s " % (__file__, __name__), "Context new", context_dict)

        store = self.getStore('context new')

        cntx = Context()

        cntx.context_gus = idops.random_context_gus()
        cntx.node_id = 1

        cntx.creation_date = gltime.utcDateNow()
        cntx.update_date = gltime.utcDateNow()
        cntx.last_activity = gltime.utcDateNow()
        cntx.receivers = []

        try:
            cntx._import_dict(context_dict)
        except KeyError:
            store.rollback()
            store.close()
            raise InvalidInputFormat("Import failed near the Storm")

        store.add(cntx)
        log.msg("Created context %s at the %s" % (cntx.name, cntx.creation_date) )
        store.commit()
        store.close()

        # return context_dict
        return cntx.context_gus
Пример #9
0
    def full_context_align(self, receiver_gus, un_context_selected):
        """
        Called by Receiver handlers (PUT|POST), roll in all the context and delete|add|skip
        with the presence of receiver_gus
        """

        context_selected = []
        for c in un_context_selected:
            context_selected.append(str(c))

        presents_context = self.store.find(Context)

        debug_counter = 0
        for c in presents_context:

            # if is not present in context.receivers and is requested: add
            if not receiver_gus in c.receivers:
                if c.context_gus in context_selected:
                    debug_counter += 1
                    c.receivers.append(str(receiver_gus))

            # if is present in receiver.contexts and is not selected: remove
            if receiver_gus in c.receivers:
                if not c.context_gus in context_selected:
                    debug_counter += 1
                    c.receivers.remove(str(receiver_gus))

        log.debug(
            "    %%%%   full_context_align in all contexts after %s has been set with %s: %d mods"
            % (receiver_gus, str(context_selected), debug_counter)
        )
Пример #10
0
    def add_comment(self, itip_id, comment, source, author_gus=None):
        """
        @param itip_id: InternalTip.id of reference, need to be addressed
        @param comment: the unicode text expected to be recorded
        @param source: the source kind of the comment (receiver, wb, system)
        @param name: the Comment author name to be show and recorded, can be absent if source is enough
        @return: None
        """
        log.debug("[D] %s %s " % (__file__, __name__), "InternalTip class", "add_comment",
            "itip_id", itip_id, "source", source, "author_gus", author_gus)

        if not source in [ u'receiver', u'whistleblower', u'system' ]:
            raise Exception("Invalid developer brain status", source)

        store = self.getStore('add_comment')

        # this approach is a little different from the other classes in ExternalTip
        # they use a new Object() in the caller method, and then Object.initialize
        # to fill with data.
        # XXX this would be refactored when TaskQueue would be engineered
        newcomment = Comment()
        newcomment.creation_time = gltime.utcTimeNow()
        newcomment.source = source
        newcomment.content = comment
        newcomment.author_gus = author_gus
        newcomment.notification_mark = u'not notified'
        newcomment.internaltip_id = itip_id
        store.add(newcomment)

        retVal = newcomment._description_dict()

        store.commit()
        store.close()

        return retVal
Пример #11
0
    def context_align(self, context_gus, receiver_selected):
        """
        Called by Context handler, (PUT|POST), just take the context and update the
        associated receivers, checks the receiver existence, and return an
        exception if do not exist.
        """
        from globaleaks.models.receiver import Receiver
        from globaleaks.rest.errors import ReceiverGusNotFound

        try:
            requested_c = self.store.find(Context, Context.context_gus == unicode(context_gus)).one()
        except NotOneError:
            raise ContextGusNotFound
        if requested_c is None:
            raise ContextGusNotFound

        requested_c.receivers = []
        for r in receiver_selected:

            try:
                selected = self.store.find(Receiver, Receiver.receiver_gus == unicode(r)).one()
            except NotOneError:
                raise ReceiverGusNotFound
            if selected is None:
                raise ReceiverGusNotFound

            requested_c.receivers.append(str(r))
            requested_c.update_date = gltime.utcTimeNow()

        log.debug("    ++++   context_align in receiver %s with receivers %s" % (context_gus, str(receiver_selected)))
Пример #12
0
    def create_receiver_tips(self, id, tier):
        """
        act on self. create the ReceiverTip based on self.receivers_map
        """
        log.debug("[D] %s %s " % (__file__, __name__), "ReceiverTip create_receiver_tips", id, "on tier", tier)

        store = self.getStore('create_receiver_tips')

        selected_it = store.find(InternalTip, InternalTip.id == id).one()

        for i, mapped in enumerate(selected_it.receivers_map):

            if not mapped['receiver_level'] == tier:
                continue

            try:
                receiver_subject = store.find(Receiver, Receiver.receiver_gus == selected_it.receivers_map[i]['receiver_gus']).one()
            except NotOneError:
                print "Fatal incredible absolute error!! handled."
                continue

            receiver_tip =  ReceiverTip()

            # is initialized a Tip that need to be notified
            receiver_tip.initialize(mapped, selected_it, receiver_subject)

            # TODO receiver_subject.update_timings()

            selected_it.receivers_map[i]['tip_gus'] = receiver_tip.tip_gus
            store.add(receiver_tip)

        # commit InternalTip.receivers_map[only requested tier]['tip_gus'] & ReceiverTip(s)
        store.commit()
        store.close()
Пример #13
0
    def do_notify(self, settings, notification_struct):

        af = settings['admin_fields']
        rf = settings['receiver_fields']

        title = self._create_title(notification_struct)
        body = self._create_email(notification_struct,  af['username'], rf['mail_addr'], title)

        try:
            smtpsock = self._get_SMTP(af['server'], af['port'], af['ssl'],
                af['username'], af['password'])

            if not smtpsock:
                log.err("[E] error in sending the email to %s (username: %s)" % (rf['mail_addr'], af['username']))
                return False

            smtpsock.sendmail(af['username'], [ rf['mail_addr'] ], body)
            smtpsock.quit()

            log.debug("Success in email %s " % rf['mail_addr'])
            return True

        except smtplib.SMTPRecipientsRefused, smtplib.SMTPSenderRefused:

            # remind, other error can be handled http://docs.python.org/2/library/smtplib.html
            log.err("[E] error in sending the email to %s (username: %s)" % (rf['mail_addr'], af['username']))
            return False
Пример #14
0
    def update_profile(self, profile_gus, settings=None, profname=None, desc=None):

        log.debug("[D] %s %s " % (__file__, __name__), "PluginConf update_fields", profile_gus)

        store = self.getStore('update_fields')

        if store.find(PluginProfiles, PluginProfiles.profile_name == profname).count() >= 1:
            store.close()
            raise ProfileNameConflict

        try:
            looked_p = store.find(PluginProfiles, PluginProfiles.profile_gus == profile_gus).one()
        except NotOneError:
            store.close()
            raise ProfileGusNotFound
        if not looked_p:
            store.close()
            raise ProfileGusNotFound

        if settings:
            looked_p.admin_fields = settings

        if profname:
            looked_p.profile_name = profname

        if desc:
            looked_p.external_description = desc

        store.commit()
        store.close()
Пример #15
0
    def updateconf(self, conf_id, settings, active):
        """
        @param conf_id:
            receiver_secret, receiver_gus and conf_id are required to authenticate and address
            correctly the configuration. without those three elements, it not permitted
            change a Receiver plugin configuration.
        @param settings: the receiver_fields
        @param active:
        @return:
        """
        log.debug("[D] %s %s " % (__file__, __name__), "Class ReceiverConfs", "updateconf", conf_id)

        store = self.getStore('updateconf')

        try:
            looked_c = store.find(ReceiverConfs, ReceiverConfs.id == conf_id).one()
        except NotOneError:
            store.close()
            raise ReceiverConfInvalid
        if not looked_c:
            store.close()
            raise ReceiverConfInvalid

        looked_c.receiver_fields = settings
        looked_c.active = active

        store.commit()
        store.close()
Пример #16
0
    def operation(self):
        """
        Goal of this function is to check if a new receiver is present, and 
        send to him/she a welcome email. This is not just a nice thing, but
        need to contain a tip-like ID, so the receiver would be able to 
        access to their preferences before receive the first Tip, and then
        configured notification/delivery as prefer, before receive the first
        whistleblowers data.

        the status of a receiver would be:

        'not welcomed'
            when a receiver has been just added, and need to be welcomed
        'welcomed'
            the welcome message has been sent.

        would be expanded to support cases when receiver NEED to configure their profile.
        """
        log.debug("[D]", self.__class__, 'operation', date.today().ctime())

        receiver_iface = Receiver()

        # noobceivers = yield receiver_iface.lookup(status=u'not welcomed')
        # noobceivers = receiver_iface.lookup(status=u'not welcomed')
        noobceivers = []

        for noob in noobceivers:
            print "need to be welcomed", noob
Пример #17
0
    def full_receiver_align(self, context_gus, un_receiver_selected):
        """
        Called by Context handlers (PUT|POST), roll in all the receiver and delete|add|skip
        with the presence of context_gus
        """
        store = self.getStore('full_receiver_align')

        receiver_selected = []
        for r in un_receiver_selected:
            receiver_selected.append(str(r))

        presents_receiver = store.find(Receiver)

        debug_counter = 0
        for r in presents_receiver:

            # if is not present in receiver.contexts and is requested: add
            if r.contexts and not context_gus in r.contexts:
                if r.receiver_gus in receiver_selected:
                    debug_counter += 1
                    r.contexts.append(str(context_gus))

            # if is present in context.receiver and is not selected: remove
            if r.contexts and context_gus in r.contexts:
                if not r.receiver_gus in receiver_selected:
                    debug_counter += 1
                    r.contexts.remove(str(context_gus))

        log.debug("    ****   full_receiver_align in all receivers after %s has been set with %s: %d mods" %
                  ( context_gus, receiver_selected, debug_counter ) )

        store.commit()
        store.close()
Пример #18
0
    def full_receiver_align(self, context_gus, un_receiver_selected):
        """
        Called by Context handlers (PUT|POST), roll in all the receiver and delete|add|skip
        with the presence of context_gus
        """

        receiver_selected = []
        for r in un_receiver_selected:
            receiver_selected.append(str(r))

        presents_receiver = self.store.find(Receiver)

        debug_counter = 0
        for r in presents_receiver:

            # if is not present in receiver.contexts and is requested: add
            if not context_gus in r.contexts:
                if r.receiver_gus in receiver_selected:
                    debug_counter += 1
                    r.contexts.append(str(context_gus))
                    r.update_date = gltime.utcTimeNow()

            # if is present in context.receiver and is not selected: remove
            if context_gus in r.contexts:
                if not r.receiver_gus in receiver_selected:
                    debug_counter += 1
                    r.contexts.remove(str(context_gus))
                    r.update_date = gltime.utcTimeNow()

        log.debug("    ****   full_receiver_align in all receivers after %s has been set with %s: %d mods" %
                  ( context_gus, str(receiver_selected), debug_counter ) )
Пример #19
0
    def context_align(self, context_gus, receiver_selected):
        """
        Called by Context handler, (PUT|POST), just take the context and update the
        associated receivers
        """
        store = self.getStore('context_align')

        try:
            requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one()
        except NotOneError:
            store.close()
            raise ContextGusNotFound
        if requested_c is None:
            store.close()
            raise ContextGusNotFound

        requested_c.receivers = []
        for r in receiver_selected:
            requested_c.receivers.append(str(r))

        log.debug("    ++++   context_align in receiver %s with receivers %s" %
                  ( context_gus, str(receiver_selected) ) )

        store.commit()
        store.close()
Пример #20
0
 def operation(self):
     """
     Every node has two timeframe which the statistics are collected 
     inside. All the operation happening during a timeframe
     are collected in the last row of PublicStats and AdminStats,
     this operation create a new row.
     """
     log.debug("[D]", self.__class__, 'operation', datetime.today().ctime())
Пример #21
0
 def saveFile(self, data, filelocation):
     """
     XXX This is currently blocking. MUST be refactored to not be blocking
     otherwise we loose...
     """
     log.debug("[D] %s %s " % (__file__, __name__), "FilesHandler", "savefile", "data", type(data), "filelocation", filelocation)
     with open(filelocation, 'a+') as f:
         f.write(data)
Пример #22
0
    def operation(self):
        """
        This operation would be defined after email notification support.
        The goal of this operation, is collect email for the same receiver,
        and then avoid a massive mailing, in case of strong activities.

        the schedule is based in a receiver/context configuration.
        """
        log.debug("[D]", self.__class__, 'operation', date.today().ctime())
Пример #23
0
    def update_fields(self, submission_gus, fields):
        log.debug("[D] %s %s " % (__file__, __name__), "Submission", "update_fields", "submission_gus", submission_gus, "fields", fields )

        store = self.getStore('update_fields')
        try:
            s = store.find(Submission, Submission.submission_gus==submission_gus).one()
        except NotOneError, e:
            store.close()
            raise SubmissionGusNotFound
Пример #24
0
    def post(self, submission_gus, *args):
        """
        Parameter: submission_gus
        Request: Unknown
        Response: Unknown
        Errors: SubmissionGusNotFound, SubmissionConcluded

        POST in fileHandlers need to be refactored-engineered
        """

        submission_iface = Submission()
        try:

            submission_desc = yield submission_iface.get_single(submission_gus)

            if submission_desc['finalize']:
                raise SubmissionConcluded

            results = []

            # XXX will this ever be bigger than 1?
            file_array, files = self.request.files.popitem()
            for file in files:
                start_time = time.time()

                file_request = { 'filename' : file.get('filename'),
                                 'content_type' : file.get('content_type'),
                                 'file_size' : len(file['body']),
                                 'submission_gus' : submission_gus,
                                 'context_gus' : submission_desc['context_gus'],
                                 'description' : ''
                        }

                print "file_request", file_request, "\n"

                file_iface = File()
                file_desc = yield file_iface.new(file_request)

                log.debug("Created file from %s with file_gus %s" % (file_request['filename'], file_desc['file_gus'] ))

                result = self.process_file(file, submission_gus, file_desc['file_gus'])
                result['elapsed_time'] = time.time() - start_time
                results.append(result)


            response = json.dumps(results, separators=(',',':'))

            if 'application/json' in self.request.headers.get('Accept'):
                self.set_header('Content-Type', 'application/json')

            self.set_status(200)
            self.write(response)

        except InvalidInputFormat, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_message})
Пример #25
0
    def get(self, *uriargs):
        """
        Parameters: None
        Response: publicStatsList
        Errors: StatsNotCollectedError

        This interface return the collected statistics for the public audience.
        """
        log.debug("[D] %s %s " % (__file__, __name__), "TO BE IMPLEMENTED", "get", uriargs)
        pass
Пример #26
0
    def admin_get_single(self, tip_gus):
        log.debug("[D] %s %s " % (__file__, __name__), "Class ReceiverTip", "admin_get_single", tip_gus)

        store = self.getStore('admin_get_single')

        try:
            requested_t = store.find(ReceiverTip, ReceiverTip.tip_gus == tip_gus).one()
        except NotOneError, e:
            store.close()
            raise TipGusNotFound
Пример #27
0
    def admin_get_single(self, receipt):
        log.debug("[D] %s %s " % (__file__, __name__), "Class WhistleBlowerTip", "admin_get_single", receipt)

        store = self.getStore('admin_get_single')

        try:
            requested_t = store.find(WhistleblowerTip, WhistleblowerTip.receipt == receipt).one()
        except NotOneError, e:
            store.close()
            raise TipReceiptNotFound
Пример #28
0
    def __init__(self):
        log.debug("[D] %s %s " % (__file__, __name__), "Starting db_threadpool")
        self.db_threadpool = ThreadPool(0, config.advanced.db_thread_pool_size)
        self.db_threadpool.start()

        log.debug("[D] %s %s " % (__file__, __name__), "Starting scheduler_threadpool")
        self.scheduler_threadpool = ThreadPool(0, config.advanced.scheduler_thread_pool_size)
        self.scheduler_threadpool.start()

        self.transactor = Transactor(self.db_threadpool)
        self.transactor.retries = 0
Пример #29
0
    def get(self, *arg, **kw):
        """
        Parameters: Unknown
        Request: None
        Response: Unknown
        Errors: Unknown

        GET in fileHandlers need to be refactored-engineered
        """
        log.debug("[D] %s %s " % (__file__, __name__), "FilesHandler", "get")
        pass
Пример #30
0
    def validate(self, file):
        """
        Takes as input a file object and raises an exception if the file does
        not conform to the criteria.
        """
        log.debug("[D] %s %s " % (__file__, __name__), "FilesHandler", "validate", "file", file)
        if self.maxFileSize and file['size'] < self.maxFileSize:
            raise HTTPError(406, "File too big")

        if not self.acceptedFileType(file['type']):
            raise HTTPError(406, "File of unsupported type")