<%session.Timeout=240%>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%

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

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

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

If Len(Request("userstr"))<>32 Then
response.write "ret=0&err=auth-failure&freehosinfo=API密码长度必须是32位"
response.end
End If

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

If Request("action")<>"activate" And Request("action")<>"renew" And Request("action")<>"getinfo" 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("userid")&"'"
		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 IsNull(Sagent("canuseapi")) Or Sagent("canuseapi")<>true Then
	ef=True
	ec="代理"&Sagent("username")&"尚未开通API的权限"
end If
End If

If Not ef Then
If isnull(Sagent("Domain_Agent_nonemd5_6")) Then
	ef=True
	ec="代理"&Sagent("username")&"需要更新代理密码后才能使用本功能，请马上到上级系统中更新代理密码。"
End if
End if


If Not ef Then
If MD5(Sagent("Domain_Agent_nonemd5_6")+"7i24.com")<>Request("userstr") Then
	ef=True
	ec="md5检查非法"
End If
End if

If Not ef Then
If Request("action")="activate" then



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
Ftpname=LCase(Trim(Request ("Ftpname")))
Ftppassword=Trim(Request ("Ftppassword"))
HostListpdid=Request ("productid")
ReqServerlistID=CStr(Request("idc"))
If Request("idc")="" Then ReqServerlistID="0"
If Ftpname="" Then'生成ftp用户名密码
Ftpname=Left(md5(now&"7i24.com"&now),8)
Ftppassword=Left(md5(now&"7i24.com"),8)
End if
End If

If session("username")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf HostListpdid="" Then
	ef=True
	ec="请选择产品！"
ElseIf not IsNumeric(HostListpdid)  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf not IsNumeric(ReqServerlistID)  Then
	ef=True
	ec="机房ID应该是数字！"
ElseIf IsNumeric(Ftpname)  Then
	ef=True
	ec="FTP用户名不能是纯数字！"
ElseIf not IsNumeric(Request ("year"))  Then
	ef=True
	ec="时间应该是数字！"
ElseIf Ftpname="" Then
	ef=True
	ec="请设置FTP用户名！"
ElseIf Len(Ftpname)<6 Then
	ef=True
	ec="FTP用户名长度不能小于6位！"
ElseIf Trim(LCase(Ftpname))="self" or Trim(LCase(Ftpname))="adm" or Trim(LCase(Ftpname))="admin" or Trim(LCase(Ftpname))="sefreehost" Or Trim(LCase(Ftpname))="administrator" Or Trim(LCase(Ftpname))="freehost" Or Trim(LCase(Ftpname))="proxy" Then
	ef=True
	ec="您输入的FTP用户名为保留用户名，请换一个ftp用户名"
ElseIf Ftppassword="" Then
	ef=True
	ec="请设置FTP密码！"
ElseIf RegExpTest("[^A-Za-z0-9]",Ftpname) Then
	ef=True
	ec="FTP用户名中有非法字符！"
ElseIf RegExpTest("[^A-Za-z0-9]",Ftppassword)  or len(Ftppassword)<6 Then
	ef=True
	ec="FTP密码有非法字符，只能是字母与数字或密码长度小于6位！"
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 ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

'if not ef then
'if ds("password")<>session("password") then
'	ef=True
'	ec="密码不正确!"
'end if
'end if

if not ef then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where id='"&HostListpdid&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品不存在！"
Else
packagename=dshost("packagename")'linux
ServerlistID=dshost ("ServerlistID")'机房选择
if  ReqServerlistID=cstr(dshost ("ServerlistID2")) and dshost ("ServerlistID2")<>0 then ServerlistID=dshost ("ServerlistID2")
if  ReqServerlistID=cstr(dshost ("ServerlistID3")) and dshost ("ServerlistID3")<>0 then ServerlistID=dshost ("ServerlistID3")
if  ReqServerlistID=cstr(dshost ("ServerlistID4")) and dshost ("ServerlistID4")<>0 then ServerlistID=dshost ("ServerlistID4")
if  ReqServerlistID=cstr(dshost ("ServerlistID5")) and dshost ("ServerlistID5")<>0 then ServerlistID=dshost ("ServerlistID5")
if ds("agent1")<>"n" then
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist_AGN where id='"&HostListpdid&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
dim isAgnHostSer
if not agnserverid.Eof then
if agnserverid ("ServerlistID")<>0 then
ServerlistID=agnserverid ("ServerlistID")
isAgnHostSer=true
else
isAgnHostSer=false
end if
end if
end if'isagn
end if
end If

if not ef then
If Request ("year")<>999 and Request ("year")<>dshost("PAY_Month") and Request ("year")<>dshost("PAY_Season")  and Request ("year")<>dshost("PAY_halfyear") and Request ("year")<>1 and Request ("year")<>dshost("PAY_2year") and Request ("year")<>dshost("PAY_3year") and Request ("year")<>dshost("PAY_4year") and Request ("year")<>dshost("PAY_5year") Then
	ef=True
	ec="请选择时间！"
end If
end if

if not ef then
if dshost("usermoney")=0 then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where username='"&session("username")&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
	ef=True
	ec="金额为零的产品，一个用户只能申请一个！"
end if
dsph.close
end if
end if

if not ef then
if Not IsNull(dshost("onlyusebyagn")) Then
If session("agentname")<>dshost("onlyusebyagn") then
	ef=True
	ec="本产品只允许特定的代理使用！"
End if
end if
end If

if not ef then
if dshost("canbyenduser")="n" And session("agentname")="n" then
	ef=True
	ec="本产品不允许最终用户开通！"
end if
end If

if not ef then
if dshost("canbyagnenduser")="n" And session("agentname")<>"n" then
	ef=True
	ec="本产品不允许用户开通！"
end if
end If

if not ef then
if dshost("canbyagn")="n" And session("AgnRunasUser")=true then
	ef=True
	ec="本产品不允许代理开通！"
end if
end if

if not ef then
if Request ("year")=999 and dshost("cantest")="n" then
	ef=True
	ec="很抱歉,本产品不可以试用！"
end if
end if
if not ef then
if Request ("year")=dshost("PAY_Month") and dshost("canmonth")="n" then
	ef=True
	ec="很抱歉,本产品不可以月付！"
end if
end if
if not ef then
if Request ("year")=dshost("PAY_Season") and dshost("canseason")="n" then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request ("year")=dshost("PAY_halfyear") and dshost("canhalfyear")="n" then
	ef=True
	ec="很抱歉,本产品不可以半年付！"
end if
end if

'IP黑名单检查
for iX=0 to ubound(Application("blockiparry"))
lenip=Len(Application("blockiparry")(iX))
If lenip>4 then
'response.write Application("blockiparry")(iX)&"<br>"
if Application("blockiparry")(iX)=Left(Request.ServerVariables("REMOTE_ADDR"),lenip) then
	ef=True
	ec="您的IP或IP段"&Request.ServerVariables("REMOTE_ADDR")&"属于黑名单IP:"&Application("blockiparry")(iX)&"@，不允许开通！"
exit for
end If

End if
Next

'response.write ubound(Application("blockiparry"))&Request.ServerVariables("REMOTE_ADDR")
'response.end

if not ef then
'	Set dsserver = Server.CreateObject("ADODB.Recordset")	
'	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&ServerlistID&"'"
'	dsserver.Open Sql,conn,1,1
'if dsserver.Eof then
'	ef=True
'	ec="服务器不存在！"
'else
 '   netby=dsserver("netby")
'	ip=dsserver("ip")
'	hostip=dsserver("ip")
'	ftpdomain=dsserver("ftpdomain")
'	ostype=dsserver("ostype")
'end if


if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Serverlist where id='"&ServerlistID&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
Else
    netby=dsserver("netby")
	ip=dsserver("ip")
	hostip=dsserver("ip")
	ftpdomain=dsserver("ftpdomain")
	ostype=dsserver("ostype")
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


end If

if not ef Then
If ostype="linux" then
If Len(Ftpname)>10 Then
	ef=True
	ec="Linux系统中FTP用户名不能超过10个字符！"
End If
If IsNumeric(Left(Ftpname,1)) Then
	ef=True
	ec="Linux系统中FTP用户名第一个字符不能是数字！"
End if
end if
end If

if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
ostype=dsserver("ostype")
If ostype="linux" then
InCmd="CMD_API_SHOW_ADMINS"
temp=DAAPIGET(URL,"admin",FreeHostsharekey,InCmd)
else
temp=SystemTest(URL,FreeHostsharekey)
End If
if not instr(temp,"成功")>1 and Not InStr(temp,"[]=admin")>1 Then
	ef=True
	ec="系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。内部原因:"&temp
Else
if (instr(temp,"2011")>1 or instr(temp,"2012")>1 or instr(temp,"2013")>1 or instr(temp,"2014")>1 or instr(temp,"2015")>1 or instr(temp,"2016")>1 or instr(temp,"2017")>1 or instr(temp,"2018")>1) and  ostype="windows" Then isnewCS=true
end If
end if
if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where Ftpname='"&Ftpname&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
	ef=True
	ec="您输入的FTP用户名已存在，请另外输入一个！"
end if
dsph.close
end if

if not ef then 'test hostname
if ds("agent1")<>"n" and len(dsserver("tempdomainagn"))>3 then
hostname=":80:"&Ftpname&"."&dsserver("tempdomainagn")&","
else
hostname=":80:"&Ftpname&"."&dsserver("tempdomain")&","
end if
'if Application("openmustre")=false Then
if dsserver("openmustre")=false Then
If (Request ("year")=999 and Application("testhostcandomain")=true) Or Request ("year")<>999 then
if trim(Request.Form ("hostname1"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname1"), " ",""),":80:","")&","

domain=replace(lcase(trim(Request.Form ("hostname1"))),"http://","")

domain=ComX.idntoac_7i24_com(cstr(domain))
domain=GetDomainMain(domain)
if dsserver("autodelicp")=true then'如果启用后台检查
	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")=ds("username")
dsICPDB("ftpname")=ftpname
dsICPDB("domain")=domain
dsICPDB("status")="尚未检测"
dsICPDB("firstaddtime")=Now
dsICPDB("agent1")=ds("agent1")
dsICPDB("agent2")=ds("agent2")
dsICPDB.update
end If
dsICPDB.close
End if

end if

end If
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='"&ServerlistID&"'"
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(replace(lcase(trim(replace(hostname_arry (i),":80:","")),"http://",""),Application("blockdomainarry")(iX))>0 Then
if InStr(LCase(replace(hostname_arry (i),":80:","")),Application("blockdomainarry")(iX))>0 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
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where username='"&session ("username")&"' and istest='y'"
	dsph.Open Sql,conn,1,3
if Request ("year")=999 then
if not dsph.Eof then
	ef=True
	ec="一个用户只能试用一个产品！"
end if
end if
end if

'if not ef then'time
'if Application("Hostopen_Time")="" then
'Application("Hostopen_Time")=now
'else
'Application.lock
'if DateDiff("s", Application("Hostopen_Time"),NOW )<40 then
'	ef=True
'	ec="请稍后再试，系统设置40秒内只能开通一个用户！"
'else
'Application("Hostopen_Time")=now
'end if
'Application.unlock
'end if
'end If




if not ef then

dim starttime,temptime,pdtype
pdtype=dshost("Hosttype")
starttime=NOW
'结束时间
y=Request ("year")
if y=1 then temptime=dateadd("yyyy",1,now)
if y=dshost("PAY_2year") then temptime=dateadd("yyyy",2,now)
if y=dshost("PAY_3year") then temptime=dateadd("yyyy",3,now)
if y=dshost("PAY_4year") then temptime=dateadd("yyyy",4,now)
if y=dshost("PAY_5year") then temptime=dateadd("yyyy",5,now)
if y=dshost("PAY_Month") then temptime=dateadd("y",31,now)
if y=dshost("PAY_Season") then temptime=dateadd("y",92,now)
if y=dshost("PAY_halfyear") then temptime=dateadd("y",182,now)
if y=999 then
temptime=dateadd("y",Application("testtime"),now)
dim isfortest
isfortest=true
end if

dim ef,ec,Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser
Userpaymoney=dsHost("usermoney")
forpayyear=Request ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="虚拟主机"
forpayid=dshost("id")
logfor="API区开通(FTP名"&Ftpname&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
DoPayMoney
end if

if not ef then
dim Subject,body'send mail
dsph.AddNew
dsph("username")=ds ("username")
dsph("ServerlistID")=dsserver("id")
dsph("Hosttype")=dshost("Hosttype")
dsph("oriHosttype")=dshost("Hosttype")
dsph("starttime")=starttime
dsph("endtime")=temptime

dsph("CDNMaxMb")=dshost("CDNMaxMb")
dsph("Maxbytes")=dshost("Maxbytes")
dsph("MaxCPU")=dshost("MaxCPU")

dsph("ostype")=ostype

dsph("Ftpname")=Ftpname
dsph("Ftppassword")=Ftppassword
dsph("hostname")=hostname
if hostname="" then '生成临时
dsph("hostname")=":80:"&dsph ("Ftpname")&"."&dsserver("tempdomain")
if ds("agent1")<>"n" and len(dsserver("tempdomainagn"))>3 then
dsph("hostname")=":80:"&dsph ("Ftpname")&"."&dsserver("tempdomainagn")
end if
end if
dsph("status")="准备开通"
if y=999 then
dsph("istest")="y"
else
dsph("istest")="n"
end if

if ds("agent1")<>"n" then
dsph("agent1")=ds("agent1")
else
dsph("agent1")="n"
end if

dsph("allowsub")=dshost("allowsub")
dsph("subweb")=dshost("subweb")
dsph("useper")=100

dsph("canseelog")=dshost("canseelog")
dsph("canrar")=dshost("canrar")
dsph("canback")=dshost("canback")
dsph("canrecypool")=dshost("canrecypool")

dsph("canchnetver")=dshost("canchnetver")
dsph("notuserar")=dshost("notuserar")

dsph("kefu")=ds("kefunow")

dsph.Update


'LOG
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where Ftpname='"&Ftpname&"'"
	dsph.Open Sql,conn,1,3
Sql="UPDATE [FreeHost].[FreeHost_Moneylog] set pdid='"&dsph("id")&"' where pdid='"&session("moneylog_pdid")&"'"
    conn.Execute Sql

if isAgnHostSer=false then 
if dshost("isbydomain")="y" then
'送域名
	Set dspre = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Preopen_Product"
	dspre.Open Sql,conn,1,3
dspre.addnew
dspre("username")=ds("username")
dspre("haveget")="n"
dspre("byid")=dsph("id")
dspre("type1")=dshost("Domaintype")
dspre("whichProduct")="虚拟主机"
dspre("attime")=now
dspre("agent1")=ds("agent1")
dspre.update
dspre.close
set dspre=nothing
end if
end if

'开通邮箱
haveopenemail=False
openemailid=0
	Set dsemailpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
	dsemailpdlist.Open Sql,conn,1,1
if not dsemailpdlist.Eof then

ServerlistID=dsemailpdlist ("ServerlistID")
	Set dsemailserver = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serveremaillist where netby='"&netby&"' and agent1='n'"
		dsemailserver.Open Sql,conn,1,1
while not dsemailserver.Eof
 if ( dsemailpdlist ("ServerlistID2")=dsemailserver ("id")  or dsemailpdlist ("ServerlistID3")=dsemailserver ("id") or dsemailpdlist ("ServerlistID4")=dsemailserver ("id") or dsemailpdlist ("ServerlistID5")=dsemailserver ("id")) then
 ServerlistID=dsemailserver("id")'优先选择可选机房中的同机房
 end if
dsemailserver.movenext
wend
dsemailserver.Requery
while not dsemailserver.Eof
 if ip=dsemailserver("ip") and ( dsemailpdlist ("ServerlistID2")=dsemailserver ("id")  or dsemailpdlist ("ServerlistID3")=dsemailserver ("id") or dsemailpdlist ("ServerlistID4")=dsemailserver ("id") or dsemailpdlist ("ServerlistID5")=dsemailserver ("id")) then
 ServerlistID=dsemailserver("id")'优先选择可选机房中的同IP
 end if
dsemailserver.movenext
wend
dsemailserver.close


	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_EmailProductlist_AGN where id='"&dsemailpdlist ("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if  agnserverid ("ServerlistID")<>0 then ServerlistID=agnserverid ("ServerlistID")
end if


Set dsphemail = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Email where username='"&session ("username")&"'"
	dsphemail.Open Sql,conn,1,3
dsphemail.addnew
dsphemail("username")=ds("username")

dsphemail("ServerlistID")=ServerlistID
dsphemail("Emailtype")=dsemailpdlist("Emailtype")
dsphemail("starttime")=starttime
dsphemail("endtime")=temptime
dsphemail("byhost")=dsph("id")
if y=999 then
dsphemail("istest")="y"
else
dsphemail("istest")="n"
end if

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

'log
	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
'response.write "赠送的邮箱产品已开通!!!!!!"
retemail="赠送的邮箱产品已开通"
FreeHost_oplog session("username"),"信息","用户自己开通，虚拟主机("&dsph ("Ftpname")&")赠送邮箱ID:"&dsphemail("id")

haveopenemail=true
openemailid=dsphemail("id")
'-------------------------------------------API专用
emailname=Application("admmailname")&"@"&ftpname&"-notuse.com"
Set dspdallemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select top 1 * from FreeHost.FreeHost_Product_ALLEmail where username='"&ds ("username")&"' and PdEID='"&dsphemail ("id")&"'"
		dspdallemail.Open Sql,conn,1,3
 dspdallemail.addnew
dspdallemail("emailname")=emailname
dspdallemail("emailpass")=ftppassword
dspdallemail("username")=ds ("username")
dspdallemail("PdEID")=dsphemail ("id")
dspdallemail("Emailtype")=dsphemail ("Emailtype")
dspdallemail("starttime")=now
dspdallemail("endtime")=dsphemail ("endtime")
dspdallemail("istest")=dsphemail ("istest")
dspdallemail("status")=dsphemail ("status")
dspdallemail("userspacelimt")=dsphemail ("userspacelimt")
dspdallemail("domainspacelimt")=dsphemail ("domainspacelimt")
dspdallemail.update
dspdallemail.close
'-------------------------------------------API专用

end if

'SQL
haveopensql=False
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select top 1 * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
If isAgnHostSer=True Then Sql="Select top 1 * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and isbyhost='y'"
If IsNumeric(Request("dsSqlpdlistID")) And Request("dsSqlpdlistID")<>"" Then Sql="Select top 1 * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and id='"&Request("dsSqlpdlistID")&"' and isbyhost='y'"
If dshost("cantwodb")=True Then sql=Replace(sql,"top 1 *","*")'如果产品允许送两个库,2013-7-23
'FreeHost_oplog session("username"),"信息","API区，用户开通虚拟主机SQL命令:"&sql
	dsSqlpdlist.Open Sql,conn,1,1
while not dsSqlpdlist.Eof
'FreeHost_oplog session("username"),"信息","API区，用户开通虚拟主机产品ID:"&dsSqlpdlist("dsSqlpdlist")
'12-27修改bug
ServerlistID=dsSqlpdlist ("ServerlistID")
	Set dsSqlserver = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Serversqllist where netby='"&netby&"' and agent1='n'"

		dsSqlserver.Open Sql,conn,1,1
while not dsSqlserver.Eof
 if (dsSqlpdlist ("ServerlistID")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID2")=dsSqlserver("id")  or dsSqlpdlist ("ServerlistID3")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID4")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID5")=dsSqlserver("id")) then
 ServerlistID=dsSqlserver("id")'优先选择可选机房中的同机房
 end if
 dsSqlserver.movenext
wend
dsSqlserver.Requery
while not dsSqlserver.Eof
 if ip=dsSqlserver("ip") and (dsSqlpdlist ("ServerlistID")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID2")=dsSqlserver("id")  or dsSqlpdlist ("ServerlistID3")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID4")=dsSqlserver("id") or dsSqlpdlist ("ServerlistID5")=dsSqlserver("id")) then
 ServerlistID=dsSqlserver("id")'优先选择可选机房中的同一IP
 end if
  dsSqlserver.movenext
wend
dsSqlserver.close

	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_SqlProductlist_AGN where id='"&dsSqlpdlist("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if  agnserverid ("ServerlistID")<>0 then ServerlistID=agnserverid ("ServerlistID")
end if


	Set dsserverSQL = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerSqllist where id='"&ServerlistID&"'"
	dsserverSQL.Open Sql,conn,1,1
if not dsserverSQL.Eof then

Set dsphSql = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where username='"&session ("username")&"'"
	dsphSql.Open Sql,conn,1,3



dsphSql.addnew
dsphSql("username")=ds("username")
dsphSql("ServerlistID")=ServerlistID
dsphSql("Sqltype")=dsSqlpdlist("Sqltype")
dsphSql("starttime")=starttime
dsphSql("endtime")=temptime
dsphSql("byhost")=dsph("id")
if y=999 then
dsphSql("istest")="y"
else
dsphSql("istest")="n"
end if

Randomize
sqlname="a"&right("0"& month(Now),2)& right("00" & day(Now),2)& right("00" & hour(Now),2)& right("00"& Minute(Now),2)& right( "00"& second(Now),2)
Randomize
id=CLng((100000000 - 20 + 7850) * Rnd + 100)
sqlpassword=id
sqlpassword=Ftppassword'--------------------------------api专用
'dsphSql("Sqlcount")=dsSqlpdlist("Sqlcount")
dsphSql("userspacelimt")=dsSqlpdlist("userspacelimt")
dsphSql("logspacelimt")=dsSqlpdlist("logspacelimt")
dsphSql("sqlname")=sqlname
dsphSql("sqlpassword")=sqlpassword
dsphSql("status")="正常"
if ds("agent1")<>"n" then
dsphSql("agent1")=ds("agent1")
else
dsphSql("agent1")="n"
end if
dsphSql.update

URL=dsserverSQL("site")
FreeHostsharekey=dsserverSQL("FreeHostsharekey")
userid=dsserverSQL ("admname")
pwd=dsserverSQL("admpass")
homedir=dsserverSQL("homedir")
ip=dsserverSQL("ip")
port=dsserverSQL("port")
userspacelimt=dsphSql("userspacelimt")
logspacelimt=dsphSql("logspacelimt")
sqlname=dsphSql("sqlname")
sqlpassword=dsphSql("sqlpassword")
'ret=SqlAdd(URL,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
'response.write ret


dim softtype,MySQLver,MSSQLver
softtype=dsserverSQL("softtype")
MySQLver=dsserverSQL("MySQLver")
MSSQLver=dsserverSQL("MSSQLver")

if softtype="SQL2000" then
retsql=SqlAdd(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
else
retsql=SqlAddmysql(URL,FreeHostsharekey,userid,pwd,homedir,userspacelimt,logspacelimt,sqlname,sqlpassword)
end if

'	dsphSql("status")="正常"
'	dsphSql.update

FreeHost_oplog session("username"),"信息","用户自己开通，虚拟主机("&dsph ("Ftpname")&")赠送数据库,数据库名:"&sqlname&" 返回信息："&retsql
haveopensql=true
dsphSql.close


'log
'	Set dsphSql = Server.CreateObject("ADODB.Recordset")	
'	Sql="Select * from FreeHost.FreeHost_Product_Sql where starttime='"&starttime&"' and username='"&ds("username")&"'"
'	dsphSql.Open Sql,conn,1,3
'	dsphSql("status")="正常"
'	dsphSql.update



end if
dsSqlpdlist.movenext
wend


'调用开通function
AccessFlags=1
if dshost("asp")="y" then
AccessFlags=513
ScriptMaps=dsserver("asp") 
end if

if dshost("aspx")="y" then
AccessFlags=513
netver=dsserver("netver")
If Not IsNull(dshost("netver")) Then netver=dshost("netver")
If netver="1.1" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx") 
If netver="2.0" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx2") 
If netver="4.0" Then ScriptMaps=ScriptMaps&"|"&dsserver("aspx4") 
dsph("netver")=netver
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 dshost("notuserar")="y" then
ScriptMaps=ScriptMaps&"|"&dsserver("notuserar") 
end if


if dsserver("infosafe")<>""  And AccessFlags>1 then
ScriptMaps=ScriptMaps&"|"&dsserver("infosafe") 
end if
ScriptMaps=trim(replace(ScriptMaps,"||","|"))

URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
ostype=dsserver("ostype")
ip=dsserver("ip")
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=ds("email")
host=dsph("hostname")
status=dsph("status")
hostcomment_arry=Split(host, ",")
hostcomment=username&"_"&Replace(hostcomment_arry(0),":80:","")&"_"&dsph ("username")
MaxConnections=dshost ("MaxConnections")
EnumAppsInPool=dshost ("AppPoolnum")

'DefaultDoc=""'dshost ("DefaultDoc")
ScriptMaps=ScriptMaps
AccessFlags=AccessFlags
'LogFileDirectory=""'dsserver ("LogFileDirectory")
'HttpErrors=""'Request.Form ("HttpErrors")
MaxBandwidth=dshost("MaxBandwidth")

hostname=host
 
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)
dsph("hostname")=hostname
dsph.update
host=hostname

if y=999 and Application("testsame")<>true then'如果是试用
MaxConnections=Application("MaxConnections")
spacelimit=Application("spacelimit")
MaxBandwidth=Application("MaxBandwidth")
end if


if dsserver("iisver")>6 Then
hostnamestr=replace(hostname, ":80:","")
hostname_arry=Split(hostnamestr, ",")
for i=0 to ubound(hostname_arry)
hostname_arry(i)=ComX.actoidc_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)
host=hostname
End If

if Application("hostoneip")=true Then
Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Host_IP where ServerlistID="&dsserver("id")&" and HostID=0 order by orderbyid desc"
		dsX.Open Sql,conn,1,3
If not dsX.Eof Then
dsX("HostID")=dsph("id")
host=Replace(host,":80:",dsX("IP")&":80:")
if Application("iphead")=true Then
host=dsX("IP")&":80:"&dsX("IP")&","&host
dsph("iphead")=true
End if
ftpdomain=dsX("IP")
hostip=dsX("IP")
dsX.update
End if
End If

'dim Subject,body


oridir=dshost("oridir")

dsph("AppPoolnum")=dshost("AppPoolnum")'2011

dsph("AppPoolnum")=dshost("AppPoolnum")'2011
dsph.update

if not ef And isnewCS=True Then
'新的受控
CurPoolname=dsph("AppPoolnum")&"_FreeHost_1"
Curpoolid=1
haneemptypool=False
	Set dsPooldist = Server.CreateObject("ADODB.Recordset")	
Sql="Select distinct CurPoolname from FreeHost.FreeHost_Product_Host where serverlistid='"&dsph("ServerlistID")&"' and hosttype<>'子目录绑定' and AppPoolnum='"&EnumAppsInPool&"' and CurPoolname is not null and CurPoolname like '"&EnumAppsInPool&"_F%' order by CurPoolname Asc"
	dsPooldist.Open Sql,conn,1,1
'	response.write sql
If dsPooldist.Eof Then haneemptypool=true'一个这样的池也没有
Do Until dsPooldist.Eof
CurPoolname=dsPooldist("CurPoolname")
If CInt(Replace(CurPoolname,dsph("AppPoolnum")&"_FreeHost_",""))>Curpoolid Then Curpoolid=CInt(Replace(CurPoolname,dsph("AppPoolnum")&"_FreeHost_",""))
'response.write "<br>"&CurPoolname&"<br>"
Set dsCurPcount = Server.CreateObject("ADODB.Recordset")	
Sql="Select count(*) from FreeHost.FreeHost_Product_Host where serverlistid='"&dsph("ServerlistID")&"' and hosttype<>'子目录绑定' and CurPoolname='"&CurPoolname&"'"
	dsCurPcount.Open Sql,conn,1,1
'	response.write dsCurPcount(0)&"<br>"
	If dsCurPcount(0)<CInt(EnumAppsInPool) Then'池没装完
	If dsCurPcount(0)>0 Then CurPoolname=dsPooldist("CurPoolname")'池名不变
	haneemptypool=true
	Exit do
	End if
	dsCurPcount.close
dsPooldist.movenext
loop
dsPooldist.close
if haneemptypool=False Then CurPoolname=EnumAppsInPool&"_FreeHost_"&CStr(Curpoolid+1)
dsph("CurPoolname")=CurPoolname
dsph.update
End if

'response.write "新的受控...........池名"&CurPoolname&dsph("CurPoolname")

Application.lock
Application("hostoptime")=now
Application("hostoplock")=true
Application.unlock

if isuseCDN=true Then host=Replace(host,":80:",":"&CDNORIport&":")
If isnewCS=true And Not IsNull(dsph("CurPoolname")) Then
siteID=dsph("id")&"000"
outpoolname=dsph("CurPoolname")
op=1
temp="新受控"&AddUser3(URL,FreeHostsharekey,Ftpname,password,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth,siteID,outpoolname,op)
else
temp=AddUser2(URL,FreeHostsharekey,Ftpname,password,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
End if
Application.lock
Application("hostoplock")=false
Application.unlock

'Set conn=Server.CreateObject("ADODB.Connection")
'	conn.Open Application("FreeHostDBlink")
Sql="update FreeHost.FreeHost_Product_Host set status='正常' where Ftpname='"&Ftpname&"'"
    conn.Execute Sql

if not isnull(oridir) then
oridir=Replace(oridir,"$ftpname",Ftpname)
todir=replace(homedir&"\web","\\","\")
if len(oridir)>5 then temp=temp&COPYDIR(URL,FreeHostsharekey,oridir,todir)
end if

FreeHost_oplog session("username"),"信息","API区，用户开通虚拟主机:("&Ftpname&") "&temp


If haveopensql Then
'dim Subject,body
EmailUserSQLOpen
ret=Send2Mail(conn,ds("username"),Subject,body)
End if

EmailUserHOSTOpen
ret=Send2Mail(conn,ds("username"),Subject,body)

If Application("smshostopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smshostopencon")
'恭喜！您的虚拟主机已开通了！用户名 ：#用户名# FTP地址：#FTP地址#服务器IP ：#IP#FTP用户名 ：#FTP#FTP密码 ：#FTP密码#到期时间是 ：#到期时间#您的帐户余款是 ：#金额# 元
smsContent=Replace(smsContent,"#用户名#",session("username"))
smsContent=Replace(smsContent,"#FTP地址#",ftpdomain)
smsContent=Replace(smsContent,"#IP#",hostip)
smsContent=Replace(smsContent,"#FTP#",Ftpname)
smsContent=Replace(smsContent,"#FTP密码#",password)
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(endtime,1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End If


CDNrefreshDomain'更新CDN


conn.close
Set conn=Nothing

response.write "ret=ok&ftpname="&Ftpname&"&ftppassword="&Ftppassword&"&sqlname="&sqlname&"&emailname="&emailname&"&endtime="&year(endtime)&"-"&month(endtime)&"-"&day(endtime)&"&cpurl="&Application("ctldomain")&"&attach="&request("attach")&"&hostdomain="&host&"&status="&status&"&ftpdomain="&ftpdomain&"&hostip="&hostip&"&ip="&ip&"&port="&port&"&sqltype="&sqltype&"&userspacelimt="&userspacelimt&"&logspacelimt="&logspacelimt
End if'正常开通



End if'开通操作.
End If



If Not ef Then
If Request("action")="renew" then

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
'登陆用户区
Ftpname=LCase(Trim(Request ("ftpname")))

If session("username")="" Then
	ef=True
	ec="请您先登陆用户区，再续费，在主机面板中不能续费。也有可能是超时造成了出错。"
ElseIf IsNumeric(Ftpname)  Then
	ef=True
	ec="FTP用户名不能是纯数字！"
ElseIf not IsNumeric(Request ("year"))  Then
	ef=True
	ec="时间应该是数字！"
ElseIf Ftpname="" Then
	ef=True
	ec="请设置FTP用户名！"
ElseIf Trim(LCase(Ftpname))="self" or Trim(LCase(Ftpname))="adm" or Trim(LCase(Ftpname))="admin" or Trim(LCase(Ftpname))="sefreehost" Or Trim(LCase(Ftpname))="administrator" Or Trim(LCase(Ftpname))="freehost" Or Trim(LCase(Ftpname))="proxy" Then
	ef=True
	ec="您输入的FTP用户名为保留用户名，请换一个ftp用户名"
ElseIf RegExpTest("[^A-Za-z0-9]",Ftpname) Then
	ef=True
	ec="FTP用户名中有非法字符！"
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_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if


if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where ftpname='"&Ftpname&"' and username='"&session("username")&"'"
			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="虚拟主机不存在！"
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="产品类型不存在！"
Else
'读取月付
PAY_Month=dshost("PAY_Month")
PAY_Season=dshost("PAY_Season")
PAY_halfyear=dshost("PAY_halfyear")
PAY_Nextyear=dshost("PAY_Nextyear")
if dsph("istest")="y" then PAY_Nextyear="1"
PAY_2year=dshost("PAY_2year")
PAY_3year=dshost("PAY_3year")
PAY_4year=dshost("PAY_4year")
PAY_5year=dshost("PAY_5year")
packagename=dshost("packagename")'linux
end if
end if

if not ef then
If Request ("year")<>PAY_Month and Request ("year")<>PAY_Season  and Request ("year")<>PAY_halfyear and Request ("year")<>PAY_Nextyear and Request ("year")<>PAY_2year and Request ("year")<>PAY_3year and Request ("year")<>PAY_4year and Request ("year")<>PAY_5year Then
	ef=True'不包含一年,不包含试用,只有续费
	ec="请选择时间！当前提交:"&Request ("year")&"数据库定义续费一年:"&PAY_Nextyear
end If
end If

if not ef then
if dsph("istest")="y" then
MaxConnections=dshost ("MaxConnections")
spacelimit=dshost ("spacelimt")
MaxBandwidth=dshost("MaxBandwidth")
end if
end if

if not ef then
if Request ("year")=PAY_Month and dshost("canmonth")="n" then
	ef=True
	ec="很抱歉,本产品不可以月付！"
end if
end if

if not ef then
if Request ("year")=PAY_Season and dshost("canseason")="n" then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request ("year")=PAY_halfyear and dshost("canhalfyear")="n" 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
	ostype=dsserver("ostype")'linux
if dsserver("agent1")="n" then
isAgnHostSer=false
else
isAgnHostSer=true
end if
end if
end if

if not ef then
'结束时间
'dim starttime,temptime,pdtype
starttime=dsph("endtime")
pdtype=dsph ("Hosttype")
oldtime=dsph("endtime")
if dsph("istest")="y" then  oldtime=now
y=Request ("year")
if y=PAY_Nextyear then temptime=dateadd("yyyy",1,oldtime)
if y=PAY_2year then temptime=dateadd("yyyy",2,oldtime)
if y=PAY_3year then temptime=dateadd("yyyy",3,oldtime)
if y=PAY_4year then temptime=dateadd("yyyy",4,oldtime)
if y=PAY_5year then temptime=dateadd("yyyy",5,oldtime)
if y=PAY_Month then temptime=dateadd("y",31,oldtime)
if y=PAY_Season then temptime=dateadd("y",92,oldtime)
if y=PAY_halfyear then temptime=dateadd("y",182,oldtime)
end if

if not ef Then
'dim ef,ec,Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser
'dim ef,ec,Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,isRepaymoney,Repaymoney
dim isRepaymoney,Repaymoney
Userpaymoney=dsHost("usermoney")
forpayyear=Request ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="虚拟主机"
forpayid=dshost("id")
logfor="API区延期(FTP名"&dsph("Ftpname")&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
if not isnull(dsph("repaymoney")) and not isAgnHostSer then'管理员单独设置续费价格
logfor="API区延期(单独价格)(FTP名"&dsph("Ftpname")&")"
Repaymoney=dsph("repaymoney")
isRepaymoney=true
else
isRepaymoney=false
end if
DoPayMoney
Sql="UPDATE [FreeHost].[FreeHost_Moneylog] set pdid='"&dsph("id")&"' where pdid='"&session("moneylog_pdid")&"'"
    conn.Execute Sql
end if


if not ef then

username=dsph("Ftpname")
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
tourl=dsserver("pauseweb")

'更新产品类别
'dsph ("Hosttype")=dshost("Hosttype")
'if dsph("istest")="y" then
dsph ("endtime")=temptime

dsph("emailstatus")=Null
dsph("smsstatus")=null

dsph("istest")="n"
'end if
dsph.update


'开通邮箱
Set dsphemail = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Email where byhost='"&dsph("id")&"' and username='"&session ("username")&"'"
	dsphemail.Open Sql,conn,1,3
if not dsphemail.Eof then
dsphemail("endtime")=temptime
dsphemail("status")="正常"
dsphemail("istest")="n"
dsphemail.update
retemail="赠送的邮箱产品已延期"
dsphemail.close
end if



'Sql

Set dsphSql = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_Sql where byhost='"&dsph("id")&"' and username='"&session ("username")&"'"
	dsphSql.Open Sql,conn,1,3
while not dsphSql.Eof
dsphSql("endtime")=temptime
dsphSql("istest")="n"
dsphSql("status")="正常"
dsphSql.update
retSql="赠送的数据库产品已延期"
dsphSql.movenext
wend
dsphSql.close

endtime=dsph("endtime")
dsph.update
homedir=""
'on error resume next
'Response.Write

If ostype="windows" then
temp=ModifyUser2(URL,FreeHostsharekey,username,comment,homedir,spacelimit,starttime,endtime,type1,type2,type3,email,host,hostcomment,MaxConnections,EnumAppsInPool,DefaultDoc,ScriptMaps,AccessFlags,LogFileDirectory,HttpErrors,MaxBandwidth)
End if

'Response.Write temp


if dsph("status")="暂停" Or ostype="linux" Then
op=0
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
Response.Write PauseSite(URL,FreeHostsharekey,username,tourl,op)
Response.Write FTPOP(URL,FreeHostsharekey,username,0)'恢复FTP权限
dsph("status")="正常"
dsph("pausereason")=0
End if
dsph.update
End if

'处理子目录绑定
Set dsphsub = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where allowsubbyid='"&dsph("id")&"'"
	dsphsub.Open Sql,conn,1,3
while not dsphsub.eof
IISID=dsphsub("IISID")
op=0
if dsph("beianstatus")="备案成功" Or (dsph("pausereason")<>4 and dsph("pausereason")<>2) then
Response.Write PauseSiteSub(URL,FreeHostsharekey,IISID,tourl,op)
dsphsub("status")="正常"
dsphsub("pausereason")=0
End If
dsphsub("endtime")=endtime
dsphsub.update
dsphsub.movenext
wend
dsphsub.close

conn.close
Set conn=Nothing

response.write "ret=ok&ftpname="&Ftpname&"&endtime="&year(endtime)&"-"&month(endtime)&"-"&day(endtime)&"&cpurl="&Application("ctldomain")&"&attach="&request("attach")
End if'正常开通


End if'续费操作.
End If
















If Not ef Then
If Request("action")="getinfo" then'查询接口--------------------------------------------------------------------------------------

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
'登陆API区
ftpname=LCase(Trim(Request ("ftpname")))

If session("username")="" Then
	ef=True
	ec="请您先登陆API区，再续费，在主机面板中不能续费。也有可能是超时造成了出错。"
ElseIf IsNumeric(ftpname)  Then
	ef=True
	ec="VPS用户名不能是纯数字！"
ElseIf not IsNumeric(Request ("year"))  Then
	ef=True
	ec="时间应该是数字！"
ElseIf ftpname="" Then
	ef=True
	ec="请设置FTP用户名！"
ElseIf Trim(LCase(ftpname))="self" or Trim(LCase(ftpname))="adm" or Trim(LCase(ftpname))="admin" or Trim(LCase(ftpname))="sefreehost" Or Trim(LCase(ftpname))="administrator" Or Trim(LCase(ftpname))="freehost" Or Trim(LCase(ftpname))="proxy" Then
	ef=True
	ec="您输入的VPS用户名为保留用户名，请换一个VPS用户名"
ElseIf RegExpTest("[^A-Za-z0-9]",ftpname) Then
	ef=True
	ec="VPS用户名中有非法字符！"
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_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

'if not ef then
'if ds("password")<>session("password") then
'	ef=True
'	ec="密码不正确!"
'end if
'end if

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
'	Sql="Select * from FreeHost.FreeHost_Product_VPS where ftpname='"&ftpname&"' and username<>'test'"
	Sql="Select * from FreeHost.FreeHost_Product_Host where username='"&session("username")&"' and ftpname='"&ftpname&"'"
			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="ftp名不存在！"&sql
end if
end if

if not ef then
	Set dshost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_HostProductlist where Hosttype='"&dsph ("Hosttype")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品类型不存在！"
Else
'读取月付
'PAY_Day=dshost("PAY_Day")
'PAY_Week=dshost("PAY_Week")
PAY_Month=dshost("PAY_Month")
PAY_Season=dshost("PAY_Season")
PAY_halfyear=dshost("PAY_halfyear")
PAY_Nextyear=dshost("PAY_Nextyear")
if dsph("istest")="y" then PAY_Nextyear="1"
PAY_2year=dshost("PAY_2year")
PAY_3year=dshost("PAY_3year")
PAY_4year=dshost("PAY_4year")
PAY_5year=dshost("PAY_5year")
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
'isONEip=dsserver("isONEip")	
ip=dsserver("IP")	
if dsserver("agent1")="n" then
isAgnSqlSer=false
else
isAgnSqlSer=true
end if
end if
end if



if not ef then

ftppassword=dsph ("ftppassword")
status=dsph ("status")
endtime=dsph ("endtime")
'ip=""
	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_HOST_IP where HostID="&dsph("id")
		dsX.Open Sql,conn,1,1
while not dsX.eof
ip=dsX("IP")&"|"&IP
dsX.movenext
wend

'dsph.update
dsph.close


conn.close
Set conn=Nothing

If Right(ip,1)="|" Then ip=Left(IP,Len(ip)-1)

response.write "ret=ok&ftpname="&ftpname&"&ftppassword="&ftppassword&"&ip="&ip&"&status="&status&"&endtime="&year(endtime)&"-"&month(endtime)&"-"&day(endtime)&" "&hour(endtime)&":"&minute(endtime)&":"&second(endtime)&"&cpurl="&Application("ctldomain")&"&attach="&request("attach")
End if'正常开通


End if'查询操作.
End If






















If ef Then
response.write "ret=0&err=auth-failure&freehosinfo="&ec
Sagent.close
Set Sagent=Nothing
conn.close
Set conn=Nothing
session.Abandon()
response.end
End if


session.Abandon()

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


%>
