<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<%
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("cansetserver")="" Then
	ef=True
	ec="您没有此操作的权限。"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="ID应该是数字！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsCDNserver = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_ServerCDNlist where id='"&Request("id")&"'"
		dsCDNserver.Open Sql,conn,1,3
If dsCDNserver.Eof Then
	ef=True
	ec="服务器不存在。"
end if
end If

if not ef then
If IsNull(Application("ctldomain")) Or Application("ctldomain")="" Then
	ef=True
	ec="请您先设置系统参数中的控制面板域名。"
End If
End if

if not ef then
'on error resume next

server.ScriptTimeout =900

URL=dsCDNserver("site")
FreeHostsharekey=dsCDNserver("FreeHostsharekey")

cdntype=dsCDNserver("cdntype")

Dim CDNret,showcdnret,CDNSYNnow
CDNSYNnow=true
showcdnret=True
isuseCDN=True
isONEip=true
usecdn1=dsCDNserver("id")
usecdn2=dsCDNserver("id")
usecdn3=dsCDNserver("id")
usecdn4=dsCDNserver("id")
usecdn5=dsCDNserver("id")
If Request("op")="syn" Then
response.write "开始同步...完成...."
If cdntype="共享IP的VPS专用" then
CDNrefreshDomainVPS
End if
If cdntype="外国免备案专用" Then
CDNrefreshDomain
End If
If cdntype="多点分布CDN加速用" Then
Dim Bindserverid1,Bindserverid2
Bindserverid1=dsCDNserver("Bindserverid1")
Bindserverid2=dsCDNserver("Bindserverid2")
If Request("op")="syn" Then 
CDNrefreshDomainCDN("不分类")
CDNrefreshDomainCDN("联通")
CDNrefreshDomainCDN("移动")
CDNrefreshDomainCDN("外国")
End if
End If
'response.write CDNret
response.end
End If

If Request("op")="show" Then
op=0
CDNcon="-p 80 mgr:info"
response.write "  查看当前运行状态:<pre>"&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)&"</pre>"
response.end
End if



op=2
CDNcon="-k reconfigure -n squid"
cachemgr=dsCDNserver("cachemgrHead")&dsCDNserver("cachemgr")
mime=dsCDNserver("mimeHead")&dsCDNserver("mime")
squid=Replace(dsCDNserver("squidHead")&vbcrlf&"access_log "&dsCDNserver("logpath")&"access.log combined"&vbcrlf&dsCDNserver("squid"),vbcrlf&vbcrlf,vbcrlf)
squid_radius_auth=dsCDNserver("squid_radius_authHead")&dsCDNserver("squid_radius_auth")
hosts=dsCDNserver("hostsHead")&dsCDNserver("hosts")

dsCDNserver("lastchangetime")=Now
dsCDNserver.update


If cdntype="多点分布CDN加速用" Or cdntype="外国免备案专用" Then

'response.write "info:"&URL&FreeHostsharekey&dsCDNserver("id")&Application("ctldomain")&op&dsCDNserver("syntime")

retstr="  发送:CDN2操作返回:"&CDNOP2(URL,FreeHostsharekey,dsCDNserver("id"),Application("ctldomain"),op,dsCDNserver("syntime"))
Else
retstr="  尝试发送配置文件:"&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)
End if

If Len(hosts)>20 then

retstr=retstr&vbcrlf&vbcrlf&vbcrlf&"  发送的squid.conf内容为:"&vbcrlf&squid
retstr=retstr&vbcrlf&vbcrlf&vbcrlf&"  发送的hosts内容为:"&vbcrlf&hosts
retstr=retstr&vbcrlf&vbcrlf&vbcrlf&"  cachemgr.conf内容为:"&vbcrlf&cachemgr

CDNcon=""

response.write "  尝试发送host配置文件:"&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)

End if

cachemgr=""
mime=""
squid=""
squid_radius_auth=""
hosts=""

op=0
CDNcon="-p 80 mgr:info"
'CDNcon="-p 80 mgr:info"
retstr=retstr&vbcrlf&vbcrlf&vbcrlf&"  查看当前运行状态:"&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)



'op=2
'CDNcon="-k parse"
'retstr=retstr&vbcrlf&vbcrlf&vbcrlf&"  检查配置返回:"&CDNOP(URL,FreeHostsharekey,CDNcon,cachemgr,mime,squid,squid_radius_auth,hosts,op)

'response.write vbcrlf&vbcrlf&vbcrlf&"  发送的squid.conf内容为:"&squid
'response.end

'if session("servertype")="Microsoft-IIS/7.0" Then
'iis7
'dsCDNserver("iisver")=7
'dsCDNserver.update
'End if

if err.number<>0 then Response.Write "出现错误："&err.description


if instr(retstr,"执行失败！")>0 Then%>
<font color=black>请检查Squid有没有安装并处于启动状态.</font>
<%end if

if instr(retstr," IMPLEMENTED")>0 Then%>
请升级受控端.
<%end if

if instr(err.description,"could not be resolved")>0 then%>
在主控服务器上，无法解析受控域名：<a href="<%=dsCDNserver("site")%>"><%=dsCDNserver("site")%></a><br>
请在主控服务器上ping 此域名试试。
<%end if%>
<%if instr(retstr," 403.6 ")>0 then%>

<font color=red>错误：403.6客户端的IP被拒绝,受控端不接受主控端的IP(<%=Request.ServerVariables("LOCAL_ADDR")%>)。</font><br>

造成这个问题的原因是，您在开始--运行受控端自动设置时，输入的IP不对，请注意，要输入的IP是主控IP(<%=Request.ServerVariables("LOCAL_ADDR")%>)，而不是受控IP，请输入正确的IP，然后点击建立受控网站再建立一次。 <br>

另一个解决办法是： 
打开受控服务器上的IIS，找到受控网站，点击受控网站的属性--目录安全性--IP地址限制中，修改为正确的主控IP(<%=Request.ServerVariables("LOCAL_ADDR")%>)，注意，如果您有多个主控IP，请全部加上。<br>
如果您的主控服务器的IP变动，您也要这样处理才能正常使用。

<%
response.end
end if%>
<%if instr(retstr," 404 ")>0 then%>

<font color=red>错误：404 受控端没找到(<%=dsCDNserver("site")%>)。</font><br>

请您检查受控网址是否正确，检查域名有没有解析好，检查受控网站有没有启动，同时，请您注意，受控网址不能和主控网址一样，受控网址也无法在IE中直接访问，只能通过自检来了解是否正常。 <br>


<%
response.end
end if%>
<%if instr(retstr,"Internal Server Error")>1 or instr(retstr,"未指定")>1 then%>

<font color=red>错误：受控端许可证无效,请重装受控许可证后重启IIS。</font><br>

<%
response.end
end if%>

<br><br>
<pre>
<%Response.Write retstr%>
</pre>
详细说明请参考：<br>
<br>
<a href="http://sys.7i24.com/system/support/show.asp?id=107100944392" target="_blank">http://sys.7i24.com/system/support/show.asp?id=107100944392</a><br>
<br>
<%
end if
if ef then
Response.Redirect "e.asp?e="&ec
end if
%>