Example #1
0
def reports(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"],
                "active": "report",
                "email": is_login["e"],
                "subnav": "reports",
                "role": is_login["r"],
                "userid": is_login["i"],
                "rgid": request.GET.get("rgid", "")
            }
            return render(request, 'report/list.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #2
0
def usage(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 = check_with_sourcegroup(is_login)
            cf_per = check_with_permission(is_login)
            page_data = {
                "subnav": "usage",
                "user": is_login["u"],
                "email": is_login["e"],
                "token": is_login["t"],
                "userid": is_login["i"],
                "with_sg": with_sg,
                "role": is_login["r"],
                "cf_per": cf_per
            }
            return render(request, 'usage/usage.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #3
0
def create_index_match_rule(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_match_rule = {
                'index_id': '',
                'appname': '',
                'tag': '',
                'description': '',
                'raw_message_regex': ''
            }
            cf_per = check_with_permission(is_login)
            page_data = {
                'index_match_rule': index_match_rule,
                "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/indexmatchrulenew.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #4
0
def configs(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'
            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'
            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, "cf_per": cf_per,
                         "rgid": request.GET.get("rgid", "")
                         }
            return render(request, 'extract/list.html', {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #5
0
def source_input_server_heka(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 = check_with_sourcegroup(is_login)
            cf_per = check_with_permission(is_login)
            return render(
                request, 'source/server_heka.html', {
                    "active": "source",
                    "subnav": "input",
                    "user": is_login["u"],
                    "email": is_login["e"],
                    "token": is_login["t"],
                    "userid": is_login["i"],
                    "role": is_login["r"],
                    "with_sg": with_sg,
                    "upload_url": upload_url,
                    "host": host,
                    "port": stream_port,
                    "cf_per": cf_per
                })
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #6
0
def indexinfo(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']:
            cf_per = check_with_permission(is_login)
            page_data = {
                "active": "indexsettings",
                "subnav": "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/indexinfo.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #7
0
def dashboard_detail(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    dashboard_id = kwargs.get("did", "")
    tab_id = kwargs.get("tid", "")
    rgids = request.GET.get('rgids', "")
    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 = {
                "active": "dashboard",
                "user": is_login["u"],
                "dashboardId": dashboard_id,
                "email": is_login["e"],
                "timeline_color": timeline_color,
                "role": is_login["r"],
                "userid": is_login["i"],
                "with_sg": with_sg,
                "dashboardType": "detail",
                "rgids": rgids,
                "tabId": tab_id
            }
            return render(request, 'dashboard/detail.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #8
0
def records(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 = check_with_sourcegroup(is_login)
            page_data = {
                "active": "alert",
                "user": is_login["u"],
                "email": is_login["e"],
                "role": is_login["r"],
                "userid": is_login["i"],
                "with_sg": with_sg,
                "alert_id": request.GET.get("alert_id", "")
            }
            return render(request, 'alert/records.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #9
0
def usage(request, offset, **kwargs):
    bid = offset.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']:
            with_sg = check_with_sourcegroup(is_login)
            page_data = {
                "user": is_login["u"],
                "email": is_login["e"],
                "beneficiary_id": bid,
                "userid": is_login["i"],
                "with_sg": with_sg
            }
            return render(request, 'payment/usage.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #10
0
def users_new(request, **kwargs):
    account = {
        'user_id': '',
        'username': '',
        'fullname': '',
        'email': '',
        'phone': '',
        'user_groups': []
    }
    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 = {
                'account': account,
                "email": is_login["e"],
                "user": is_login["u"],
                "role": is_login["r"],
                "userid": is_login["i"],
                "show_fullname": show_fullname
            }
            return render(request, 'account/users_new.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #11
0
def update(request, offset, **kwargs):
    alert_id = offset.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']:
            with_sg = check_with_sourcegroup(is_login)
            alert_res = BackendRequest.get_alert({
                'id': alert_id,
                'token': is_login['t'],
                'operator': is_login['u']
            })
            # print "###########alert_res: ",alert_res
            if alert_res['result']:
                a_alert = alert_res['alert']
                alert = {
                    'alert_id':
                    alert_id,
                    'alert_name':
                    a_alert['name'].encode('utf-8'),
                    'alert_description':
                    a_alert.get("description", "").encode('utf-8'),
                }
                # for meta in alert['alert_meta']:
                # meta['alias'] = meta.get('alias','').encode('utf-8')
                # for config in meta.get('config',[]):
                # config['alias'] = config.get('alias','').encode('utf-8')
                # config['default_value'] = config.get('default_value','').encode('utf-8')
                # config['name'] = config.get('name','').encode('utf-8')
                # config['value'] = config.get('value','').encode('utf-8')
                # alert['alert_meta'] = json.dumps(alert['alert_meta'])
            else:
                alert = {
                    'alert_id': alert_id,
                    'alert_name': '',
                    'alert_description': '',
                }
            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/')
Example #12
0
def update(request, uid, **kwargs):
    user_id = uid
    account = {
        'user_id': user_id.encode('utf-8'),
        'username': '',
        'fullname': '',
        'email': '',
        'phone': '',
        'user_groups': []
    }
    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']) or user_id == str(
                    is_login['i']):
            user_param = {
                'id': user_id,
                'token': is_login['t'],
                'operator': is_login['u']
            }
            res = BackendRequest.get_account(user_param)
            if res['result']:
                one_account = res.get('accounts', [])[0]
                account['username'] = one_account['name'].encode('utf-8')
                account['fullname'] = one_account['full_name'].encode('utf-8')
                account['email'] = one_account['email'].encode('utf-8')
                account['phone'] = one_account['phone'].encode('utf-8')
                account['user_groups'] = one_account['user_groups']

            page_data = {
                'account': account,
                "email": is_login["e"],
                "user": is_login["u"],
                "userid": is_login["i"]
            }
            return render(request, 'account/users_new.html',
                          {"page_data": json.dumps(page_data)})

        else:
            raise PermissionDenied
    elif is_login:
        page_data = {
            "user": is_login["u"],
            "email": is_login["e"],
            "userid": is_login["i"]
        }
        return render(request, 'account/users.html',
                      {"page_data": json.dumps(page_data)})
    else:
        return HttpResponseRedirect('/auth/login/')
Example #13
0
def update_index_info(request, offset, **kwargs):
    indexInfo_id = offset.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']:
            index_info_res = BackendRequest.get_index_info({
                'id':
                indexInfo_id,
                'token':
                is_login['t'],
                'operator':
                is_login['u']
            })
            if index_info_res['result']:
                a_index_info = index_info_res['index_info']
                index_info = {
                    'id': indexInfo_id,
                    'name': a_index_info['name'].encode('utf-8'),
                    'description': a_index_info['description'].encode('utf-8'),
                    'domain_id': a_index_info['domain_id'],
                    'disabled':
                    'true' if a_index_info['disabled'] else 'false',
                    'act': 'update'
                }
                expired_time = a_index_info['expired_time'].encode('utf-8')
                index_info['expired_time'] = expired_time[0:-1]
                index_info['expired_time_unit'] = expired_time[-1]
                rotation_period = a_index_info['rotation_period'].encode(
                    'utf-8')
                index_info['rotation_period'] = rotation_period[0:-1]
                index_info['rotation_period_unit'] = rotation_period[-1]
            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/indexinfoupdate.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #14
0
def report_update(request, offset, **kwargs):
    report_id = offset
    report = {'id': report_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']:
            # get source group information
            report_param = {
                'account': report_id,
                'token': is_login['t'],
                "operator": is_login['u']
            }
            domain = is_login["d"]
            owner = str(is_login["i"]) + "|" + str(is_login["u"]) + "|" + str(
                is_login["t"])

            try:
                conn = pymysql.connect(host=host,
                                       user=user,
                                       passwd=pwd,
                                       db=database,
                                       charset='utf8',
                                       cursorclass=pymysql.cursors.DictCursor)
                cur = conn.cursor()
                sql = "SELECT * FROM Report WHERE domain='%s' AND owner='%s' AND id='%s' ORDER BY id" % (
                    domain, owner, report_id)
                cur.execute(sql)
                res = cur.fetchone()

                cur.close()
                conn.close()

                page_data = {
                    'report': report,
                    "active": "report",
                    "user": is_login["u"],
                    "email": is_login["e"],
                    "subnav": "reprot",
                    "role": is_login["r"],
                    "userid": is_login["i"]
                }
                return render(request, 'report/new.html',
                              {"page_data": json.dumps(page_data)})
            except pymysql.Error, e:
                return HttpResponseRedirect('/auth/login/')
        else:
            raise PermissionDenied
Example #15
0
def source_sourcegroups_update(request, offset, **kwargs):
    source_group_name = offset
    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']:
            sourcegroup = {
                "id": "",
                "name": source_group_name,
                "description": "",
                "host": "",
                "application": "",
                "tag": ""
            }
            res = BackendRequest.get_source_group({
                "token": is_login["t"],
                "name": source_group_name,
                "operator": is_login["u"]
            })
            if res["result"]:
                a_sg = res["items"][0]
                sourcegroup["id"] = a_sg.get("id", "").encode('utf-8')
                sourcegroup["name"] = a_sg.get("name", "").encode('UTF-8')
                sourcegroup["description"] = a_sg.get("description",
                                                      "").encode('utf-8')
                sourcegroup["host"] = a_sg.get("hostname", "").encode('utf-8')
                sourcegroup["application"] = a_sg.get("appname",
                                                      "").encode('utf-8')
                sourcegroup["tag"] = a_sg.get("tag", "").encode('utf-8')
            with_sg = check_with_sourcegroup(is_login)
            cf_per = check_with_permission(is_login)
            page_data = {
                "sourcegroup": sourcegroup,
                "active": "source",
                "subnav": "sourcegroups",
                "email": is_login["e"],
                "user": is_login["u"],
                "userid": is_login["i"],
                "role": is_login["r"],
                "with_sg": with_sg,
                "cf_per": cf_per
            }
            return render(request, 'source/sourcegroups-new.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #16
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
Example #17
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/')
Example #18
0
def lists(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'
            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": "dictionary",
                "subnav": "dictionary",
                "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, 'dictionary/list.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #19
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
Example #20
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/')
Example #21
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/')
Example #22
0
def usergroups_update(request, ug_id, **kwargs):
    group = {'id': ug_id}
    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']:
            param = {
                'token': is_login['t'],
                'operator': is_login['u'],
                'id': ug_id
            }
            res = BackendRequest.get_user_group(param)
            if res['result']:
                page_data = {
                    'group': group,
                    "email": is_login["e"],
                    "role": is_login["r"],
                    "user": is_login["u"],
                    "userid": is_login["i"]
                }
                return render(request, 'account/usergroup_new.html',
                              {"page_data": json.dumps(page_data)})
            else:
                logger.error(
                    "%s get user group error, redirect to usergroup list!",
                    is_login['u'])
                return render(
                    request, 'account/usergroup.html', {
                        "user": is_login["u"],
                        "userid": is_login["i"],
                        "role": is_login["r"]
                    })
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #23
0
def search(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'
            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'
            page_data = {
                "active": "search",
                "user": is_login["u"],
                "email": is_login["e"],
                "role": is_login["r"],
                "userid": is_login["i"],
                "timeline_color": timeline_color,
                "syslog": syslog,
                "with_sg": with_sg,
                "fields_limit": fields_limit,
                'ri': is_login["ri"],
                'loading_auto_search': loading_auto_search,
                'auto_search': auto_search
            }
            return render(request, 'search/search.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #24
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/')
Example #25
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/')
Example #26
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/')
Example #27
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
Example #28
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/')
Example #29
0
def usergroups_new(request, **kwargs):
    group = {'id': '', 'name': ''}
    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 = {
                'group': group,
                "email": is_login["e"],
                "user": is_login["u"],
                "userid": is_login["i"]
            }
            return render(request, 'account/usergroup_new.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')
Example #30
0
def resourcegroups_update(request, rg_id, **kwargs):
    rg_data = {'rg_id': rg_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 = {
                "edit_rg": rg_data,
                "user": is_login["u"],
                "userid": is_login["i"],
                "role": is_login["r"]
            }
            return render(request, 'account/resourcegroups_new.html',
                          {"page_data": json.dumps(page_data)})
        else:
            raise PermissionDenied
    else:
        return HttpResponseRedirect('/auth/login/')