<%

Sub CDNBindANALOG
if hour(now)=1 Then
Response.Write "开始更新CDN服务器的流量表"
set dsCDNserver = Server.CreateObject("ADODB.Recordset")	
'	Sql="Select * from FreeHost.FreeHost_ServerCDNlist where cdntype='多点分布CDN加速用'" ' and (lastlogtime<'"&date&"' or lastlogtime is null)"
	Sql="Select * from FreeHost.FreeHost_ServerCDNlist where cdntype='多点分布CDN加速用'  and (lastlogtime<'"&date&"' or lastlogtime is null)"
'if hour(now)=4 Or hour(now)=5 Or hour(now)=6 Then
'sql="Select top 25 * from FreeHost.FreeHost_ServerCDNlist where lastlogtime<'"&date&"' or lastlogtime is null"
'End If

'if hour(now)=7 Then
'sql="Select * from FreeHost.FreeHost_ServerCDNlist where lastlogtime<'"&date&"'
'End if

	dsCDNserver.Open Sql,conn,1,1
while not dsCDNserver.Eof
On Error Resume Next
Bindserverid1=dsCDNserver ("Bindserverid1")
Bindserverid2=dsCDNserver ("Bindserverid2")
URL=dsCDNserver("site")
FreeHostsharekey=dsCDNserver("FreeHostsharekey")

'5.更新流量表
'if hour(now)=4 Or hour(now)=5 Or hour(now)=6 Or hour(now)=7 Then '早上4点更新
serverbyte=0
 txml=dateadd("y",-1,now)
 httpurl=Url&"/log/CDN_"&year(txml)&"_"&month(txml)&"_"&day(txml)&".xml"
'Response.Write "开始更新以下CDN服务器的流量表id:"&dsCDNserver("id")&" url:"&httpurl&vbcrlf
conn.Execute "delete [FreeHost].[FreeHost_CDN_analog] where  ServerlistID="&dsCDNserver("id")&""'  and CDNdomain='"&CDNdomain&"'"

'Response.end
FreeHost_oplog "自动任务","信息","开始更新以下CDN-多点分布CDN加速用-服务器的流量表:"&dsCDNserver("id")&"受控网址:"&URL&vbcrlf

Set http=Server.CreateObject("MSXML2.ServerXMLHTTP")
http.Open "GET",httpurl,False
http.send
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.load(http.ResponseXML)

Set root = xmlDoc.documentElement
   For i = 0 To (root.childNodes.length - 1)

CDNdomain=Trim(LCase(root.childNodes.Item(i).childNodes.Item(0).Text))
CDNdomainbyte=root.childNodes.Item(i).childNodes.Item(1).Text

If RegExpTest("[^A-Za-z0-9_.\-]",CDNdomain) Or Len(CDNdomain)<3 Then
response.write "err--非法域名:("&CDNdomain&")"
Else
   	Set dsphtemp = Server.CreateObject("ADODB.Recordset")
Sql="Select top 1 * from FreeHost.FreeHost_CDN_analog"
dsphtemp.Open Sql,conn,1,3
dsphtemp.addnew
dsphtemp("lastlogtime")=Now
dsphtemp("CDNdomain")=CDNdomain
dsphtemp("CDNdomainbyteMB")=Clng(CDNdomainbyte/1024/1024)
dsphtemp("ServerlistID")=dsCDNserver("id")

		Set dsVpname = Server.CreateObject("ADODB.Recordset")	
Sql="Select ftpname from FreeHost.FreeHost_Product_CDN where (Bindserverid1='"&Bindserverid1&"' or Bindserverid1='"&Bindserverid2&"' or Bindserverid2='"&Bindserverid1&"' or Bindserverid2='"&Bindserverid2&"') and hostname+',' like '%:"&CDNdomain&",%'"
'response.write sql&"<br>"
dsVpname.Open Sql,conn,1,1
If Not dsVpname.eof Then
dsphtemp("CDNname")=dsVpname("ftpname")
'response.write "<br>"
response.write dsphtemp("CDNname")
response.write "<br>"
Else
response.write "不存在:("&CDNdomain&")"
End if
dsVpname.close

dsphtemp.update
serverbyte=serverbyte+CDbl(CDNdomainbyte)
end if
   Next

'serverbyteMB=Clng(FormatNumber(serverbyte/1024/1024,0,-1,0,0))
serverbyteMB=Clng(serverbyte/1024/1024)
response.write vbcrlf&"<br>CDN服务器服ID:"&dsCDNserver("id")&"总流量："&serverbyte&"("&serverbyteMB&"MB)<br>"' Xml文件网址:"&httpurl&vbcrlf
conn.Execute "update freehost.FreeHost_ServerCDNlist set lastlogtime='"&now&"',serverbyteMB='"&serverbyteMB&"' where id="&dsCDNserver("id")&""

'end if'是4点
'列出所有用这个CDN的产品,更新它

dsCDNserver.movenext
wend

'列出所有DNS服务器


'	Sql="Select * From FreeHost.FreeHost_ServerBindlist Where ID In (Select Min(ID) From FreeHost.FreeHost_ServerBindlist Group By typeid) and cdntype='多点分布CDN加速用'"



'列出这台服务器所有域名,
	Set dsph = Server.CreateObject("ADODB.Recordset")
Sql="Select * from FreeHost.FreeHost_Product_CDN"
	dsph.Open Sql,conn,1,3
while not dsph.Eof
If Not IsNull(dsph("hostname")) Then
If len(dsph("hostname"))>3 Then
'统计表中这个域名的记录

		Set sumRS = Server.CreateObject("ADODB.Recordset")	
Sql="Select sum(CDNdomainbyteMB) from FreeHost.FreeHost_CDN_analog where cdnname='"&dsph("ftpname")&"'"
sumRS.Open Sql,conn,1,1
If sumRS(0)>0 then
response.write dsph("ftpname")&" "&sumRS(0)&"<br>"
dsph("CDNMB"&day(txml))=sumRS(0)
dsph("CDNMBthismonth")=dsph("CDNMBthismonth")+sumRS(0)
End if
sumRS.close

dsph.update
End if
End if
dsph.movenext
wend



'


End if'是0点
End sub
%>