<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
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

If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("tiaokuan")<>"y"  Then
	ef=True
	ec="请您先选择同意服务条款！"
ElseIf Request.Form ("username")=""  or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="请输入用户名！"
'ElseIf trim(lcase(Request.Form ("username")))=trim(lcase(session("agentusername"))) Then
'	ef=True
'	ec="如果作为代理给自己开通产品，请在代理区--用户管理，用代理名作用户名切换到用户模式！"
ElseIf Request.Form ("Hosttype")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Not IsNumeric(Request.Form ("Hosttype"))  Then
	ef=True
	ec="非法产品类型！"
ElseIf not IsNumeric(Request.Form ("usermoney"))  Then
	ef=True
	ec="金额应该是数字！"
ElseIf Request.Form ("Ftpname")="" Then
	ef=True
	ec="请设置FTP用户名！"
ElseIf IsNumeric(Request.Form ("Ftpname"))  Then
	ef=True
	ec="FTP用户名不能是纯数字！"
'ElseIf Request.Form ("Ftppassword")="" Then
'	ef=True
'	ec="请设置FTP密码！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("Ftpname")) Then
	ef=True
	ec="FTP用户名中有非法字符！"
ElseIf Len(Request ("Ftpname"))<6 Then
	ef=True
	ec="FTP用户名长度不能小于6位！"
ElseIf Trim(LCase(Request ("Ftpname")))="self" or Trim(LCase(Request ("Ftpname")))="adm" or Trim(LCase(Request ("Ftpname")))="admin" or Trim(LCase(Request ("Ftpname")))="sefreehost" Or Trim(LCase(Request ("Ftpname")))="administrator" Or Trim(LCase(Request ("Ftpname")))="freehost" Or Trim(LCase(Request ("Ftpname")))="proxy" Or Trim(LCase(Request ("Ftpname")))="windows" Or Trim(LCase(Request ("Ftpname")))="system32" Then
	ef=True
	ec="您输入的FTP用户名为保留用户名，请换一个ftp用户名"
'ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("Ftppassword"))  or len(Request.Form ("Ftppassword"))<6 Then
'	ef=True
'	ec="FTP密码有非法字符，只能是字母与数字/密码没填/或密码长度小于6位！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
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
If Request.Form ("usermoney")<0  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  (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and username='"&Request.Form ("username")&"'"
				if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		ds.Open Sql,conn,1,3
if ds.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 id='"&Request.Form ("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
packagename=dshost("packagename")'linux
ServerlistID=dshost ("ServerlistID")
if  Request.Form("ServerlistID")=cstr(dshost ("ServerlistID2")) and dshost ("ServerlistID2")<>0 then ServerlistID=dshost ("ServerlistID2")
if  Request.Form("ServerlistID")=cstr(dshost ("ServerlistID3")) and dshost ("ServerlistID3")<>0 then ServerlistID=dshost ("ServerlistID3")
if  Request.Form("ServerlistID")=cstr(dshost ("ServerlistID4")) and dshost ("ServerlistID4")<>0 then ServerlistID=dshost ("ServerlistID4")
if  Request.Form("ServerlistID")=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='"&dshost ("id")&"' 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.Form ("year")<>999 and Request.Form ("year")<>dshost("PAY_Month") and Request.Form ("year")<>dshost("PAY_Season")  and Request.Form ("year")<>dshost("PAY_halfyear") and Request.Form ("year")<>1 and Request.Form ("year")<>dshost("PAY_2year") and Request.Form ("year")<>dshost("PAY_3year") and Request.Form ("year")<>dshost("PAY_4year") and Request.Form ("year")<>dshost("PAY_5year") Then
	ef=True
	ec="请选择时间！"
end If
end If

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

if not ef then
'if not dshost("canbyenduser")="y" and not dshost("canbyagnenduser")="y" and not dshost("canbyagn")="y" Then
if dshost("canbyagn")="n" then
	ef=True
	ec="本产品不允许开通！"
end if
end if

if not ef then
if Request.Form ("year")=999 and dshost("isbydomain")="y" and Application("Agentcantest")=false then
	ef=True
	ec="很抱歉,送域名的虚拟主机不能设为试用！"
end if
end if

if not ef then
if Request.Form ("year")=999 And dshost("cantest")="n" and Application("Agentcantest")=false then
	ef=True
	ec="很抱歉,管理员设置为不能设为试用！"
end if
end if

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

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


if not ef Then
If ostype="linux" then
If Len(Request.Form("Ftpname"))>10 Then
	ef=True
	ec="Linux系统中FTP用户名不能超过10个字符！"
End If
If IsNumeric(Left(Request.Form("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
if instr(temp,"could not be resolved")>0 Then Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员，也可以稍后再试。原因：在主控服务器上，无法解析受控域名，请在主控服务器上ping 受控域名试试。"
Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。内部原因:"&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
'if dsserver("openmustre")=true Then
if 1=2 then
for ihname=1 to 5
if 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 提交备案信息。"
end if
end if
next
end if
end if

if not ef then 'test hostname
if trim(Request.Form ("hostname1"))<>"" then
hostname=":80:"&replace(replace(Request.Form ("hostname1"), " ",""),":80:","")&","
end if
if trim(Request.Form ("hostname2"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname2"), " ",""),":80:","")&","
end if
if trim(Request.Form ("hostname3"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname3"), " ",""),":80:","")&","
end if
if trim(Request.Form ("hostname4"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname4"), " ",""),":80:","")&","
end if
if trim(Request.Form ("hostname5"))<>"" then
hostname=hostname&":80:"&replace(replace(Request.Form ("hostname5"), " ",""),":80:","")&","
end if
if right(hostname,1)="," then hostname=left(hostname,len(hostname)-1)
'response.write hostname
hostname=replace(hostname,"http://","")
hostname=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  (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and 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(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 Ftpname='"&trim(Request.Form ("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,1
if not dsph.Eof then
	ef=True
	ec="您输入的FTP用户名已存在，请另外输入一个！"
end if
dsph.close
end if


if not ef then
if hostname="" then '生成临时
temphostname=":80:"&trim(Request.Form ("Ftpname"))&"."&dsserver("tempdomain")
if ds("agent1")<>"n" and len(dsserver("tempdomainagn"))>3 then
temphostname=":80:"&trim(Request.Form ("Ftpname"))&"."&dsserver("tempdomainagn")
end if
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where hostname like '%"&temphostname&"%'"
	dsph.Open Sql,conn,1,1
if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
if not dsph.Eof then
	ef=True
	ec="FTP用户名已存在，请您另外输入一个！"
end if
dsph.close
end if
end if

if not ef then
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_Host where  (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and username='"&session ("username")&"' and istest='y'"
	dsph.Open Sql,conn,1,3
if Request.Form ("year")=999 then
if not dsph.Eof then
	ef=True
	ec="一个用户只能试用一个产品！"
end if
end if
end if


if not ef then

dim starttime,temptime,pdtype
pdtype=dshost("Hosttype")
starttime=NOW
'结束时间
y=Request.Form ("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)
isfortest=true
end if
if isAgnHostSer=true then
if request.Form ("endtime")<>"" then temptime=request.Form ("endtime")
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.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="虚拟主机"
forpayid=dshost("id")
logfor="自动开通新建(AG)(FTP名"&trim(Request.Form ("Ftpname"))&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=false
DoPayMoney
end if

if not ef then
dim Subject,body'send mail
Ftpname=LCase(trim(Request.Form ("Ftpname")))
'Ftppassword=trim(Request.Form ("Ftppassword"))
ftpRkey=CLng((100000000 - 20 + 7850) * Rnd + 100)
Ftppassword=Ucase(Left(md5(now&ftpRkey),10))&right(md5(now&ftpRkey),4)'2010-8-5



'hostname=trim(replace(Request.Form ("hostname")," ",""))

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("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
dsph("corewhat")=Request.Form ("corewhat")

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

'开通邮箱
	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")&"' and istest='y'"
	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

FreeHost_oplog session("agentusername"),"信息","代理帮用户"&dsphemail ("username")&"开通虚拟主机"&trim(Request.Form ("Ftpname"))&"赠送邮箱产品ID:"&dsphemail("id")

retemail="赠送的邮箱产品已开通"
end if




'SQL
haveopensql=false
	Set dsSqlpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * 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 * from FreeHost.FreeHost_SqlProductlist where Hosttype='"&dshost("Hosttype")&"' and id='"&Request("dsSqlpdlistID")&"' and isbyhost='y'"
	dsSqlpdlist.Open Sql,conn,1,1
while not dsSqlpdlist.Eof

'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 ("ServerlistID2")=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 ("ServerlistID2")=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='"&ds ("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("00"& 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
'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)


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

ret=" SQL:"&ret
'response.write ret

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

FreeHost_oplog session("agentusername"),"信息","代理帮用户("&ds("username")&")开通，虚拟主机("&dsph ("Ftpname")&")赠送数据库,数据库ID:"&dsphSql("id")&"名:"&sqlname&" 返回信息："&retsql

haveopensql=true


end if

dsSqlpdlist.movenext
wend











%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
 　虚拟主机管理
 <%=htmlwrite("html6")%>
<%
'调用开通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")
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")
hostcomment_arry=Split(host, ",")
hostcomment=username&"_"&Replace(hostcomment_arry(0),":80:","")&"_"&dsph ("username")
MaxConnections=dshost ("MaxConnections")
EnumAppsInPool=dshost ("AppPoolnum")
MaxBandwidth=dshost ("MaxBandwidth")
'DefaultDoc=""'dshost ("DefaultDoc")
ScriptMaps=ScriptMaps
AccessFlags=AccessFlags
'LogFileDirectory=""'dsserver ("LogFileDirectory")
'HttpErrors=""'Request.Form ("HttpErrors")

if isAgnHostSer=true then
'DefaultDoc=Request.Form ("DefaultDoc")
'ScriptMaps=Request.Form ("ScriptMaps")
'AccessFlags=Request.Form ("AccessFlags")
'LogFileDirectory=Request.Form ("LogFileDirectory")
'HttpErrors=Request.Form ("HttpErrors")
MaxBandwidth=Request.Form ("MaxBandwidth")
MaxConnections=Request.Form ("MaxConnections")
EnumAppsInPool=Request.Form ("AppPoolnum")
spacelimit=Request.Form ("spacelimit")
end if

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

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)
End If

host=hostname

if y=999 and Application("testsame")<>true then'如果是试用
MaxConnections=Application("MaxConnections")
spacelimit=Application("spacelimit")
MaxBandwidth=Application("MaxBandwidth")
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


dsph("AppPoolnum")=EnumAppsInPool'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")

if isuseCDN=true Then host=Replace(host,":80:",":"&CDNORIport&":")
Application.lock
Application("hostoptime")=now
Application("hostoplock")=true
Application.unlock
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


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

if isAgnHostSer=true then response.write temp



FreeHost_oplog session("agentusername"),"信息","代理开通虚拟主机: "&temp


	dsph("status")="正常"
	dsph.Update

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,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#FTP地址#",ftpdomain)
smsContent=Replace(smsContent,"#IP#",hostip)
smsContent=Replace(smsContent,"#FTP#",dsph("ftpname"))
smsContent=Replace(smsContent,"#FTP密码#",dsph("Ftppassword"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if

dsph.close

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


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

CDNrefreshDomain'更新CDN

%>
<br>
<font color=red><%=retemail%></font><br>
<br>
<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="39" colspan="4"><font color="#000000">　　　</font><font color="#990000"><font color="#FF0000">虚拟主机开通成功，以下是相关的资料：</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td width="44%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="56%" colspan="3"><font color="#000000"><%=olduser_money%>元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=red><%=moneych%></font><font color=#FF0000> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 用户的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=newuser_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的原金额：</font></td>
    <td colspan="3"><font color="#000000"><%=oldagn_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的金额变化：</font></td>
    <td colspan="3"><font color=red><%=newagn_money-oldagn_money%></font><font color="#000000"> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 我的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=newagn_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000">　　　 用户的FTP登陆用户名是：</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=Ftpname%></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 用户的FTP密码是：</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=password%></td>
  </tr>
<%If UBound(hostcomment_arry)>0 then%>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="42"><font color="#000000">　　　 </font><font color="#000000"> 您的网址为：</font></td>
    <td height="42"><font color="#000000"><a href="http://<%=Replace(hostcomment_arry(1),":80:","")%>" target=_blank><font color="#000000">http://<%=Replace(hostcomment_arry(1),":80:","")%></font></a></font>
<%if session("waitCDNsyn")=true then%>
<br>
<font color=red>注意：您的产品使用了CDN功能，因此新增加或修改的域名您要等候25分钟后才能生效。</font>
<br><br>
<%end if%>	
	</td>
  </tr>
<%else%>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="42"><font color="#000000">　　　 </font><font color="#000000"> 您的网址为：</font></td>
    <td height="42"><font color="#000000"><a href="http://<%=Replace(hostcomment_arry(0),":80:","")%>" target=_blank><font color="#000000">http://<%=Replace(hostcomment_arry(0),":80:","")%></font></a></font>
<%if session("waitCDNsyn")=true then%>
<br>
<font color=red>注意：您的产品使用了CDN功能，因此新增加或修改的域名您要等候25分钟后才能生效。</font>
<br><br>
<%end if%>	
	</td>
  </tr>
<%End if%>
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="40" colspan="4"><font color="#000000"> 　　　  FTP地址是：<font color=red><%=ftpdomain%></font></font></td>
  </tr>
    <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td height="40" colspan="4"><font color="#000000"> 　　　  服务器IP是：<font color=red><%=hostip%></font></font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 现在的到期时间是:</font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=temptime%></td>
  </tr>
<%if y=999 And ostype="windows" then%>
    <tr bordercolor="#000000">
    <td height="60" bgcolor="#eeeeee"><font color="#000000"> 　　　 试用说明：</font></td>
    <td bgcolor="#eeeeee">由于您开通的是试用虚拟主机，它的空间大小<br>
      及速度等都受到限制。如果您要使用全部的功能，<br>
      请您升级到正式的虚拟主机。</td>
  </tr>
<%end if%>
<!--<%if Application("openmustre")=true then%>
    <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 网站暂停中：</font></td>
    <td bgcolor="#eeeeee"><a href="hostadm.asp"><font color="#000000">由于国家要求先备案后开通，请您先备案。</font></a></td>
  </tr>
<%end if%>-->
</table>
<br>
<br>
<%=htmlwrite("html7")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
