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

If Request.Form ("Batcount")>1 Then server.Transfer "admvps3bat.asp"'进入批量处理，检查用户名是否可以用

server.ScriptTimeout =240
If session("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request.Form ("username")="" Then
	ef=True
	ec="请输入用户名！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) Then
	ef=True
	ec="用户名中有非法字符！"
ElseIf Request.Form ("vpstype")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Not IsNumeric(Request.Form ("vpstype")) then
	ef=True
	ec="产品类型有非法字符！"
ElseIf Not IsNumeric(Request.Form ("ServerlistID")) then
	ef=True
	ec="产品类型有非法字符！"
ElseIf Request.Form ("vpsname")="" Then
	ef=True
	ec="请设置VPS户名！"
ElseIf IsNumeric(Request.Form ("vpsname"))  Then
	ef=True
	ec="VPS户名不能是纯数字！"
ElseIf Not IsNumeric(Request.Form ("MAXspace"))  Then
	ef=True
	ec="硬盘大小必须是纯数字！"
ElseIf CLng(Request.Form ("MAXspace"))<11  Then
	ef=True
	ec="硬盘大小必须大于10！"
ElseIf Request.Form ("VPSpassword")="" Then
	ef=True
	ec="请设置云服务器密码！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("vpsname")) Then
	ef=True
	ec="VPS户名中有非法字符！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("VPSpassword"))  or Request.Form ("VPSpassword")="123456" or Request.Form ("VPSpassword")="12345"  or len(Request.Form ("VPSpassword"))<4 Then
	ef=True
	ec="云服务器密码有非法字符，只能是字母与数字/密码没填/或密码过于简单！"
ElseIf Not IsNumeric(Request.Form ("Batcount"))  Then
	ef=True
	ec="开通数量必须是纯数字！"
ElseIf Request.Form ("Batcount")<>"" And CLng(Request.Form ("Batcount"))<1  Then
	ef=True
	ec="开通数量必须大于0！"
elseIf session("canadmvpsadd")="" And session("canadmvpsaddtest")="" Then
	ef=True
	ec="您没有此操作的权限。"
end If

if not ef then
if Request.Form ("year")<>999 And session("canadmvpsadd")="" then
	ef=True
	ec="您只有开通试用产品的权限,请返回选择试用！"
end If
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='"&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_VPSProductlist where id='"&Request.Form ("vpstype")&"'"
	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
NetCardlimtype=dshost("NetCardlimtype")
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 Request.Form ("CpuValue")<1 Then
	ef=True
	ec="CPU不能小于1个核心！"
ElseIf not IsNumeric(Request.Form ("RamValue"))  Then
	ef=True
	ec="CPU应该是数字！"
ElseIf Request.Form ("RamValue")<256 Then
	ef=True
	ec="内存不能小于256M！"
ElseIf not IsNumeric(Request.Form ("VHDValue"))  Then
	ef=True
	ec="虚拟硬盘大小应该是数字！"
ElseIf Request.Form ("VHDValue")<10 Then
	ef=True
	ec="虚拟硬盘大小不能小于10G！"
ElseIf not IsNumeric(Request.Form ("MbpsValue"))  Then
	ef=True
	ec="带宽大小应该是数字！"
ElseIf Request.Form ("MbpsValue")<1 Then
	ef=True
	ec="带宽不能小于1Mbps！"
ElseIf not IsNumeric(Request.Form ("SNAValue"))  Then
	ef=True
	ec="快照数量应该是数字！"
ElseIf Request.Form ("SNAValue")<0 Then
	ef=True
	ec="快照不能小于0个！"
ElseIf not IsNumeric(Request.Form ("BakValue"))  Then
	ef=True
	ec="备份数量应该是数字！"
ElseIf Request.Form ("BakValue")<0 Then
	ef=True
	ec="备份不能小于0个！"
ElseIf not IsNumeric(Request.Form ("NGBValue"))  Then
	ef=True
	ec="流量上限应该是数字！"
ElseIf Request.Form ("NGBValue")<0 Then
	ef=True
	ec="流量上限不能小于0个！"
ElseIf not IsNumeric(Request.Form ("IPValue"))  Then
	ef=True
	ec="IP上限应该是数字！"
ElseIf Request.Form ("IPValue")<1 Then
	ef=True
	ec="IP上限不能小于1个！"
ElseIf not IsNumeric(Request.Form ("IopsValue"))  Then
	ef=True
	ec="IOPS上限应该是数字！"
ElseIf Request.Form ("IopsValue")<0 Then
	ef=True
	ec="IOPS上限不能小于1个！"
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 dshost("isagentpd")=true Then
if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&Request.Form ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
else
    netby=dsserver("netby")
	serverip=dsserver("ip")
	homedir=dsserver("homedir")
	'hostip=dsserver("ip")
	'ftpdomain=dsserver("ftpdomain")
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 dsserver("OStype")="Windows 2008R2" And Request.Form ("CpuNum")>4 Then 
	ef=True
	ec="操作系统是win2012才能设置超过4个CPU！"
end if
end If

if not ef Then
firstvpsid=0
Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
'		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" and VPSID=0  and ipbyid=0 and id="&request("ipid")&" order by orderbyid desc"
'		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" and VPSID=0  and ipbyid=0 order by orderbyid desc"
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ServerlistID="&dsserver("id")&" order by orderbyid desc"
		dsVPSip.Open Sql,conn,1,3
If dsVPSip.Eof Then
	ef=True
	ec="很抱歉,本台服务器的的IP已用光了."
Else
While Not dsVPSip.Eof
If CLng(request("ipid"&dsVPSip("id")))=dsVPSip("id") then'如果选中2014
firstvpsid=dsVPSip("id")
If dsVPSip("VPSID")>0 Then
	ef=True
	ec="很抱歉,这个IP已被使用了："&dsVPSip("ip")
'Else'设置为已用状态
End if
End if
dsVPSip.movenext
wend
End If
End If

if not ef then
If firstvpsid=0 Then 
	ef=True
	ec="请先选择IP！"
end if
end If

if not ef Then
firstvpsADSLid=0
Set dsVPSADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_ADSL where ServerlistID="&dsserver("id")&" order by orderbyid desc"
		dsVPSADSL.Open Sql,conn,1,3
If Not dsVPSADSL.Eof Then
While Not dsVPSip.Eof
If CLng(request("ADSLid"&dsVPSADSL("id")))=dsVPSADSL("id") then'如果选中2014
firstvpsADSLid=dsVPSADSL("id")
If dsVPSADSL("VPSID")>0 Then
	ef=True
	ec="很抱歉,这个拨号用户名已被使用了："&dsVPSADSL("ADSLName")
End if
End if
dsVPSADSL.movenext
wend
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

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
	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="您输入的VPS户名已存在，请另外输入一个！"
end if
dsph.close
end if

if not ef Then
If Request.Form ("Batcount")>1 Then'进入批量处理，检查用户名是否可以用
'检查最后的ID
	Set dsphTop = Server.CreateObject("ADODB.Recordset")	
	Sql="Select top 1 * from FreeHost.FreeHost_Product_VPS order by id desc"
	dsphTop.Open Sql,conn,1,1
if dsphTop.Eof then
VPSTopID=0
Else
VPSTopID=dsphTop("id")
end if
dsphTop.close

For i=1 To Request.Form ("Batcount")'列出所有生成的VPS名检查有没有重复的
BatNewVPSName=Left(trim(LCASE(Request.Form ("vpsname"))),3)&Left(VPSTopID,6)&"A"&i
	Set dsphDU = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where vpsname='"&BatNewVPSName&"'"
	Response.write sql&"<br>"
	dsphDU.Open Sql,conn,1,1
if not dsphDU.Eof then
	ef=True
	ec="您输入的VPS户名已存在，请另外输入一个！vpsname:"&BatNewVPSName
end if
dsphDU.close
Next

End if
end If

'Response.Write EC
'Response.end

if not ef then
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where username='"&session ("username")&"' and istest='y'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if Request.Form ("year")=999 then
if not dsph.Eof then
'	ef=True
'	ec="一个用户只能试用一个产品！"
end if
end if
end if



if not ef then
dim Subject,body'send mail
vpsname=lcase(trim(Request.Form ("vpsname")))
VPSpassword=trim(Request.Form ("VPSpassword"))
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)
end if
if request.Form ("endtime")<>"" then temptime=request.Form ("endtime")
end if


if not ef then
'hostname=trim(replace(Request.Form ("hostname")," ",""))
dsph.AddNew
dsph("username")=ds ("username")
if Not dshost("isagentpd")=true Then dsph("ServerlistID")=dsserver("id")
dsph("vpstype")=dshost("vpstype")
dsph("starttime")=starttime
dsph("endtime")=temptime

dsph("vpsname")=vpsname
dsph("VPSpassword")=VPSpassword

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("Cpunum")=request("Cpunum")
dsph("MaxRAM")=request("MaxRAM")
dsph("StartRam")=request("StartRam")

dsph("Maxmbps8")=request("Maxmbps8")
If dsph("Maxmbps8")>1 Then
dsph("Minmbps8")=Fix(dsph("Maxmbps8")/2)
Else
dsph("Minmbps8")=1
End If

dsph("MaxCPU")=request("MaxCPU")
dsph("MaxSpace")=request("MaxSpace")
dsph("canbackupvhd")=dshost("canbackupvhd")

dsph("allowdomain")=request("allowdomain")
If Request.Form("CDNMaxMb")>0 Then dsph("CDNMaxMb")=Request.Form("CDNMaxMb")

If Len(request("vhdpath"))>4 Then
dsph("vhdpath")=LCase(trim(request("vhdpath")))
else
if Not dshost("isagentpd")=true Then dsph("vhdpath")=replace(dsserver("homedir")&"\"&dsph("vpsname")&"."&dsserver("vhdtype"),"\\","\")
End If

dsph("MaxIP")=request("MaxIP")

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")=1
If IsNumeric(Request.Form("OSAllList")) Then dsph("FirstOSid")=Request.Form("OSAllList")
end if

dsph("MaxIOPS")=request("MaxIOPS")
dsph("MaxIOPS2")=request("MaxIOPS2")

VLANid=0


If request("ADSLname")<>"" then
dsph("ADSLname")=Trim(request("ADSLname"))
dsph("ADSLpass")=Trim(request("ADSLpass"))
End if

dsph.Update

olduser_money=ds("usermoney")
moneych=0
If Request.Form ("chmoney")<>"" Then
'变更金额
ds("usermoney")=ds("usermoney")-Request.Form ("usermoney")
moneych=-Request.Form ("usermoney")
ds.update
end if
newuser_money=ds("usermoney")
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where vpsname='"&vpsname&"'"
	dsph.Open Sql,conn,1,3
pdtype=dsph("vpstype")
FreeHost_moneyNewlog conn,"y","n","y","n","n",isAgnHostSer,-moneych,dsph ("username"),session("admusername"),dsph ("username"),olduser_money,newuser_money,agnusername,agnStmoney,agnEndmoney,session("admusername"),"管理员新建云服务器产品(云服务器名"&trim(Request.Form ("vpsname"))&")","管理员新建云服务器产品(云服务器名"&trim(Request.Form ("vpsname"))&")","云服务器产品",dsph("id"),pingzheng,type1,bank,haveget,havecheck

if Not dshost("isagentpd")=true Then 
'dsVPSip("VPSID")=dsph("id")
'ip=dsVPSip("ip")
'dsVPSip.update
'conn.Execute "update FreeHost.FreeHost_Product_VPS_IP set VPSID='"&dsph("id")&"' where ipbyid='"&dsVPSip("ID")&"'"'havenextIP=true

Set dsVPSADSL = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_ADSL where ServerlistID="&dsserver("id")&" and VPSID=0 order by orderbyid desc"
		dsVPSADSL.Open Sql,conn,1,3
While Not dsVPSADSL.Eof
If CLng(request("ADSLid"&dsVPSADSL("id")))=dsVPSADSL("id") then'ADSL
dsVPSADSL("VPSID")=dsph("id")
If dsVPSADSL("VLANid")>0 Then VLANid=dsVPSADSL("VLANid")
dsVPSADSL.update
End If
dsVPSADSL.movenext
wend
dsVPSADSL.close

If request("VLANid")>0 Then
dsph("VLANid")=request("VLANid")
VLANid=dsph("VLANid")
End If


IP2=0
IP2mask=0
IP2gateway=0
IP2dns1=0
IP2dns2=0

havenextIP=False
dsVPSip.movefirst
Set dsVPSip2 = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ipbyid='"&firstvpsid&"' and VPSID=0 order by orderbyid desc"
		dsVPSip2.Open Sql,conn,1,3
If Not dsVPSip2.Eof Then
'有附属IP时
Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where id='"&firstvpsid&"'"
		dsVPSip.Open Sql,conn,1,3
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

If havenextIP=false then
dsVPSip.movefirst
While Not dsVPSip.Eof
If CLng(request("ipid"&dsVPSip("id")))=dsVPSip("id") then'如果选中2014
dsVPSip("VPSID")=dsph("id")
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'havenext IP

End if



%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html8")%>
<%=htmlwrite("html9")%>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 background="img/midtop4.gif">
  <TBODY>
    <TR>
      <TD width=53 align="left" background="img/midtop1.gif"><strong> 　 </strong><font color="#FFFFFF">─<strong>&gt;</strong></font> </TD>
      <TD align="left"><table height="59"  border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="7" background="img/midtop.gif">&nbsp;</td>
          <td width="150" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="admvps.asp"><font color="#FFFFFF"><strong>云服务器产品管理</strong></font></a></td>
          <td width="5" background="img/midtop2.gif">&nbsp;</td>
        </tr>
      </table></TD>
      <TD width="83">&nbsp;</TD>
      <TD width="83" align="left">&nbsp;</TD>
      <TD align="left">&nbsp;</TD>
      <TD width=23 align="right"><IMG height=59 
                  src="img/rtop4.jpg" 
                  width=19></TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
    <TR>
      <TD width=19 background="img/midlef.gif" id=rightid>&nbsp;</TD>
      <TD height="300" align="center" vAlign=top bgcolor="#FFFFFF">
<table width="65%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<br>
<DIV class="tableborder"><br>
<br>
受控端返回信息：
<%
if Not dshost("isagentpd")=true 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")

Minmbps8=dsph("Minmbps8")
Maxmbps8=dsph("Maxmbps8")

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

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





todir=dsph("vhdpath")

MaxIOPS=dsph("MaxIOPS")
MaxIOPS2=dsph("MaxIOPS2")

varcon="makevps "&username&" "&vpsname&" "&CpuNum&" "&MAXcpu&" "&MAXRam&" "&MAXspace&" "&vhdpath&" "&StartRam
if Not dshost("isagentpd")=true Then 
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"))
'Response.write varcon
'Response.end
temp=VPSOP(URL,FreeHostsharekey,varcon,0)

If Not isnull(dsserver("SwitchName2")) Then '处理switch
'Response.write temp&"<br>"
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
Response.write dsph("MAC")&"<br>"
Response.write dsph("MAC2")&"<br>"
'Response.write arysw3(0)&"<br>"
'Response.write replace(arysw3(1),"MacAddress : ","")&"<br>"
'Response.write replace(arysw3(3),"SwitchName : ","")&"<br>"
'Response.write replace(arysw3(4),"MacAddress : ","")&"<br>"
End if
End if'完成switch


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("admusername"),"信息","管理区，管理员开通云服务器产品:("&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
response.write temp
FreeHost_oplog session("admusername"),"信息","管理员开通云服务器名: ("&vpsname&") "&temp&"("&ip&")"
if Not dshost("isagentpd")=true Then
dsph("status")="等待安装操作系统"
End if
dsph.Update


if request.Form ("installos")="yes" and Not dshost("isagentpd")=true Then
oridir=dsserver("osfile1")'2016414
If request.Form ("OSAllList")<>"" Then oridir=dsserver("osfile"&request.Form ("OSAllList"))'2016414
if len(oridir)>3 Then
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)

'Response.Write varcon
'Response.end

temp=VPSOP(URL,FreeHostsharekey,varcon,1)'0=now

Response.Write "装入操作系统"&dsserver("osname1")&"操作结果："
dsph("status")="正常"
dsph.update
Response.Write temp
FreeHost_oplog session("admusername"),"信息","管理员预装云服务器产品操作系统: "&temp%>
如果您预装的是Windows操作系统,请您
请稍等 <font color=red><b>25分钟</b></font> 后
用远程桌面连接您的云服务器：</p>
<p>IP：<%=EndIP%></p>
<%If isONEip then%>
<p>端口：<%=portstart-4%></p>
<%else%>
<p>端口：3389</p>
<%End if%>
<p>用户名：administrator</p>
<p>密码：<%=VPSpassword%><br>
如果您预装的是Linux操作系统,请您
请稍等 <font color=red><b>25分钟</b></font> 后
用SSH连接您的云服务器：</p>
<p>IP：<%=EndIP%></p>
<%If isONEip then%>
<p>端口：<%=portstart-4+1%></p>
<%End if%>
<p>密码：<%=VPSpassword%><br>
  <br>
<%If ADSLtxtInfo<>"" then%><br><br> 拨号资源：<%=ADSLtxtInfo%><br><br><%End if%>
<%
Else
Response.Write "管理员没定义原始的操作系统文件,请联系管理员处理."
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)

'dsph.close
%>
<br>
<br>

</div>
	
	</td>
  </tr>
</table>

<br>
<table width="65%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	
	
	<br><DIV class="tableborder">
<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="1">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="24" colspan="4" background="img/tablebg.gif"><font color="#990000"><font color="#FFFFFF">云服务器产品开通成功，以下是相关的资料</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td width="53%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="47%" colspan="3"><font color="#000000"><%=olduser_money%>元</font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <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="#E4EAF2">
    <td height="39"><font color="#000000">　　　 用户的新金额：</font></td>
    <td colspan="3"><font color="#000000"><%=newuser_money%> 元</font></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>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 分配的独立ＩＰ：</font></td>
    <td colspan="3"><%=ip%></td>
  </tr>

<%if y=999 then%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 现在的到期时间是:</font></td>
    <td colspan="3"><%=temptime%></td>
  </tr>
<%end if%> 
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 现在的到期时间是:</font></td>
    <td colspan="3"><%=temptime%></td>
  </tr>

<%if request.Form ("installos")="yes" Then%>
<%If isONEip=false then%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 预装操作系统：</font></td>
    <td colspan="3">您选了马上预装操作系统,程序会在后台自动完成,需要大约25分钟,25分钟后请用远程桌面连接新开的VPS就可以管理,IP:<%=ip%>,端口3389,用户名:Administrator,密码:888888</td>
  </tr>
<%end if%>
<%end if%>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37" colspan="4" align="right" bgcolor="#E4EAF2"><font color="#000000"> 　　　</font><a href="#top"><font color="#6B9EDE" face="Arial, Helvetica, sans-serif">Top↑</font></a>	</td>
    </tr>
</table>
	</div>

	</td>
  </tr>
</table>

</TD>
      <TD width=18 background="img/midri.gif">&nbsp;</TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
    <TR>
      <TD width=30><IMG height=19 
                  src="img/rb1.jpg" 
                  width=30></TD>
      <TD 
                background=img/rb2.jpg>&nbsp;</TD>
      <TD width=30><IMG height=19 
                  src="img/rb3.jpg" 
                  width=30></TD>
    </TR>
  </TBODY>
</TABLE>
<%=htmlwrite("html10")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
