Exemple #1
0
    def post(self):
        """
        Request: None
        Response: SubmissionDesc (Token)
        Errors: ContextIdNotFound, InvalidInputFormat, SubmissionValidationFailure

        This API create a Token, a temporary memory only object able to keep
        track of the submission. If the system is under stress, complete the
        submission will require some actions to be performed before the
        submission can be concluded (e.g. hashcash and captchas).
        """
        if not GLSettings.memory_copy.accept_submissions:
            raise errors.SubmissionDisabled

        request = self.validate_message(self.request.body,
                                        requests.SubmissionDesc)

        token = Token('submission', request['context_id'])
        token.set_difficulty(Alarm().get_token_difficulty())
        token_answer = token.serialize_token()

        token_answer.update({'id': token_answer['token_id']})
        token_answer.update({'context_id': request['context_id']})
        token_answer.update({'receivers': []})
        token_answer.update({'answers': {}})
        token_answer.update({'human_captcha_answer': 0})
        token_answer.update({'graph_captcha_answer': ""})
        token_answer.update({'proof_of_work': 0})

        self.set_status(201)  # Created
        self.finish(token_answer)
Exemple #2
0
    def generate_token_challenge(self, challenges_dict=None):
        # initialization
        self.human_captcha = False
        self.graph_captcha = False
        self.proof_of_work = False

        if challenges_dict is None:
            challenges_dict = Alarm().get_token_difficulty()

        if challenges_dict['human_captcha']:
            random_a = randint(0, 99)
            random_b = randint(0, 99)

            self.human_captcha = {
                'question': u"%d + %d" % (random_a, random_b),
                'answer': u"%d" % (random_a + random_b)
            }

        if challenges_dict['proof_of_work']:
            # still not implemented
            pass

        if challenges_dict['graph_captcha']:
            # still not implemented
            pass
Exemple #3
0
    def operation(self):
        free_disk_bytes, total_disk_bytes = get_workingdir_space()
        free_ramdisk_bytes, total_ramdisk_bytes = get_ramdisk_space()

        alarm = Alarm()
        alarm.check_disk_anomalies(free_disk_bytes, total_disk_bytes,
                                   free_ramdisk_bytes, total_ramdisk_bytes)
Exemple #4
0
def getAlarm(state):
    from globaleaks.anomaly import Alarm
    return Alarm(state)
    def operation(self):
        free_bytes = ResourceChecker.get_free_space()

        alarm = Alarm()
        alarm.report_disk_usage(free_bytes)