Ejemplo n.º 1
0
    def get_debug_user(self):
        user = users.get_current_user()

        if user:
            query = User.gql("WHERE auth_ids = :auth_ids", auth_ids="debug:" + user.user_id())
            all_users = query.fetch(1)

            if all_users:
                user = all_users[0]

                if not hasattr(user, 'admin'):
                    user.admin = False
                    user.put()

                return user
            else:
                _attrs = {}

                _attrs['name'] = users.get_current_user().nickname()
                _attrs['share_report_key'] = generate_string(8)
                _attrs['share_report_and_list_key'] = generate_string(7)
                _attrs['provider'] = "debug"
                _attrs['admin'] = False

                ok, user = User.create_user("debug:" + user.user_id(), **_attrs)

                return user

        return None
Ejemplo n.º 2
0
    def get(self):

        matches = re.match(r"/shared/(?P<key>[0-9a-z_]+)/.*",
                           self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(
                    shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(
                        generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {
                    'status': '404 - Not found',
                    'title': 'What a headache!',
                    'message':
                    "Sorry, we couldn't find what you're looking for."
                }

                self.response.status = 404
                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {
                'status': '404 - Not found',
                'title': 'What a headache!',
                'message': "Sorry, we couldn't find what you're looking for."
            }

            self.response.status = 404
            path = os.path.join(
                os.path.join(os.path.dirname(__file__), 'html'),
                '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))
Ejemplo n.º 3
0
    def get(self):

        matches = re.match(
                r"/shared/(?P<key>[0-9a-z_]+)/.*",
                self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {'status': '404 - Not found',
                                   'title': 'What a headache!',
                                   'message': "Sorry, we couldn't find what you're looking for."}

                self.response.status = 404
                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {'status': '404 - Not found',
                               'title': 'What a headache!',
                               'message': "Sorry, we couldn't find what you're looking for."}

            self.response.status = 404
            path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))