<%@ 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.Form ("id")="" Then
	ef=True
	ec="请输入产品ID！"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf Instr(1, Request.Form ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf trim(Request.Form ("hostname1"))="" and trim(Request.Form ("hostname2"))="" and trim(Request.Form ("hostname3"))="" and trim(Request.Form ("hostname4"))="" and trim(Request.Form ("hostname5"))="" Then
	ef=True
	ec="域名不能为空!"
'ElseIf trim(Request.Form ("hostname1"))="" Then
'	ef=True
'	ec="默认的第一个域名不能删除!"
'ElseIf trim(Request.Form ("hostname16"))<>"" Then
'	ef=True
'	ec="最多只允许设置15个域名!"
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='"&Request.Form ("id")&"'"
			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("allowsubbyid")<> session("HOSTAUID") then
	ef=True
	ec="这个虚拟主机不是您名下的！"
end if
end if


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

if not ef then
	Set dsHostpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsphpar("Hosttype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostpdlist.Open Sql,conn,1,1
if dsHostpdlist.Eof then
	ef=True
	ec="产品不存在！"
Else
If IsNull(dsph("domaincount")) Then
domaincount=dsHostpdlist("allowdomain")
Else
domaincount=dsph("domaincount")
End If
If trim(Request.Form ("hostname"&(domaincount+2)))<>"" Then
	ef=True
	ec="最多只允许设置"&domaincount&"个域名!"
end If
tdomain=domaincount
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
 
for ihname=1 to domaincount+1
OriDomain=Request.Form ("hostname"&ihname)
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
next
end if

if not ef then
for ihname=1 to domaincount+1
for ihame2=1 to domaincount+1

tempdomain=replace(replace(lcase(trim(Request.Form ("hostname"&ihname))),"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 ihname<>ihame2 then
if replace(lcase(trim(Request.Form ("hostname"&ihname))),"http://","")=replace(lcase(trim(Request.Form ("hostname"&ihame2))),"http://","") and lcase(trim(Request.Form ("hostname"&ihame2)))<>"" and lcase(trim(Request.Form ("hostname"&ihname)))<>"" then
	ef=True
	ec="不能重复捆绑同一个域名!"
	exit for
end if
end if
next
next
end If

if not ef then
if dsserver("autodelicp")=true Or dsserver("openmustre")=True then'如果启用后台检查
for ihname=1 to domaincount+1
if Request.Form ("hostname"&ihname)<>session("hostname"&ihname) and Request.Form ("hostname"&ihname)<>"" then'为新域名

domain=replace(lcase(trim(Request.Form ("hostname"&ihname))),"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
dsICPDB.update
if Application("beianusecode")=-1 Then Application("noticemesg")=Application("noticemesg")&"　用户提交"&domain&"绑定等候审核。"
end If
dsICPDB.close

end if
next
end if
end if

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





if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
username=dsph("ftpname")

for tempi=1 to abs(tdomain)+1
        if trim(Request.Form ("hostname"&tempi))<>"" then
        hostname=hostname&":80:"&replace(replace(Request.Form ("hostname"&tempi), " ",""),":80:","")&","
        end if
Next


if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
'response.write hostname
hostname=replace(hostname,"http://","")
hostname=replace(hostname,"　","")
hostname=replace(hostname,"/","")
hostname=lcase(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 id<>'"&Request.Form ("id")&"' and hostname+',' like '%"&hostname_arry (i)&",%' and ServerlistID='"&dsserver("id")&"'"
'	Response.Write sql&"<br>"

			if Instr(1,sql, ";", 1)>0 or Instr(1,replace(sql,"xn-",""), "--", 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:","")&"属于黑名单域名，不允许绑定！！"&Application("blockdomainarry")(iX)
exit for
end If
End if
next

next
end if

'	Response.End


	
if not ef then

 

if dsserver("iisver")=6 then
hostnamestr=replace(hostname, ":80:","")
hostname_arry=Split(hostnamestr, ",")
for i=0 to ubound(hostname_arry)
hostname_arry(i)=ComX.idntoac_7i24_com(cstr(hostname_arry(i)))
next
hostname=""
for i=0 to ubound(hostname_arry)
hostname=hostname&":80:"&replace(replace(hostname_arry(i), " ",""),":80:","")&","
next
if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
End if
'调用开通function
host=hostname


if dsserver("iisver")>6 Then
hostnamestr=replace(host, ":80:","")
hostname_arry=Split(hostnamestr, ",")
for i=0 to ubound(hostname_arry)
hostname_arry(i)=ComX.actoidc_7i24_com(cstr(hostname_arry(i)))
next
host=""
for i=0 to ubound(hostname_arry)
host=host&":80:"&replace(replace(hostname_arry(i), " ",""),":80:","")&","
next
if right(host,1)="," then host=left(host,len(host)-1)
End If


if Application("hostoneip")=true then
Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Host_IP where HostID="&dsph("allowsubbyid")
		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
End if
End if

IISID=dsph("IISID")
if isuseCDN=true Then host=Replace(host,":80:",":"&CDNORIport&":")
temp=ModifyUserSub(URL,FreeHostsharekey,username,password,IISID,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
'Response.Write temp
'Response.end



dsph("hostname")=hostname


'显示备案成功
alldomainok=1
hostname=dsph("hostname")
hostname=replace(hostname, ":80:","")
hostname_arry=Split(hostname, ",")
for i=0 to ubound(hostname_arry)
domain=hostname_arry(i)

domain=ComX.idntoac_7i24_com(cstr(domain))
	Set dsICPDB = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ICPDB where domain='"&GetDomainMain(domain)&"'"
	dsICPDB.Open Sql,conn,1,3
if dsICPDB.Eof Then
alldomainok=0
Else
If dsICPDB("status")<>"备案成功" Then alldomainok=0
end If
dsICPDB.close
Next
If alldomainok=1 Then 
dsph("alldomainok")=1
dsph("beianstatus")="备案成功"
Else
If dsph("beianstatus")="备案成功" then
dsph("alldomainok")=0
dsph("beianstatus")=Null
End If
If dsphpar("beianstatus")="备案成功" then
dsphpar("alldomainok")=0
dsphpar("beianstatus")=Null
dsphpar.update
End if
End If

'显示备案成功
If alldomainok=1 Then 
hostname=dsphpar("hostname")
hostname=replace(hostname, ":80:","")
hostname_arry=Split(hostname, ",")
for i=0 to ubound(hostname_arry)
domain=hostname_arry(i)

domain=ComX.idntoac_7i24_com(cstr(domain))
	Set dsICPDB = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ICPDB where domain='"&GetDomainMain(domain)&"'"
	dsICPDB.Open Sql,conn,1,3
if dsICPDB.Eof Then
alldomainok=0
Else
If dsICPDB("status")<>"备案成功" Then alldomainok=0
end If
dsICPDB.close
Next
If alldomainok=1 Then 
dsphpar("alldomainok")=1
dsphpar("beianstatus")="备案成功"
Else
If dsphpar("beianstatus")="备案成功" then
dsphpar("alldomainok")=0
dsphpar("beianstatus")=Null
End if
End If
dsphpar.update
End if


dsph.update
dsph.close


CDNrefreshDomain'更新CDN

Response.Redirect "subhostname1.asp?id="&Request.Form ("id")
%>
<%end if
if ef then
Response.Redirect "e2.asp?goto=subhostname1.asp?id="&Request.Form ("id")&"&e="&ec
end if%>
