Example #1
0
    def csv_download(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        data = []
        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            file_name = kwargs['fid']
            root_path = os.getcwd()
            my_var = MyVariable()
            data_path = my_var.get_var('path', 'data_path')
            tmp_path = data_path + "yottaweb_tmp/" + es_check["d"] + "/" + es_check["u"] + "/"
            filename = tmp_path + file_name
            wrapper = FileWrapper(file(filename))
            resp = HttpResponse(wrapper, content_type='text/plain')

            # resp = self.create_response(request, wrapper)
            resp['Content-Length'] = os.path.getsize(filename)
            resp['Content-Encoding'] = 'utf-8'
            resp['Content-Disposition'] = 'attachment;filename=%s' % file_name
        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
Example #2
0
    def reourcegroup_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': "SourceGroup",
                '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"

        bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
        response_data = bundle
        resp = self.create_response(request, response_data)
        return resp
Example #3
0
def download(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"
        return render(
            request, 'download/download.html', {
                "active": "download",
                "subnav": "download",
                "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', "")
            })
    else:
        return HttpResponseRedirect('/auth/login/')
Example #4
0
    def report_trends(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 = BackendRequest.get_all_trends(param)
            if res['result']:
                dummy_data["status"] = "1"
                list = []
                for item in res.get('trends', []):
                    list.append({
                        "key": item.get("id"),
                        "value": item.get("name")
                    })
                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
Example #5
0
    def table_info(self, request, **kwargs):
        self.method_check(request, allowed=['get'])

        sid = kwargs.get('sid')

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            info = {}
            try:
                my_var = MyVariable()
                data_path = my_var.get_var('path', 'data_path')
                config_path = data_path + "custom"
                real_file = config_path + '/tables.json'
                with open(real_file, 'r') as f:
                    config = json.load(f)
                tables = config["tables"]
                for item in tables:
                    if item["id"] == sid:
                        info = item
            except Exception, e:
                print e
                info = {}
            dummy_data["status"] = "1"
            dummy_data["table"] = info.get("content", {})
Example #6
0
def table(request, cid, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        try:
            my_var = MyVariable()
            data_path = my_var.get_var('path', 'data_path')
            config_path = data_path + "custom"
            real_file = config_path + '/tables.json'
            info = {}
            with open(real_file, 'r') as f:
                config = json.load(f)
            tables = config["tables"]
            for item in tables:
                if item["id"] == cid:
                    info = item
        except Exception, e:
            print e
            info = {}
        page_data = {
            "active": "applications",
            "subnav": "overview",
            "user": is_login["u"],
            "email": is_login["e"],
            "token": is_login["t"],
            "userid": is_login["i"],
            "table_info": info,
            "role": is_login["r"]
        }
        return render(request, 'application/custom/table.html',
                      {"page_data": json.dumps(page_data)})
Example #7
0
    def check_auth(request, **kwargs):
        """
            Used to check and return authentication result
        """

        my_auth = MyBasicAuthentication()
        return my_auth.is_authenticated(request, **kwargs)
Example #8
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 #9
0
    def logo_reset(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        dummy_data = {}
        if es_check:
            logoType = request.POST.get('type', '')

            try:
                cf = ConfigParser.ConfigParser()
                real_path = os.getcwd() + '/config'
                cf.read(real_path + "/yottaweb.ini")
                navLogoSmallPathName = cf.get('logo', 'nav_logo_path_name')
                navLogoSmallPathNameBk = cf.get('logo', 'nav_logo_path_name_bk')
                navLogoLargePathName = cf.get('logo', 'login_logo_path_name')
                navLogoLargePathNameBk = cf.get('logo', 'login_logo_path_name_bk')

                if logoType == 'small':
                    if os.path.isfile(navLogoSmallPathNameBk):
                        os.remove(navLogoSmallPathName)
                        os.rename(navLogoSmallPathNameBk, navLogoSmallPathName)
                elif logoType == 'large':
                    if os.path.isfile(navLogoLargePathNameBk):
                        os.remove(navLogoLargePathName)
                        os.rename(navLogoLargePathNameBk, navLogoLargePathName)

                dummy_data["status"] = "1"
            except Exception, e:
                dummy_data["status"] = "0"
                dummy_data["msg"] = "get error!"
Example #10
0
 def notices(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 = {
             'act': 'get_notice_list',
             'token': es_check['t'],
             'operator': es_check['u'],
             'account_id': es_check['i'],
         }
         res = BackendRequest.get_notice(param)
         if res['result']:
             dummy_data["status"] = '1'
             dummy_data["data"] =res.get('notices') 
         else:
             dummy_data["status"] = '0'
             dummy_data["msg"] =res.get('error','get notices error!')
     else:
         dummy_data["status"] = "0"
         dummy_data["msg"] = "auth error!"
         dummy_data["location"] = "/auth/login/"
     bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
     response_data = bundle
     resp = self.create_response(request, response_data)
     return resp
Example #11
0
 def clear(self, request, **kwargs):
     self.method_check(request, allowed=['post'])
     notice_id = kwargs['notice_id'].encode('utf-8')
     dummy_data = {}
     es_check = False
     my_auth = MyBasicAuthentication()
     es_check = my_auth.is_authenticated(request, **kwargs)
     if es_check:
         param = {
             'act': 'update_notice_state',
             'token': es_check['t'],
             'operator': es_check['u'],
             'account_id': es_check['i'],
             'notice_ids': notice_id,
         }
         print "######################clear param: ",param
         res = BackendRequest.get_notice(param)
         if res['result']:
             dummy_data["status"] = '1'
         else:
             dummy_data["status"] = '0'
             dummy_data["msg"] =res.get('error','clear notices error!')
     else:
         dummy_data["status"] = "0"
         dummy_data["msg"] = "auth error!"
         dummy_data["location"] = "/auth/login/"
     bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
     response_data = bundle
     resp = self.create_response(request, response_data)
     return resp
Example #12
0
    def saved_rg_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': 'SavedSearch',
                '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', 'get dashboards ungrouped rg 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
Example #13
0
    def saved_rg_assigned(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        rid = kwargs['rid']
        dummy_data = {}
        es_check = False
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            param = {
                'resource_id': rid,
                'category': "SavedSearch",
                'token': es_check['t'],
                'operator': es_check['u']
            }
            res = BackendRequest.list_assigned_resource_group(param)
            if res['result']:
                data = self.rebuild_assigned_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 assigned 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
Example #14
0
def config(request, ip_port, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        with_sg = check_with_sourcegroup(is_login)
        cf_per = check_with_permission(is_login)
        os = request.GET.get('os', "linux")
        version = request.GET.get('version', '')
        platform = request.GET.get('platform', 'linux')
        proxy = request.GET.get('proxy', '')
        page_data = {
            "active": "source",
            "subnav": "agent",
            "user": is_login["u"],
            "email": is_login["e"],
            "token": is_login["t"],
            "userid": is_login["i"],
            "role": is_login["r"],
            "with_sg": with_sg,
            'proxy': proxy,
            "cf_per": cf_per,
            "ip_port": ip_port,
            "os": os,
            "version": version,
            "platform": platform
        }
        return render(request, 'agent/config.html',
                      {"page_data": json.dumps(page_data)})
    else:
        return HttpResponseRedirect('/auth/login/')
Example #15
0
 def get_index_info_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 = BackendRequest.get_index_info_list(param)
         print res
         if res["result"]:
             if res["index_infos"]:
                 dummy_data["status"] = "1"
                 dummy_data["list"] = res["index_infos"]
         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)
Example #16
0
    def tables_delete(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        dummy_data = {}
        id = kwargs.get("aid", "")
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)

        if es_check:
            my_var = MyVariable()
            data_path = my_var.get_var('path', 'data_path')
            config_path = data_path + "custom"
            real_file = config_path + '/tables.json'

            try:
                with open(real_file, 'r') as f:
                    config = json.load(f)
                f.close()
                tables = config.get("tables", [])

            except Exception, e:
                print e
                tables = []

            cur_id = -1
            for i in range(len(tables)):
                if tables[i]["id"] == id:
                    cur_id = i
            try:
                if cur_id > -1:
                    del(tables[cur_id])
            except Exception, e:
                print e
Example #17
0
    def delete_offlinetask(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        post_data = request.POST

        file_name = post_data.get("file_name", "")

        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        dummy_data = {}
        if es_check:
            param = {
                'token': es_check['t'],
                'operator': es_check['u'],
                'file_name': file_name
            }
            res = BackendRequest.delete_download(param)
            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
Example #18
0
    def system_custom(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        dummy_data = {}
        if es_check:
            imgString = request.POST.get('img', '')
            logoType = request.POST.get('type', '')
            data = imgString.split('base64,').pop()
            binary_data = a2b_base64(data)

            try:
                cf = ConfigParser.ConfigParser()
                real_path = os.getcwd() + '/config'
                cf.read(real_path + "/yottaweb.ini")
                navLogoSmallPathName = cf.get('logo', 'nav_logo_path_name')
                navLogoSmallPathNameBk = cf.get('logo', 'nav_logo_path_name_bk')
                navLogoLargePathName = cf.get('logo', 'login_logo_path_name')
                navLogoLargePathNameBk = cf.get('logo', 'login_logo_path_name_bk')

                if logoType == 'small':
                    if not os.path.isfile(navLogoSmallPathNameBk):
                        os.rename(navLogoSmallPathName, navLogoSmallPathNameBk)
                    with open(navLogoSmallPathName, 'wb') as f:
                        f.write(binary_data)
                elif logoType == 'large':
                    if not os.path.isfile(navLogoLargePathNameBk):
                        os.rename(navLogoLargePathName, navLogoLargePathNameBk)
                    with open(navLogoLargePathName, 'wb') as f:
                        f.write(binary_data)

                dummy_data["status"] = "1"
            except Exception, e:
                dummy_data["status"] = "0"
                dummy_data["msg"] = "get error!"
Example #19
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 #20
0
    def themes_color(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        dummy_data = {}
        path = os.path.dirname(os.path.realpath(__file__))
        if es_check:
            dummy_data["status"] = "1"
            dummy_data["color"] = {
                "mainColor": "329BE6",
                "mainColorHover": "3282F5",
                "leftNav": "1C2237",
                "dashboard": "16191C",
                "icon": "9BB4C8"
            }

            scssfile_check = os.path.isfile(path + '/../../static/scss/var.scss')
            backfile_check = os.path.isfile(path + '/../../static/scss/var.scss.back')
            prevfile_check = os.path.isfile(path + '/../../static/scss/var.scss.prev')
            if scssfile_check is False:
                if prevfile_check is False:
                    if backfile_check is False:
                        req_logger.error("no any scss files")
                        dummy_data["status"] = "0"
                        dummy_data["msg"] = "no any scss files, please contact the service provider"
                    else:
                        copyfile(path + '/../../static/scss/var.scss.back', path + '/../../static/scss/var.scss')
                else:
                    copyfile(path + '/../../static/scss/var.scss.prev', path + '/../../static/scss/var.scss')
            if scssfile_check is True or backfile_check is True or prevfile_check is True:
                for line in fileinput.input(path + '/../../static/scss/var.scss'):
                    match_main = re.search(r'\$yw-bg-btn-blue: #?(?P<hex>[a-zA-Z0-9]+);', line.rstrip())
                    if match_main is not None:
                        dummy_data["color"]["mainColor"] = match_main.group('hex')

                    match_main_hover = re.search(r'\$yw-bg-btn-blue-hover: #?(?P<hex>[a-zA-Z0-9]+);', line.rstrip())
                    if match_main_hover is not None:
                        dummy_data["color"]["mainColorHover"] = match_main_hover.group('hex')
                    
                    match_nav = re.search(r'\$yw-bg-leftnav-blue: #?(?P<hex>[a-zA-Z0-9]+);', line.rstrip())
                    if match_nav is not None:
                        dummy_data["color"]["leftNav"] = match_nav.group('hex')
                    
                    match_dashboard = re.search(r'\$yw-bg-dashboard-night: #?(?P<hex>[a-zA-Z0-9]+);', line.rstrip())
                    if match_dashboard is not None:
                        dummy_data["color"]["dashboard"] = match_dashboard.group('hex')
                    
                    match_icon = re.search(r'\$yw-icon-info: #?(?P<hex>[a-zA-Z0-9]+);', line.rstrip())
                    if match_icon is not None:
                        dummy_data["color"]["icon"] = match_icon.group('hex')
                    
                fileinput.close()
        else:
            req_logger.error("auth error")
            dummy_data["status"] = "0"
            dummy_data["msg"] = "get 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
Example #21
0
    def report_files(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:
            domain = es_check["d"]
            owner = str(es_check["i"]) + "|" + str(es_check["u"]) + "|" + str(
                es_check["t"])
            my_var = MyVariable()
            data_path = my_var.get_var('path', 'report_path')
            tmp_path = data_path + "yottaweb_reports/" + es_check[
                "t"] + "/" + str(es_check["i"]) + "/"
            tmp_files = os.listdir(tmp_path)
            file_list = []
            for one_file in tmp_files:
                file_list.append({
                    'name': one_file,
                    'owner': es_check['u'],
                    'created_time': one_file.split('_')[-1]
                })
            dummy_data["list"] = file_list
            dummy_data["status"] = "1"
        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
Example #22
0
def logout(request, **kwargs):
    # auth.logout(request)
    # print "#############request ",request

    url_scheme = request.META.get('wsgi.url_scheme')
    port = request.META.get('SERVER_PORT')
    referer = request.META.get('HTTP_REFERER')
    host = urlparse(referer).netloc
    domain = host.split('.')[0]
    my_auth = MyBasicAuthentication()
    es_check = my_auth.is_authenticated(request, **kwargs)

    logger = logging.getLogger("yottaweb.audit")

    to_log = {
        "timestamp": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
        "action": "logout",
        "user_name": es_check["u"],
        "user_id": es_check["u"],
        "domain": es_check['d']
    }
    logger.info(json.dumps(to_log))

    url = url_scheme + "://" + domain + from_url + "/auth/login/"
    if int(port) != 80:
        url = url_scheme + "://" + domain + from_url + ":" + port + "/auth/login/"
    if es_check:
        del request.session['user_name']
        del request.session['user_pwd']
        del request.session['user_tkn']
        del request.session['user_yottac']
        return HttpResponseRedirect('/auth/login/')
    else:
        return HttpResponseRedirect(url)
Example #23
0
    def steps(self, request, **kwargs):
        self.method_check(request, allowed=['get'])

        sid = kwargs.get('sid')

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            info = {}
            try:
                my_var = MyVariable()
                data_path = my_var.get_var('path', 'data_path')
                config_path = data_path + "custom"
                real_file = config_path + '/apps.json'
                with open(real_file, 'r') as f:
                    config = json.load(f)
                apps = config["apps"]
                for item in apps:
                    if item["id"] == sid:
                        info = item
            except Exception, e:
                print e
                info = {}
            dummy_data["status"] = "1"
            dummy_data["name"] = info.get("name", "")
            dummy_data["auto_search"] = info.get("auto_search", "no")
            dummy_data["sumSection"] = info.get("sumSection", {})
            dummy_data["steps"] = info.get("content", [])
Example #24
0
def new(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)

    domain_name = utility.domain_name(request)
    validate_order = Order.current_validate_order(domain_name)
    if validate_order:
        current_subscription = {
            'end_day': validate_order.pre_expire_time,
            'start_day': validate_order.validate_time,
            'volume': utility.mb_to_gb(validate_order.volume),
            'price': validate_order.charge,
            'order_id': validate_order.order_id(),
        }
        current_subscriptions = [current_subscription]
    else:
        current_subscriptions = []

    if is_login:
        return render(
            request, 'subscription/new.html', {
                "user": is_login["u"],
                "email": is_login["e"],
                "userid": is_login["i"],
                "current_subscriptions": current_subscriptions,
                "role": is_login["r"]
            })
    else:
        return HttpResponseRedirect('/auth/login/')
Example #25
0
def config(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, 'security/config.html', {
                    "active": "source",
                    "subnav": "security",
                    "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/')
Example #26
0
def overview(request, **kwargs):
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        with_sg = check_with_sourcegroup(is_login)
        cf_per = check_with_permission(is_login)
        my_var = MyVariable()
        data_path = my_var.get_var('path', 'data_path')
        config_path = data_path + "custom"
        real_file = config_path + '/apps.json'
        try:
            with open(real_file, 'r') as f:
                config = json.load(f)
            apps = config["apps"]
        except Exception, e:
            print e
            apps = []
            config = {}
        table_file = config_path + '/tables.json'
        try:
            with open(table_file, 'r') as f:
                config = json.load(f)
            tables = config["tables"]
        except Exception, e:
            print e
            tables = []
            config = {}
Example #27
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 #28
0
    def delete_index_match_rule(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        index_match_rule_id = kwargs['id']

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            res = BackendRequest.delete_index_match_rule({
                'token':
                es_check['t'],
                'operator':
                es_check['u'],
                'id':
                index_match_rule_id
            })
            if res['result']:
                dummy_data["status"] = "1"
            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
Example #29
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 #30
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/')