<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
server.ScriptTimeout =2400
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


If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf not IsNumeric(Request("ServerlistID")) Then
	ef=True
	ec="编号必须是数字"
elseIf session("canrebuild")="" Then
	ef=True
	ec="您没有此操作的权限。"
end if

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select top 1 * from FreeHost.FreeHost_Product_Host where serverlistid='"&request("ServerlistID")&"' and hosttype<>'子目录绑定'"
	dsph.Open Sql,conn,1,1
if dsph.Eof Then
	ef=True
	ec="此类内容不存在！"
end if
end If

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&request("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
else
    netby=dsserver("netby")
	ip=dsserver("ip")
	hostip=dsserver("ip")
	ftpdomain=dsserver("ftpdomain")
	ostype=dsserver("ostype")
end if
end If

If Not ef Then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsph ("Hosttype")&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof Then
	ef=True
	ec="产品不存在！产品名:"&dsph ("Hosttype")&"FTP用户名："&dsph ("Ftpname")
End if
End If


if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
ostype=dsserver("ostype")
temp=SystemTest(URL,FreeHostsharekey)
if not instr(temp,"成功")>1 Then
if instr(temp,"could not be resolved")>0 Then Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员，也可以稍后再试。原因：在主控服务器上，无法解析受控域名，请在主控服务器上ping 受控域名试试。"
Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。内部原因:"&temp
end If
if not instr(temp,"2011")>1 And not instr(temp,"2012")>1 And Not instr(temp,"2013")>1 And Not instr(temp,"2014")>1 And Not instr(temp,"2015")>1 And Not instr(temp,"2016")>1 And Not instr(temp,"2017")>1 And Not instr(temp,"2018")>1 And Not instr(temp,"2019")>1 And Not instr(temp,"2020")>1 And Not instr(temp,"2021")>1 Then Response.Redirect "rebuild2.asp?ServerlistID="&request("ServerlistID")
end if


if not ef then%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html8")%>
<%=htmlwrite("html9")%>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 background="img/midtop4.gif">
  <TBODY>
    <TR>
      <TD width=53 align="left" background="img/midtop1.gif"><strong> 　 </strong><font color="#FFFFFF">─<strong>&gt;</strong></font> </TD>
      <TD width="83"><table height="59"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="7" background="img/midtop.gif">&nbsp;</td>
            <td width="60" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="rebuild.asp"><font color="#FFFFFF">重建池</font></a></td>
            <td width="5" background="img/midtop2.gif">&nbsp;</td>
          </tr>
      </table></TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83" align="left">&nbsp;</TD>
      <TD align="left">&nbsp;</TD>
      <TD width=23 align="right"><IMG height=59 
                  src="img/rtop4.jpg" 
                  width=19></TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
    <TR>
      <TD width=19 background="img/midlef.gif" id=rightid>&nbsp;</TD>
      <TD height="300" align="center" vAlign=top bgcolor="#FFFFFF">本服务器需要在服务器上生成以下的池(下面的池已自动建立)<font color=red>(注意本页可以重复刷新直到不出错！)</font>：<br>
<br>
        <br>
        <a href="rebuild2.asp?ServerlistID=<%=request("ServerlistID")%>&havebuildpool=true" target="_blank"><font color="#FF0000">池建立完成后请点击下一步进入网站列表>>></font></a><br>


<%
'response.write "处理FTP名:"&dsph("ftpname")
conn.Execute "update FreeHost.FreeHost_Product_Host set AppPoolnum=null,CurPoolname=null where CurPoolname like '_FreeHost_%'"

	Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select AppPoolnum,CurPoolname from FreeHost.FreeHost_Product_Host where serverlistid='"&request("ServerlistID")&"' and hosttype<>'子目录绑定' and CurPoolname is null order by id desc"
	dsph.Open Sql,conn,1,3
'先分析这个id的池是不是空的,如果是空,就从产品中取得
Dim aryPool()
aryPool_len=0
While Not dsph.eof

'response.write "处理FTP名:"&dsph("ftpname")

havethispool=False
poolcount=0
EnumAppsInPool=dshost ("AppPoolnum")
if not isnull(dsph("AppPoolnum")) then  EnumAppsInPool=dsph("AppPoolnum")
'response.write EnumAppsInPool&"---"&dsph("ftpname")&"<br>"
If aryPool_len>0 then
For i=0 To UBound(aryPool)
'如果池 EnumAppsInPool_FreeHost_1不存在,就建立
If InStr(aryPool(i),EnumAppsInPool&"_FreeHost")=1 then
havethispool=True
'列出这个池中所有站数量
'response.write "have.有池"&aryPool(i)&"<br>"

Set dsphList = Server.CreateObject("ADODB.Recordset")	
Sql="Select CurPoolname from FreeHost.FreeHost_Product_Host where serverlistid='"&request("ServerlistID")&"' and hosttype<>'子目录绑定' and CurPoolname='"&aryPool(i)&"'"
	dsphList.Open Sql,conn,1,1
'response.write "用这个池的网站数量:"&dsphList.recordcount&"<br>"
If dsphList.recordcount<CInt(EnumAppsInPool) Then
If dsphList.recordcount>0 Then CurPoolname=dsphList("CurPoolname")
If dsphList.recordcount=0 Then CurPoolname=EnumAppsInPool&"_FreeHost_1"
'response.write "池没装完"&CurPoolname&"<br>"
Else'此池已装完
'CurPoolname
J=CInt(Replace(dsphList("CurPoolname"),EnumAppsInPool&"_FreeHost_",""))
'response.write J&":J此池已装完<br>"
If J>poolcount Then poolcount=J
end if
	dsphList.close

End If'是否有这个池
Next
End If

If havethispool=False Or poolcount>0 Then'//有此类池但已用光 或不存在这个池
'response.write "不存在这个池,有此类池但已用光<br>"
If havethispool=False Then CurPoolname=EnumAppsInPool&"_FreeHost_1"
If poolcount>0 Then
poolcount=poolcount+1
CurPoolname=EnumAppsInPool&"_FreeHost_"&poolcount
End If
'response.write "最后池名"&CurPoolname&"<br>"
If aryPool_len>0 Then
'response.write CurPoolname&":curA<br>"
ReDim Preserve aryPool(UBound(aryPool)+1)
aryPool(UBound(aryPool))=CurPoolname
aryPool_len=UBound(aryPool)
'response.write UBound(aryPool)&":ub<br>"&aryPool(UBound(aryPool))
Else
'response.write CurPoolname&":curB<br>"
ReDim Preserve aryPool(0)
aryPool(0)=CurPoolname
aryPool_len=UBound(aryPool)+1
'response.write UBound(aryPool)&":ub2<br>"
End If
'response.write CurPoolname&":cur<br>"
'dsph("CurPoolname")=CurPoolname
'dsph.update
End If

If IsNull(dsph("CurPoolname")) Then
dsph("CurPoolname")=CurPoolname
dsph.update
Else
If dsph("CurPoolname")<>CurPoolname Then
dsph("CurPoolname")=CurPoolname
dsph.update
End If

'response.write "最后池名"&dsph("CurPoolname")&"<br>"

End if
'dsphplist.update

dsph.movenext
Wend
'response.End
dsph.close

%>



        <table width="98%" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#333333">
          <tr bgcolor="#C1BFBF" align="center">
		  <td height="30">编号</td>
            <td >池名</td>
            <td>重建池时受控返回信息</td>
          </tr>
		  
		<%
yx=0
	Set dsph = Server.CreateObject("ADODB.Recordset")	
Sql="Select distinct CurPoolname from FreeHost.FreeHost_Product_Host where serverlistid='"&request("ServerlistID")&"' and hosttype<>'子目录绑定'"
	dsph.Open Sql,conn,1,1
While not dsph.Eof
yx=yx+1
CurPoolname=dsph("CurPoolname")

'response.write "最后池名"&dsph("CurPoolname")&"<br>"

Set dsCurPcount = Server.CreateObject("ADODB.Recordset")	
Sql="Select count(*) from FreeHost.FreeHost_Product_Host where serverlistid='"&request("ServerlistID")&"' and hosttype<>'子目录绑定' and CurPoolname='"&CurPoolname&"'"
	dsCurPcount.Open Sql,conn,1,1
	CurPcount=dsCurPcount(0)
	dsCurPcount.close

%>


          <tr align="center" bgcolor="#FFFFFF">
		  <td><%=yx%></td>
            <td><%=CurPoolname%>　<%=CurPcount%>个网站</td>
            <td><%=CreatePoolDirect(URL,FreeHostsharekey,CurPoolname)%></td>
          </tr>
<%

dsph.movenext
wend
dsph.close
set dsph=nothing
%>
        </table>

        <br>
        <br>
        <a href="rebuild2.asp?ServerlistID=<%=request("ServerlistID")%>&havebuildpool=true" target="_blank"><font color="#FF0000">池建立完成后请点击下一步进入网站列表>>></font></a><br>
        <br>
        <br>
        <br>
</TD>
      <TD width=18 background="img/midri.gif">&nbsp;</TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
      <TD width=30><IMG height=19 
                  src="img/rb1.jpg" 
                  width=30></TD>
      <TD 
                background=img/rb2.jpg>&nbsp;</TD>
      <TD width=30><IMG height=19 
                  src="img/rb3.jpg" 
                  width=30></TD>
    </TR>
  </TBODY>
</TABLE>

<%=htmlwrite("html10")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
