<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<%
If session("HOSTAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseif request("op")<>"downlog" Then
if (Request.Form ("url")="" or RegExpTest("[^.A-Za-z0-9_]",Replace(Replace(Replace(Request.Form ("url"),"http://",""),"/",""),":",""))) Then
	ef=True
	ec="url没填或非法！"
End if
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&session("HOSTAUID")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="不存在的虚拟主机ID！"
end if
end if


If not ef then
if dsph("status")="暂停" or dsph("status")="停止" then
		ef=True
		ec="必须是处于正常状态的主机才能管理！"
end if
end If

if not ef then
If IsNull(dsph("hostname")) then
	ef=True
	ec="绑定域名后才能下载日志或更新URL！"
end if
end If


if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
else
isuseCDN=dsserver("isuseCDN")	
usecdn1=dsserver("usecdn1")
usecdn2=dsserver("usecdn2")
usecdn3=dsserver("usecdn3")
usecdn4=dsserver("usecdn4")
usecdn5=dsserver("usecdn5")
end if
end if

if not ef then
if isuseCDN=true then
	Set dsCDNserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerCDNlist where cdntype='外国免备案专用' and (iserr=0 or iserr is null) and (id='"&usecdn1&"' or id='"&usecdn2&"' or id='"&usecdn3&"' or id='"&usecdn4&"' or id='"&usecdn5&"')"
	dsCDNserver.Open Sql,conn,1,1
if dsCDNserver.Eof then
	ef=True
	ec="CDN服务器不存在！"
end if
end if
end If

if request("op")="downlog" then
if not ef then
if DateDiff("s",Application("candowncdn"&dsCDNserver("id")&"optime"),NOW )<300 and Application("candowncdn"&dsCDNserver("id"))=true then
	ef=True
	ec="系统繁忙，前一个RAR操作尚未处理完，请您稍等五分钟后再试，谢谢您的支持。"
end if
end if
if not ef then'time
Application.lock
Application("candowncdn"&dsCDNserver("id")&"optime")=now
Application("candowncdn"&dsCDNserver("id"))=true
Application.unlock
end If
End if


if not ef then
URL=dsCDNserver("site")
FreeHostsharekey=dsCDNserver("FreeHostsharekey")
%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
 　CDN操作返回信息
 
<br><br><br><%

If Request.Form ("Submit")="马上更新缓存" Then
pushurl=Request.Form ("url")
op=0
CDNcon=" -p 80 -m PURGE "+pushurl
retstr="  尝试发送命令："&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)
response.write retstr&" 如果提示命令失败很可能是URL不存在，或并没有缓存。"'&CDNcon
end if

if request("op")="downlog" then
while not dsCDNserver.Eof

txml=dateadd("y",-1,now)		
logfilename=dsph("ftpname")&"_"&md5(dsph("ftpname")&dsph("starttime"))&".txt"
'response.write dsCDNserver("site")
aryport=Split(Replace(dsCDNserver("site"),"http://",""),":")
sysport=":"&aryport(1)
downurl="http://"&Replace(dsCDNserver("ip")&sysport&"/"&logfilename,"//","/")

hostname_arry=Split(dsph("hostname"), ",")
SQL=""
for i=0 to ubound(hostname_arry)
domain=replace(hostname_arry(i), " ","")
domainary=Split(domain,":")
SQL="Field3='"&domainary(2)&"' or "&SQL
Next

SQL=left(SQL,Len(SQL)-3)

'response.write sql
'response.end

URL=dsCDNserver("site")
FreeHostsharekey=dsCDNserver("FreeHostsharekey")
timedif="cdnop downlog "&logfilename&" """&SQL&""""
response.Write	CountLOG(URL,FreeHostsharekey,timedif)
		
		%><br>请您记下以下的URL,十分钟后下载:

		<%=downurl%>
		<br>
				<%
dsCDNserver.movenext
wend
		%>

<%end if%>
<br>
<br>
<br>
<br>

<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>