<%@ Language=VBScript %>
<%server.scripttimeout=240%>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
isagentpd=False
autoselect=False'自动优选服务器20175-5
If session("username")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
ElseIf IsNumeric(Request.Form ("vpsname"))  Then
	ef=True
	ec="云服务器名不能是纯数字！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
ElseIf Request.Form ("vpsname")="" Then
	ef=True
	ec="请设置云服务器名！"
ElseIf Len(Request.Form ("vpsname"))<3 Then
	ef=True
	ec="云服务器名长度不能小于3位！"
ElseIf Len(Request.Form ("vpsname"))>14 Then
	ef=True
	ec="云服务器名长度不能大于14位！"
ElseIf Len(Request.Form ("VPSpassword"))<3 Then
	ef=True
	ec="云服务器密码长度不能小于3位！"
ElseIf Trim(LCase(Request.Form ("vpsname")))="self" or Trim(LCase(Request.Form ("vpsname")))="adm" Or Trim(LCase(Request.Form ("vpsname")))="administrator" Or Trim(LCase(Request.Form ("vpsname")))="freehost" Or Trim(LCase(Request.Form ("vpsname")))="proxy" Then
	ef=True
	ec="您输入的VPS户名为保留用户名，请换一个云服务器名"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("vpsname")) Then
	ef=True
	ec="云服务器名中有非法字符！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("VPSpassword")) 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
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_VPSProductlist where id='"&Request.Form ("id")&"'"
	dshost.Open Sql,conn,1,1
if dshost.Eof then
	ef=True
	ec="产品不存在！"
Else
If dshost ("autoselect")=True Then autoselect=true'自动优选服务器20175-5
Servertypeid=dshost ("Servertypeid")
If dshost ("isagentpd")=True Then isagentpd=true'代理的产品
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_VPSProductlist_AGN where id='"&Request.Form ("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

'弹性部分1
if not ef then
if dshost("cancloud")=false And Request.Form ("CpuValue")<>"" then
	ef=True
	ec="本产品不允许弹性购买"
end if
end If

if not ef then
if dshost("cancloud")=true then'是弹性购买产品
If not IsNumeric(Request.Form ("CpuValue"))  Then
	ef=True
	ec="CPU应该是数字！"
ElseIf CInt(Request.Form ("CpuValue"))<1 Then
	ef=True
	ec="CPU不能小于1个核心！"
ElseIf not IsNumeric(Request.Form ("RamValue"))  Then
	ef=True
	ec="RAM应该是数字！"
ElseIf Clng(Request.Form ("RamValue"))<256 Then
	ef=True
	ec="内存不能小于256M！"
ElseIf not IsNumeric(Request.Form ("VHDValue"))  Then
	ef=True
	ec="虚拟硬盘大小应该是数字！"
ElseIf CInt(Request.Form ("VHDValue"))<10 Then
	ef=True
	ec="虚拟硬盘大小不能小于10G！"
ElseIf not IsNumeric(Request.Form ("MbpsValue"))  Then
	ef=True
	ec="带宽大小应该是数字！"
ElseIf CInt(Request.Form ("MbpsValue"))<1 Then
	ef=True
	ec="带宽不能小于1Mbps！"
ElseIf not IsNumeric(Request.Form ("SNAValue"))  Then
	ef=True
	ec="快照数量应该是数字！"
ElseIf CInt(Request.Form ("SNAValue"))<0 Then
	ef=True
	ec="快照不能小于0个！"
ElseIf not IsNumeric(Request.Form ("BakValue"))  Then
	ef=True
	ec="备份数量应该是数字！"
ElseIf CInt(Request.Form ("BakValue"))<0 Then
	ef=True
	ec="备份不能小于0个！"
ElseIf not IsNumeric(Request.Form ("NGBValue"))  Then
	ef=True
	ec="流量上限应该是数字！"
ElseIf CInt(Request.Form ("NGBValue"))<0 Then
	ef=True
	ec="流量上限不能小于0个！"
ElseIf not IsNumeric(Request.Form ("IPValue"))  Then
	ef=True
	ec="IP上限应该是数字！"
ElseIf CInt(Request.Form ("IPValue"))<1 Then
	ef=True
	ec="IP上限不能小于1个！"
ElseIf not IsNumeric(Request.Form ("IopsValue"))  Then
	ef=True
	ec="IOPS上限应该是数字！"
ElseIf CInt(Request.Form ("IopsValue"))<0 Then
	ef=True
	ec="IOPS上限不能小于1个！"
ElseIf Request.Form ("OSAllList")<>"" And not IsNumeric(Request.Form ("OSAllList"))  Then
	ef=True
	ec="操作系统ID应该是数字！错误的ID为："&Request.Form ("OSAllList")
ElseIf CInt(Request.Form ("OSAllList"))<1 Or CInt(Request.Form ("OSAllList"))>16 Then
	ef=True
	ec="操作系统ID不能小于1或大于16！错误的ID为："&Request.Form ("OSAllList")
end If
end if
end If

if not ef then
If Request.Form ("year")<>999 and Request.Form ("year")<>dshost("PAY_DAY") and Request.Form ("year")<>dshost("PAY_WEEK") 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 dshost("usermoney")=0 then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS 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.Form ("year")=999 and dshost("cantest")="n" then
	ef=True
	ec="很抱歉,本产品不可以试用！"
end if
end If

if not ef then
if Request.Form ("year")=999 and Application("vpscantest")=True And ds("usermoney")<0.01 then
	ef=True
	ec="很抱歉,余款为零的用户不可以试用！"
end if
end If

if not ef then
if Request.Form ("year")=999 and (Hour(now)<Application("vpscantestST") or Hour(now)>Application("vpscantestEN"))then
	ef=True
	ec="很抱歉,现在的时间段不可以试用！"
end if
end If

if not ef then
if Request.Form ("year")=dshost("PAY_DAY") and dshost("canday")="n" then
	ef=True
	ec="很抱歉,本产品不可以日付！"
end if
end If

if not ef then
if Request.Form ("year")=dshost("PAY_WeeK") and dshost("canweek")="n" then
	ef=True
	ec="很抱歉,本产品不可以周付！"
end if
end If

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

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

If Not autoselect then'不是优选服务器再执行
If Not isagentpd then'不是代理产品时再执行
if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist 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")
end if
end If

if not ef then
if dshost("canADSL")=True then
Set dsVPSADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS_ADSL where ServerlistID="&dsserver("id")&""
		dsVPSADSL.Open Sql,conn,1,1
If dsVPSADSL(0)<1 Then
	ef=True
	ec="很抱歉,您选取的服务器的云服务器拨号资源已用光,请联系管理员处理."'&sql
End If
dsVPSADSL.close
End If
End If

if not ef then
Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" and VPSID=0"
		dsVPSip.Open Sql,conn,1,1
If dsVPSip(0)=0 Then
	ef=True
	ec="很抱歉,您选取的服务器的IP资源已用光,管理员尚未分配可用IP,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSip(0)<CInt(Request.Form ("IPValue")) Then
	ef=True
	ec="很抱歉,您选取的服务器的IP资源已用光,请联系管理员处理."'&Request.Form ("IPValue")&dsVPSip(0)
End If
End If
End if


'检查内存有没有用光
if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select sum(maxram) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
		dsVPSMax.Open Sql,conn,1,1
If (dsVPSMax(0)+dshost("MaxRAM"))>dsserver("maxram") Then
	ef=True
	ec="很抱歉,您选取的服务器的内存资源已用光,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSMax(0)+Request.Form ("RamValue")>dsserver("maxram") Then
	ef=True
	ec="很抱歉,您选取的服务器的内存资源已用光,请联系管理员处理."
End If
End If
dsVPSMax.close
End if

'检查space有没有用光
if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select sum(Maxspace) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
		dsVPSMax.Open Sql,conn,1,1
If dsVPSMax(0)+dshost("Maxspace")>dsserver("Maxspace") Then
	ef=True
	ec="很抱歉,您选取的服务器的硬盘资源已用光,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSMax(0)+Request.Form ("VHDValue")>dsserver("Maxspace") Then
	ef=True
	ec="很抱歉,您选取的服务器的硬盘资源已用光,请联系管理员处理."
End If
End If
dsVPSMax.close
End If

if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
'		Response.write sql
'				Response.end
		dsVPSMax.Open Sql,conn,1,1
If dsVPSMax(0)+1>dsserver("MaxVPS") Then
	ef=True
	ec="很抱歉,您选取的服务器的云服务器数量资源已用光,请联系管理员处理."'&sql
End If
dsVPSMax.close
End If

if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
temp=VPSOP(URL,FreeHostsharekey,"list all now",0)
if instr(temp,"名称: "&LCase(trim(Request.Form ("vpsname"))))>0 Then Response.Redirect "e.asp?e=服务器上已存在同名的VPS,请您联系管理员处理,或换一个云服务器名重试。"
if not instr(temp,"成功")>1 Or instr(temp,"失败")>1 Then
if instr(temp,"could not be resolved")>0 Then Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员，也可以稍后再试。原因：在主控服务器上，无法解析受控域名，请在主控服务器上ping 受控域名试试。"
Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。"
end if
end If

if not ef then
If dsserver("OStype")="Windows 2008R2" And dshost("Cpunum")>4 Then 
	ef=True
	ec="操作系统是win2012才能设置超过4个CPU！"
end if
end If

End If'不是代理产品时再执行
End If'Not autoselect'2017-5-5不是自动优选服务器时



If autoselect then'//是优选服务器再执行'Is autoselect'2017-5-5 //是自动优选服务器时
If Not isagentpd then'不是代理产品时再执行
if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where Canselectnow=1 order by orderbyid desc,id asc"
If Servertypeid>0 Then 	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where Canselectnow=1 and typeid='"&Servertypeid&"' order by orderbyid desc,id asc"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"'&sql
End If

Do While not dsserver.Eof '进入服务器do while
    netby=dsserver("netby")
	ip=dsserver("ip")
	hostip=dsserver("ip")


if not ef then
if dshost("canADSL")=True then
Set dsVPSADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS_ADSL where ServerlistID="&dsserver("id")&""
		dsVPSADSL.Open Sql,conn,1,1
If dsVPSADSL(0)<1 Then
	ef=True
'	ec="很抱歉,您选取的服务器的云服务器拨号资源已用光,请联系管理员处理."'&sql
End If
dsVPSADSL.close
End If
End If

if not ef then
Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" and VPSID=0"
		dsVPSip.Open Sql,conn,1,1
If dsVPSip(0)=0 Then
	ef=True
'	ec="很抱歉,您选取的服务器的IP资源已用光,管理员尚未分配可用IP,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSip(0)<CInt(Request.Form ("IPValue")) Then
	ef=True
'	ec="很抱歉,您选取的服务器的IP资源已用光,请联系管理员处理."'&Request.Form ("IPValue")&dsVPSip(0)
End If
End If
End if


'检查内存有没有用光
if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select sum(maxram) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
		dsVPSMax.Open Sql,conn,1,1
If (dsVPSMax(0)+dshost("MaxRAM"))>dsserver("maxram") Then
	ef=True
'	ec="很抱歉,您选取的服务器的内存资源已用光,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSMax(0)+Request.Form ("RamValue")>dsserver("maxram") Then
	ef=True
'	ec="很抱歉,您选取的服务器的内存资源已用光,请联系管理员处理."
End If
End If
dsVPSMax.close
End if

'检查space有没有用光
if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select sum(Maxspace) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
		dsVPSMax.Open Sql,conn,1,1
If dsVPSMax(0)+dshost("Maxspace")>dsserver("Maxspace") Then
	ef=True
'	ec="很抱歉,您选取的服务器的硬盘资源已用光,请联系管理员处理."
End If
if dshost("cancloud")=true then'是弹性购买产品
If dsVPSMax(0)+Request.Form ("VHDValue")>dsserver("Maxspace") Then
	ef=True
'	ec="很抱歉,您选取的服务器的硬盘资源已用光,请联系管理员处理."
End If
End If
dsVPSMax.close
End If

if not ef then
Set dsVPSMax = Server.CreateObject("ADODB.Recordset")	
		Sql="Select count(*) from FreeHost.FreeHost_Product_VPS where ServerlistID="&dsserver("id")&""
'		Response.write sql
'				Response.end
		dsVPSMax.Open Sql,conn,1,1
If dsVPSMax(0)+1>dsserver("MaxVPS") Then
	ef=True
'	ec="很抱歉,您选取的服务器的云服务器数量资源已用光,请联系管理员处理."'&sql
End If
dsVPSMax.close
End If

if not ef then
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
temp=VPSOP(URL,FreeHostsharekey,"list all now",0)
if instr(temp,"名称: "&LCase(trim(Request.Form ("vpsname"))))>0 Then Response.Redirect "e.asp?e=服务器上已存在同名的VPS,请您联系管理员处理,或换一个云服务器名重试。"
if not instr(temp,"成功")>1 Or instr(temp,"失败")>1 Then
if instr(temp,"could not be resolved")>0 Then Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员，也可以稍后再试。原因：在主控服务器上，无法解析受控域名，请在主控服务器上ping 受控域名试试。"
Response.Redirect "e.asp?e=系统暂时不可用，请联系管理员在管理区自检来了解原因，也可以稍后再试。"
end if
end If

if not ef then
If dsserver("OStype")="Windows 2008R2" And dshost("Cpunum")>4 Then 
	ef=True
'	ec="操作系统是win2012才能设置超过4个CPU！"
end if
end If
If Not ef Then Exit do
dsserver.movenext
	ef=false
Loop '服务器while list end
End if'整体ef
End If'不是代理产品时再执行
End If'Is autoselect'2017-5-5 //是自动优选服务器时

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where vpsname='"&trim(Request.Form ("vpsname"))&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
	ef=True
	ec="您输入的云服务器名已存在，请另外输入一个！"
end if
dsph.close
end if

if not ef then
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where 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("VPStype")
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_DAY") then temptime=dateadd("s",86400,now)
if y=dshost("PAY_WEEK") then temptime=dateadd("n",10080,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)
If Application("VPStestHour")>0 Then temptime=dateadd("n",Application("VPStestHour")*60,now)
dim isfortest
isfortest=true
end If
end if

if not ef then
if dshost("cancloud")=true then'是弹性购买产品'计算增量部分的普通用户情况下的金额

	'PAY_1yearvar=dsHost("usermoney")
	
'默认最小值addcpuMIN
'当前值addcpuNow
'增量每步addcpuNum
'每步需要钱数addCpuCost
if CInt(Request.Form("CpuValue"))>dsHost("addCpuLim") Then
	ef=True
	ec="CPU超出上限！"
End If
if Clng(Request.Form("RamValue"))>dsHost("addRamLim") Then
	ef=True
	ec="内存超出上限！"
End If
if CInt(Request.Form("VHDValue"))>dsHost("addVHDLim") Then
	ef=True
	ec="虚拟硬盘超出上限！"
End If
if CInt(Request.Form("MbpsValue"))>dsHost("addMbpsLim") Then
	ef=True
	ec="带宽超出上限！"
End If
If dsHost("CDNMaxMb")>0 then
if CInt(Request.Form("NGBValue"))>dsHost("addNGBLim") Then
	ef=True
	ec="流量超出上限！"
End If
End If
If dsHost("MaxIOPS")>0 then
if CInt(Request.Form("IopsValue"))>dsHost("addIOPSLim") Then
	ef=True
	ec="IOPS超出上限！"
End If
End if
if CInt(Request.Form("SNAValue"))>dsHost("addSnaLim") Then
	ef=True
	ec="快照超出上限！"
End If
if CInt(Request.Form("BakValue"))>dsHost("addBakLim") Then
	ef=True
	ec="备份数量超出上限！"
End If
if CInt(Request.Form("IPValue"))>dsHost("addIPLim") Then
	ef=True
	ec="IP数量超出上限！"
End If
if (CInt(Request.Form("CpuValue"))<dsHost("OSLimbyCPU")) Or (Clng(Request.Form("RamValue"))<dsHost("OSLimbyRam")) Then
If InStr(","&dsHost("OSlim"),","&Request.Form("OSAllList")&",")>0 then
	ef=True
	ec="由于内存或CPU限制不能预装这个操作系统！"
End If
End If

Dim cloudAddmoney
cloudAddmoney=0
if (CInt(Request.Form("CpuValue"))>dsHost("CpuNum")) then	cloudAddmoney=cloudAddmoney+((Request.Form("CpuValue")-dsHost("CpuNum"))/dsHost("addCpuNum"))*dsHost("addCpuCost")
if (Clng(Request.Form("RamValue"))>dsHost("MAXRAM")) then	cloudAddmoney=cloudAddmoney+((Request.Form("RamValue")-dsHost("MAXRAM"))/dsHost("addRamNum"))*dsHost("addRamCost")
if (CInt(Request.Form("VHDValue"))>dsHost("Maxspace")) then	cloudAddmoney=cloudAddmoney+((Request.Form("VHDValue")-dsHost("Maxspace"))/dsHost("addVHDNum"))*dsHost("addVHDCost")
if (CInt(Request.Form("MbpsValue"))>dsHost("Maxmbps8")) then	cloudAddmoney=cloudAddmoney+((Request.Form("MbpsValue")-dsHost("Maxmbps8"))/dsHost("addMbpsNum"))*dsHost("addMbpsCost")
If dsHost("CDNMaxMb")>0 then'如果限制流量
if (CInt(Request.Form("NGBValue"))>dsHost("CDNMaxMb")) then	cloudAddmoney=cloudAddmoney+((Request.Form("NGBValue")-dsHost("CDNMaxMb"))/1000/dsHost("addNGBNum"))*dsHost("addNGBCost")
End If
If dsHost("MaxIOPS")>0 then'如果限制IOPS
if (CInt(Request.Form("IopsValue"))>dsHost("MaxIOPS")) then	cloudAddmoney=cloudAddmoney+((Request.Form("IopsValue")-dsHost("MaxIOPS"))/dsHost("addIOPSNum"))*dsHost("addIOPSCost")
End if
if (CInt(Request.Form("SNAValue"))>dsHost("MaxSNA")) then	cloudAddmoney=cloudAddmoney+((Request.Form("SNAValue")-dsHost("MaxSNA"))/dsHost("addSnaNum"))*dsHost("addSnaCost")
if (CInt(Request.Form("BakValue"))>dsHost("MaxBak")) then	cloudAddmoney=cloudAddmoney+((Request.Form("BakValue")-dsHost("MaxBak"))/dsHost("addBakNum"))*dsHost("addBakCost")
if (CInt(Request.Form("IPValue"))>dsHost("MaxIP")) then	cloudAddmoney=cloudAddmoney+((Request.Form("IPValue")-dsHost("MaxIP"))/dsHost("addIpNum"))*dsHost("addIPCost")

cloudAddmoney=Clng(FormatNumber(cloudAddmoney,0,-1,0,0))'四舍五入'弹性购买的基准增量价格

end If
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
Userpaymoney=dsHost("usermoney")
forpayyear=Request.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="云服务器产品"
forpayid=dshost("id")
logfor="用户区开通(云服务器名"&trim(Request.Form ("vpsname"))&")"
pubisagnSer=isAgnHostSer
AgnRunasUser=session("AgnRunasUser")
DoPayMoney
end if

if not ef then
dim Subject,body'send mail
vpsname=lcase(trim(Request.Form ("vpsname")))
dsph.AddNew
dsph("username")=ds ("username")
dsph("VPStype")=dshost("VPStype")
dsph("starttime")=starttime
dsph("endtime")=temptime
dsph("Cpunum")=dshost("Cpunum")
dsph("MaxRAM")=dshost("MaxRAM")
dsph("StartRam")=dshost("StartRam")
dsph("Maxmbps8")=dshost("Maxmbps8")
dsph("Minmbps8")=dshost("Minmbps8")
dsph("MaxCPU")=dshost("MaxCPU")
dsph("MaxSpace")=dshost("MaxSpace")
dsph("allowdomain")=dshost("allowdomain")
dsph("CDNMaxMb")=dshost("CDNMaxMb")
dsph("vpsname")=vpsname
dsph("VPSpassword")=Request.Form ("VPSpassword")
dsph("canbackupvhd")=dshost("canbackupvhd")
dsph("MaxIOPS")=dshost("MaxIOPS")
dsph("MaxIOPS2")=dshost("MaxIOPS2")
dsph("MaxIP")=dshost("MaxIP")
dsph("VLANid")=dshost("VLANid")
NetCardlimtype=dshost("NetCardlimtype")

if dshost("cancloud")=true then'是弹性购买产品
dsph("Cpunum")=Request.Form("CpuValue")
dsph("MaxRAM")=Request.Form("RamValue")
dsph("MaxSpace")=Request.Form("VHDValue")
dsph("Maxmbps8")=Request.Form("MbpsValue")
dsph("MaxSNA")=Request.Form("SNAValue")
dsph("MaxBak")=Request.Form("BakValue")
dsph("MaxIP")=Request.Form("IPValue")
If dsHost("MaxIOPS")>0 And Request.Form("IopsValue")>0 Then dsph("MaxIOPS2")=Request.Form("IopsValue")'只限制第二硬盘速度'就算用户选不限制产品默认值更优先
If dsHost("CDNMaxMb")>0 Then dsph("CDNMaxMb")=Request.Form("NGBValue")*1000
dsph("FirstOSid")=Request.Form("OSAllList")
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("caninstallos")=dshost("caninstallos")
dsph("canbackupvhd")=dshost("canbackupvhd")


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

If Not isagentpd then'不是代理产品时再执行
dsph("ServerlistID")=dsserver("id")
dsph("vhdpath")=replace(dsserver("homedir")&"\"&dsph("vpsname")&"."&dsserver("vhdtype"),"\\","\")
Else
dsph("ServerlistID")=0
End if

dsph.Update


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


if Not dshost("isagentpd")=true Then

'if dshost("canADSL")=True Then conn.Execute "UPDATE FreeHost.FreeHost_Product_VPS_ADSL SET  VPSID='"&dsph("id")&"' WHERE ID in (SELECT TOP (1) Id FROM FreeHost.FreeHost_Product_VPS_ADSL WHERE VPSID=0 ORDER BY orderbyid DESC);"
if dshost("canADSL")=True then
Set dsVPSADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select top 1 * from FreeHost.FreeHost_Product_VPS_ADSL where ServerlistID="&dsserver("id")&" and VPSID=0 order by orderbyid desc"
		dsVPSADSL.Open Sql,conn,1,3
if Not dsVPSADSL.Eof then
dsVPSADSL("VPSID")=dsph("id")
If dsVPSADSL("VLANid")>0 Then dsph("VLANid")=dsVPSADSL("VLANid")
dsVPSADSL.update
dsVPSADSL.close
End If
End if

Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" and VPSID=0  and ipbyid=0 order by orderbyid desc"
		dsVPSip.Open Sql,conn,1,3
IP2="0"
IP2mask=0
IP2gateway=0
IP2dns1=0
IP2dns2=0
ipcount=0

havenextIP=false
Set dsVPSip2 = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ipbyid='"&dsVPSip("ID")&"' and VPSID=0 order by orderbyid desc"
		dsVPSip2.Open Sql,conn,1,3
If Not dsVPSip2.Eof Then
'有附属IP时
ip=dsVPSip("ip")
IPmask=dsVPSip("IPmask")
IPgateway=dsVPSip("IPgateway")
IPdns1=dsVPSip("IPdns1")
IPdns2=dsVPSip("IPdns2")
dsVPSip("VPSID")=dsph("id")
dsVPSip.update

IP2=dsVPSip2("IP")
IP2mask=dsVPSip2("IPmask")
IP2gateway=dsVPSip2("IPgateway")
IP2dns1=dsVPSip2("IPdns1")
IP2dns2=dsVPSip2("IPdns2")
dsVPSip2("VPSID")=dsph("id")
dsVPSip2.update
dsVPSip2.close
havenextIP=true
end if

'dsVPSip.movefirst
If havenextIP=false then
While Not dsVPSip.Eof
'Response.write dsVPSip("VPSID")&":vpsidA<br>"
If ipcount<dsph("MaxIP") then'如果选中2014
'Response.write ipcount&"<br>"
dsVPSip("VPSID")=dsph("id")
ipcount=ipcount+1
If IP2="0" And ip<>"" then
IP2=dsVPSip("IP")
IP2mask=dsVPSip("IPmask")
IP2gateway=dsVPSip("IPgateway")
IP2dns1=dsVPSip("IPdns1")
IP2dns2=dsVPSip("IPdns2")
End if
If IP="" then
IP=dsVPSip("IP")
IPmask=dsVPSip("IPmask")
IPgateway=dsVPSip("IPgateway")
IPdns1=dsVPSip("IPdns1")
IPdns2=dsVPSip("IPdns2")
End if
dsVPSip.update
End If
dsVPSip.movenext
Wend
dsVPSip.movefirst
End If

End if





%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>
　云服务器开通成功
<%=htmlwrite("html3")%>
<%
If Application("smsVPSopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsVPSopencon")
'恭喜！您的邮箱产品已开通了！用户名 ：#用户名#产品类型 ：#产品类型#到期时间是 ：#到期时间#您的帐户余款是 ：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("VPStype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if

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


'调用开通function
If Not isagentpd then'不是代理产品时再执行
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
username=dsph ("vpsname")
username=dsph ("username")
homedir=dsserver("homedir")
starttime=dsph("starttime")
endtime=dsph("endtime")
type1=dsph("VPStype")


MAXcpu=dsph("MAXCPU")
CpuNum=dsph("CpuNum")
MAXRam=dsph("MAXRam")
StartRam=dsph("StartRam")
Maxmbps8=dsph("Maxmbps8")
Minmbps8=dsph("Minmbps8")

MAXspace=dsph("MAXspace")
vhdpath=dsph("vhdpath")

'IP=dsph("ip")'分配的IP

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


Application.lock
Application("hostoptime")=now
Application("hostoplock")=true
Application.unlock
varcon="makevps "&username&" "&vpsname&" "&CpuNum&" "&MAXcpu&" "&MAXRam&" "&MAXspace&" "&vhdpath&" "&StartRam
If dsserver("OStype")="Windows Server 2012" Then varcon=varcon&" 0 "&Maxmbps8*1024*1024
If dsserver("OStype")="Windows Server 2012R2" Or dsserver("OStype")="Windows Server 2016" Then varcon=varcon&" 0 "&Maxmbps8*1024*1024&" "&dsserver("SwitchName")&" "&StartRam&" "&Replace(vhdpath,".vhd","-2.vhd")&" 10 "&(MAXspace-10)&" defaultClusterNameby7i24 "&MaxIOPS&" "&MaxIOPS2&" NULLswitchname "&VLANid&" "&NetCardlimtype
If dsserver("IsCluster")=true Then varcon=Replace(varcon,"defaultClusterNameby7i24",dsserver("ClusterName"))
If Not isnull(dsserver("SwitchName2")) Then varcon=Replace(varcon,"NULLswitchname",dsserver("SwitchName2"))

temp=VPSOP(URL,FreeHostsharekey,varcon,0)

If Not isnull(dsserver("SwitchName2")) Then '处理switch
If InStr(temp,vbcrlf&vbcrlf&vbcrlf&"SwitchName : ") Then
arysw=Split(temp,vbcrlf&vbcrlf&vbcrlf&"SwitchName : ")
arysw2=Split(arysw(1),vbcrlf&vbcrlf&vbcrlf)
arysw3=Split(arysw2(0),vbcrlf)
If dsserver("SwitchName")=arysw3(0) Then
dsph("MAC")=replace(arysw3(1),"MacAddress : ","")
dsph("MAC2")=replace(arysw3(4),"MacAddress : ","")
Else
dsph("MAC")=replace(arysw3(4),"MacAddress : ","")
dsph("MAC2")=replace(arysw3(1),"MacAddress : ","")
End If
End if
End if'完成switch

dsph.update

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

FreeHost_oplog session("username"),"信息","用户区，用户开通云服务器产品:("&vpsname&") "&temp&"("&ip&")"

Sql="update FreeHost.FreeHost_Product_VPS set status='等待安装操作系统' where vpsname='"&vpsname&"'"
    conn.Execute Sql
'conn.close
'Set conn=Nothing

else'是代理产品

dsph("isagentpd")=dshost("isagentpd")
dsph("VPSComName")=dshost("VPSComName")
dsph("VPSApiName")=dshost("VPSApiName")
dsph("VPScpdomain")=dshost("VPScpdomain")
dsph("Agnuserid")=dshost("Agnuserid")
dsph("Domain_Agent_nonemd5_6")=dshost("Domain_Agent_nonemd5_6")
dsph("Agnidc")=dshost("Agnidc")
dsph("Agnproductid")=dshost("Agnproductid")
dsph.update

VPSApiName=dsph("VPSApiName")
userid=dsph("Agnuserid")
userstr=md5(dsph("Domain_Agent_nonemd5_6")&"7i24.com")
yearAgn=Request.Form ("year")
idc=dsph("Agnidc")
productid=dsph("Agnproductid")
attach=ds("username")

tar="http://"&VPSApiName&"/api/cloudapi.asp?userid="&userid&"&userstr="&userstr&"&year="&yearAgn&"&vpsname="&vpsname&"&VPSpassword="&dsph ("VPSpassword")&"&idc="&idc&"&productid="&productid&"&action=activate&attach="&attach&"&CpuValue="&Request.Form("CpuValue")&"&RamValue="&Request.Form("RamValue")&"&VHDValue="&Request.Form("VHDValue")&"&MbpsValue="&Request.Form("MbpsValue")&"&NGBValue="&Request.Form("NGBValue")&"&IopsValue="&Request.Form("IopsValue")&"&OSAllList=1&SNAValue="&Request.Form("SNAValue")&"&BakValue="&Request.Form("BakValue")&"&IPValue="&Request.Form("IPValue")
'Response.write tar
temp=ONLY_GET(tar,"")

FreeHost_oplog session("username"),"信息","用户区，用户开通云服务器产品(代理上级):("&vpsname&") "&temp

If InStr(temp,"et=ok") then
Sql="update FreeHost.FreeHost_Product_VPS set status='正常' where vpsname='"&vpsname&"'"
    conn.Execute Sql
Else
Sql="update FreeHost.FreeHost_Product_VPS set status='失败' where vpsname='"&vpsname&"'"
    conn.Execute Sql
Response.Redirect "e.asp?e=调用上级API时出错，开通失败，但费用已扣，请联系管理员手工处理！出错原因为："&server.urlencode(temp)
End If


End if'不是代理产品时再执行





%>

<br>
　　　　　　　　　　　　　<br>
<table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="39" colspan="2"><font color="#000000">　　　</font><font color="#990000"><font color="#FF0000">恭喜您的云服务器开通成功，以下是您的资料：</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td width="39%" height="30"><font color="#000000"> 　　　 您的原金额：</font></td>
    <td width="61%"><font color="#000000"><%=olduser_money%>元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="41"><font color="#000000">　　　 您的金额变化：</font></td>
    <td><font color=#000000><%=moneych%> 元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="39"><font color="#000000">　　　 您的新金额：</font></td>
    <td><font color="#000000"><%=newuser_money%> 元</font></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000">　　　 您的云服务器名称：</font></td>
    <td bgcolor="#eeeeee"><%=Request.Form ("vpsname")%></td>
  </tr>
  <tr bordercolor="#000000">
    <td height="37" bgcolor="#eeeeee"><font color="#000000"> 　　　 到期时间是：</font></td>
    <td bgcolor="#eeeeee"><%=temptime%></td>
  </tr>
<%if y=999 then%>
    <tr bordercolor="#000000">
    <td height="60" bgcolor="#eeeeee"><font color="#000000"> 　　　 试用说明：</font></td>
    <td bgcolor="#eeeeee">由于您开通的是试用云服务器，它的硬盘大小<br>
      及速度等都受到限制。如果您要使用全部的功能，<br>
      请您升级到正式的云服务器产品。</td>
  </tr>
<%end if%>
    <tr bordercolor="#000000">
    <td height="60" bgcolor="#eeeeee"><font color="#000000"> 　　　 使用说明：</font></td>
    <td bgcolor="#eeeeee"><a href="/user/vpsadm2.asp?id=<%=pdid%>&go=e"><font color="#000000">云服务器产品虽然已开通,但是您要在线安装操作系统才能远程使用,请访问这儿安装操作系统>>>>>></font></a></td>
  </tr>
  <tr align="center" bordercolor="#000000">
    <td height="34" colspan="2" bgcolor="#999999"> <font color="#990000">　我　们　为　您　提　供　优　质　的　服　务！</font></td>
  </tr>
</table>
<br>
<%=htmlwrite("html4")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
