<%
Dim ef,ec,returncodevalue,failreason,enc,Enddomaintypeid
dim starttime,temptime,pdtype
Dim Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,RsDlist,regapi
'Dim Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,RsDlist,
Dim isreplay,domainRepayAPI
session.Timeout=1%>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostDomain.asp"-->
<!--#include virtual="/inc-freehost-function/ZPapi.asp"-->
<!--#include virtual="/inc-freehost-function/xml.cls.asp"-->
<%

If Request("client")="" And Request.QueryString("method")="GetProductKey" Then
response.write "ret=0&name=null&key=null&err=name-null&err=encode-null&err=client-null&err=verify-null&freehosinfo=请输入代理用户名"
response.end
End If

If Request("client")="" Then
response.write "ret=0&err=auth-failure&freehosinfo=请输入代理用户名"
response.end
End If

If RegExpTest("[^A-Za-z0-9]",Request("client")) Then
response.write "ret=0&err=auth-failure&freehosinfo=代理用户名非法"
response.end
End If

If RegExpTest("[^A-Za-z0-9]",Request("checksum")) Then
response.write "ret=0&err=auth-failure&freehosinfo=API密码非法"
response.end
End If

If RegExpTest("[^A-Za-z0-9]",Request("Optype")) Then
response.write "ret=0&err=auth-failure&freehosinfo=操作类型非法"
response.end
End if

Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
  Set Sagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request("client")&"'"
		Sagent.Open Sql,conn,1,3
If Sagent.Eof Then
	ef=True
	ec="代理会员名不存在！"
end If

If Not ef Then
If IsNull(Sagent("canuseapi")) Or Sagent("canuseapi")<>true Then
	ef=True
	ec="代理"&Sagent("username")&"尚未开通API的权限"
end If
End If

If Not ef Then
If Request.QueryString("method")="check" Then
'检查域名是否可注册
postbody=Replace(Request.Form,"client="&Request.Form("client"),"client="&Application("Domain_Agent_username_2"))
retdns=ONLY_POST(Application("API2Check"),Application("API2Check"),postbody)
'返回
response.write retdns'&"&freehosinfo=域名检查成功"
response.End'处理完成后就停止运行
End If
End If

If Not ef Then
If Request.QueryString("method")="Register" Then
If MD5("Register"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("dn")+Request.form("aemail")+Request.form("uname2"))<>Request.form("checksum") Then
'response.write "ret=0&err=verify-failure&freehosinfo=API密码加密码检查非法:提交内容:"&("Register"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("dn")+Request.form("aemail")+Request.form("uname2"))&":"&MD5("Register"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("dn")+Request.form("aemail")+Request.form("uname2"))&":"&Request.form("checksum")
response.write "ret=0&err=verify-failure&freehosinfo=API密码加密码检查非法"
response.End
Else














'sub APIRegisterDomain()

if not ef then
 
hostname=Request.form("dn")
hostname=ComX.idntoac_7i24_com(cstr(hostname))
hostname=replace(hostname,".","")
hostname=replace(hostname,"xn--","")
If RegExpTest("[^A-Za-z0-9--]",hostname) Then
	ef=True
	ec="请输入合法的域名！"
end if
end if

session("username")=Sagent("username")
session("agentname")=Sagent("username")
session("agenttype")=Sagent("agenttype")
session("atspace")="API区"
if session("agentname")=session("username") then
session("AgnRunasUser")=True
else
session("AgnRunasUser")=false
end if
'登陆用户区

'加入域名表中

'Dim enc
Enddomaintypeid=GetDomaintype(request.form("dn"))

If session("username")="" And session("agentusername")="" And (session("admau")="" and session("DomainNameModid")="") then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=授权非法，有可能是超时造成的。"
elseIf Enddomaintypeid=0 Then
	ef=True
	ec="ret=0&err=name-wrong&freehostinfo=无效的域名类型！"
elseif Application("onlyone")=true and Request.Form ("period")>1 and not (Enddomaintypeid=9 or Enddomaintypeid=4 or Enddomaintypeid=5) then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=管理员限制了首次注册只能注册一年！"
elseIf not IsNumeric(Request.Form ("period")) Then
	ef=True
	ec="ret=0&err=period-invalid&freehostinfo=年必须是数字！"
ElseIf Instr(1, Request.Form ("dn"), "'", 1)>0 then
	ef=True
	ec="ret=0&err=name-wrong&freehostinfo=域名有非法字符！"
ElseIf Instr(1, Request.Form ("dn"), "64", 1)>0 And Enddomaintypeid=2 then
	ef=True
	ec="ret=0&err=domainnme-restricted&freehostinfo=域名有非法字符64！"
ElseIf Instr(1, Request.Form ("dn"), "89", 1)>0 then
	ef=True
	ec="ret=0&err=domainnme-restricted&freehostinfo=域名有非法字符！"
ElseIf Enddomaintypeid=2 And Len(Request.Form ("dn"))<6 And Enddomaintypeid=2 then
	ef=True
	ec="ret=0&err=domainnme-restricted&freehostinfo=域名太短不允许注册！"
ElseIf Request.Form ("uname1")="" then
	ef=True
	ec="ret=0&err=uname1-invalid&freehostinfo=单位名称(中文)不能为空"
ElseIf Not CheckStrinAsc(Replace(Replace(Request.Form ("uname2"),".",""),",","")) then
	ef=True
	ec="ret=0&err=uname2-invalid&freehostinfo=单位名称(英文)不能为空，输入的内容必须是半角，长度在3-50个字符内。"
ElseIf not Instr(Trim(Request.Form ("uname2")), " ")>1 then
	ef=True
	ec="ret=0&err=uname2-invalid&freehostinfo=单位名称(英文)，必须有空格！"
ElseIf Instr(Trim(Request.Form ("uname2")), "  ")>1 then
	ef=True
	ec="ret=0&err=uname2-invalid&freehostinfo=单位名称(英文)，空格只能有一个,不能输入两个空格！"
'ElseIf Instr(Trim(Request.Form ("uname2")), ".")>1 then
'	ef=True
'	ec="ret=0&err=uname2-invalid&freehostinfo=单位名称(英文)，不能有.号！"	
ElseIf Request.Form ("rname1")="" then
	ef=True
	ec="ret=0&err=rname1-invalid&freehostinfo=单位负责人：（中文）不能为空"
ElseIf Not CheckStrinAsc(Request.Form ("rname2")) then
	ef=True
	ec="ret=0&err=rname2-invalid&freehostinfo=单位负责人：（英文）不能为空，输入的内容必须是半角，长度在3-50个字符内。"
ElseIf Instr(Trim(Request.Form ("rname2")), "  ")>1 then
	ef=True
	ec="ret=0&err=rname2-invalid&freehostinfo=单位负责人(英文)，空格只能有一个,不能输入两个空格！"
ElseIf not Instr(Trim(Request.Form ("rname2")), " ")>1 then
	ef=True
	ec="ret=0&err=rname2-invalid&freehostinfo=单位负责人(英文)，必须有空格！"
ElseIf Request.Form ("uprov")="" then
	ef=True
	ec="ret=0&err=uprov-invalid&freehostinfo=省份：不能为空"
ElseIf Request.Form ("ucity1")="" then
	ef=True
	ec="ret=0&err=ucity1-invalid&freehostinfo=城市：（中文）不能为空"
ElseIf Not CheckStrinAsc(Request.Form ("ucity2")) then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=城市：（英文）不能为空，输入的内容必须是半角，长度在3-50个字符内。"
ElseIf Request.Form ("uaddr1")="" then
	ef=True
	ec="ret=0&err=uaddr1-invalid&freehostinfo=街道地址：（中文）不能为空"
ElseIf Len(Request.Form ("uaddr1"))<6 then
	ef=True
	ec="ret=0&err=uaddr1-invalid&freehostinfo=街道地址：（中文）必须在6个字以上的长度"
ElseIf Not CheckStrinAsc(Request.Form ("uaddr2")) then
	ef=True
	ec="ret=0&err=uaddr2-invalid&freehostinfo=街道地址：（英文）不能为空，输入的内容必须是半角，长度在3-50个字符内。"
ElseIf Len(Request.Form ("uaddr2"))<6 then
	ef=True
	ec="ret=0&err=uaddr2-invalid&freehostinfo=街道地址：（英文）必须在6个字以上的长度"
ElseIf Request.Form ("uzip")="" then
	ef=True
	ec="ret=0&err=uzip&freehostinfo=邮政编码：不能为空"
elseIf not Chk_Num(Request.Form ("uzip")) Then
	ef=True
	ec="ret=0&err=uzip&freehostinfo=邮政编码必须是半角数字！"
ElseIf Request.Form ("uemail")="" then
	ef=True
	ec="ret=0&err=uemail-invalid&freehostinfo=电子邮件：不能为空"
ElseIf Trim(Request.Form ("uteln"))="" then
	ef=True
	ec="ret=0&err=uteln-invalid&freehostinfo=注册人电话号码不能为空"
elseIf not Chk_Num(Request.Form ("uteln")) Then
	ef=True
	ec="ret=0&err=uteln-invalid&freehostinfo=注册人电话号码必须是半角数字！"
elseIf len(Request.Form ("uteln"))>8 Then
	ef=True
	ec="ret=0&err=uteln-invalid&freehostinfo=注册人电话号码不能超过8位,请用固定号码！"
elseIf len(Request.Form ("uteln"))<7 Then
	ef=True
	ec="ret=0&err=uteln-invalid&freehostinfo=注册人电话号码不能小于7位,请用固定号码！"
elseIf clng(Request.Form ("uteln"))=88888888 Or clng(Request.Form ("uteln"))=8888888 Or clng(Request.Form ("uteln"))=0 Or clng(Request.Form ("uteln"))=12345678 Or clng(Request.Form ("uteln"))=1234567 Then
	ef=True
	ec="ret=0&err=uteln-invalid&freehostinfo=注册人电话号码不能为8888888/0000000/12345678/1234567/8888888/000000,请用固定号码！"
ElseIf Trim(Request.Form ("ufaxn"))="" then
	ef=True
	ec="ret=0&err=ufaxn-invalid&freehostinfo=注册人传真号码不能为空"
elseIf not Chk_Num(Request.Form ("ufaxn")) Then
	ef=True
	ec="ret=0&err=ufaxn-invalid&freehostinfo=注册人传真号码必须是半角数字！"
elseIf len(Request.Form ("ufaxn"))>8 Then
	ef=True
	ec="ret=0&err=ufaxn-invalid&freehostinfo=注册人传真号码不能超过8位,请用固定号码！"
elseIf len(Request.Form ("ufaxn"))<7 Then
	ef=True
	ec="ret=0&err=ufaxn-invalid&freehostinfo=注册人传真号码不能小于7位,请用固定号码！"
elseIf clng(Request.Form ("ufaxn"))=88888888 Or clng(Request.Form ("ufaxn"))=8888888 Or clng(Request.Form ("ufaxn"))=0 Or clng(Request.Form ("ufaxn"))=12345678 Or clng(Request.Form ("ufaxn"))=1234567 Then
	ef=True
	ec="ret=0&err=ufaxn-invalid&freehostinfo=注册人传真号码不能为8888888/0000000/12345678/1234567/8888888/000000,请用固定号码！"
ElseIf RegExpTest("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$",Request("uemail"))=False then
	ef=True
	ec="ret=0&err=uemail-invalid&freehostinfo=注册人信息的内容：Email无效"
ElseIf Trim(Request.Form ("utela"))="" then
	ef=True
	ec="ret=0&err=utela-invalid&freehostinfo=注册人电话区号不能为空"
elseIf not Chk_Num(Request.Form ("utela")) Then
	ef=True
	ec="ret=0&err=utela-invalid&freehostinfo=注册人电话区号必须是半角数字！"
elseIf len(Request.Form ("utela"))>4 Then
	ef=True
	ec="ret=0&err=utela-invalid&freehostinfo=注册人电话区号不能超过4位！"
elseIf len(Request.Form ("utela"))<2 Then
	ef=True
	ec="ret=0&err=utela-invalid&freehostinfo=注册人电话区号不能小于2位！"
ElseIf Trim(Request.Form ("ufaxa"))="" then
	ef=True
	ec="ret=0&err=ufaxa-invalid&freehostinfo=注册人传真区号不能为空"
elseIf not Chk_Num(Request.Form ("ufaxa")) Then
	ef=True
	ec="ret=0&err=ufaxa-invalid&freehostinfo=注册人传真区号必须是半角数字！"
elseIf len(Request.Form ("ufaxa"))>4 Then
	ef=True
	ec="ret=0&err=ufaxa-invalid&freehostinfo=注册人传真区号不能超过4位！"
elseIf len(Request.Form ("ufaxa"))<2 Then
	ef=True
	ec="ret=0&err=ufaxa-invalid&freehostinfo=注册人传真区号不能小于2位！"
end if

if not ef then


'Set conn=Server.CreateObject("ADODB.Connection")
'	conn.Open Application("FreeHostDBlink")


Domain_API=0
	Set RsDlist = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_DomainProductlist where id="&Enddomaintypeid
		RsDlist.Open Sql,conn,1,1
if not RsDlist.eof Then
Domain_API=RsDlist("regapi")
Else
response.write "没有这个类型"
response.end
end If
If Application("usercanselectapi")=true Then
If Application("api1")=True And request.form("usercanselectapi")=1 Then Domain_API=request.form("usercanselectapi")
If Application("api2")=True And request.form("usercanselectapi")=2 Then Domain_API=request.form("usercanselectapi")
If Application("api3")=True And request.form("usercanselectapi")=3 Then Domain_API=request.form("usercanselectapi")
If Application("api4")=True And request.form("usercanselectapi")=4 Then Domain_API=request.form("usercanselectapi")
If Application("api5")=True And request.form("usercanselectapi")=5 Then Domain_API=request.form("usercanselectapi")
If Application("api6")=True And request.form("usercanselectapi")=6 Then Domain_API=request.form("usercanselectapi")
End if'有这个类型




Set dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain"
	dsdom.Open sql,conn,1,3
if session("DomainNameModid")="" then
dsdom.addnew
dsdom("username")=session("username")
dsdom("agent1")=session("agentname")
if session("agentusername")<>"" Then
dsdom("username")=session("agentusername")
dsdom("agent1")=session("agentusername")
End If
dsdom("Domain")=lcase(trim(request.form("dn")))
If Enddomaintypeid=3 And Right(dsdom("Domain"),"7")=".net.cn" Then dsdom("Domain")=Replace(dsdom("Domain"),".net.cn",".网络")
If Enddomaintypeid=3 And Right(dsdom("Domain"),"7")=".com.cn" Then dsdom("Domain")=Replace(dsdom("Domain"),".com.cn",".公司")
If Enddomaintypeid=3 And Right(dsdom("Domain"),"3")=".cn" Then dsdom("Domain")=Replace(dsdom("Domain")&"_",".cn_",".中国")

dsdom("Domain_API")=Domain_API


dsdom("ServerlistID")=1
dsdom("Domaintype")=""
dsdom("status")="预注册成功"
dsdom("starttime")=NOW
end if

dsdom("years")=request.form("period")
if Application("DNS_API")=1 then dsdom("DNS_API")=1
dsdom("uname1")=Trim(request.form("uname1"))
dsdom("uname2")=Trim(request.form("uname2"))
dsdom("rname1")=Trim(request.form("rname1"))
dsdom("rname2")=Trim(request.form("rname2"))
'dsdom("ust")=request.form("ust")
dsdom("ust")="CN"
dsdom("uprov")=Trim(request.form("uprov"))
dsdom("ucity1")=Trim(request.form("ucity1"))
dsdom("ucity2")=Trim(request.form("ucity2"))
dsdom("uaddr1")=Trim(request.form("uaddr1"))
dsdom("uaddr2")=Trim(request.form("uaddr2"))
dsdom("uzip")=Trim(request.form("uzip"))
'dsdom("utelc")=request.form("utelc")
dsdom("utelc")="86"
dsdom("utela")=Trim(request.form("utela"))
dsdom("uteln")=Trim(request.form("uteln"))
'dsdom("ufaxc")=request.form("ufaxc")
dsdom("ufaxc")="86"
dsdom("ufaxa")=Trim(request.form("ufaxa"))
dsdom("ufaxn")=Trim(request.form("ufaxn"))
dsdom("uemail")=Trim(request.form("uemail"))
if request.form("istemplate")="y" then
dsdom("istemplate")="y"
else
dsdom("istemplate")="n"
end if

if request.form("dns1")<>"" Then
dsdom("dns1")=Trim(request.form("dns1"))
dsdom("dns2")=Trim(request.form("dns2"))
End If

dsdom.update
dsdom.close
End If

if not ef then
Set dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&session("username")&"' and Domain='"&lcase(trim(request.form("dn")))&"' order by starttime desc"
	dsdom.Open sql,conn,1,3
if dsdom.eof then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=不存在的域名！"
end if
end if


if not ef then
if dsdom("Domain_API")=4 then
If TOLOGINZP()=true then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=登陆API4域名接口失败，可能是网络忙的原因造成的，请再试一次，或请联系管理员。相关出错信息为:"&server.URLEncode(ZPEC)
end if
end if
end If


if not ef then
	Set dsDlist = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_DomainProductlist where id='"&Enddomaintypeid&"'"
		dsDlist.Open Sql,conn,1,1
if dsDlist.eof then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=管理员没有定义域名的价格，请联系管理员！"
else
usermoney=dsDlist("usermoney")
myrealcost=dsDlist("usermoneyagn")
end if
end if

if not ef then
yearstr=dsdom("years")
if yearstr="" then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=未能找到注册的时间长度！"
end if
end if

if not ef then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,3,2
if ds.eof then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=用户不存在!"
end if
end if

if not ef then
	Set dspre = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Preopen_Product where username='"&ds ("username")&"' and haveget='n' and type1='"&dsDlist("Domaintype")&"'"
	dspre.Open Sql,conn,1,3
if not dspre.Eof then
if Clng(yearstr)=1 then
havehostget=true
havehostgetcon="赠送"
end if
end if
end if

if not ef then
if DateDiff("s", Application("domainoptime"),NOW )<Application("domainopmax") and Application("domainoplock")=true then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=系统繁忙，前一个操作尚未处理完，请您稍等两分钟后再试，谢谢您的支持。"
end if
end if

if not ef then
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock

'dim starttime,temptime,pdtype
pdtype=dsdom("Domain")
starttime=NOW
temptime=dateadd("yyyy",yearstr,now)

'dim ef,ec,
'Dim Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,RsDlist,regapi
regapi=dsdom("Domain_API")
set RsDlist=dsDlist
Userpaymoney=dsDlist("usermoney")
if havehostget=false then
forpayyear=yearstr
else
forpayyear=999
end if
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="域名产品"
forpayid=dsDlist("id")
logfor="用户区开通(域名"&dsdom("Domain")&")(API)"
if havehostget then logfor=logfor&"(虚拟主机赠送免费开通)(API)"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
session("moneylog_pdid")=dsdom("id")
DoPayMoneyDomainNew
Application.lock
Application("domainoplock")=false
Application.unlock
end if

if not ef then
if havehostget=true then
dspre("haveget")="y"
dsdom("isbyhost")="y"
dsdom("Hosttype")=dspre("type1")
dsdom("byid")=dspre("byid")
dspre.update
dspre.close
'删除重复
		Sql="delete from FreeHost.FreeHost_Preopen_Product where byid="&dsdom("byid")&" and haveget='n'"
  conn.Execute Sql
end if
end If

if ef then
response.write "ret=0&err="&ec'处理财务后
response.end
end if

if not ef then
'赠送的邮箱
'开通邮箱
starttime=now
	Set dsemailpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Domaintype='"&dsDlist("Domaintype")&"' and isbydomain='y'"
	dsemailpdlist.Open Sql,conn,1,1
if not dsemailpdlist.Eof then
Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&ds ("username")&"'"
	dsphemail.Open Sql,conn,1,3
dsphemail.addnew
dsphemail("username")=ds("username")
dsphemail("ServerlistID")=dsemailpdlist("ServerlistID")
dsphemail("Emailtype")=dsemailpdlist("Emailtype")
dsphemail("starttime")=starttime
dsphemail("endtime")=temptime
dsphemail("bydomain")=dsdom("id")
dsphemail("istest")="n"
dsphemail("emailcount")=dsemailpdlist("emailcount")
dsphemail("userspacelimt")=dsemailpdlist("userspacelimt")
dsphemail("domainspacelimt")=dsemailpdlist("domainspacelimt")
dsphemail("domainmustsame")=dsemailpdlist("domainmustsame")
dsphemail("status")="正常"
if ds("agent1")<>"n" then
dsphemail("agent1")=ds("agent1")
else
dsphemail("agent1")="n"
end if
dsphemail.update
dsphemail.close
	Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsphemail.Open Sql,conn,1,1
FreeHost_oplog session("username"),"信息","用户(API)自己开通域名"&dsdom("Domain")&"赠送邮箱产品ID:"&dsphemail("id")
retemail="赠送的邮箱产品已开通"
end if
'结束赠送

dsdom("status")="失败"
dsdom.update

Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock

'dim returncodevalue,failreason
RegisterDomainNow()


Application.lock
Application("domainoplock")=false
Application.unlock

dsdom.update


end if

if ef Then
ecArry=Split(ec,"代码为：")
If UBound(ecArry)=1 Then ec=Replace(ecArry(1),"代码为：","")
response.write ec
response.end
end if


if not ef then

dsdom("starttime")=starttime
dsdom("endtime")=temptime
dsdom("Domaintype")=""
dsdom("status")="正常"
dsdom.update
'action

'pass

if Application("DNS_API")=1 then
dsdom("DNS_API")=Application("DNS_API")
end if
dsdom.update

end if

if ef then
response.write "ret=0&err="&ec
response.end
end if


'扣费

'调用开通sub

'返回

'进入注册处理
response.write "ret=100&info=reg-success&freehosinfo=域名注册成功"

'end sub

















response.End'处理完成后就停止运行
End if
End If
End If
'---------------------------------------------'上面是register

If Not ef Then
If Request.QueryString("method")="GetProductKey" Then
If MD5("GetProductKey"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("name")+Request.form("enc"))<>Request.form("checksum") Then
response.write "ret=0&err=verify-failure&freehosinfo=API密码加密码检查非法"
response.End
Else

 
hostname=Request.form("name")
hostname=ComX.idntoac_7i24_com(cstr(hostname))
hostname=replace(hostname,".","")
hostname=replace(hostname,"xn--","")
If RegExpTest("[^A-Za-z0-9--]",hostname) Then
	ef=True
	ec="请输入合法的域名！"
end if

session("username")=Sagent("username")
session("agentname")=Sagent("username")
session("agenttype")=Sagent("agenttype")
session("atspace")="API区"
if session("agentname")=session("username") then
session("AgnRunasUser")=True
else
session("AgnRunasUser")=false
end if
'登陆用户区
If Not ef Then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
Set dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&session("username")&"' and status='正常' and Domain='"&Request.form ("name")&"'"
	dsdom.Open sql,conn,1,1
if dsdom.eof then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=注册成功状态的域名中不存在这个域名！"
end if
end if

if not ef then
If dsdom("status")<>"正常" Then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=未付费的产品不能设置！"
end if
end if

If Not ef Then
'If keyname=MyDnsPass keyname=Password keyname=ExpireDate
If Request.form("keyname")="ExpireDate" Then
response.write "name="&Request.form("name")&"&key="&year(dsdom("endtime"))&"-"&right("0"&month(dsdom("endtime")),2)&"-"&right("0"&day(dsdom("endtime")),2)
else
response.write "name="&Request.form("name")&"&key="&dsdom("inipass")
End if
End if

If ef Then
response.write ec
End if
response.End'处理完成后就停止运行
End if
End If
End If



'---------------------------------------------'上面是getpass

If Not ef Then
If Request.QueryString("method")="ChangeProductKey" Then
If MD5("ChangeProductKey"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("dn")+Request.form("enc"))<>Request.form("checksum") Then
response.write "ret=0&err=verify-failure&freehosinfo=API密码加密码检查非法"
response.End
Else

 
hostname=Request.form("dn")
hostname=ComX.idntoac_7i24_com(cstr(hostname))
hostname=replace(hostname,".","")
hostname=replace(hostname,"xn--","")
If RegExpTest("[^A-Za-z0-9--]",hostname) Then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=请输入合法的域名！"
end if

session("username")=Sagent("username")
session("agentname")=Sagent("username")
session("agenttype")=Sagent("agenttype")
session("atspace")="API区"
if session("agentname")=session("username") then
session("AgnRunasUser")=True
else
session("AgnRunasUser")=false
end if
'登陆用户区
If Not ef Then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
Set dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&session("username")&"' and status='正常' and Domain='"&Request.form ("dn")&"'"
	dsdom.Open sql,conn,1,3
if dsdom.eof then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=不存在的域名！"
end if
end if

if not ef then
If dsdom("status")<>"正常" Then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=未付费的产品不能设置！"
end if
end if

if not ef then
'dim returncodevalue,failreason
Dim passarry3,passarry5
Dim Newdomainpass,domainpass
Newdomainpass=Request.form ("newkey")
domainpass=dsdom("inipass")
	If Newdomainpass<>"" Then domainpass=Newdomainpass'新密码
Enddomaintypeid=GetDomaintype(request.form("dn"))
ChangeDomainPD()
dsdom.update
end If

If Not ef Then
response.write "ret=100&name="&Request.form("name")&"&keyname=Password&key="&dsdom("inipass")
'        成功: ret=100&name=dfdaf.org&keyname=Password&key=xdsfd
 '       失败: ret=0&name=dfdaf.org&keyname=MyDnsPass&key=xdsfd
End if
If ef Then
response.write "ret=0&err=oldkey-invalid&name="&Request.form("name")&"&keyname=Password&key="&dsdom("inipass")&"&freehostinfo="&ec
End if
response.End'处理完成后就停止运行
End if
End If
End If










''开始续费------------------------------------------------
If Not ef Then
If Request.QueryString("method")="DomainRenew" Then
'checksum=MD5("DomainRenew"+client+password+dn+enc+begindate)
If MD5("DomainRenew"+Request("client")+Sagent("Domain_Agent_nonemd5_6")+Request.form("dn")+Request.form("enc")+Request.form("begindate"))<>Request.form("checksum") Then
response.write "ret=0&err=verify-failure&freehosinfo=API密码加密码检查非法"
response.End
Else

 
hostname=Request.form("dn")
hostname=ComX.idntoac_7i24_com(cstr(hostname))
hostname=replace(hostname,".","")
hostname=replace(hostname,"xn--","")
If RegExpTest("[^A-Za-z0-9--]",hostname) Then
	ef=True
	ec="请输入合法的域名！"
end if

session("username")=Sagent("username")
session("agentname")=Sagent("username")
session("agenttype")=Sagent("agenttype")
session("atspace")="API区"
if session("agentname")=session("username") then
session("AgnRunasUser")=True
else
session("AgnRunasUser")=false
end if
'登陆用户区
If Not ef Then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
Set dsdom = Server.CreateObject("ADODB.Recordset")
sql="Select * from FreeHost.FreeHost_Product_Domain where username='"&session("username")&"' and Domain='"&Request.form ("dn")&"'"
	dsdom.Open sql,conn,1,3
if dsdom.eof then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=不存在的域名！"
end if
end if

if not ef then
If dsdom("status")<>"正常" Then
	ef=True
	ec="ret=0&err=name-invalid&freehostinfo=未付费的产品不能设置！"
end if
end if


if not ef Then
'Dim enc
Enddomaintypeid=GetDomaintype(dsdom("Domain"))
end if

if not ef then
	Set dsDlist = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_DomainProductlist where id='"&Enddomaintypeid&"'"
		dsDlist.Open Sql,conn,1,1
if dsDlist.eof then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=管理员没有定义域名的价格，请联系管理员！"
else
usermoney=dsDlist("usermoneyrepay")
myrealcost=dsDlist("usermoneyagnrepay")
end if
end if

if not ef then
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&dsdom("username")&"'"
		ds.Open Sql,conn,3,2
if ds.eof then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=用户不存在!"
end if
end if


if not ef then
yearstr=Request("period")
end if

If Not ef Then
Dim cnrepay
cnrepay=false
if Application("cnrepay")=true then
if Enddomaintypeid=2 And Clng(yearstr)=1 Then
If dsdom("starttime")>CDate(#2007-3-7 12:00:00#) and dsdom("starttime")<CDate(#2008-12-31 23:59:59#) And dsdom("endtime")>CDate(#2008-3-7 12:00:00#) and dsdom("endtime")<CDate(#2009-12-31 23:59:59#) and now<CDate(#2010-3-1 00:00:01#) Then
cnrepay=true
End if
End if
end If
end If

if not ef then
if dsdom("Domain_API")<>1 and dsdom("Domain_API")<>2 and dsdom("Domain_API")<>3 and dsdom("Domain_API")<>4  and dsdom("Domain_API")<>5  And dsdom("Domain_API")<>6 then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=非法API！"
end if
end if

if not ef then
if DateDiff("s", Application("domainoptime"),NOW )<Application("domainopmax") and Application("domainoplock")=true then
	ef=True
	ec="ret=0&err=auth-failure&freehostinfo=系统繁忙，前一个操作尚未处理完，请您稍等两分钟后再试，谢谢您的支持。"
end if
end if




if not ef then
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock
'dim starttime,temptime,pdtype
starttime=dsdom("endtime")
pdtype=dsdom("Domain")

oldtime=dsdom("endtime")
tend=dsdom("endtime")
temptime=dateadd("yyyy",yearstr,tend)

'dim ef,ec,
'Dim Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,RsDlist,isreplay,domainRepayAPI
isreplay=true
set RsDlist=dsDlist
Userpaymoney=dsDlist("usermoneyrepay")'续费价
domainRepayAPI=dsdom("Domain_API")
If domainRepayAPI<>1 Then Userpaymoney=dsDlist("usermoneyrepay"&domainRepayAPI)'api
if havehostget=false then
forpayyear=yearstr
else
forpayyear=999
end if
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="域名产品"
forpayid=dsDlist("id")
logfor="管理区续费(域名"&dsdom("Domain")&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
'AgnRunasUser=false'管理区 作为代理自己操作
session("moneylog_pdid")=dsdom("id")
DoPayMoneyDomain
Application.lock
Application("domainoplock")=false
Application.unlock
end if

if not ef Then
dsdom("status")="续费失败"
dsdom.update
Application.lock
Application("domainoptime")=now
Application("domainoplock")=true
Application.unlock


'dim returncodevalue,failreason
RepayDomainNow()

Application.lock
Application("domainoplock")=false
Application.unlock
end if


if not ef Then
dsdom("status")="正常"
dsdom("endtime")=temptime
dsdom("emailstatus")=Null
dsdom("smsstatus")=null
dsdom.update

'email
'开通邮箱
	Set dsemailpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Domaintype='"&dsDlist("Domaintype")&"' and isbydomain='y'"
	dsemailpdlist.Open Sql,conn,1,1
if not dsemailpdlist.Eof then
Set dsphemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&ds ("username")&"' and starttime='"&dsdom("starttime")&"'"
	dsphemail.Open Sql,conn,1,3
if not dsphemail.Eof then
dsphemail("endtime")=temptime
dsphemail.update
FreeHost_oplog session("username"),"信息","用户自己操作域名延期，域名赠送邮箱产品自动延期 ID:"&dsphemail("id")
retemail="赠送的邮箱产品已延期"
dsphemail.close
end if
end If
end if

If Not ef Then
response.write "ret=100&info=renew-success"
End if

If ef Then
response.write ec
End if
response.End'处理完成后就停止运行
End if
End If
End If
'---------------------------------------------'上面是续费




If Not ef Then
If IsNull(Sagent("Domain_Agent_md5_6")) Or Sagent("Domain_Agent_md5_6")<>Request("checksum") Then
	ef=True
	ec="代理API密码不正确！"
end If
End If

'If Not ef Then
'If Sagent("apiip1")<>Request.ServerVariables("REMOTE_ADDR") and Sagent("apiip2")<>Request.ServerVariables("REMOTE_ADDR") And Sagent("apiip3")<>Request.ServerVariables("REMOTE_ADDR") And 'Sagent("apiip4")<>Request.ServerVariables("REMOTE_ADDR") Then
'	ef=True
'	ec="您的IP没有没有被授权，请检查代理区有没有设置允许当前的IP调用："&Request.ServerVariables("REMOTE_ADDR")
'end If
'End if

If ef Then
response.write ec
Sagent.close
Set Sagent=Nothing
conn.close
Set conn=nothing
response.end
End if



If Request("Optype")="systemtest" Then
response.write "授权通过，连接上级主控服务器自检成功,API的版本为1.0"
End If

If Request("Optype")="checkdomain" Then
'Server.Execute "/style/info/domaincheckpub.asp"
End if
'Server.Execute "/default.asp"












'加入域名表中FUN
Function CLen(HzStr)
L = len(HzStr)
For n=1 to L
If Asc(mid( HzStr,n,1))<0 Then HzNum = HzNum + 1
Next
Clen = L + HzNum
End Function
for each item in Request.Form
if instr(Request.Form(item),"'")>0 Then
	ef=True
	ec="ret=0&err=invalid&freehostinfo=出错，请不要输入'字符！"
end If
if instr(Request.Form(item),"&")>0 Then
	ef=True
	ec="ret=0&err=invalid&freehostinfo=出错，请不要输入&字符！"
end If
if CLen(Request.Form(item))>50 Then
	ef=True
	ec="ret=0&err=invalid&freehostinfo=出错，请不要输入超出50个字母或25个汉字！"&Request.Form(item)&" 字数为："&CLen(Request.Form(item))
end If
next

Function Chk_Num(number)
Chk_Num = True
ChkStr = "0123456789"
For cnt = 1 To Len(number)
Str1Chara = Mid(number, cnt, 1)
If InStr(ChkStr, Str1Chara) = 0 Then
Chk_Num = False
Exit For
End If
Next
End Function

	Function CheckStrinAsc(str)
		CheckStrinAsc = True
		If Len(str)=0 Or str = Null Then CheckStrinAsc = False:Exit Function
		For i = 1 To Len(str)
			If asc(mid(str,i,1)) < 0 Then	CheckStrinAsc = False:Exit Function
		Next
		If Len(str)<3 Then	CheckStrinAsc = False:Exit Function
		if CLen(str)>50 Then CheckStrinAsc = False:Exit Function
	End Function
%>
