Exemple #1
0
    def reourcegroup_filter(self, request, **kwargs):
        """
        """

        self.method_check(request, allowed=['post'])

        req_data = request.POST
        ids = req_data.get('ids', "")
        dummy_data = {}

        es_check = ReportResource.check_auth(request, **kwargs)

        if es_check:
            # reource group ids is passed to frontend in string form which each id is separated by comma
            param = ReportResource.generate_param(es_check, {'ids': ids})

            res = BackendRequest.get_batch_report(param)

            if res['result']:
                dummy_data["status"] = "1"
                dummy_data["list"] = res['list']
                dummy_data["total"] = len(res['list'])

                permits = []
                for i in res['list']:
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Report",
                        "action": "Update"
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Report",
                        "action": "Delete"
                    })
                permits.append({"target": "Report", "action": "Create"})
                permits.append({
                    "target": "DerelictResource",
                    "action": "Possess"
                })

                permit_param = {
                    'token': es_check['t'],
                    'operator': es_check['u']
                }
                permit_data = {'permits': permits}
                permit_res = BackendRequest.batch_permit_can(
                    permit_param, permit_data)
                if permit_res['result']:
                    dummy_data["permit_list"] = permit_res["short_permits"]
                else:
                    dummy_data["permit_list"] = []
            else:
                dummy_data['status'] = 0
                dummy_data['msg'] = res.get('error', "Unknow server error")
        else:
            dummy_data['status'] = 0
            dummy_data['msg'] = "auth failed/error"

        return ReportResource.generate_response(self, dummy_data, request)
Exemple #2
0
    def report_list(self, request, **kwargs):
        """
            Used to get the list of all current existing reports
        """

        self.method_check(request, allowed=['get'])
        dummy_data = {}

        es_check = ReportResource.check_auth(request, **kwargs)

        if es_check:
            permits = []

            owner = str(es_check["i"]) + "|" + str(es_check["u"]) + "|" + str(
                es_check["t"])
            param = ReportResource.generate_param(es_check, {'owner': owner})

            res = BackendRequest.get_report_list(param)

            if res['result']:
                data = res.get('list', [])
                dummy_data['status'] = "1"
                dummy_data['list'] = data

                for i in data:
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Report",
                        "action": "Update"
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Report",
                        "action": "Delete"
                    })
                permits.append({"target": "Report", "action": "Create"})
                permits.append({
                    "target": "DerelictResource",
                    "action": "Possess"
                })

                permit_param = {
                    'token': es_check['t'],
                    'operator': es_check['u']
                }
                permit_data = {'permits': permits}
                permit_res = BackendRequest.batch_permit_can(
                    permit_param, permit_data)
                if permit_res['result']:
                    dummy_data["permit_list"] = permit_res["short_permits"]
                else:
                    dummy_data["permit_list"] = []
            else:
                dummy_data = ReportResource.error_handler(res)
        else:
            dummy_data = ReportResource.error_handler(None, True)

        return ReportResource.generate_response(self,
                                                data=dummy_data,
                                                request=request)
Exemple #3
0
    def dict_lists(self, request, **kwargs):
        """
            Used to get a list of all existing dictionaries.
        """

        self.method_check(request, allowed=['get'])
        dummy_data = {}

        es_check = DictionaryResource.check_auth(request, **kwargs)

        if es_check:
            param = DictionaryResource.generate_param(es_check)
            res = BackendRequest.get_dict_list(param)
            permits = []

            if res['result']:
                dummy_data["status"] = "1"
                data = res.get("list", [])
                dummy_data["list"] = data
                DictionaryResource.timestamp_format(dummy_data['list'])

                for i in data:
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Dictionary",
                        "action": "Update"
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "Dictionary",
                        "action": "Delete"
                    })
                permits.append({
                    "target": "Dictionary",
                    "action": "Create"
                })
                permits.append({
                    "target": "DerelictResource",
                    "action": "Possess"
                })
                
                permit_param = {
                    'token': es_check['t'],
                    'operator': es_check['u']
                }
                permit_data = {
                    'permits': permits
                }
                permit_res = BackendRequest.batch_permit_can(permit_param, permit_data)
                if permit_res['result']:
                    dummy_data["permit_list"] = permit_res["short_permits"]
                else:
                    dummy_data["permit_list"] = []
            else:
                dummy_data = DictionaryResource.error_handler(res, False)
        else:
            dummy_data = DictionaryResource.error_handler(None, True)

        return DictionaryResource.generate_response(self, dummy_data, request)
Exemple #4
0
    def reourcegroup_filter(self, request, **kwargs):
        """
        """

        self.method_check(request, allowed=['post'])

        req_data = request.POST
        ids = req_data.get('ids', "")
        dummy_data = {}

        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)

        if es_check:
            param = {
                'token': es_check['t'],
                'operator': es_check['u'],
                'ids': ids
            }

            res = BackendRequest.get_batch_sourcegroup(param)

            if res['result']:
                data = self.rebuild_sourcegroup_list(res['source_groups'])
                dummy_data["status"] = "1"
                dummy_data["total"] = len(data)
                dummy_data["list"] = data

                permits = []
                for i in res['source_groups']:
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "SourceGroup",
                        "action": "Update"
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "SourceGroup",
                        "action": "Delete"
                    })
                permits.append({
                    "target": "SourceGroup",
                    "action": "Create"
                })
                permits.append({
                    "target": "DerelictResource",
                    "action": "Possess"
                })

                param = {
                    'token': es_check['t'],
                    'operator': es_check['u']
                }
                permit_param = {
                    'permits': permits
                }
                permit_res = BackendRequest.batch_permit_can(param, permit_param)
                if permit_res['result']:
                    dummy_data["permit_list"] = permit_res["short_permits"]
                else:
                    dummy_data["permit_list"] = []
            else:
                dummy_data['status'] = 0
                dummy_data['msg'] = res.get('error', "Unknow server error")
        else:
            dummy_data['status'] = 0
            dummy_data['msg'] = "auth failed/error"

        bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
        response_data = bundle
        resp = self.create_response(request, response_data)

        return resp
Exemple #5
0
 def sourcegroups_list(self, request, **kwargs):
     '''
     {"sourcegroup_id": "11", "sGroup": "Moroni", "description": "afdds", "contents": "fff",
          "created": "wangqiushi", "activity": [12, 23, 12, 14, 53, 24, 45, 2, 4, 5, 3, 55], "restricted": "aa",
          "edit": "false"}
     :param request:
     :param kwargs:
     :return:
     '''
     self.method_check(request, allowed=['get'])
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         source_group = []
         permits = []
         res = BackendRequest.get_source_group({
             "token": es_check["t"],
             'operator': es_check['u']
         })
         if res['result']:
             for i in res['items']:
                 group_list = filter(lambda x: not x == '' and x is not None, i.get('user_groups', []))
                 source_group.append({
                     'sourcegroup_id': i['id'].encode('utf-8'),
                     'sGroup': i['name'].encode('utf-8'),
                     "description": i.get('description', "").encode('utf-8'),
                     "activity": [],
                     "created": i.get('owner_name', "").encode('utf-8'),
                     "edit": i.get('edit', "false").encode('utf-8'),
                     "contents": i.get('contents', "").encode('utf-8'),
                     "restricted": ','.join(group_list)
                 })
                 permits.append({
                     "resource_id": int(i['id']),
                     "target": "SourceGroup",
                     "action": "Update"
                 })
                 permits.append({
                     "resource_id": int(i['id']),
                     "target": "SourceGroup",
                     "action": "Delete"
                 })
             permits.append({
                 "target": "SourceGroup",
                 "action": "Create"
             })
             permits.append({
                 "target": "DerelictResource",
                 "action": "Possess"
             })
             dummy_data["status"] = "1"
             dummy_data["totle"] = len(source_group)
             dummy_data["list"] = source_group
             param = {
                 'token': es_check['t'],
                 'operator': es_check['u']
             }
             permit_param = {
                 'permits': permits
             }
             permit_res = BackendRequest.batch_permit_can(param, permit_param)
             if permit_res['result']:
                 dummy_data["permit_list"] = permit_res["short_permits"]
             else:
                 dummy_data["permit_list"] = []
         else:
             dummy_data = err_data.build_error(res)
     else:
         data = err_data.build_error({}, "auth error!")
         data["location"] = "/auth/login/"
         dummy_data = data
     bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
     response_data = bundle
     resp = self.create_response(request, response_data)
     return resp
Exemple #6
0
    def saved_list(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            res = BackendRequest.get_all_saved_search({
                "token": es_check["t"],
                'operator': es_check['u']
            })
            saved_searches = []
            permits = []
            if res['result']:
                for i in res['items']:
                    anonymous = i.get('anonymous', False)
                    if anonymous:
                        continue
                    saved_searches.append({
                        'savedsearch_id':
                        i['id'].encode('utf-8'),
                        'savedsearch_name':
                        i['name'].encode('utf-8'),
                        "related_alert_num":
                        i.get('alert_count', 0),
                        'query':
                        i['query'].encode('utf-8'),
                        "sourcegroup":
                        i['source_groups'].encode('utf-8'),
                        "owner":
                        i.get('owner_name', "").encode('utf-8'),
                        "rg_ids":
                        i.get("resource_group_ids", []),
                        "timerange":
                        i.get('time_range', "").encode('utf-8'),
                        "filters":
                        i.get('filters', "").encode('utf-8') if i.get(
                            'filters', "") else "",
                        "fav":
                        'yes' if i.get('like', True) else 'no'
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "SavedSearch",
                        "action": "Update"
                    })
                    permits.append({
                        "resource_id": int(i['id']),
                        "target": "SavedSearch",
                        "action": "Delete"
                    })
                permits.append({"target": "SavedSearch", "action": "Create"})
                permits.append({
                    "target": "DerelictResource",
                    "action": "Possess"
                })

                dummy_data["status"] = "1"
                dummy_data["totle"] = len(saved_searches)
                dummy_data["list"] = sorted(saved_searches,
                                            key=lambda x: x['fav'],
                                            reverse=True)
                param = {'token': es_check['t'], 'operator': es_check['u']}
                permit_param = {'permits': permits}
                permit_res = BackendRequest.batch_permit_can(
                    param, permit_param)
                if permit_res['result']:
                    dummy_data["permit_list"] = permit_res["short_permits"]
                else:
                    dummy_data["permit_list"] = []
            else:
                dummy_data = err_data.build_error(res)
        else:
            data = err_data.build_error({}, "auth error!")
            data["location"] = "/auth/login/"
            dummy_data = data
        bundle = self.build_bundle(obj=dummy_data,
                                   data=dummy_data,
                                   request=request)
        response_data = bundle
        resp = self.create_response(request, response_data)
        return resp