<%@ Language=VBScript %>
<%server.scripttimeout=240%>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
	Response.Expires = 0 
	Response.AddHeader "Pragma","no-cache"
	Response.AddHeader "cache-ctrol","no-cache"
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("HOSTAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="ID应该是数字！"
ElseIf Request.Form ("dirname")="" Then
	ef=True
	ec="请设置子目录名！"
ElseIf len(Request.Form ("dirname"))>30 Then
	ef=True
	ec="子目录名超过允许的长度！"
ElseIf RegExpTest("[^A-Za-z0-9]",replace(Request.Form ("dirname"),"\","")) Then
	ef=True
	ec="子目录名中有非法字符！"
ElseIf trim(Request.Form ("hostname1"))="" Then
	ef=True
	ec="请设置域名！"
'ElseIf Request.Form ("useper")="" Then
'	ef=True
'	ec="请设置资源分配！"
'ElseIf not IsNumeric(Request.Form ("useper"))  Then
'	ef=True
'	ec="资源分配应该是数字！"
'ElseIf IsNumeric(Request.Form ("useper"))  and (Request.Form ("useper")<1 or Request.Form ("useper")>99) Then
'	ef=True
'	ec="资源分配应该在1至99之间！"
end If

if not ef then
if DateDiff("s", Application("hostoptime"),NOW )<180 and Application("hostoplock")=true then
	ef=True
	ec="系统繁忙，前一个网站开通操作尚未处理完，请您稍等两分钟后再试，谢谢您的支持。"
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！"
Else
netver=dsph("netver")
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="产品类型不存在！"
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
hostip=dsserver("ip")
isuseCDN=dsserver("isuseCDN")	
usecdn1=dsserver("usecdn1")
usecdn2=dsserver("usecdn2")
usecdn3=dsserver("usecdn3")
usecdn4=dsserver("usecdn4")
usecdn5=dsserver("usecdn5")
CDNORIport=dsserver("port")
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 id='"&dsserver ("usecdn1")&"'"
	dsCDNserver.Open Sql,conn,1,3
if dsCDNserver.Eof then
	ef=True
	ec="CDN服务器不存在！"
end if
end if
end if


if not ef then
if dsph("istest")="y" then
	ef=True
	ec="很抱歉,试用期的主机不能绑子目录！"
end if
end if

if not ef then
if not dsph("allowsub")="y" then
	ef=True
	ec="很抱歉,这个主机不允许绑子目录！"
end if
end if

if not ef then
if dsph("status")<>"正常" then
	ef=True
	ec="不是正常状态的主机不能绑定！"
end if
end if

if not ef Then
 
OriDomain=Request.Form ("hostname1")
If OriDomain<>"" Then
If Len(OriDomain)<4 Then
	ef=True
	ec="域名太短!"
End if
OriDomain=ComX.idntoac_7i24_com(Cstr(OriDomain))
If RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="域名非法！"&server.urlencode(OriDomain)
End If
End if
end if

if not ef then
if dsserver("autodelicp")=true  Or dsserver("openmustre")=true then'如果启用后台检查
domain=replace(lcase(trim(Request.Form ("hostname1"))),"http://","")

domain=ComX.idntoac_7i24_com(cstr(domain))
domain=GetDomainMain(domain)
	Set dsICPDB = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ICPDB where domain='"&domain&"'"
	dsICPDB.Open Sql,conn,1,3
if dsICPDB.Eof Then
dsICPDB.addnew
dsICPDB("username")=dsph("username")
dsICPDB("ftpname")=dsph("ftpname")
dsICPDB("domain")=domain
dsICPDB("status")="尚未检测"
dsICPDB("firstaddtime")=Now
dsICPDB("agent1")=dsph("agent1")
dsICPDB("agent2")=dsph("agent2")
dsph("alldomainok")=0
if Application("beianusecode")=-1 Then Application("noticemesg")=Application("noticemesg")&"　用户提交"&domain&"绑定等候审核。"
dsICPDB.update
end If
dsICPDB.close
end if
end if

if not ef then
if dsserver("openmustre")=true then
'check domain in domaindb
status=""
if CheckDomainDB(replace(lcase(trim(Request.Form ("hostname1"))),"http://",""))=false then
	ef=True
	ec="此域名 "&Request.Form ("hostname1")&" 没有通过备案，当前状态："&status&"，请到 http://www.miitbeian.gov.cn 查询是否成功备案。"
	If Application("beianupsaok")=True Then	ec="此域名 "&Request.Form ("hostname1")&" 尚未在工信部提交备案信息，当前状态："&status&"，请到先到 http://www.miitbeian.gov.cn 提交备案信息。"
	if Application("beianusecode")=-1 Then 	ec="此域名 "&Request.Form ("hostname1")&" 尚未通过管理员审核，当前状态："&status&"，请您耐心等候,我们会在24小时内审核,审核通过后您再次绑定这个域名就会马上生效。您现在可以点返回并[刷新]查看当前的审核状态。"
end if
end if
end if

tempdomain=replace(replace(lcase(trim(Request.Form ("hostname1"))),"http://",""),".","")
if tempdomain<>"" and IsNumeric(tempdomain) then
	ef=True
	ec="域名不能是IP!"
end if
if instr(tempdomain,"*")>0 or instr(tempdomain,":")>0 or instr(tempdomain,"/")>0 then
	ef=True
	ec="域名中有特殊符号!"
end if

if not ef then 'test hostname
if trim(Request.Form ("hostname1"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname1"), " ",""),":80:","")&","
end if
'if trim(Request.Form ("hostname2"))<>"" then
'hostname=hostname&":80:"&replace(replace(Request.Form ("hostname2"), " ",""),":80:","")&","
'end if
'if trim(Request.Form ("hostname3"))<>"" then
'hostname=hostname&":80:"&replace(replace(Request.Form ("hostname3"), " ",""),":80:","")&","
'end if
'if trim(Request.Form ("hostname4"))<>"" then
'hostname=hostname&":80:"&replace(replace(Request.Form ("hostname4"), " ",""),":80:","")&","
'end if
'if trim(Request.Form ("hostname5"))<>"" then
'hostname=hostname&":80:"&replace(replace(Request.Form ("hostname5"), " ",""),":80:","")&","
'end if
if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
'response.write hostname
hostname=replace(hostname,"http://","")
hostname=lcase(replace(hostname,"　",""))






if hostname<>"" then
'hostname=trim(replace(Request.Form ("hostname")," ",""))
hostname_arry=Split(hostname, ",")
for i=0 to ubound(hostname_arry)
	Set dshostname = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where hostname+',' like '%"&hostname_arry (i)&",%' and ServerlistID='"&dsserver("id")&"'"
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dshostname.Open Sql,conn,1,1
if not dshostname.Eof then
	ef=True
	ec="您要绑定的域名"&replace(hostname_arry (i),":80:","")&"已存在，其他用户绑定了这个用户名，FTP是："&dshostname("ftpname")
end if
dshostname.close
Set dshostname = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where domain = '"&replace(hostname_arry (i),":80:","")&"'"
	dshostname.Open Sql,conn,1,1
if not dshostname.Eof then
	ef=True
	ec="您要绑定的域名"&replace(hostname_arry (i),":80:","")&"已存在,其他代理商在服务域名中绑定了这个域名！代理名是："&dshostname("username")
end if
dshostname.close
for iX=0 to ubound(Application("sitearry"))
if Application("sitearry")(iX)=replace(hostname_arry (i),":80:","") or Request.ServerVariables("LOCAL_ADDR")=replace(hostname_arry (i),":80:","") then
	ef=True
	ec="您要绑定的域名"&replace(hostname_arry (i),":80:","")&"已存在于主控域名中！"
exit for
end if
Next

for iX=0 to ubound(Application("blockdomainarry"))
If Len(Application("blockdomainarry")(iX))>1 then
if InStr(lcase(replace(hostname_arry (i),":80:","")),Application("blockdomainarry")(iX))>0 Or lcase(replace(hostname_arry (i),":80:",""))="net.cn" Or lcase(replace(hostname_arry (i),":80:",""))="com.cn"  then
	ef=True
	ec="您要绑定的域名"&replace(hostname_arry (i),":80:","")&"属于黑名单域名，不允许绑定！"
exit for
end If
End if
next

next
end if
end if



if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
temp=SystemTest(URL,FreeHostsharekey)
if not instr(temp,"成功")>1 then
Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。"
end if
end if

if not ef then
if dsph("subweb")>0 then
Set dsper = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where id='"&dsph("id")&"' or allowsubbyid='"&dsph("id")&"'"
	dsper.Open Sql,conn,1,1
if dsper.RecordCount>dsph("subweb") then
	ef=True
	ec="超过了允许绑定的最大数量！"
end if
end if
end if

if not ef then
'读取主目录的影射
username=dsph ("Ftpname")
returnstr = ShowUser2(URL,FreeHostsharekey,username)
if (instr(1,returnstr,"用户不存在！")>0) then 
Response.Write returnstr
Response.End 
end if 
if Not instr(returnstr,"用户名：")>1 then 
Response.Write "这台受控服务器自检没有通过，请在站点管理，虚拟主机中自检来分析原因。"
Response.End 
end if 
ScriptMaps=GETvalue(returnstr,";应用程序影射：",";自定义出错信息：")
end if

if not ef then

Ftpname=dsph ("Ftpname")
Ftppassword=dsph ("Ftppassword")
starttime=dsph("starttime")
temptime=dsph("endtime")
Hosttype="子目录绑定"
parentid=dsph("id")
username=dsph("username")
agent1=dsph("agent1")
dsph.AddNew
dsph("username")=username
dsph("ServerlistID")=dsserver("id")
dsph("Hosttype")=Hosttype
dsph("oriHosttype")=Hosttype
dsph("starttime")=starttime
dsph("endtime")=temptime

dsph("Ftpname")=Ftpname
dsph("Ftppassword")=Ftppassword
dsph("hostname")=hostname
dsph("status")="准备开通"
dsph("istest")="n"
dsph("agent1")=agent1
'------------------
dsph("allowsubbyid")=parentid
dsph("dirname")=trim(Request.Form ("dirname"))
dsph("allowsub")="n"
dsph("subweb")=0
dsph("useper")=0'trim(Request.Form ("useper"))

'dsph.Update



%>
<!--#include virtual="/inc-freehost-function/template-hostadm-top.asp"-->
　虚拟主机开通成功

<%
'调用开通function
'AccessFlags=1
'if dshost("asp")="y" then
'AccessFlags=513
'ScriptMaps=dsserver("asp") 
'end if
'if dshost("aspx")="y" then
'AccessFlags=513
'ScriptMaps=ScriptMaps&"|"&dsserver("aspx") 
'end if
'if dshost("cgi")="y" then
'AccessFlags=517
'ScriptMaps=ScriptMaps&"|"&dsserver("cgi") 
'end if
'if dshost("php")="y" then
'AccessFlags=513
'ScriptMaps=ScriptMaps&"|"&dsserver("php") 
'end if
'if dsserver("infosafe")<>"" then
'ScriptMaps=ScriptMaps&"|"&dsserver("infosafe") 
'end if
ScriptMaps=trim(replace(ScriptMaps,"||","|"))

URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
username=dsph ("Ftpname")
password=dsph("Ftppassword")
comment=dsph ("username")
homedir=dsserver("homedir")
spacelimit=dshost ("spacelimt")
starttime=dsph("starttime")
endtime=dsph("endtime")
type1=dsph("Hosttype")
email="子目录绑定"
host=dsph("hostname")
hostcomment_arry=Split(host, ",")
hostcomment="Sub_"&username&"_"&Replace(hostcomment_arry(0),":80:","")&"_"&dsph ("username")
MaxConnections=3'----------------------初始化的链接数
EnumAppsInPool=50'----------------------

'DefaultDoc=""'dshost ("DefaultDoc")
ScriptMaps=ScriptMaps
AccessFlags=AccessFlags
MaxBandwidth=1024'----------------------

dsph("netver")=netver

if Application("hostoneip")=true then
Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Host_IP where HostID="&parentid
		dsX.Open Sql,conn,1,1
If not dsX.Eof Then
host=Replace(host,":80:",dsX("IP")&":80:")
'host=dsX("IP")&":80:"&dsX("IP")&","&host
hostip=dsX("IP")
End if
End if

if isuseCDN=true Then host=Replace(host,":80:",":"&CDNORIport&":")
Application.lock
Application("hostoptime")=now
Application("hostoplock")=true
Application.unlock
temp=AddUserSub(URL,FreeHostsharekey,username,password,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
Application.lock
Application("hostoplock")=false
Application.unlock

if instr(temp,"出错")>0 then
Response.Redirect "e.asp?e="&temp
end if

IISID=GETvalue(temp,"此目录的虚拟主机ID为：_","_号;")
NOWIISID=IISID
	dsph("status")="正常"
	dsph("IISID")=IISID

'if Application("openmustre")=true then'转向未备案页
'op=1
'tourl=dsserver("pauseweb4")
'temp=temp&" 由于备案要求此网站被转向到备案页:"&PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
'	dsph("status")="暂停"
'end if
FreeHost_oplog dsph("username"),"信息","用户新加绑定子目录虚拟主机: "&temp
	dsph.Update

dsph.close


CDNrefreshDomain'更新CDN

%>

<br>
　　　　　　　　　　　　　<br>
<table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#CCCCCC">
    <td height="39" colspan="2"><font color="#000000">　　　</font><font color="#FFFFFF">恭喜您的子目录绑定成功，以下是您的资料：</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="42"><font color="#000000">　　　 </font><font color="#000000"> 您的网址为：</font></td>
    <td height="42"><font color="#000000"><a href="http://<%=Replace(hostcomment_arry(0),":80:","")%>" target=_blank><font color="#000000">http://<%=Replace(hostcomment_arry(0),":80:","")%></font></a></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="39"><font color="#000000"> 　　　  您绑定的目录是： </font></td>
    <td height="39"><font color="#000000"><font color=red><%=Request.Form ("dirname")%></font></font></td>
  </tr>
    <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="39"><font color="#000000"> 　　　  服务器IP是： </font></td>
    <td height="39"><font color="#000000"><font color=red><%=hostip%></font></font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 分配资源：</font></td>
    <td bgcolor="#eeeeee"><a href="useper.asp?id=<%=session("HOSTAUID")%>">指定这个目录所能用的资源>>></a></td>
  </tr>
<!--<%if Application("openmustre")=true then%>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 网站暂停中：</font></td>
    <td bgcolor="#eeeeee">由于国家要求先备案后开通，请您返回备案。</td>
  </tr>
<%end if%>-->
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td colspan="2"><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000">　</font><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000"> 　　　</font> 　</td>
  </tr>
</table>
<br>
<!--#include virtual="/inc-freehost-function/template-hostadm-end.asp"-->
<%end if
if ef then
'Response.Redirect "e.asp?e="&ec
Response.Redirect "e2.asp?goto=selfhostaddsub.asp?id="&session("HOSTAUID")&"&e="&ec
end if%>
