<%@ Language=VBScript %>
<!--#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"

If session("CDNAUID")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf not IsNumeric(session("CDNAUID"))  Then
	ef=True
	ec="osid应该是数字！"
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="域名不能为空!"
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_CDN where id='"&session("CDNAUID")&"'"
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="不存在的数据库产品ID！"
end if
end if

if not ef then
	Set dsCDNpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_CDNProductlist where CDNtype='"&dsph("CDNtype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsCDNpdlist.Open Sql,conn,1,1
if dsCDNpdlist.Eof then
	ef=True
	ec="产品不存在！"
Else
If IsNull(dsph("allowdomain")) Then
domaincount=dsHostpdlist("allowdomain")
Else
domaincount=dsph("allowdomain")
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_ServerBindlist where id='"&dsph ("Bindserverid2")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="DNS服务器2不存在！"
end if
end If

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerBindlist where id='"&dsph ("Bindserverid1")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="DNS服务器1不存在！"
end if
end If

if not ef Then
Bindserverid1=dsph ("Bindserverid1")
Bindserverid2=dsph ("Bindserverid2")
	Set dsCDNserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerCDNlist where cdntype='多点分布CDN加速用'  and (Bindserverid1='"&Bindserverid1&"' or Bindserverid1='"&Bindserverid2&"' or Bindserverid2='"&Bindserverid1&"' or Bindserverid2='"&Bindserverid2&"')"
	dsCDNserver.Open Sql,conn,1,1
if dsCDNserver.Eof then
	ef=True
	ec="CDN服务器不存在！"
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
'response.write OriDomain&"<br>"
'response.write Request.Form ("IP"&ihname)&"<br>"
'response.write Request.Form ("port"&ihname)&"<br>"

If Request.Form ("IP"&ihname)="" Or InStr(Request.Form ("IP"&ihname),"-") Or not IsNumeric(Replace(Request.Form ("IP"&ihname),".","")) Then
	ef=True
	ec="IP非法！"&Request.Form ("IP"&ihname)
End If
If Request.Form ("IP"&ihname)="" Then
	ef=True
	ec="IP非法A！"&Request.Form ("IP"&ihname)
End If
OriDomain=ComX.idntoac_7i24_com(Cstr(Request.Form ("IP"&ihname)))
If RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="IP非法B！"&server.urlencode(OriDomain)
End if
If Request.Form ("port"&ihname)="" Or not IsNumeric(Request.Form ("port"&ihname)) Then
	ef=True
	ec="端口非法！"&Request.Form ("port"&ihname)
Else
If CLng(Request.Form ("port"&ihname))>60000 Or CLng(Request.Form ("port"&ihname))<80 then
	ef=True
	ec="端口超出允许的范围！"&Request.Form ("port"&ihname)
End if
End If

If Len(Request.Form ("IPCNC"&ihname))>5 then
If Request.Form ("IPCNC"&ihname)="" Or InStr(Request.Form ("IPCNC"&ihname),"-") Or not IsNumeric(Replace(Request.Form ("IPCNC"&ihname),".","")) Then
	ef=True
	ec="IP非法！"&Request.Form ("IPCNC"&ihname)
End If
If Request.Form ("IPCNC"&ihname)="" Then
	ef=True
	ec="IP非法A！"&Request.Form ("IPCNC"&ihname)
End If
OriDomain=ComX.idntoac_7i24_com(Cstr(Request.Form ("IPCNC"&ihname)))
If RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="IP联通非法B！"&server.urlencode(OriDomain)
End If
If Request.Form ("portCNC"&ihname)="" Or not IsNumeric(Request.Form ("portCNC"&ihname)) Then
	ef=True
	ec="端口非法！"&Request.Form ("portCNC"&ihname)
Else
If CLng(Request.Form ("portCNC"&ihname))>60000 Or CLng(Request.Form ("portCNC"&ihname))<80 then
	ef=True
	ec="端口超出允许的范围！"&Request.Form ("portCNC"&ihname)
End if
End If
End If 

If Len(Request.Form ("IPMOB"&ihname))>5 then
If Request.Form ("IPMOB"&ihname)="" Or InStr(Request.Form ("IPMOB"&ihname),"-") Or not IsNumeric(Replace(Request.Form ("IPMOB"&ihname),".","")) Then
	ef=True
	ec="IP非法！"&Request.Form ("IPMOB"&ihname)
End If
If Request.Form ("IPMOB"&ihname)="" Then
	ef=True
	ec="IP非法A！"&Request.Form ("IPMOB"&ihname)
End If
OriDomain=ComX.idntoac_7i24_com(Cstr(Request.Form ("IPMOB"&ihname)))
If RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="IP移动非法B！"&server.urlencode(OriDomain)
End If
If Request.Form ("portMOB"&ihname)="" Or not IsNumeric(Request.Form ("portMOB"&ihname)) Then
	ef=True
	ec="端口非法！"&Request.Form ("portMOB"&ihname)
Else
If CLng(Request.Form ("portMOB"&ihname))>60000 Or CLng(Request.Form ("portMOB"&ihname))<80 then
	ef=True
	ec="端口超出允许的范围！"&Request.Form ("portMOB"&ihname)
End if
End If
End If

If Len(Request.Form ("IPUSA"&ihname))>5 then
If Request.Form ("IPUSA"&ihname)="" Or InStr(Request.Form ("IPUSA"&ihname),"-") Or not IsNumeric(Replace(Request.Form ("IPUSA"&ihname),".","")) Then
	ef=True
	ec="IP非法！"&Request.Form ("IPUSA"&ihname)
End If
If Request.Form ("IPUSA"&ihname)="" Then
	ef=True
	ec="IP非法A！"&Request.Form ("IPUSA"&ihname)
End If
OriDomain=ComX.idntoac_7i24_com(Cstr(Request.Form ("IPUSA"&ihname)))
If RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="IP联通外国B！"&server.urlencode(OriDomain)
End If
If Request.Form ("portUSA"&ihname)="" Or not IsNumeric(Request.Form ("portUSA"&ihname)) Then
	ef=True
	ec="端口非法！"&Request.Form ("portUSA"&ihname)
Else
If CLng(Request.Form ("portUSA"&ihname))>60000 Or CLng(Request.Form ("portUSA"&ihname))<80 then
	ef=True
	ec="端口超出允许的范围！"&Request.Form ("portUSA"&ihname)
End if
End If
End if

OriDomain=Request.Form ("hostname"&ihname)
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 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
for ihname=1 to domaincount+1
if Request.Form ("hostname"&ihname)<>session("hostname"&ihname) and Request.Form ("hostname"&ihname)<>"" then'为新域名
for iX=0 to ubound(Application("blockdomainarry"))
If Len(Application("blockdomainarry")(iX))>1 then
if InStr(replace(lcase(trim(Request.Form ("hostname"&ihname))),"http://",""),Application("blockdomainarry")(iX))>0 Or replace(lcase(trim(Request.Form ("hostname"&ihname))),"http://","")="net.cn" Or  replace(lcase(trim(Request.Form ("hostname"&ihname))),"http://","")="com.cn" then
	ef=True
	ec="您要绑定的域名"&(replace(lcase(trim(Request.Form ("hostname"&ihname))),"http://",""))&"属于黑名单类域名，不允许绑定！"
exit for
end If
end if
Next
End if
next
end if

if not ef then
if dsCDNserver("autodelicp")=true Or dsCDNserver("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 dsCDNserver("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小时内审核,审核通过后您再次绑定这个域名就会马上生效。您现在可以点返回并[刷新]查看当前的审核状态。"
	Response.Redirect "e.asp?goto=CDNop.asp?id="&Request.Form ("id")&"&e="&ec
end if

end if
next
end if
end If


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

'hostname
':80:www.7i24.com,:80:7i24.com
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_CDN where id<>'"&session("CDNAUID")&"' and hostname+',' like '%"&hostname_arry (i)&",%' and (Bindserverid1='"&Bindserverid1&"' or Bindserverid2='"&Bindserverid2&"')"
			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")
	ec="您要绑定的域名"&replace(hostname_arry (i),":80:","")&"已存在，其他用户绑定了这个域名"
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




Next



end if

if not ef Then

hostname=""
for tempi=1 to abs(tdomain)+1
        if trim(Request.Form ("hostname"&tempi))<>"" Then
        enddomain=ComX.idntoac_7i24_com(LCase(replace(Replace(replace(replace(replace(Request.Form ("hostname"&tempi), " ",""),":80:",""),"http://",""),"　",""),"/","")))


        hostname=hostname&Request.Form ("ip"&tempi)&":"&Request.Form ("port"&tempi)

		If Len(Request.Form ("IPCNC"&tempi))>5 Then
		hostname=hostname&"|CNC-"&Request.Form ("ipCNC"&tempi)&":"&Request.Form ("portCNC"&tempi)
		End If
		If Len(Request.Form ("IPMOB"&tempi))>5 Then
		hostname=hostname&"|MOB-"&Request.Form ("ipMOB"&tempi)&":"&Request.Form ("portMOB"&tempi)
		End If
		If Len(Request.Form ("IPUSA"&tempi))>5 Then
		hostname=hostname&"|USA-"&Request.Form ("ipUSA"&tempi)&":"&Request.Form ("portUSA"&tempi)
		End if		


		        hostname=hostname&":"&enddomain&","



        end if
next
if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)

'response.write hostname
'response.end



dsph("hostname")=hostname
dsph.update
dsph.close

'192.168.0.222:80:agnssss.test.com

conn.Execute "update FreeHost.FreeHost_ServerCDNlist set lastchangetime='"&now&"' where cdntype='多点分布CDN加速用' and (Bindserverid1='"&Bindserverid1&"' or Bindserverid1='"&Bindserverid2&"' or Bindserverid2='"&Bindserverid1&"' or Bindserverid2='"&Bindserverid2&"')"

'On Error Resume next
'CDNrefreshDomainCDN'更新CDN

CDNrefreshDomainCDN("不分类")
CDNrefreshDomainCDN("联通")
CDNrefreshDomainCDN("移动")
CDNrefreshDomainCDN("外国")

'response.end

Response.Redirect "CDNop.asp?id="&Request.Form ("id")

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