<%@ 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 dsHostserver = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&Request("id")&"'"
		dsHostserver.Open Sql,conn,1,3
If dsHostserver.Eof Then
	ef=True
	ec="服务器不存在。"
end if
end if

if not ef Then

if dsHostserver("ostype")="linux" Then
URL=dsHostserver("site")
FreeHostsharekey=dsHostserver("FreeHostsharekey")
on error resume next
response.write "自检返回信息:"

response.write "尝试列出所有管理员:"
InCmd="CMD_API_SHOW_ADMINS"
retstr=DAAPIGET(URL,"admin",FreeHostsharekey,InCmd)

if err.number<>0 then Response.Write "出现错误："&err.description
if instr(err.description,"could not be resolved")>0 then%>
在主控服务器上，无法解析受控域名：<a href="<%=dsHostserver("site")%>"><%=dsHostserver("site")%></a><br>
请在主控服务器上ping 此域名试试。
<%end if

if err.number=0 then
If InStr(retstr,"[]=admin")>1 Then
response.write retstr
response.write "自检通过."
Else
response.write "<font color=red>自检失败!请检查admin密码是否对!</font>,返回信息:"
response.write retstr
response.end
End if

response.write "尝试建立名为freehostpak产品包:"
InCmd="CMD_API_MANAGE_RESELLER_PACKAGES"
PostBody="ubandwidth=ON&uquota=ON&uvdomains=ON&unsubdomains=ON&ips=0&unemails=ON&unemailf=ON&unemailml=ON&unemailr=ON&umysql=ON&udomainptr=ON&uftp=ON&cgi=ON&php=ON&spam=ON&catchall=ON&ssl=ON&oversell=ON&cron=ON&sysinfo=ON&dns=OFF&serverip=ON&packagename=freehostpak&add=Save"
retstr=DAAPIPOST(URL,"admin",FreeHostsharekey,InCmd,PostBody)
response.write "返回信息:"&retstr
If InStr(retstr,"text=Saved")>1 Then response.write ",产品包建立成功."

response.write "尝试建立名为sefreehost的DA产品代理:"
InCmd="CMD_ACCOUNT_RESELLER"
PostBody="action=create&username=sefreehost&email=webmaster@"&dsHostserver("tempdomain")&"&passwd="&FreeHostsharekey&"&passwd2="&FreeHostsharekey&"&domain=sefreehost."&dsHostserver("tempdomain")&"&package=freehostpak&ip=shared&add=Submit"
retstr=DAAPIPOST(URL,"admin",FreeHostsharekey,InCmd,PostBody)
'response.write "返回信息:"&retstr
If InStr(retstr,"created successfully")>1 Then response.write ",建立成功."
If InStr(retstr,"username already exists")>1 Then response.write ",已存在同名的DA产品代理,不需要重复建立."
If InStr(retstr,"domain already exists")>1 Then response.write ",已存在一域名的DA产品代理,建立失败."

response.write "尝试同步sefreehost的DA产品代理的密码:"
InCmd="CMD_API_USER_PASSWD"
body="username=sefreehost&passwd="&FreeHostsharekey&"&passwd2="&FreeHostsharekey
returnstr=DAAPIPOST(URL,"admin",FreeHostsharekey,InCmd,body)
If InStr(returnstr,"Password Changed")>1 Then
response.write ",修改成功."
Else
response.write ",修改失败.返回:"&returnstr
End if


End if
%>
<br><br>
<br>详细说明请参考：<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>

<%else'windwos
session("servertype")=""
on error resume next
URL=dsHostserver("site")
FreeHostsharekey=dsHostserver("FreeHostsharekey")
FreeHostDir=dsHostserver("homedir")
retstr=SystemTestNew(URL,FreeHostsharekey,FreeHostDir)
'retstr=SystemTest(URL,FreeHostsharekey)

if session("servertype")="Microsoft-IIS/7.0" Or session("servertype")="Microsoft-IIS/7.5" Then
'iis7
dsHostserver("iisver")=7
dsHostserver.update
'response.write session("servertype")
End If

if session("servertype")="Microsoft-IIS/6.0" Then
'iis7
dsHostserver("iisver")=6
dsHostserver.update
End If

if session("servertype")="Microsoft-IIS/8.0" Or session("servertype")="Microsoft-IIS/8.5" Then
'iis8
dsHostserver("iisver")=8
dsHostserver.update
'response.write session("servertype")
End If

if session("servertype")="Microsoft-IIS/10.0" Or session("servertype")="Microsoft-IIS/8.5" Then
'iis8
dsHostserver("iisver")=10
dsHostserver.update
'response.write session("servertype")
End If

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

if instr(retstr," IMPLEMENTED")>0 Then
retstr=SystemTest(URL,FreeHostsharekey)
end if

if instr(err.description,"could not be resolved")>0 then%>
在主控服务器上，无法解析受控域名：<a href="<%=dsHostserver("site")%>"><%=dsHostserver("site")%></a><br>
请在主控服务器上ping 此域名试试。
<%end if%>
<%if instr(retstr," 403.6 ")>0 or instr(retstr,"403.503")>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 受控端没找到(<%=dsHostserver("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%>

<%if instr(retstr,"255.255.255.255")>1 or instr(retstr,"web.config")>1 then%>

<font color=red>错误：请先删除受控服务器上的c:\windows\7i24.com\freehost\web.config。</font><br>

<%
response.end
end if%>

<br><br>
<%Response.Write retstr%>
详细说明请参考：<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>
<%
If dsHostserver("iisver")=7 Then %>受控服务器的操作系统为Windows 2008
<%
End If

End if'windows

end if
if ef then
Response.Redirect "e.asp?e="&ec
end if

Function SystemTestNew(URL,FreeHostsharekey,FreeHostDir)
Set MaintoCSCom=Server.CreateObject("www.7i24.com")
body=URLEncoding("FreeHostDir="&LCase(FreeHostDir))
RetInfo=MaintoCSCom.DOHTTPSSL(Url&"?SystemTestNew",FreeHostsharekey,body,FreeHost_t1,FreeHost_t2,FreeHost_t3,FreeHost_t4)
Set MaintoCSCom =Nothing
SystemTestNew=RetInfo
End Function

Function SystemTest(URL,FreeHostsharekey)
Set MaintoCSCom=Server.CreateObject("www.7i24.com")
RetInfo=MaintoCSCom.DOHTTPSSL(Url&"?",FreeHostsharekey," ",FreeHost_t1,FreeHost_t2,FreeHost_t3,FreeHost_t4)
Set MaintoCSCom =Nothing
SystemTest=RetInfo
End Function
%>