Exemplo n.º 1
0
def xmlToFlowPointList(ret, reportType):
    ''' 返回xml 转换成 带 FlowPoint对象列表的FlowProcessResult对象'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = getDateFormat(reportType)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    flowPointListNode = util.getChildNode(doc, 'flow-report')
    flowSummary = util.getChildNodeText(flowPointListNode, 'flow-summary')
    flowPointList = []
    flowDataList = util.getChildNodeList(flowPointListNode, 'flow-data')
    for flowNode in flowDataList:
        pointStr = util.getChildNodeText(flowNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        flow = util.getChildNodeText(flowNode, 'flow')
        flowPoint = FlowPoint(point, flow)
        flowPointList.append(flowPoint)
    return FlowProcessResult(ret.status,
                             'OK',
                             xCncRequestId=requestId,
                             flowPoints=flowPointList,
                             flowSummary=flowSummary)
Exemplo n.º 2
0
def parseVisitControlRulesList(nodeList):
    vistControlRulesList = []
    for node in nodeList:
        pathPattern = util.getChildNodeText(node, 'path-pattern')
        allowNullReffer = util.getChildNodeText(node, 'allownullreferer')
        validReferRootNode = util.getChildNode(node, "valid-referers")
        validRNode = util.getChildNodeList(validReferRootNode, 'referer')
        validRefers = []
        for ref in validRNode:
            validRefers.append(util.getChildNodeText(ref, "referer"))

        invalidReferRootNode = util.getChildNode(node, "invalid-referers")
        invalidRNode = util.getChildNodeList(invalidReferRootNode, 'referer')
        invalidRefers = []
        for ref in invalidRNode:
            invalidRefers.append(util.getChildNodeText(ref, "referer"))

        forbiddenIps = splitStr(util.getChildNodeText(node, 'forbidden-ips'))

        visitControlRule = VisitControlRule(pathPattern, allowNullReffer,
                                            validRefers, invalidRefers,
                                            forbiddenIps)
        vistControlRulesList.append(visitControlRule)

    return vistControlRulesList
Exemplo n.º 3
0
def xmlToLogList(ret):
    ''' 返回xml 转换成 带Log对象列表的LogProcessResult对象 '''
    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)
   
    isoFormat = "%Y-%m-%d-%H%M"
    
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    logListNode = util.getChildNode(doc, 'logs')
    logList = []
    logDataList = util.getChildNodeList(logListNode, 'log')
    for logNode in logDataList:
        dateFromStr = util.getChildNodeText(logNode, 'datefrom')
        dateToStr = util.getChildNodeText(logNode, 'dateto')
        url = util.getChildNodeText(logNode, 'log-url')
        fileSize = util.getChildNodeText(logNode, 'file-size')
        
        dateFrom = datetime.datetime.strptime(dateFromStr, isoFormat)
        dateTo = datetime.datetime.strptime(dateToStr, isoFormat)
        
        log = Log(dateFrom, dateTo, url, fileSize)
        logList.append(log)
    return LogProcessResult(ret.status, 'OK', xCncRequestId = requestId, logs = logList);
Exemplo n.º 4
0
def xmlToLogList(ret):
    ''' 返回xml 转换成 带Log对象列表的LogProcessResult对象 '''
    global X_CNC_REQUEST_ID
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = "%Y-%m-%d-%H%M"

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    logListNode = util.getChildNode(doc, 'logs')
    logList = []
    logDataList = util.getChildNodeList(logListNode, 'log')
    for logNode in logDataList:
        dateFromStr = util.getChildNodeText(logNode, 'datefrom')
        dateToStr = util.getChildNodeText(logNode, 'dateto')
        url = util.getChildNodeText(logNode, 'log-url')
        fileSize = util.getChildNodeText(logNode, 'file-size')

        dateFrom = datetime.datetime.strptime(dateFromStr, isoFormat)
        dateTo = datetime.datetime.strptime(dateToStr, isoFormat)

        log = Log(dateFrom, dateTo, url, fileSize)
        logList.append(log)
    return LogProcessResult(ret.status,
                            'OK',
                            xCncRequestId=requestId,
                            logs=logList)
Exemplo n.º 5
0
def parseQueryStringSettingListNode(nodeList):
    queryStringSettingList = []
    for queryStringSetting in nodeList:
        pathPattern = util.getChildNodeText(queryStringSetting, 'path-pattern')
        ignoreQueryStringStr = util.getChildNodeText(queryStringSetting, 'ignore-query-string')
        if ignoreQueryStringStr == "false":
            ignoreQueryString = False
        else:
            ignoreQueryString = True 
        queryStringSetting = QueryStringSetting(pathPattern, ignoreQueryString)
        queryStringSettingList.append(queryStringSetting)
    return queryStringSettingList
Exemplo n.º 6
0
def parseQueryStringSettingListNode(nodeList):
    queryStringSettingList = []
    for queryStringSetting in nodeList:
        pathPattern = util.getChildNodeText(queryStringSetting, 'path-pattern')
        ignoreQueryStringStr = util.getChildNodeText(queryStringSetting,
                                                     'ignore-query-string')
        if ignoreQueryStringStr == "false":
            ignoreQueryString = False
        else:
            ignoreQueryString = True
        queryStringSetting = QueryStringSetting(pathPattern, ignoreQueryString)
        queryStringSettingList.append(queryStringSetting)
    return queryStringSettingList
Exemplo n.º 7
0
def parseCacheBehaviorList(nodeList):
    cacheBehaviorList = []
    for cacheBehavior in nodeList:
        pathPattern = util.getChildNodeText(cacheBehavior, 'path-pattern')
        priority = util.getChildNodeText(cacheBehavior, 'priority')
        ignoreCacheControlStr = util.getChildNodeText(cacheBehavior, 'ignore-cache-control')
        if ignoreCacheControlStr == "false":
            ignoreCacheControl = False
        else:
            ignoreCacheControl = True 
        cacheTTL = util.getChildNodeText(cacheBehavior, 'cache-ttl')
        cacheBehavior = CacheBehavior(pathPattern, ignoreCacheControl, cacheTTL)
        cacheBehaviorList.append(cacheBehavior)
    return cacheBehaviorList
Exemplo n.º 8
0
def parseAdvOriginConfigList(nodeList):
    advOriginConfigList = []
    for advOriginConfigNode in nodeList:
        ispsList = util.getChildNodeText(advOriginConfigNode, 'isp')
        masterIpsList = util.getChildNodeText(advOriginConfigNode, 'master-ips')
        backupIpsList = util.getChildNodeText(advOriginConfigNode, 'backup-ips')
        detectUrl = util.getChildNodeText(advOriginConfigNode, 'detect-url')
        detectPeriod = util.getChildNodeText(advOriginConfigNode, 'detect-period')
        isps = splitStr(ispsList)
        masterIps = splitStr(masterIpsList)
        backupIps = splitStr(backupIpsList)
        advOriginConfig = AdvOriginConfig(isps = isps, masterIps = masterIps, backupIps = backupIps, 
                                          detectUrl = detectUrl, detectPeriod = detectPeriod)
        advOriginConfigList.append(advOriginConfig)
    return advOriginConfigList
Exemplo n.º 9
0
def parseCacheBehaviorList(nodeList):
    cacheBehaviorList = []
    for cacheBehavior in nodeList:
        pathPattern = util.getChildNodeText(cacheBehavior, 'path-pattern')
        priority = util.getChildNodeText(cacheBehavior, 'priority')
        ignoreCacheControlStr = util.getChildNodeText(cacheBehavior,
                                                      'ignore-cache-control')
        if ignoreCacheControlStr == "false":
            ignoreCacheControl = False
        else:
            ignoreCacheControl = True
        cacheTTL = util.getChildNodeText(cacheBehavior, 'cache-ttl')
        cacheBehavior = CacheBehavior(pathPattern, ignoreCacheControl,
                                      cacheTTL)
        cacheBehaviorList.append(cacheBehavior)
    return cacheBehaviorList
Exemplo n.º 10
0
def xmlToDomainList(ret):
    ''' 返回xml 转换成 带 Domain对象列表的ProcessResult对象, 在查询用户下所有频道时候使用'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    domainListNode = util.getChildNode(doc, 'domain-list')
    domainList = []
    domainSummaryList = util.getChildNodeList(domainListNode, 'domain-summary')
    for domainNode in domainSummaryList:
        domainId = util.getChildNodeText(domainNode, 'domain-id')
        cname = util.getChildNodeText(domainNode, 'cname')
        domainName = util.getChildNodeText(domainNode, 'domain-name')
        status = util.getChildNodeText(domainNode, 'status')
        serviceType = util.getChildNodeText(domainNode, "service-type")
        enabled = util.getChildNodeText(domainNode, 'enabled') == 'true'
        cdnServiceStatus = util.getChildNodeText(
            domainNode, 'cdn-service-status') == 'true'
        domainSummary = DomainSummary(domainId, domainName, cname, status,
                                      enabled, serviceType, cdnServiceStatus)
        domainList.append(domainSummary)
    return ProcessResult(0,
                         'OK',
                         xCncRequestId=requestId,
                         domainSummarys=domainList)
Exemplo n.º 11
0
def parseAdvOriginConfigList(nodeList):
    advOriginConfigList = []
    for advOriginConfigNode in nodeList:
        ispsList = util.getChildNodeText(advOriginConfigNode, 'isp')
        masterIpsList = util.getChildNodeText(advOriginConfigNode,
                                              'master-ips')
        backupIpsList = util.getChildNodeText(advOriginConfigNode,
                                              'backup-ips')
        detectUrl = util.getChildNodeText(advOriginConfigNode, 'detect-url')
        detectPeriod = util.getChildNodeText(advOriginConfigNode,
                                             'detect-period')
        isps = splitStr(ispsList)
        masterIps = splitStr(masterIpsList)
        backupIps = splitStr(backupIpsList)
        advOriginConfig = AdvOriginConfig(isps=isps,
                                          masterIps=masterIps,
                                          backupIps=backupIps,
                                          detectUrl=detectUrl,
                                          detectPeriod=detectPeriod)
        advOriginConfigList.append(advOriginConfig)
    return advOriginConfigList
Exemplo n.º 12
0
def xmlToHitPointList(ret, reportType):
    ''' 返回xml 转换成 带 HitPoint对象列表的HitProcessResult对象 '''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    isoFormat = getDateFormat(reportType)
   
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    hitPointListNode = util.getChildNode(doc, 'hit-report')
    hitPointList = []
    hitDataList = util.getChildNodeList(hitPointListNode, 'hit-data')
    for hitNode in hitDataList:
        pointStr = util.getChildNodeText(hitNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        hit = util.getChildNodeText(hitNode, 'hit')
        hitPoint = HitPoint(point, hit)
        hitPointList.append(hitPoint)
    return HitProcessResult(ret.status, 'OK', xCncRequestId = requestId, hitPoints = hitPointList)
Exemplo n.º 13
0
def xmlToFlowPointList(ret, reportType):
    ''' 返回xml 转换成 带 FlowPoint对象列表的FlowProcessResult对象'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
   
    isoFormat = getDateFormat(reportType)
   
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    flowPointListNode = util.getChildNode(doc, 'flow-report')
    flowSummary = util.getChildNodeText(flowPointListNode, 'flow-summary')
    flowPointList = []
    flowDataList = util.getChildNodeList(flowPointListNode, 'flow-data')
    for flowNode in flowDataList:
        pointStr = util.getChildNodeText(flowNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        flow = util.getChildNodeText(flowNode, 'flow')
        flowPoint = FlowPoint(point, flow)
        flowPointList.append(flowPoint)
    return FlowProcessResult(ret.status, 'OK', xCncRequestId = requestId, flowPoints = flowPointList, flowSummary = flowSummary);
Exemplo n.º 14
0
def parseVisitControlRulesList(nodeList):
    vistControlRulesList = []
    for node in nodeList:
        pathPattern = util.getChildNodeText(node, 'path-pattern')
        allowNullReffer = util.getChildNodeText(node, 'allownullreferer')
        validReferRootNode = util.getChildNode(node, "valid-referers")
        validRNode = util.getChildNodeList(validReferRootNode, 'referer')
        validRefers = []
        for ref in validRNode:
            validRefers.append(util.getChildNodeText(ref, "referer"))
        
        invalidReferRootNode = util.getChildNode(node, "invalid-referers")
        invalidRNode = util.getChildNodeList(invalidReferRootNode, 'referer')
        invalidRefers = []
        for ref in invalidRNode:
            invalidRefers.append(util.getChildNodeText(ref, "referer"))
        
        forbiddenIps = splitStr(util.getChildNodeText(node, 'forbidden-ips'))
        
        visitControlRule = VisitControlRule(pathPattern, allowNullReffer, validRefers, invalidRefers, forbiddenIps)
        vistControlRulesList.append(visitControlRule)
        
    return vistControlRulesList
Exemplo n.º 15
0
def xmlToHitPointList(ret, reportType):
    ''' 返回xml 转换成 带 HitPoint对象列表的HitProcessResult对象 '''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    isoFormat = getDateFormat(reportType)

    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    hitPointListNode = util.getChildNode(doc, 'hit-report')
    hitPointList = []
    hitDataList = util.getChildNodeList(hitPointListNode, 'hit-data')
    for hitNode in hitDataList:
        pointStr = util.getChildNodeText(hitNode, 'timestamp')
        gaga = re.sub('24:00:00', '00:00:00', pointStr)
        point = datetime.datetime.strptime(gaga, isoFormat)
        hit = util.getChildNodeText(hitNode, 'hit')
        hitPoint = HitPoint(point, hit)
        hitPointList.append(hitPoint)
    return HitProcessResult(ret.status,
                            'OK',
                            xCncRequestId=requestId,
                            hitPoints=hitPointList)
Exemplo n.º 16
0
def xmlToDomainList(ret):
    ''' 返回xml 转换成 带 Domain对象列表的ProcessResult对象, 在查询用户下所有频道时候使用'''
    global X_CNC_REQUEST_ID, X_CNC_LOCATION
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logging.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    domainListNode = util.getChildNode(doc, 'domain-list')
    domainList = []
    domainSummaryList = util.getChildNodeList(domainListNode, 'domain-summary')
    for domainNode in domainSummaryList:
        domainId = util.getChildNodeText(domainNode, 'domain-id')
        cname = util.getChildNodeText(domainNode, 'cname')
        domainName = util.getChildNodeText(domainNode, 'domain-name')
        status = util.getChildNodeText(domainNode, 'status')
        serviceType = util.getChildNodeText(domainNode, "service-type")
        enabled = util.getChildNodeText(domainNode, 'enabled') == 'true'
        cdnServiceStatus = util.getChildNodeText(domainNode, 'cdn-service-status') == 'true'
        domainSummary = DomainSummary(domainId, domainName, cname,
                  status, enabled,
                  serviceType, cdnServiceStatus)
        domainList.append(domainSummary)
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domainSummarys = domainList);
Exemplo n.º 17
0
def xmlToDomain(ret):
    ''' 返回xml 转换成 带 Domain对象的ProcessResult对象, 在查询频道信息的时候使用'''

    global X_CNC_REQUEST_ID, X_CNC_LOCATION, logger
    requestId = ret.getheader(X_CNC_REQUEST_ID)

    xmlString = ret.read().decode("utf-8")
    logger.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)

    domainNode = util.getChildNode(doc, 'domain')
    domainName = util.getChildNodeText(domainNode, 'domain-name')
    domainId = util.getChildNodeText(domainNode, 'domain-id')
    serviceType = util.getChildNodeText(domainNode, 'service-type')
    comment = util.getChildNodeText(domainNode, 'comment')
    serviceAreas = util.getChildNodeText(domainNode, 'service-areas')
    enabled = util.getChildNodeText(domainNode, 'enabled')
    cname = util.getChildNodeText(domainNode, 'cname')
    status = util.getChildNodeText(domainNode, 'status')

    domain = Domain(domainName=domainName,
                    serviceType=serviceType,
                    domainId=domainId,
                    comment=comment,
                    serviceAreas=serviceAreas,
                    enabled=enabled,
                    cname=cname,
                    status=status)

    originConfigNode = util.getChildNode(domainNode, 'origin-config')
    if originConfigNode is not None:
        originIpsStr = util.getChildNodeText(originConfigNode, 'origin-ips')
        originIps = splitStr(originIpsStr)
        originDomainName = util.getChildNodeText(originConfigNode,
                                                 'origin-domain-name')
        advOriginConfigListRootNode = util.getChildNode(
            originConfigNode, 'adv-origin-configs')
        if advOriginConfigListRootNode is not None:
            advOriginConfigListNode = util.getChildNodeList(
                advOriginConfigListRootNode, 'adv-origin-config')
            advOriginConfigs = []
            if advOriginConfigListNode is not None:
                advOriginConfigs = parseAdvOriginConfigList(
                    advOriginConfigListNode)
                originConfig = OriginConfig(originIps, originDomainName,
                                            advOriginConfigs)
                domain.originConfig = originConfig
        else:
            originConfig = OriginConfig(originIps, originDomainName)
            domain.originConfig = originConfig

    queryStringSettingListRootNode = util.getChildNode(
        domainNode, 'query-string-settings')
    if queryStringSettingListRootNode is not None:
        queryStringSettingListNode = util.getChildNodeList(
            queryStringSettingListRootNode, 'query-string-setting')
        if queryStringSettingListNode is not None:
            queryStringSettingList = parseQueryStringSettingListNode(
                queryStringSettingListNode)
            domain.queryStringSettings = queryStringSettingList

    cacheBehaviorListRootNode = util.getChildNode(domainNode,
                                                  'cache-behaviors')
    if cacheBehaviorListRootNode is not None:
        cacheBehaviorListNode = util.getChildNodeList(
            cacheBehaviorListRootNode, 'cache-behavior')
        if cacheBehaviorListNode is not None:
            cacheBehaviorList = parseCacheBehaviorList(cacheBehaviorListNode)
            domain.cacheBehaviors = cacheBehaviorList

    visitControlRulesListRootNode = util.getChildNode(domainNode,
                                                      'visit-control-rules')
    if visitControlRulesListRootNode is not None:
        visitControlRulesListNode = util.getChildNodeList(
            visitControlRulesListRootNode, 'visit-control-rule')
        if visitControlRulesListNode is not None:
            visitControlRulesList = parseVisitControlRulesList(
                visitControlRulesListNode)
            domain.visitControlRules = visitControlRulesList

    return ProcessResult(0, 'OK', xCncRequestId=requestId, domain=domain)
Exemplo n.º 18
0
def xmlToDomain(ret):
    ''' 返回xml 转换成 带 Domain对象的ProcessResult对象, 在查询频道信息的时候使用'''
    
    global X_CNC_REQUEST_ID, X_CNC_LOCATION, logger
    requestId = ret.getheader(X_CNC_REQUEST_ID)
    
    xmlString = ret.read().decode("utf-8")
    logger.debug("response:" + xmlString)
    doc = minidom.parseString(xmlString)
    
    domainNode = util.getChildNode(doc, 'domain')
    domainName = util.getChildNodeText(domainNode, 'domain-name')
    domainId = util.getChildNodeText(domainNode, 'domain-id')
    serviceType = util.getChildNodeText(domainNode, 'service-type')
    comment = util.getChildNodeText(domainNode, 'comment')
    serviceAreas = util.getChildNodeText(domainNode, 'service-areas')
    enabled = util.getChildNodeText(domainNode, 'enabled')
    cname = util.getChildNodeText(domainNode, 'cname')
    status = util.getChildNodeText(domainNode, 'status')
    
    domain = Domain(domainName = domainName, 
                    serviceType = serviceType, 
                    domainId = domainId,
                    comment = comment, 
                    serviceAreas = serviceAreas,
                    enabled = enabled, 
                    cname = cname,
                    status = status)
    
    originConfigNode = util.getChildNode(domainNode, 'origin-config')
    if originConfigNode is not None:
        originIpsStr = util.getChildNodeText(originConfigNode, 'origin-ips')
        originIps = splitStr(originIpsStr)
        originDomainName = util.getChildNodeText(originConfigNode, 'origin-domain-name')
        advOriginConfigListRootNode = util.getChildNode(originConfigNode, 'adv-origin-configs')
        if advOriginConfigListRootNode is not None:
            advOriginConfigListNode = util.getChildNodeList(advOriginConfigListRootNode, 'adv-origin-config')
            advOriginConfigs = []
            if advOriginConfigListNode is not None:
                advOriginConfigs = parseAdvOriginConfigList(advOriginConfigListNode)
                originConfig = OriginConfig(originIps, originDomainName, advOriginConfigs)
                domain.originConfig = originConfig   
        else:
            originConfig = OriginConfig(originIps, originDomainName)
            domain.originConfig = originConfig   
    
    queryStringSettingListRootNode = util.getChildNode(domainNode, 'query-string-settings')
    if queryStringSettingListRootNode is not None:
        queryStringSettingListNode = util.getChildNodeList(queryStringSettingListRootNode, 'query-string-setting')
        if queryStringSettingListNode is not None:
            queryStringSettingList = parseQueryStringSettingListNode(queryStringSettingListNode)
            domain.queryStringSettings = queryStringSettingList
    
    cacheBehaviorListRootNode = util.getChildNode(domainNode, 'cache-behaviors')
    if cacheBehaviorListRootNode is not None:
        cacheBehaviorListNode = util.getChildNodeList(cacheBehaviorListRootNode, 'cache-behavior')
        if cacheBehaviorListNode is not None:
            cacheBehaviorList = parseCacheBehaviorList(cacheBehaviorListNode)
            domain.cacheBehaviors = cacheBehaviorList
    
    visitControlRulesListRootNode = util.getChildNode(domainNode, 'visit-control-rules')
    if visitControlRulesListRootNode is not None:
        visitControlRulesListNode = util.getChildNodeList(visitControlRulesListRootNode, 'visit-control-rule')
        if visitControlRulesListNode is not None:
            visitControlRulesList = parseVisitControlRulesList(visitControlRulesListNode)
            domain.visitControlRules = visitControlRulesList
        
    return ProcessResult(0, 'OK', xCncRequestId = requestId, domain = domain);