Example #1
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
Example #2
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)
Example #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);
Example #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)
Example #5
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)
Example #6
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
Example #7
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)
Example #8
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);
Example #9
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);
Example #10
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)
Example #11
0
def domainToXml(domain):
    ''' Domain 对象 转换成 xml '''

    doc = dom.getDOMImplementation().createDocument('', 'domain', '')
    domainNode = util.getChildNode(doc, 'domain')
    util.addElement(doc, domainNode, 'version', "1.0.0")
    if domain.domainName is not None:
        util.addElement(doc, domainNode, 'domain-name', domain.domainName)
    if domain.serviceType is not None:
        util.addElement(doc, domainNode, 'service-type', domain.serviceType)
    if domain.comment is not None:
        util.addElement(doc, domainNode, 'comment', domain.comment)

    if domain.serviceAreas is not None:
        util.addElement(doc, domainNode, 'service-areas', domain.serviceAreas)
    else:
        util.addElement(doc, domainNode, 'service-areas', 'cn')

    if domain.originConfig is not None:
        originConfigNode = util.addElement(doc, domainNode, 'origin-config')
        if domain.originConfig.originIps is not None:
            originIps = domain.originConfig.originIps
            util.addElement(doc, originConfigNode, 'origin-ips',
                            ';'.join(originIps))
        if domain.originConfig.originDomainName is not None:
            util.addElement(doc, originConfigNode, 'origin-domain-name',
                            domain.originConfig.originDomainName)
        if domain.originConfig.advOriginConfigs is not None:
            advOriginConfigsNode = util.addElement(doc, originConfigNode,
                                                   'adv-origin-configs')
            for advOriginConfig in domain.originConfig.advOriginConfigs:
                isps = advOriginConfig.isps
                advOriginConfigNode = util.addElement(doc,
                                                      advOriginConfigsNode,
                                                      'adv-origin-config')
                util.addElement(doc, advOriginConfigNode, 'isp',
                                ';'.join(isps))
                util.addElement(doc, advOriginConfigNode, 'master-ips',
                                ';'.join(advOriginConfig.masterIps))
                util.addElement(doc, advOriginConfigNode, 'backup-ips',
                                ';'.join(advOriginConfig.backupIps))
                util.addElement(doc, advOriginConfigNode, 'detect-url',
                                advOriginConfig.detectUrl)
                util.addElement(doc, advOriginConfigNode, 'detect-period',
                                advOriginConfig.detectPeriod)

    if domain.queryStringSettings is not None:
        queryStringSettingsNode = util.addElement(doc, domainNode,
                                                  'query-string-settings')
        for queryStringSetting in domain.queryStringSettings:
            queryStringSettingNode = util.addElement(doc,
                                                     queryStringSettingsNode,
                                                     'query-string-setting')
            util.addElement(doc, queryStringSettingNode, 'path-pattern',
                            queryStringSetting.pathPattern)
            if queryStringSetting.ignoreQueryString == False:
                util.addElement(doc, queryStringSettingNode,
                                'ignore-query-string', "false")
            else:
                util.addElement(doc, queryStringSettingNode,
                                'ignore-query-string', "true")

    if domain.cacheBehaviors is not None:
        cacheBehaviorsNode = util.addElement(doc, domainNode,
                                             'cache-behaviors')
        for cacheBehavior in domain.cacheBehaviors:
            cacheBehaviorNode = util.addElement(doc, cacheBehaviorsNode,
                                                'cache-behavior')
            util.addElement(doc, cacheBehaviorNode, 'path-pattern',
                            cacheBehavior.pathPattern)
            if cacheBehavior.ignoreCacheControl == False:
                util.addElement(doc, cacheBehaviorNode, 'ignore-cache-control',
                                "false")
            else:
                util.addElement(doc, cacheBehaviorNode, 'ignore-cache-control',
                                "true")
            util.addElement(doc, cacheBehaviorNode, 'cache-ttl',
                            cacheBehavior.cacheTtl)

    if domain.visitControlRules is not None:
        visitControlRulesNode = util.addElement(doc, domainNode,
                                                'visit-control-rules')
        for visitControl in domain.visitControlRules:
            visitControlNode = util.addElement(doc, visitControlRulesNode,
                                               "visit-control-rule")
            if visitControl.allowNullReferer == True:
                util.addElement(doc, visitControlNode, 'allownullreferer',
                                "true")
            elif visitControl.allowNullReferer == False:
                util.addElement(doc, visitControlNode, 'allownullreferer',
                                "false")

            util.addElement(doc, visitControlNode, 'path-pattern',
                            visitControl.pathPattern)
            validRNode = util.addElement(doc, visitControlNode,
                                         'valid-referers')
            validReferers = visitControl.validReferers
            if validReferers is not None and len(validReferers) > 0:
                for referer in validReferers:
                    util.addElement(doc, validRNode, 'referer', referer)
            invalidRNode = util.addElement(doc, visitControlNode,
                                           'invalid-referers')
            invalidReferers = visitControl.invalidReferers
            if invalidReferers is not None and len(invalidReferers) > 0:
                for referer in invalidReferers:
                    util.addElement(doc, invalidRNode, 'referer', referer)
            forbiddenIps = visitControl.forbiddenIps
            if forbiddenIps is not None and len(forbiddenIps) > 0:
                util.addElement(doc, visitControlNode, 'forbidden-ips',
                                ';'.join(visitControl.forbiddenIps))
    return doc.toprettyxml(indent="", newl="", encoding='utf-8')
Example #12
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)
Example #13
0
def domainToXml(domain):
    ''' Domain 对象 转换成 xml '''
    
    doc = dom.getDOMImplementation().createDocument('', 'domain', '')
    domainNode = util.getChildNode(doc, 'domain')
    util.addElement(doc, domainNode, 'version', "1.0.0")
    if domain.domainName is not None:
        util.addElement(doc, domainNode, 'domain-name',  domain.domainName)
    if domain.serviceType is not None:
        util.addElement(doc, domainNode, 'service-type',  domain.serviceType)
    if domain.comment is not None:
        util.addElement(doc, domainNode, 'comment',  domain.comment)
    
    if domain.serviceAreas is not None:
        util.addElement(doc, domainNode, 'service-areas', domain.serviceAreas)
    else:
        util.addElement(doc, domainNode, 'service-areas', 'cn')
    
    if domain.originConfig is not None:
        originConfigNode = util.addElement(doc, domainNode, 'origin-config')
        if domain.originConfig.originIps is not None:
            originIps = domain.originConfig.originIps
            util.addElement(doc, originConfigNode, 'origin-ips', ';'.join(originIps))
        if domain.originConfig.originDomainName is not None:
            util.addElement(doc, originConfigNode, 'origin-domain-name', domain.originConfig.originDomainName)
        if domain.originConfig.advOriginConfigs is not None:
            advOriginConfigsNode = util.addElement(doc, originConfigNode, 'adv-origin-configs')
            for advOriginConfig in domain.originConfig.advOriginConfigs:
                isps = advOriginConfig.isps
                advOriginConfigNode = util.addElement(doc, advOriginConfigsNode, 'adv-origin-config')
                util.addElement(doc, advOriginConfigNode, 'isp', ';'.join(isps))
                util.addElement(doc, advOriginConfigNode, 'master-ips', ';'.join(advOriginConfig.masterIps))
                util.addElement(doc, advOriginConfigNode, 'backup-ips', ';'.join(advOriginConfig.backupIps))
                util.addElement(doc, advOriginConfigNode, 'detect-url', advOriginConfig.detectUrl)
                util.addElement(doc, advOriginConfigNode, 'detect-period', advOriginConfig.detectPeriod)                
    
    if domain.queryStringSettings is not None:
        queryStringSettingsNode = util.addElement(doc, domainNode, 'query-string-settings')
        for queryStringSetting in domain.queryStringSettings:
            queryStringSettingNode = util.addElement(doc, queryStringSettingsNode, 'query-string-setting')
            util.addElement(doc, queryStringSettingNode, 'path-pattern', queryStringSetting.pathPattern)
            if queryStringSetting.ignoreQueryString == False:
                util.addElement(doc, queryStringSettingNode, 'ignore-query-string', "false")
            else:
                util.addElement(doc, queryStringSettingNode, 'ignore-query-string', "true")
    
    if domain.cacheBehaviors is not None:
        cacheBehaviorsNode = util.addElement(doc, domainNode, 'cache-behaviors')
        for cacheBehavior in domain.cacheBehaviors:
            cacheBehaviorNode = util.addElement(doc, cacheBehaviorsNode, 'cache-behavior')
            util.addElement(doc, cacheBehaviorNode, 'path-pattern', cacheBehavior.pathPattern)
            if cacheBehavior.ignoreCacheControl == False:
                util.addElement(doc, cacheBehaviorNode, 'ignore-cache-control', "false")
            else:
                util.addElement(doc, cacheBehaviorNode, 'ignore-cache-control', "true")
            util.addElement(doc, cacheBehaviorNode, 'cache-ttl', cacheBehavior.cacheTtl)
    
    if domain.visitControlRules is not None:
        visitControlRulesNode = util.addElement(doc, domainNode, 'visit-control-rules')
        for visitControl in domain.visitControlRules:
            visitControlNode = util.addElement(doc, visitControlRulesNode, "visit-control-rule")
            if visitControl.allowNullReferer == True:
                util.addElement(doc, visitControlNode, 'allownullreferer', "true")
            elif visitControl.allowNullReferer == False:
                util.addElement(doc, visitControlNode, 'allownullreferer', "false")
            
            util.addElement(doc, visitControlNode, 'path-pattern', visitControl.pathPattern)
            validRNode = util.addElement(doc, visitControlNode, 'valid-referers')
            validReferers = visitControl.validReferers
            if validReferers is not None and len(validReferers) > 0 :
                for referer in validReferers:
                    util.addElement(doc, validRNode, 'referer', referer)
            invalidRNode = util.addElement(doc, visitControlNode, 'invalid-referers')
            invalidReferers = visitControl.invalidReferers
            if invalidReferers is not None and len(invalidReferers) > 0 :
                for referer in invalidReferers:
                    util.addElement(doc, invalidRNode, 'referer', referer)
            forbiddenIps = visitControl.forbiddenIps
            if forbiddenIps is not None and len(forbiddenIps) > 0:
                util.addElement(doc, visitControlNode, 'forbidden-ips', ';'.join(visitControl.forbiddenIps))
    return doc.toprettyxml(indent = "", newl="", encoding = 'utf-8')
Example #14
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);