<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
isagentpd=False
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request("username")=""  or RegExpTest("[^A-Za-z0-9]",Request("username")) Then
	ef=True
	ec="请输入用户名！"
ElseIf Request("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Not IsNumeric(Request("id"))  Then
	ef=True
	ec="非法产品类型！"
ElseIf Request.Form ("vpsname")="" Then
	ef=True
	ec="请设置云服务器名！"
ElseIf Len(Request.Form ("vpsname"))<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="云服务器名中有非法字符！"
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("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_vpsProductlist where id='"&Request("id")&"'"
			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
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")

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

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="CPU应该是数字！"
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 not IsNumeric(Request.Form ("OSAllList"))  Then
	ef=True
	ec="操作系统ID应该是数字！"
ElseIf CInt(Request.Form ("OSAllList"))<1 Or CInt(Request.Form ("OSAllList"))>16 Then
	ef=True
	ec="操作系统ID不能小于1或大于16！"
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 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 dshost("canbyagn")="n" then
	ef=True
	ec="本产品不允许开通！"
end if
end If

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

if not ef then
if Request.Form ("year")=dshost("PAY_WeeK") and dshost("canweek")="n" and Application("Agentcanunlimit")=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
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
	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 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
isONEip=dsserver("isONEip")	
end if
end If

if not ef Then
if isONEip=true then
	Set dsPORTserver = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_ServerPORTlist where id='"&dsserver("useportserver")&"'"
		dsPORTserver.Open Sql,conn,1,3
If dsPORTserver.Eof Then
	ef=True
	ec="PORT服务器不存在。"
Else
IPopen=dsPORTserver("ip")
If Not isnull(dsPORTserver("cname")) Then IPopen=dsPORTserver("cname")
end If
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 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")&""
		dsVPSMax.Open Sql,conn,1,1
If dsVPSMax(0)+1>dsserver("MaxVPS") Then
	ef=True
	ec="很抱歉,您选取的服务器的VPS数量资源已用光,请联系管理员处理."
End If
dsVPSMax.close
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
If dsserver("OStype")="Windows 2008R2" And dshost("Cpunum")>4 Then
	ef=True
	ec="操作系统是win2012才能设置超过4个CPU！"
end if
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

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

if not ef then

dim starttime,temptime,pdtype,isAgnHostSer
isAgnHostSer=isAgnvpsSer
pdtype=dshost("id")
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)
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="开通新建(AG)(云服务器名"&lcase(trim(Request.Form ("vpsname")))&")"
pubisagnSer=isAgnvpsSer
AgnRunasUser=false
DoPayMoney
end if

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_vps"
	dsph.Open Sql,conn,1,3
dsph.addnew
dsph("username")=ds("username")
'dsph("ServerlistID")=dsserver("id")
dsph("vpstype")=dshost("vpstype")
dsph("starttime")=starttime
dsph("endtime")=temptime

vpsname=lcase(trim(Request.Form ("vpsname")))
VPSpassword=trim(Request.Form ("VPSpassword"))
dsph("vpsname")=vpsname
dsph("VPSpassword")=VPSpassword

'dsph("vhdpath")=replace(dsserver("homedir")&"\"&dsph("vpsname")&"."&dsserver("vhdtype"),"\\","\")

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



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("canbackupvhd")=dshost("canbackupvhd")

dsph("allowdomain")=dshost("allowdomain")
dsph("CDNMaxMb")=dshost("CDNMaxMb")
dsph("kefu")=ds("kefunow")
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 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"
dim isfortest
isfortest=true
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.update
'dsph.close

'log
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_vps where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,3
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
If ipcount<dsph("MaxIP") then'如果选中2014
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




If Not isagentpd then'不是代理产品时再执行
URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
homedir=dsserver("homedir")
End if
vpsname=dsph ("vpsname")
username=dsph ("username")
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")

todir=dsph("vhdpath")
MaxIOPS=dsph("MaxIOPS")
MaxIOPS2=dsph("MaxIOPS2")
VLANid=dsph("VLANid")

If Not isagentpd then'不是代理产品时再执行
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

'Response.Write varcon

FreeHost_oplog session("agentusername"),"信息","代理开通云服务器产品: ("&vpsname&") "&temp&"("&ip&")"

dsph("status")="等待安装操作系统"


dsph.update



if request.Form ("installos")="yes" Then
oridir=dsserver("osfile1")
if len(oridir)>3 Then

EndIP=IP
VPSpassword=dsph("VPSpassword")
portstart=0
portend=0
If isONEip Then
EndIP=IPopen
portstart=dsVPSip("portstart")+4
portend=dsVPSip("portstart")+dsPORTserver("portperip")-1
End If



Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where VPSID="&dsph("id")&" order by SwitchName asc"
		dsVPSip.Open Sql,conn,1,1
IParycon=""'前面是IP，后面是MAC，网卡代号，虚拟交换机名
while not dsVPSip.eof
If isONEip Then
EndIP=IPopen
portstart=dsVPSip("portstart")+4
portend=dsVPSip("portstart")+dsPORTserver("portperip")-1
End If
SwitchName=dsserver("SwitchName")
MAC=dsph("MAC")
If dsVPSip("SwitchName")=2 Then SwitchName=dsserver("SwitchName2")
If dsVPSip("SwitchName")=2 Then MAC=dsph("MAC2")
If isnull(MAC) Then MAC="NULL"
IParycon=IParycon&""&dsVPSip("IP")&"$"&dsVPSip("IPmask")&"$"&dsVPSip("IPgateway")&"$"&dsVPSip("IPdns1")&"$"&dsVPSip("IPdns2")&"$"&MAC&"$"&SwitchName&"#"
dsVPSip.movenext
Wend
dsVPSip.close
varcon="installos "&username&" "&vpsname&" "&oridir&" "&todir&" "&IP&" "&IPmask&" "&IPgateway&" "&IPdns1&" "&IPdns2&" 1 "&MAXspace&" "&VPSpassword&" "&portstart&" "&portend&" "&IP2&" "&IP2mask&" "&IP2gateway&" "&IP2dns1&" "&IP2dns2&" NotCluster NOADSL- 0 0 []"&iparycon
If dsserver("IsCluster")=true Then varcon=Replace(varcon,"NotCluster","isCluster")

if not isnull(dsph("ADSLName")) Then
ADSLtxtInfo=dsph("ADSLName")&"/"&dsph("ADSLpass")
else
	Set dsADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_ADSL where VPSID="&dsph("id")
		dsADSL.Open Sql,conn,1,1
while not dsADSL.eof
ADSLtxtInfo=dsADSL("ADSLName")&"/"&dsADSL("ADSLpass")&" "&ADSLtxtInfo
dsADSL.movenext
Wend
ADSLtxtInfo=RTrim(ADSLtxtInfo)
end If
If ADSLtxtInfo<>"" Then varcon=Replace(varcon,"NOADSL-","HAVEADSL-"&ADSLtxtInfo)

temp=VPSOP(URL,FreeHostsharekey,varcon,1)'0=now
'Response.Write varconA
'Response.Write "装入网站"&dsserver("osname1")&"操作结果："
dsph("status")="正常"
dsph.update
'Response.Write temp
FreeHost_oplog session("agentusername"),"信息","代理预装云服务器产品操作系统: "&temp
Else
Response.Write "管理员没定义原始的操作系统文件,请联系管理员处理."
End If
End If

Else'是代理产品
vpsname=dsph("vpsname")
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("agentusername"),"信息","代理区，用户开通云服务器产品:("&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


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)
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
　开通云服务器
<%=htmlwrite("html6")%>
<br>
<br>
<table width="84%"  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="50%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="50%" 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><%=mymoneych%></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"> 　　　 <font color="#FF0000">现在的到期时间是:</font></font></td>
    <td colspan="3" bgcolor="#eeeeee"><%=temptime%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000">　　　 云服务器名是：</font></td>
    <td colspan="3"><%=vpsname%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 云服务器密码是：</font></td>
    <td colspan="3"><%=VPSpassword%></td>
  </tr>
<%If Not isagentpd then'不是代理产品时再执行
%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 分配的独立ＩＰ：</font></td>
    <td colspan="3"><%=ip%></td>
  </tr>  
<%end If%>     
<%if request.Form ("installos")="yes" Then
If Not isagentpd then'不是代理产品时再执行
%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 预装操作系统：</font></td>
    <td colspan="3">您选了马上预装操作系统,程序会在后台自动完成,需要大约25分钟,25分钟后请用远程桌面连接新开的VPS就可以管理,
<br>
以下内容请您记下来!
<br>
如果您预装的是Windows操作系统,请您
请稍等 <font color=red><b>25分钟</b></font> 后
用远程桌面连接您的云服务器：</p>
<p>IP：<%=EndIP%></p>
<%If isONEip then%>
<p>端口：<%=portstart%></p>
<%else%>
<p>端口：3389</p>
<%End if%>
<p>用户名：administrator</p>
<p>密码：<%=VPSpassword%><br>
  <br>
如果您预装的是Linux操作系统,请您
请稍等 <font color=red><b>25分钟</b></font> 后
用SSH连接您的云服务器：</p>
<p>IP：<%=EndIP%></p>
<%If isONEip then%>
<p>端口：<%=portstart+1%></p>
<%End if%>
<p>密码：<%=VPSpassword%><br>
  <br>
<%If ADSLtxtInfo<>"" then%><br><br> 拨号资源：<%=ADSLtxtInfo%><br><br><%End if%>
</td>
  </tr>
<%end If
End if%>     
  <tr bordercolor="#000000" bgcolor="#eeeeee">
    <td colspan="4"><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000">　</font><font color="#000000">　　　</font><font color="#000000">　　　</font><font color="#000000"> 　　　</font> 　</td>
  </tr>
  <tr align="center" bordercolor="#000000">
    <td height="34" colspan="4" bgcolor="#999999"><font color="#990000">　我　们　为　您　提　供　优　质　的　服　务！</font></td>
  </tr>
</table>
<br>
<%=htmlwrite("html7")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
