<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent where username='"&session("agentusername")&"'"
		ds.Open Sql,conn,1,1
if ds.eof then
	ef=True
	ec="代理会员不存在！"
end if
end If

if not ef then
if ds("haveclosehtml")=true then
	ef=True
	ec="管理员已关闭了您的服务域名及模板管理功能"
end if
end if


if not ef then
	Set dsC = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_domain where id=0"
		dsC.Open Sql,conn,1,1
if dsC.eof then
	ef=True
	ec="请先设置代理用的临时域名！"
end if
end if


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

if not ef then
if Application("autodelicp")=true Or Application("openmustre")=true then'如果启用后台检查
for ihname=1 To 5
if Request.Form ("domain"&ihname)<>session("domain"&ihname) and Request.Form ("domain"&ihname)<>"" then'为新域名
domain=replace(lcase(trim(Request.Form ("domain"&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")=session("agentusername")
'dsICPDB("ftpname")=dsph("ftpname")
dsICPDB("domain")=domain
dsICPDB("status")="尚未检测"
dsICPDB("firstaddtime")=Now
dsICPDB("agent1")=session("agentusername")
dsICPDB("agent2")="n"
'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 Application("openmustre")=true then
for ihname=1 to 5
if Request.Form ("domain"&ihname)<>session("domain"&ihname) and Request.Form ("domain"&ihname)<>"" then'为新域名
status=""
if CheckDomainDB(replace(lcase(trim(Request.Form ("domain"&ihname))),"http://",""))=false then
	ef=True
	ec="此域名 "&Request.Form ("domain"&ihname)&" 没有通过备案，当前状态："&status&"，请到 http://www.miitbeian.gov.cn 查询是否成功备案。"
	If Application("beianupsaok")=True Then	ec="此域名 "&Request.Form ("domain"&ihname)&" 尚未在工信部提交备案信息，当前状态："&status&"，请到先到 http://www.miitbeian.gov.cn 提交备案信息。"
	if Application("beianusecode")=-1 Then 	ec="此域名 "&Request.Form ("domain"&ihname)&" 尚未通过管理员审核，当前状态："&status&"，请您耐心等候,我们会在24小时内审核,审核通过后您再次绑定这个域名就会马上生效。您现在可以点返回并[刷新]查看当前的审核状态。"
end if
end if
next
end if
end if


if not ef then
for i=1 to 5
If LCASE(trim(Request.Form ("domain"&i)))<>"" Then

	Set dsagentdomain = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where username<>'"&session("agentusername")&"' and domain='"&LCASE(trim(Request.Form ("domain"&i)))&"'"
		dsagentdomain.Open Sql,conn,1,1
if not dsagentdomain.eof then
	ef=True
	ec=Request.Form ("domain"&i)&" 此域名已被其他代理用户使用了。"
end if
if dsC ("domain")=LCASE(trim(Request.Form ("domain"&i)))  then
	ef=True
	ec=Request.Form ("domain"&i)&" 为特殊域名。原因一:现域名:"&LCASE(trim(Request.Form ("domain"&i)))&" 原绑定:"&dsC ("domain")&",此域名已存在,请您在管理区,代理折扣中,不要设置一样的临时域名."
end If
if LCASE(replace("www."&Request.Form ("domain"&i),"..",".")) = dsC ("domain") then
	ef=True
	ec=Request.Form ("domain"&i)&" 为特殊域名。原因二:现域名:"&LCASE(replace("www."&Request.Form ("domain"&i),"..","."))&" 原绑定:"&dsC ("domain")&",此域名已存在,请您在管理区,代理折扣中,不要设置一样的临时域名."
end if
dsagentdomain.close


Set dshostname = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where hostname+',' like '%:80:"&LCASE(trim(Request.Form ("domain"&i)))&",%'"
	dshostname.Open Sql,conn,1,1
if not dshostname.Eof then
	ef=True
	ec="您要绑定的域名已存在 :"&Request.Form ("domain"&i)&" ftp名:"&dshostname("ftpname")
end if
dshostname.close
for iX=0 to ubound(Application("sitearry"))
if Application("sitearry")(iX)=LCASE(trim(Request.Form ("domain"&i))) or Request.ServerVariables("LOCAL_ADDR")=LCASE(trim(Request.Form ("domain"&i))) then
if Application("sitearry")(iX)<>"" then
	ef=True
	ec="您要绑定的域名已存在于主控端中！"'&Request.Form ("domain"&i)&" - "&Application("sitearry")(iX)
end if
exit for
End if
next



End if
next
end if

if not ef then
	Set dsagentdomain = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where username='"&session("agentusername")&"' order by id asc"
		dsagentdomain.Open Sql,conn,1,3
i=1
while not dsagentdomain.eof
if i>1 then
dsagentdomain.delete
dsagentdomain.update
end if
dsagentdomain.movenext
i=i+1
wend
dsagentdomain.close
end if

if not ef Then

'删除
conn.Execute "delete from FreeHost.FreeHost_Agent_ALLdomain where username='"&session("agentusername")&"'"

for i=1 to 5
if trim(Request.Form ("domain"&i))<>"" then

	Set dsagentdomain = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_ALLdomain where username='"&session("agentusername")&"' and domain='"&trim(Request.Form ("domain"&i))&"'"
'		response.write sql
				if Instr(1,sql, ";", 1)>0 or Instr(1,replace(sql,"xn--",""), "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsagentdomain.Open Sql,conn,1,3
		If dsagentdomain.eof Then dsagentdomain.addnew
		dsagentdomain("username")=session("agentusername")
		dsagentdomain("domain")=LCASE(replace(Request.Form ("domain"&i),"..","."))
dsagentdomain("domain")=ComX.idntoac_7i24_com(Cstr(dsagentdomain("domain")))
		dsagentdomain("agent1")=ds("agent1")
		dsagentdomain("agent2")="n"
dsagentdomain.update
       
dsagentdomain.close
end if
next
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>　服务域名
<%=htmlwrite("html6")%>
<br><br><br>设置成功！
<%=htmlwrite("html7")%>
<%
end if
if ef then
Response.Redirect "e2.asp?goto=mydomain.asp&e="&ec
end if


Function RegExpTest(patrn, strng)
  Dim regEx
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = False
  RegExpTest = regEx.Test(strng)
End Function %>
