Esempio n. 1
0
def configs_steps(request, name, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)

    visit_permit = BackendRequest.can_visit({
        "token": is_login['t'],
        "operator": is_login['u'],
        "requestUrl": request.path[1:]
    })
    if visit_permit['result'] and visit_permit['can_visit']:
        return render(request, 'config/steps/'+name+'.html', {"active": "source", "subnav": "configs"})
    else:
        raise PermissionDenied
Esempio n. 2
0
def check_with_sourcegroup(login):
    with_sg = 'no'
    sg_param = {
        'account': login['i'],
        'token': login['t'],
        'operator': login['u']
    }
    sg_res = BackendRequest.get_source_group(sg_param)
    if sg_res['result']:
        item = sg_res.get('items', [])
        if item:
            with_sg = 'yes'
    return with_sg
Esempio n. 3
0
def schedule_detail(request, s_id, s_ts, **kwargs):
    schedule_id = s_id.encode('utf-8')
    schedule_timestamp = s_ts.encode('utf-8')
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            res = BackendRequest.get_saved_schedule({
                'token': is_login['t'],
                'id': schedule_id,
                'operator': is_login['u']
            })
            if res['result']:
                schedule_info = res.get('saved_schedule', {})
                name = schedule_info.get('name', '')
                page_data = {
                    "active": "schedule",
                    'id': schedule_id,
                    "name": name,
                    "user": is_login["u"],
                    'timestamp': schedule_timestamp,
                    "email": is_login["e"],
                    "role": is_login["r"],
                    "userid": is_login["i"]
                }
                return render(request, 'schedule/schedule_detail.html',
                              {"page_data": json.dumps(page_data)})
            else:
                raise Http404
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 4
0
    def get_index_match_rule_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:
            param = {
                'token': es_check['t'],
                'operator': es_check['u'],
            }
            res_info = BackendRequest.get_index_info_list(param)
            res_index_map = {}
            if res_info['result']:
                if res_info["index_infos"]:
                    res_info_list = res_info["index_infos"]
                    print res_info_list
                    for item in res_info_list:
                        res_index_map[item['id']] = item['name']

            res = BackendRequest.get_index_match_rule_list(param)
            if res["result"]:
                if res["rules"]:
                    dummy_data["status"] = "1"
                    dummy_data["list"] = []
                    for item in res["rules"]:
                        item['index_name'] = res_index_map.get(
                            item['index_id'], '')
                        dummy_data["list"].append(item)
            else:
                dummy_data = err_data.build_error_new(res)
        else:
            data = err_data.build_error({}, "auth error!")
            data["location"] = "/auth/login/"
            dummy_data = data
        response_data = self.build_bundle(obj=dummy_data,
                                          data=dummy_data,
                                          request=request)
        return self.create_response(request, response_data)
Esempio n. 5
0
 def report_enable(self, request, **kwargs):
     self.method_check(request, allowed=['get'])
     report_id = kwargs['rid']
     report_enabled = int(kwargs['enable'])
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         param = {
             'id': report_id,
             'token': es_check['t'],
             'operator': es_check['u']
         }
         if report_enabled == 1:
             # enabled ==> disbaled
             res = BackendRequest.disable_report(param)
         else:
             # disabled ==> enabled
             res = BackendRequest.enable_report(param)
         if res['result']:
             dummy_data["status"] = "1"
             dummy_data["enabled"] = res.get("res",
                                             {}).get("enabled", False)
             dummy_data["msg"] = "enable/disable successfully"
         else:
             dummy_data = err_data.build_error(res)
             # dummy_data["list"] = data
     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
Esempio n. 6
0
def offlinetask(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        with_sg = 'no'
        config_permission = "no"
        sg_param = {
            'account': is_login['i'],
            'token': is_login['t'],
            'operator': is_login['u']
        }
        sg_res = BackendRequest.get_source_group(sg_param)
        if sg_res['result']:
            item = sg_res.get('items', [])
            if item:
                with_sg = 'yes'

        func_auth_res = BackendRequest.get_func_auth({'token': is_login['t']})
        if func_auth_res['result']:
            if func_auth_res["results"]["parser_conf"]:
                config_permission = "yes"
        page_data = {
            "active": "offlinetask",
            "subnav": "offlinetask",
            "user": is_login["u"],
            "email": is_login["e"],
            "cf_per": config_permission,
            "role": is_login["r"],
            "userid": is_login["i"],
            "with_sg": with_sg,
            "rgid": request.GET.get('rgid', "")
        }
        return render(request, 'offlinetask/offlinetask.html',
                      {"page_data": json.dumps(page_data)})
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 7
0
    def report_delete(self, request, **kwargs):
        """
            Used to delete an existing report identified by its id.
        """

        self.method_check(request, allowed=['post'])
        report_id = kwargs["rid"]
        dummy_data = {}

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

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

            to_log = {
                "timestamp": time.strftime("%Y-%m-%d %H:%M:%S",
                                           time.localtime()),
                "action": "delete",
                "model": "report",
                "user_name": es_check["u"],
                "user_id": es_check["i"],
                "domain": es_check["d"],
                "target": report_id,
                "result": "success"
            }

            res = BackendRequest.delete_report(param)

            if res['result']:
                dummy_data['status'] = "1"
                dummy_data['list'] = res.get('list', [])
                dummy_data['id'] = res.get('id', "")
            else:
                dummy_data = ReportResource.error_handler(res)
                to_log["result"] = "error"
                to_log["msg"] = res.get("error", "")
            audit_logger.info(json.dumps(to_log))
        else:
            dummy_data = ReportResource.error_handler(None, True)

        return ReportResource.generate_response(self,
                                                data=dummy_data,
                                                request=request)
Esempio n. 8
0
def custom_table(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            page_data = {'role': is_login['r'], "subnav": "table", "tableType": "list", "user": is_login["u"],
                                                "userid": is_login["i"]}
            return render(request, 'system/custom_table.html', {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 9
0
    def feedback_new(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        req_data = request.POST
        feedback_type = req_data.get('type', '')
        feedback_content = req_data.get('content', '')
        feedback_referrer = req_data.get('ref', '')

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            user_info_res = BackendRequest.get_account({
                "id": es_check['i'],
                'token': es_check['t'],
                'operator': es_check['u']
            })
            account = {
                "username": "",
                "fullname": "",
                "email": ""
            }
            if user_info_res["result"]:
                one_account = user_info_res.get('accounts', [])[0]
                account['username'] = one_account['name']
                account['fullname'] = one_account['full_name']
                account['email'] = one_account['email']

            ua = request.META.get('HTTP_USER_AGENT')

            email = "问题描述:"+ feedback_content + "</br></br>" + "-----------------------------------------</br>" + "useragent: " + \
                ua + "</br>" + "url:" + feedback_referrer + "</br>" + "</br>-----------------------------------------</br>" + "用户名:" + \
                    account['username'] +"</br>姓名:" + account["fullname"] + "</br>邮件:" + \
                account['email']
            res = self.send_mail(feedback_type, email)
            if res:
                dummy_data["status"] = "1"
            else:
                dummy_data = err_data.build_error({})
        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
Esempio n. 10
0
    def get_resourcegroup_list(self, request, **kwargs):
        """Get a list of available resource groups in aspect of current user.
        """

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

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

        if es_check:
            # 'action' specifies what action is performed: Read, Assign
            # 'target' specifies what module is requesting
            param = {}
            if kwargs['action'].lower() == "read":
                param['action'] = "Read"
                param['category'] = "SourceGroup"
                param['token'] = es_check['t']
                param['operator'] = es_check['u']
                param['target'] = "ResourceGroup"
            elif kwargs['action'].lower() == "assign":
                param['action'] = "Assign"
                param['token'] = es_check['t']
                param['operator'] = es_check['u']
                param['target'] = "SourceGroup"

            res = BackendRequest.permit_list_resource_group(param)

            if res['result']:
                data = self.rebuild_resource_group_list(res['resource_groups'])
                dummy_data["status"] = "1"
                dummy_data["total"] = len(data)
                dummy_data["list"] = data
            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
Esempio n. 11
0
 def update_index_info(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     index_info_id = kwargs['id']
     req_data = request.POST
     post_data = {
         'name': req_data.get('name', ''),
         'alias': req_data.get('alias', ''),
         'description': req_data.get('description', ''),
         'expired_time': req_data.get('expired_time', ''),
         'rotation_period': req_data.get('rotation_period', ''),
         'disabled': req_data.get('disabled', 'false')
     }
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         param = {
             'id': index_info_id,
             'token': es_check['t'],
             'operator': es_check['u'],
             'name': post_data['name'],
             'alias': post_data['alias'],
             'description': post_data['description'],
             'expired_time': post_data['expired_time'],
             'rotation_period': post_data['rotation_period'],
             'disabled': post_data['disabled']
         }
         res = BackendRequest.update_index_info(param)
         if res['result']:
             dummy_data["status"] = "1"
             dummy_data["location"] = "/indexsettings/indexinfo/"
         else:
             data = err_data.build_error(res)
             dummy_data = data
     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
Esempio n. 12
0
    def sourcegroups_update(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        source_group_id = kwargs["sgid"]
        req_data = request.POST
        # username = request.POST['username']
        # password = request.POST['password']
        post_data = {
            'id': source_group_id,
            'name': req_data.get('name', ''),
            'description': req_data.get('desc', ''),
            'hostname': req_data.get('host', ''),
            'appname': req_data.get('application', ''),
            'tag': req_data.get('tag', ''),
            'resource_group_ids': req_data.get('resource_group_ids', "")
        }
        # if req_data.get('host', '') != '':
        # post_data['hostname'] = req_data.get('host', '')
        # if req_data.get('application', '') != '':
        # post_data['appname'] = req_data.get('application', '')
        # if req_data.get('tag', '') != '':
        # post_data['tag'] = req_data.get('tag', '')

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            post_data["token"] = es_check["t"]
            post_data['operator'] = es_check['u']
            res = BackendRequest.update_source_group(post_data)
            if res["result"]:
                dummy_data["status"] = "1"
                dummy_data["location"] = "/sources/sourcegroups/"
            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
Esempio n. 13
0
def service(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        res = BackendRequest.get_func_auth({
            "token": is_login["t"],
        })
        if res["results"]["enable_security"]:
            with_sg = check_with_sourcegroup(is_login)
            cf_per = check_with_permission(is_login)
            return render(request, 'application/apache/service.html',
                          {"active": "applications", "subnav": "service", "user": is_login["u"], "email": is_login["e"],
                           "token": is_login["t"], "userid": is_login["i"],
                           "role": is_login["r"], "with_sg": with_sg,
                           "cf_per": cf_per})
        else:
            raise Http404
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 14
0
 def update_index_match_rule(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     index_match_rule_id = kwargs['id']
     req_data = request.POST
     post_data = {
         'index_id': req_data.get('index_id', ''),
         'appname': req_data.get('appname', ''),
         'description': req_data.get('description', ''),
         'tag': req_data.get('tag', ''),
         'raw_message_regex': req_data.get('raw_message_regex', '')
     }
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         param = {
             'id': index_match_rule_id,
             'token': es_check['t'],
             'operator': es_check['u'],
             'index_id': post_data['index_id'],
             'appname': post_data['appname'],
             'description': post_data['description'],
             'tag': post_data['tag'],
             'raw_message_regex': post_data['raw_message_regex']
         }
         res = BackendRequest.update_index_match_rule(param)
         if res['result']:
             dummy_data["status"] = "1"
             dummy_data["location"] = "/indexsettings/indexmatchrule/"
         else:
             data = err_data.build_error(res)
             dummy_data = data
     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
Esempio n. 15
0
def configs_update(request, id, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)

    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            domain = is_login["d"]
            try:
                conn = pymysql.connect(host=host, user=user, passwd=pwd, db=database, charset='utf8',
                                    cursorclass=pymysql.cursors.DictCursor)
                cur = conn.cursor()
                sql = "SELECT id FROM Domain WHERE name=%s"
                cur.execute(sql, domain)
                res = cur.fetchone()
                domain_id = res.get("id", "")
                if domain_id:
                    sql = "SELECT * FROM ParserRule WHERE id=%s AND domain_id IN (%s,%s)"
                    cur.execute(sql, (id, domain_id, '0'))
                    detail_res = cur.fetchone()
                    print detail_res
                    c_id = detail_res.get("category_id", 0)
                    print c_id
                    if not c_id == 1000:
                        raise Http404
                    with_sg = 'no'
                    cf_per = check_with_permission(is_login)
                    page_data = {"active": "source", "subnav": "configs", "user": is_login["u"],
                                 "email": is_login["e"],
                                 "role": is_login["r"], "userid": is_login["i"],
                                 "with_sg": with_sg, 'config_id': id, "cf_per": cf_per}
                    return render(request, 'extract/new.html', {"page_data": json.dumps(page_data)})
                else:
                    raise Http404
            except pymysql.Error, e:
                raise Http404
        else:
            raise PermissionDenied
Esempio n. 16
0
def custom_dash_update(request, dash_id, **kwargs):
    dash = {
        "id": dash_id.encode('utf-8')
    }
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            page_data = {'role': is_login['r'], "subnav": "dashboard", "dashboardType": "update", "dash": dash,
                                                "user": is_login["u"], "userid": is_login["i"]}
            return render(request, 'system/custom_dash.html', {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 17
0
def configs_helper(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            with_sg = 'no'
            cf_per = check_with_permission(is_login)
            return render(request, 'config/usual.html', {"active": "source", "subnav": "configs", "user": is_login["u"],
                                                            "email": is_login["e"],
                                                            "role": is_login["r"], "userid": is_login["i"],
                                                            "config_obj": {}, "with_sg": with_sg, "cf_per": cf_per})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 18
0
 def upload_volum_info(self, request, **kwargs):
     self.method_check(request, allowed=['get'])
     # print "################upload_volum_info: "
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     dummy_data = {}
     if es_check:
         dummy_data = BackendRequest.get_upload_status({
             "token": es_check["t"],
             'operator': es_check['u']
         })
         # print "################upload_volum_info: ",dummy_data
     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
Esempio n. 19
0
    def token_retired_list(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        data = [
            {"token": "01234kjhasak12j3l4lh3jh41lkh322j315kph12vasd", "description": "ddd",
             "created": "20140706", "edit": "false"},
            {"token": "31aaagghk12j3l4lh12k3jh41lkh322j315kph12vasd", "description": "ssssss",
             "created": "20140706", "edit": "false"},
            {"token": "aasdkvocinwj3l4lh12k3jh41lkh322j315kph12vasd", "description": "afffdsfadds",
             "created": "20140706", "edit": "false"}
        ]
        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']
            }
            res = BackendRequest.get_domain(param)
            if res['result']:
                list = []
                for a_domain in res['domain']:
                    list.append({
                        'token': a_domain['token'],
                        'created': a_domain['create_time'] * 1000
                    })
                data = res['domain']['token']
                dummy_data["status"] = "1"
                dummy_data["totle"] = len(data)
                dummy_data["list"] = 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
Esempio n. 20
0
def roles(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            page_data = {
                "user": is_login["u"],
                "userid": is_login["i"],
                "role": is_login["r"]
            }
            return render(request, 'account/roles.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 21
0
def create_index_info(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:

            index_info = {
                'id': '',
                'name': '',
                'description': '',
                'domain_id': '',
                'expired_time': '',
                'expired_time_unit': 'd',
                'rotation_period': '',
                'rotation_period_unit': 'd',
                'disabled': 'false',
                'act': 'new'
            }
            cf_per = check_with_permission(is_login)
            page_data = {
                'index_info': index_info,
                "active": "indexsettings",
                "user": is_login["u"],
                "email": is_login["e"],
                "role": is_login["r"],
                "userid": is_login["i"],
                "rgid": request.GET.get('rgid', ""),
                "cf_per": cf_per
            }
            return render(request, 'indexsettings/indexinfonew.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 22
0
    def saved_rg_action(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        dummy_data = {}
        es_check = False
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            param = {}
            if kwargs['action'].lower() == "read":
                param['action'] = "Read"
                param['category'] = "SavedSearch"
                param['token'] = es_check['t']
                param['operator'] = es_check['u']
                param['target'] = "ResourceGroup"
            elif kwargs['action'].lower() == "assign":
                param['action'] = "Assign"
                param['token'] = es_check['t']
                param['operator'] = es_check['u']
                param['target'] = "SavedSearch"

            res = BackendRequest.permit_list_resource_group(param)
            if res['result']:
                data = self.rebuild_resource_group_list(res['resource_groups'])
                dummy_data["status"] = "1"
                dummy_data["total"] = len(data)
                dummy_data["rg_list"] = data
            else:
                dummy_data["status"] = 0
                dummy_data["msg"] = res.get('error',
                                            'get saved rg action error!')
        else:
            dummy_data["status"] = "0"

        bundle = self.build_bundle(obj=dummy_data,
                                   data=dummy_data,
                                   request=request)
        response_data = bundle
        resp = self.create_response(request, response_data)
        return resp
Esempio n. 23
0
 def get_resourcegroup_ungrouped(self, request, **kwargs):
     self.method_check(request, allowed=['get'])
     dummy_data = {}
     es_check = False
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         param = {
             'category': "Report",
             'token': es_check['t'],
             'operator': es_check['u']
         }
         res = BackendRequest.list_derelict_resource_ids(param)
         if res['result']:
             dummy_data["status"] = "1"
             dummy_data["ids"] = res['resource_ids']
         else:
             dummy_data['status'] = 0
             dummy_data['msg'] = res.get('error', "Unknow server error")
     else:
         dummy_data["status"] = "0"
     return ReportResource.generate_response(self, dummy_data, request)
Esempio n. 24
0
def reports_list(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            return render(
                request, 'report/list_view.html', {
                    "user": is_login["u"],
                    "email": is_login["e"],
                    "userid": is_login["i"],
                    "subnav": "reports",
                    "role": is_login["r"]
                })
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 25
0
 def offlinetask_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:
         param = {
             'token': es_check['t'],
             'operator': es_check['u'],
             'category': 'search'
         }
         res = BackendRequest.get_job_list(param)
         print res
         try:
             if res["rc"] == 0:
                 if res["jobs"]:
                     dummy_data["status"] = "1"
                     dummy_data["list"] = res["jobs"]
             else:
                 dummy_data = err_data.build_error_new(error_code=res.get("rc", "1"), msg=res.get("error", ""), origin="spl")
         except Exception, e:
             dummy_data = err_data.build_error_new(res.get("rc", "1"))
Esempio n. 26
0
    def dict_delete(self, request, **kwargs):
        """
            Used to delete the given dictionary identified by its id.
        """

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

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

        if es_check:
            param = DictionaryResource.generate_param(es_check, {'id': kwargs.get("id", "")})
            res = BackendRequest.delete_dict(param)

            if res['result']:
                dummy_data['status'] = "1"
            else:
                dummy_data = DictionaryResource.error_handler(res, False)
        else:
            dummy_data = DictionaryResource.error_handler(res, True)

        return DictionaryResource.generate_response(self, dummy_data, request)
Esempio n. 27
0
 def saved_update(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     req_data = request.POST
     query = req_data.get('query', '')
     timerange = req_data.get('time_range', '')
     sg = req_data.get('sourcegroup', '')
     sourcegroup = req_data.get('sourcegroupCn',
                                '') if not sg == 'all' else 'all'
     filters = req_data.get('filters', '')
     name = req_data.get('name', '')
     savedsearch_id = kwargs['ssid']
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         res = BackendRequest.update_saved_search({
             "token": es_check["t"],
             "operator": es_check["u"],
             "id": savedsearch_id,
             "name": name,
             "query": query,
             "time_range": timerange,
             "source_groups": sourcegroup,
             "filters": filters
         })
         if res["result"]:
             dummy_data["status"] = "1"
         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
Esempio n. 28
0
 def update_ttls(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     ttls = json.loads(request.POST.get('ttls'))
     dummy_data = {}
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         tmpList = []
         ttls.pop()
         for ttl in ttls:
             tmpStr = str(ttl.get('pattern', '')) + ':' + str(
                 ttl.get('ttl', ''))
             tmpList.append(tmpStr)
         ttl = ",".join(tmpList)
         param = {
             'token': es_check['t'],
             'operator': es_check['u'],
             'ttl': ttl
         }
         # print "#################update_ttls param: ",param
         res = BackendRequest.update_ttls(param)
         # print "#################update_ttls: ",res
         if res["result"]:
             data = {
                 "status": 1,
             }
             dummy_data = data
         else:
             dummy_data = err_data.build_error({}, "update_ttls error!")
     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
Esempio n. 29
0
def alerts_new(request, **kwargs):
    alert = {
        'alert_id': '',
        'saved_searches': [],
        'alert_mails': [],
        'alert_release': '0',
        'level': '1',
        'alert_mail_enable': True,
        'alert_release': '0',
        'includeLatestEvents': True,
        'alert_enable': True
    }
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if visit_permit['result'] and visit_permit['can_visit']:
            with_sg = check_with_sourcegroup(is_login)
            page_data = {
                'alert': alert,
                "active": "alert",
                "user": is_login["u"],
                "email": is_login["e"],
                "with_sg": with_sg,
                "syslog": syslog,
                "role": is_login["r"],
                "userid": is_login["i"]
            }
            return render(request, 'alert/update.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 30
0
def source_input_linux(request, offset, **kwargs):
    platform = offset.encode('utf-8')
    if platform == "win" or platform == "linux":
        my_auth = MyBasicAuthentication()
        is_login = my_auth.is_authenticated(request, **kwargs)
        if is_login:
            visit_permit = BackendRequest.can_visit({
                "token":
                is_login['t'],
                "operator":
                is_login['u'],
                "requestUrl":
                request.path[1:]
            })
            if visit_permit['result'] and visit_permit['can_visit']:
                cf_per = check_with_permission(is_login)
                with_sg = check_with_sourcegroup(is_login)
                page_data = {
                    "active": "source",
                    "subnav": "input",
                    "user": is_login["u"],
                    "email": is_login["e"],
                    "token": is_login["t"],
                    "userid": is_login["i"],
                    "role": is_login["r"],
                    "platform": platform,
                    "with_sg": with_sg,
                    "upload_url": upload_url,
                    "cf_per": cf_per
                }
                return render(request, 'source/linux.html',
                              {"page_data": json.dumps(page_data)})
            else:
                return HttpResponseRedirect('/auth/login/')
        else:
            raise PermissionDenied
    else:
        raise Http404