Beispiel #1
0
def upgrade_list(request):

    group_id = int(request.GET.get('group_id', 0))

    list_group = center_cache.get_group_list()

    list_record = []
    if group_id == 0:
        list_record = Upgrade.objects.all()
    else:
        list_record = Upgrade.objects.filter(group__id=group_id)

    parg = {}
    parg["list_record"] = list_record
    parg["list_group"] = list_group
    parg["group_id"] = group_id

    return render_to_response('server/upgrade_list.html', parg)
Beispiel #2
0
def get_group_server_list(is_root):
    group_server_list = []
    group_list = center_cache.get_group_list()
    if is_root:
        for group in group_list:
            server_list = center_cache.get_group_server_list(group.id)
            group_server_list.append({
                'group': group,
                'server_list': server_list
            })
    else:
        from GameManage.models import Group
        tmp_group = Group()
        tmp_group.id = 99
        tmp_group.name = '服务器'
        group_server_list.append({
            'group':
            tmp_group,
            'server_list':
            center_cache.get_user_server_list(usm.get_the_user())
        })

    return group_server_list
Beispiel #3
0
def upgrade_edit(request, model_id=0):
    model_id = int(model_id)

    if model_id == 0:
        model_id = int(request.GET.get('model_id', '0'))

    model = None
    if model_id > 0:
        model = Upgrade.objects.using('read').get(id=model_id)

    channel_list = center_cache.get_channel_list()
    group_list = center_cache.get_group_list()
    if model == None:
        model = Upgrade()
        model.id = 0
    else:
        model.remark = model.remark.replace('\\n', '\r\n')

        list_channel_selected = model.channel.all()
        channel_selected = {}
        for item in list_channel_selected:
            channel_selected[item.id] = 1
        for item in channel_list:
            item.is_show = channel_selected.get(item.id, 0)

        for item in group_list:
            if len(model.group.filter(id=item.id)) > 0:
                item.is_show = 1
            else:
                item.is_show = 0

    parg = {}
    parg["model"] = model
    parg["channel_list"] = channel_list
    parg["group_list"] = group_list

    return render_to_response('server/upgrade_edit.html', parg)
Beispiel #4
0
def query_view(request, query_id=0):
    query_id = int(query_id)

    if 0 == query_id:
        query_id = int(request.GET.get('id', request.POST.get('id', 0)))

    s_list = request.POST.getlist('s')
    if 0 == s_list.__len__():
        s_list = request.GET.getlist('s')

    page_num = int(request.GET.get('page_num', '1'))
    sdate = request.GET.get('sdate', '')
    edate = request.GET.get('edate', '')
    query_channel = request.GET.getlist('channel_id')
    group_id = int(request.GET.get('group_id', '0'))
    ajax = request.GET.get('ajax', False)
    exprot = int(request.GET.get('exprot', '0'))
    close_export = int(request.GET.get('close_export', '0'))
    clear_export_old_file = int(request.GET.get('clear_export_old_file', '0'))
    is_post_back = request.GET.get('post_back', False)
    exprot_file_key = request.GET.get('exprot_file_key', '')
    exprot_file_key = exprot_file_key.strip()
    more_serv_exprot = False
    if exprot_file_key != '':
        more_serv_exprot = True
    begin_exec_time = datetime.datetime.now()
    page_size = 50
    mc = MemcachedUtil()
    if exprot > 0:
        page_size = 500

    list_group = []
    usm = UserStateManager(request)
    the_user = usm.get_the_user()
    if query_id > 0:
        the_query = log_cache.get_query(query_id, mc)

    log_define = log_cache.get_logDefine(the_query.log_type, mc)

    #是否在中央服务器的查询
    is_centerQuery = False

    if log.the_log_in_center(log_define):  #check_user
        is_centerQuery = True
        is_select_server = False
    else:
        is_centerQuery = False
        is_select_server = True

    has_sql = False
    if the_query.sql != '':
        has_sql = True

    if not has_sql or -1 != the_query.sql.find('{{server_id}}'):
        is_select_server = True

    list_query = log_cache.get_query_list_by_logType(the_query.log_type, mc)
    if is_select_server:
        list_group = center_cache.get_group_list()

    if group_id != 0 and usm.current_userRole_is_root():
        list_server = center_cache.get_server_list(group_id, mc)
    else:
        if usm.current_userRole_is_root():
            list_server = center_cache.get_server_list(mc_util=mc)
        else:
            list_server = center_cache.get_user_server_list(the_user)

    #取出字段定义
    list_field = log_cache.get_fielddef_list_by_logType(the_query.log_type, mc)

    server_id = int(request.GET.get('server_id', '0'))
    if is_centerQuery and s_list.__len__() == 0:
        s_list = [str(item.id) for item in list_server]
        if not usm.current_userRole_is_root() and s_list.__len__() == 0:
            return HttpResponse(u"非法操作")
    elif server_id == 0 and len(list_server) > 0:
        server_id = list_server[0].id
        if server_id == 0:
            return HttpResponse(u"非法操作")

    if usm.current_userRole_is_root():
        list_channel = center_cache.get_channel_list(mc)
    else:
        list_channel = center_cache.get_user_channel_list(the_user, mc)

    #是否在页面上显示查询channel
    allowChannel = False

    if query_channel.__len__() == 0 and not usm.current_userRole_is_root():
        query_channel = []
        for item in list_channel:
            query_channel.append(str(item.id))

    if (not has_sql and list_channel.__len__() > 0) or (
            -1 != the_query.sql.find('{{qchannel')):
        allowChannel = True

    for item1 in list_channel:
        if query_channel.__len__() > 0:
            if str(item1.id) in query_channel:
                item1.is_show = 1
        else:
            item1.is_show = 0

    field_value = request.GET.get('field_value', '')
    field_value = filter_inject_sql(field_value)
    field_id = int(request.GET.get('field_id', '0'))

    if has_sql:
        field_value = request.GET.getlist('field_value')

    err_msg = ''

    pager_str = 'limit %s,%s' % ((page_num - 1) * page_size, page_size)

    fields = the_query.select.split(',')

    query_date = ''

    now = datetime.datetime.now()

    if not is_post_back:  #如果第一次进入该页面默认时间范围是昨天数据
        if sdate == '':
            sdate = (now -
                     datetime.timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')

        if edate == '':
            edate = now.strftime('%Y-%m-%d 00:00:00')

    if not has_sql or the_query.sql.find('{{keyword}}') != -1:
        is_search = True
    else:
        is_search = False

    has_sdate = True
    has_edate = True

    if the_query.sql != '':
        if -1 == the_query.sql.find('{{sdate}}'):
            has_sdate = False

        if -1 == the_query.sql.find('{{edate}}'):
            has_edate = False

        if -1 != the_query.sql.find('{{qdate}}'):
            has_sdate = True
            has_edate = True

        if -1 == the_query.sql.find('{{qchannel'):
            allowChannel = False

    keywords = []
    lost_param = False
    if has_sql:
        sql = the_query.sql
        r_keyword_name = '(@keywords.+)'
        keyword_name_ary = re.findall(r_keyword_name, sql, re.I)

        if keyword_name_ary.__len__() != 0:
            keyword_name = keyword_name_ary[0]
            names_str = keyword_name.split(':')[1]
            names = names_str.split(',')
            for i in range(names.__len__()):
                name = names[i]
                value = ''
                if field_value.__len__() > i:
                    value = field_value[i]
                keywords.append({"name": name, "value": value})
            the_query.sql = re.sub(keyword_name, '', sql, re.I)
        else:
            k_len = the_query.sql.lower().count('{{keyword}}')
            for i in range(k_len):
                value = ''
                if field_value.__len__() > i:
                    value = field_value[i]
                if value == '':
                    lost_param = True
                keywords.append({"name": '输入框%s' % i, "value": value})

    #print keywords.__len__()
    list_data = []
    total_record = 0
    parg = {}
    parg['keywords'] = keywords
    parg['has_sql'] = has_sql
    parg['is_centerQuery'] = is_centerQuery
    parg['has_sdate'] = has_sdate
    parg['has_edate'] = has_edate
    parg["allowChannel"] = allowChannel
    parg["the_query"] = the_query
    parg["usm"] = usm
    parg["list_query"] = list_query
    parg["is_select_server"] = is_select_server
    parg["list_group"] = list_group
    parg["list_server"] = list_server
    parg["list_channel"] = list_channel
    parg["s_list"] = s_list
    parg["server_id"] = server_id
    parg["query_id"] = query_id
    parg["is_search"] = is_search
    parg["group_id"] = group_id
    parg["field_id"] = field_id
    parg["field_value"] = field_value
    parg["list_field"] = list_field
    parg["sdate"] = sdate
    parg["edate"] = edate
    parg["fields"] = fields

    parg["page_num"] = page_num
    parg["page_size"] = page_size
    parg["total_record"] = total_record

    if not is_post_back and not ajax:  #如果没有点击查询按钮并不是ajax提交则不查询数据(第一次进入页面不查询数据)    ——zhenwei  2012-10-22
        return render_to_response('log/query_view.html', parg)

    if is_select_server and not is_centerQuery:
        if server_id > 0:
            try:
                conn = getConn(server_id)
            except:
                err_msg = '数据库链接出错!'
    else:
        conn = connections['read']

    if err_msg != '':
        return render_to_response('feedback.html', locals())

    try:
        if sdate != '':
            sdate = datetime.datetime.strptime(
                sdate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S')
            query_date = ' a.log_time>=\'%s\'' % sdate
        if edate != '':
            if query_date != '':
                query_date += ' and '
            edate = datetime.datetime.strptime(
                edate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S')
            query_date += ' a.log_time<=\'%s\'' % edate
    except:
        sdate = ''
        edate = ''

    #是否有channel 查询条件
    channel_condition = query_channel.__len__() > 0
    query_key = ''
    if not has_sql:

        query_field = the_query.select
        query_where = the_query.where
        query_order = the_query.order
        query_group = the_query.group

        field_name = ''
        for field_item in list_field:
            query_field = query_field.replace(field_item.name,
                                              field_item.field_name)
            query_where = query_where.replace(field_item.name,
                                              field_item.field_name)
            query_order = query_order.replace(field_item.name,
                                              field_item.field_name)
            query_group = query_group.replace(field_item.name,
                                              field_item.field_name)
            if field_id == field_item.id:
                field_name = field_item.field_name

        #处理字段值查询
        if field_name != '':
            the_values = ValueDefine.objects.filter(field_id=field_id,
                                                    value=field_value)
            if len(the_values) > 0:
                field_value = the_values[0].value_id
            if query_where != '':
                query_where += ' and '
            query_where += u'a.%s=\'%s\'' % (field_name, field_value)

        if query_date != '':
            if query_where != '':
                query_where += ' and '
            query_where += query_date

        if channel_condition:
            if query_where != '':
                query_where += ' and '
            query_where += 'a.log_channel in(%s)' % (','.join(query_channel))

        if query_where != '':
            query_where = 'where %s' % query_where

        if query_order != '':
            query_order = ' order by a.%s' % query_order

            if the_query.order_type == 1:
                query_order += ' desc'

        count_sql = 'select count(0) from log_%s a %s' % (log_define.key,
                                                          query_where)

        query_sql = 'select %s from log_%s a %s %s %s' % (
            query_field, log_define.key, query_where, query_order, pager_str)

        query_key = md5('%s_%s' % (query_sql, server_id))
        if exprot_file_key == '':
            exprot_file_key = md5('%s_%s' % (query_sql, server_id))
        #print(query_sql)
    else:

        query_sql = the_query.sql.replace('\r\n\t', ' ').replace('\r\n', ' ')

        if is_centerQuery and s_list.__len__() > 0:
            server_list_str = ' IN (%s) ' % (','.join(s_list))
            query_sql = re.sub('=[\s]*{{server_id}}', server_list_str,
                               query_sql)
        elif server_id > 0:
            query_sql = query_sql.replace('{{server_id}}', str(server_id))

        if query_date != '':
            query_sql = query_sql.replace("{{qdate}}", query_date)
            query_sql = query_sql.replace('{{sdate}}', '%s' % sdate).replace(
                '{{edate}}',
                '%s' % edate)  #支持自定对非log表的日期支持   -zhenwei 2012-10-25
        else:
            query_sql = query_sql.replace('and {{qdate}}',
                                          '').replace('where {{qdate}}', '')
            query_sql = query_sql.replace(
                '\'{{sdate}}\'', 'DATE(\'2001-01-01\')').replace(
                    '\'{{edate}}\'',
                    'NOW()')  #支持自定对非log表的日期支持   -zhenwei 2012-10-25

        if lost_param:
            err_msg = '请输入查询条件'
            return render_to_response('feedback.html', {"err_msg": err_msg})


#        if field_value != '':
#            query_sql = query_sql.replace("{{keyword}}", field_value)
#        else:
#            if -1 != query_sql.find('{{keyword}}'):
#                err_msg = '请输入查询条件'
#                return render_to_response('feedback.html', {"err_msg":err_msg})

        if channel_condition:
            query_sql = query_sql.replace(
                '{{qchannel}}',
                'log_channel in(%s)' % (','.join(query_channel)))
        else:
            query_sql = query_sql.replace('and {{qchannel}}',
                                          '').replace('where {{qchannel}}', '')

        if channel_condition:
            query_sql = query_sql.replace(
                '{{qchannela}}',
                'a.log_channel in(%s)' % (','.join(query_channel)))
        else:
            query_sql = query_sql.replace('and {{qchannela}}',
                                          '').replace('where {{qchannela}}',
                                                      '')

        if channel_condition:
            query_sql = query_sql.replace(
                '{{qchannelb}}',
                'b.log_channel in(%s)' % (','.join(query_channel)))
        else:
            query_sql = query_sql.replace('and {{qchannelb}}',
                                          '').replace('where {{qchannelb}}',
                                                      '')

        if channel_condition:
            query_sql = query_sql.replace(
                '{{qchannelid}}',
                'channel_id in (%s)' % (','.join(query_channel)))

        query_sql = filter_keyword(query_sql, field_value)

        count_sql = 'select count(0) from (%s) newTable' % query_sql

        if exprot_file_key == '':
            exprot_file_key = md5('%s_%s' % (query_sql, server_id))

        if query_sql.find('limit') == -1:
            query_sql = '%s %s' % (query_sql, pager_str)

        query_key = md5('%s_%s' % (query_sql, server_id))

    parg['has_sdate'] = has_sdate
    parg['has_edate'] = has_edate

    print count_sql
    print query_sql
    #raise Exception, count_sql
    #desc = cursor.description
    cursor = conn.cursor()
    # update log_create_role
    channelKey_id_dic = {}

    query_memcache = mc
    if the_query.cache_validate != None and 0 != the_query.cache_validate:
        query_memcache = MemcachedUtil(valid_date=the_query.cache_validate)

    for item1 in list_channel:
        channelKey_id_dic[item1.key] = int(item1.id)
    try:
        count_query_key = md5('%s_%s' % (count_sql, server_id))
        total_record = log_cache.get_query_count(count_sql, count_query_key,
                                                 cursor, query_memcache)
    except Exception, e:
        raise Exception, e
        print('query_view error:', e)
        return render_to_response('feedback.html', {"err_msg": "查询数据时出错"})
Beispiel #5
0
def get_result(content_json, reason_phrase, gm_def, result_code, usm):
    result = None
    result_def = json.loads(gm_def.result_define)
    if gm_def.result_type == 'json_result':
        result = {}
        result['content_json'] = json.dumps(content_json)

    elif gm_def.result_type == 'msg':
        result = result_def.get('msg_values', {})
        #print '-==============================='
        #print result
        #print result.get(str(content_json))
        result = result.get(str(content_json), u'错误,错误码:%s' % content_json)
    elif gm_def.result_type == 'form':

        list_infos = []

        form_items = result_def['form_items']

        form_items_list = []
        for key, value in form_items.items():
            #print key
            form_items_list.append({'key': key, 'json': value})
        form_items = form_items_list

        form_items.sort(cmp=lambda x, y: cmp(x['json'].get('order', 0), y[
            'json'].get('order', 0)))

        for _item in form_items:
            key = _item.get('key')
            def_item = _item.get('json')
            allow_empty = def_item.get('allow_empty', 0)
            has_value = False
            content_json_type = type(content_json)
            if dict == content_json_type:
                for r_key, value in content_json.items():
                    if key != r_key:
                        continue
                    has_value = True
                    item = FormItem(key, False, False, value, {}, 'text')
                    item.name = def_item.get('name', key)
                    item.is_modify = def_item.get('is_modify', False)
                    item.is_textarea = def_item.get('is_textarea', False)
                    item.is_append = def_item.get('is_append', False)
                    item.attr_type = def_item.get('type', 'text')
                    item.enum = def_item.get('enum', {})

                    list_infos.append(item)
            elif list == content_json_type:
                item = FormItem(key, False, False, value, {}, 'text')
                item.name = def_item.get('name', key)
                item.is_modify = def_item.get('is_modify', False)
                item.is_textarea = def_item.get('is_textarea', False)
                item.is_append = def_item.get('is_append', False)
                item.attr_type = def_item.get('type', 'text')
                item.enum = def_item.get('enum', {})
                item.value = json.dumps(content_json)
                list_infos.append(item)

            if not has_value and allow_empty:

                item = FormItem(key, False, False, '', {}, 'text')
                item.name = def_item.get('name', key)
                item.is_modify = def_item.get('is_modify', False)
                item.is_textarea = def_item.get('is_textarea', False)
                item.is_append = def_item.get('is_append', False)
                item.attr_type = def_item.get('type', 'text')
                item.enum = def_item.get('enum', {})

                list_infos.append(item)

        result = {}
        result['form_action'] = result_def.get('form_action', '')
        result['form_type'] = result_def.get('form_type', '')
        result['form_key'] = result_def.get('form_key', '')

        server_list_chkbox = result_def.get('server_list_chkbox', False)

        if server_list_chkbox:

            group_server_dic = {}
            if usm.current_userRole_is_root():
                group_list = center_cache.get_group_list()
                for item in group_list:
                    group_server_dic[item.name] = center_cache.get_server_list(
                        item.id)
            else:
                group_server_dic['服务器'] = center_cache.get_user_server_list(
                    usm.get_the_user())

            result['group_server_dic'] = group_server_dic

        result['server_list_chkbox'] = server_list_chkbox
        result['list_infos'] = list_infos

    elif gm_def.result_type == 'list':
        list_items_def = result_def.get('list_items', {})
        list_action = result_def.get('action', [])

        #排序
        #先转数组

        field_array = []
        for key, value in list_items_def.items():

            field_array.append({"key": key, "json": value})
        #排序
        try:
            field_array.sort(cmp=lambda x, y: cmp(x['json'].get('order', 0), y[
                'json'].get('order', 0)))
        except Exception, ex:
            print ex
        list_data = []
        if list != type(content_json):
            try:
                print content_json
                content_json = json.loads(content_json)
            except Exception, ex:
                print 'get_reult type is list json loads error:'
                print ex
                content_json = []
Beispiel #6
0
        for item in def_params:
            if server_info.get(item[0], None) != None:
                remark = ''
                if 4 <= item.__len__():
                    remark = item[3]
                list_infos.append({
                    'name': item[1],
                    'key': item[0],
                    'value': server_info.get(item[0]),
                    'is_modify': item[2],
                    'remark': remark
                })
    except Exception, e:
        err_msg = '发生错误:%s!' % e

    group_list = center_cache.get_group_list()
    group_server_list = center_cache.get_cache_server_list_group_by()

    parg = {}
    parg['list_infos'] = list_infos
    parg["config_type"] = config_type
    parg["net_id"] = net_id
    parg["server_id"] = server_id
    parg["group_list"] = group_list
    parg["group_server_list"] = group_server_list
    parg["err_msg"] = err_msg

    return render_to_response('game/server_info.html', parg)


def get_server_info(server_id, net_id=-1, config_type=0):
Beispiel #7
0
def player_list(request, server_id=0):
    page_size = 30
    page_num = int(request.GET.get("page_num", "1"))
    is_block = int(request.GET.get("block", 0))
    group_id = int(request.GET.get("group_id", 0))
    post_back = int(request.GET.get('post_back', '0'))

    list_group = center_cache.get_group_list()

    if (page_num < 1):
        page_num = 1

    usm = UserStateManager(request)
    the_user = usm.get_the_user()

    list_channel = center_cache.get_channel_list()

    itemChannelList = {}
    for item in list_channel:
        itemChannelList[item.id] = item.name

    list_group_server = []
    if group_id != 0:
        list_group_server = center_cache.get_group_server_list(group_id)

    if usm.current_userRole_is_root():
        list_server = center_cache.get_server_list()
    else:
        list_server = center_cache.get_user_server_list(the_user)

    tmp_list_server = []
    if 0 != list_group_server.__len__():
        for item in list_group_server:
            if list_server.__contains__(item):
                tmp_list_server.append(item)
        list_server = tmp_list_server

    itemServerList = {}
    for item in list_server:
        itemServerList[item.id] = item.name

    player_key = request.GET.get('key', '')
    key_type = request.GET.get('key_type', '0')
    user_type = int(request.GET.get('user_type', '-1'))
    channel_id = int(request.session.get('channelId', '0'))

    server_id = int(request.GET.get("server_id", "0"))

    if server_id <= 0:
        server_id = int(request.session.get("serverId", "0"))
    if server_id <= 0 and len(list_server) > 0:
        server_id = list_server[0].id

    #账号状态
    status_condition = 0
    if is_block == 1:
        status_condition = -1

    total_record = 0
    player_list = []
    player_list1 = []

    if 0 != post_back and server_id > 0:
        conn = getConn(server_id)
        cursor = conn.cursor()

        query = []
        query.append("status=%d" % status_condition)
        if channel_id > 0:
            query.append('channel_id=%d' % channel_id)

        if player_key != "":
            if key_type == '0':
                query.append('player_id=\'%s\'' % player_key)
            elif key_type == '1':
                query.append('player_name like \'%s%%\'' %
                             player_key.encode('utf-8'))
            elif key_type == '2':
                query.append('link_key=\'%s\'' % player_key)
            elif key_type == '3':
                query.append('mobile_key=\'%s\'' % player_key)
        if user_type > -1:
            query.append('user_type=%d' % player_key)

        if not usm.current_userRole_is_root():
            channel_list = center_cache.get_user_channel_list(the_user)
            channel_id_list_query = ' channel_id in (%s) ' % ','.join(
                [str(item.id) for item in channel_list])
            query.append(channel_id_list_query)

        if len(query) > 0:
            sql1 = 'select count(1) from player_%d where %s' % (
                server_id, ' and '.join(query))
            sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d where %s order by id desc limit %d,%d' % (
                server_id, ' and '.join(query),
                (page_num - 1) * page_size, page_num * page_size)
        else:
            sql1 = 'select count(1) from player_%d' % server_id
            sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d order by id desc limit %d,%d' % (
                server_id, (page_num - 1) * page_size, page_num * page_size)

        print(sql1, sql2)
        cursor.execute(sql1)
        count_list = cursor.fetchone()
        total_record = int(count_list[0])
        if total_record > 0:
            cursor.execute(sql2)
            player_list1 = cursor.fetchall()
        user_type_name = {
            0: '游爱',
            1: '当乐',
            2: 'UC',
            3: '91',
            4: '云游',
            5: '飞流',
            6: '乐逗',
            8: '小虎',
            9: '4399',
            10: 'facebook',
            11: 'qq'
        }
        for item in player_list1:
            item = list(item)

            item[2] = itemChannelList.get(int(item[2]), item[2])

            item[3] = user_type_name.get(int(item[3]), item[3])

            player_list.append(item)
        cursor.close()
    parg = {}
    parg["server_id"] = server_id
    parg["list_group"] = list_group
    parg["list_server"] = list_server
    parg["player_key"] = player_key
    parg["server_id"] = server_id
    parg["player_list"] = player_list
    parg["is_block"] = is_block
    parg["usm"] = usm

    parg["page_num"] = page_num
    parg["page_size"] = page_size
    parg["total_record"] = total_record

    return render_to_response('player/player_list.html', parg)