<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("username")="" Then
	ef=True
	ec="请您先登陆用户区，再续费，在主机面板中不能续费。也有可能是超时造成了出错。"
ElseIf Request.Form ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.Form ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request.Form ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
end If

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&session("username")&"'"
		ds.Open Sql,conn,1,3
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_VPS where id='"&Request.Form ("id")&"' and username='"&session("username")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsph.Open Sql,conn,1,3
if dsph.Eof then
	ef=True
	ec="不存在的云服务器ID！"
end if
end if

if not ef then
	Set dsHost = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_VPSProductlist where VPStype='"&dsph ("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="产品不存在！"
end if
end If

if not ef then
	Set dsserver = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_ServerVPSlist where id='"&dsph ("ServerlistID")&"'"
	dsserver.Open Sql,conn,1,1
if dsserver.Eof then
	ef=True
	ec="服务器不存在！"
Else
dim isAgnHostSer
if dsserver("agent1")="n" Then
isAgnHostSer=false
else
isAgnHostSer=true
end if
end if
end if

if not ef then
if dsHost("cancloud")=false then
	ef=True
	ec="弹性购买的产品才能使用本功能"
end if
end If


if not ef Then
daytoend=DateDiff("d",NOW,dsph("endtime"))
if daytoend<0 Then
	ef=True
	ec="您原来的产品已过期了，请您先延期原产品后才能升级。"
End If
End If

if not ef then
if dsph("istest")="y" then
	ef=True
	ec="试用状态的产品必须延期后成为正式产品才可以升级到高级别！"
end if
end If


if not ef then


'开始升级
dim starttime,temptime,pdtype
'pdtype="弹性产品类型不变："&dsph ("VPStype")



iporiary=""

idarry=split(request.form("ipid"),",")
for dsphid=0 to ubound(idarry)
If IsNumeric(idarry(dsphid))  Then

Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where VPSID="&dsph("id")&" and id='"&idarry(dsphid)&"'"
'		response.write sql
		dsX.Open Sql,conn,1,3
If not dsX.eof then
'Response.write idarry(dsphid)&"<br>" 
'response.write dsX("ip")&"<br>" 

If iporiary=""Then
iporiary=dsX("id")
else
iporiary=iporiary&","&dsX("id")
End if


Else
Response.write idarry(dsphid)&"<br>" 
Response.write "IP不存在!<br>" 
Response.end
End If

End If'isnumeric
next

IPoriA=split(iporiary,",")
'Response.write iporiary&"<br>" 

If ubound(IPoriA)<0 Then
Response.write "IP最少要有一个!<br>" 
Response.end
End if

'重新生成IP数组

'清空所有这个VPS名下的IP
Sql="update FreeHost.FreeHost_Product_VPS_IP set VPSID=0 where VPSID='"&dsph("id")&"'"
conn.Execute Sql
'Response.write "<br><br><br><br>" 


ipcount=0
for OldIParyid=0 to ubound(IPoriA)
If IsNumeric(IPoriA(OldIParyid)) Then

If IPoriA(OldIParyid)>0 then
'Response.write IPoriA(OldIParyid)&"<br>" 

Sql="update FreeHost.FreeHost_Product_VPS_IP set VPSID="&dsph("id")&" where ID='"&IPoriA(OldIParyid)&"'"
conn.Execute Sql
ipcount=ipcount+1
End if

End if
next

'Response.end



dsph("MaxIP")=ipcount

'更新产品类别
'dsph ("VPStype")=dshost("VPStype")
'dsph("MAXCPU")=dshost("MAXCPU")
'dsph("CpuNum")=dshost("CpuNum")
'dsph("MAXRam")=dshost("MAXRam")
'dsph("StartRam")=dshost("StartRam")
'dsph("Maxmbps8")=dshost("Maxmbps8")
'dsph("Minmbps8")=dshost("Minmbps8")
'dsph("MAXspace")=dshost("MAXspace")
'dsph("allowdomain")=dshost("allowdomain")
'dsph("CDNMaxMb")=dshost("CDNMaxMb")
'dsph("status")="正常"
'starttime=dsph ("endtime")'时间不变
'temptime=dsph ("endtime")
dsph.update

'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")
'dsph.update
'end If

'URL=dsserver("site")
'FreeHostsharekey=dsserver("FreeHostsharekey")
'vpsname=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")
'MaxIOPS=dsph("MaxIOPS")
'MaxIOPS2=dsph("MaxIOPS2")




'Response.Write varcon
'Response.Write temp

FreeHost_oplog session("username"),"信息","用户自己降级，减少IP,云服务器名:"&vpsname&" 返回信息："&temp

end If


if not ef then%><!--<%=oldusermoney%>;<%=oldusermoneyleft%>;<%=daytoend%>-->
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html12")%>
　云服务器
<%=htmlwrite("html13")%>

<%

	Set dsVPSip = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ipbyid=0 and VPSID="&dsph("id")
		dsVPSip.Open Sql,conn,1,1
'If not dsVPSip.Eof Then
'while not dsVPSip.eof
IP=dsVPSip("IP")
IPmask=dsVPSip("IPmask")
IPgateway=dsVPSip("IPgateway")
IPdns1=dsVPSip("IPdns1")
IPdns2=dsVPSip("IPdns2")


URL=dsserver("site")
FreeHostsharekey=dsserver("FreeHostsharekey")
username=dsph("username")
vpsname=dsph("vpsname")
'oridir=dsserver("osfile"&Request.Form ("osid"))
'homedir=dsserver("homedir")
todir=dsph("vhdpath")
MAXspace=dsph("MAXspace")
'IP=dsVPSip("IP")
'IPmask=dsVPSip("IPmask")
'IPgateway=dsVPSip("IPgateway")
'IPdns1=dsVPSip("IPdns1")
'IPdns2=dsVPSip("IPdns2")
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
IP2=0
IP2mask=0
IP2gateway=0
IP2dns1=0
IP2dns2=0

Set dsVPSip2 = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Product_VPS_IP where ipbyid='"&dsVPSip("ID")&"' order by orderbyid desc"
		dsVPSip2.Open Sql,conn,1,1
If Not dsVPSip2.Eof Then
IP2=dsVPSip2("IP")
IP2mask=dsVPSip2("IPmask")
IP2gateway=dsVPSip2("IPgateway")
IP2dns1=dsVPSip2("IPdns1")
IP2dns2=dsVPSip2("IPdns2")
end if

oridir="X:\setipby7i24"
todir=oridir
'VPSpassword=Request.Form ("newpassword")
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
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

FreeHost_oplog session("username"),"信息","用户减少IP同步云服务器管理员密码"&username&" 云主机: "&vpsname

varcon="setippass "&username&" "&vpsname&" "&oridir&" "&todir&" "&IP&" "&IPmask&" "&IPgateway&" "&IPdns1&" "&IPdns2&" 1 "&MAXspace&" "&VPSpassword&" "&portstart&" "&portend&" "&IP2&" "&IP2mask&" "&IP2gateway&" "&IP2dns1&" "&IP2dns2&" 0 0 0 0 []"&iparycon
temp=VPSOP(URL,FreeHostsharekey,varcon,1)'0=now

'Response.Write varcon

Response.Write "<br><br><br><br>设置密码及IP的操作结果："

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

'If	InStr(temp,"会复制目录中") Then
'Response.Write "2分钟后开始复制."
'Else
Response.Write temp
%>


<br>
<br>
如果您的操作系统是Windows操作系统,请您
请稍等 <font color=red><b>10分钟</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>
  <br>
如果您的操作系统是Linux操作系统,请您
请稍等 <font color=red><b>10分钟</b></font> 后
用SSH连接您的云服务器：</p>
<p>IP：<%=EndIP%></p>
<%If isONEip then%>
<p>端口：<%=portstart-4+1%></p>
<%End if%>
<p>密码：<%=VPSpassword%><br>
  <br>
<%
End if



%>
<br>

<br>
<br>
<br>

<br>

<br>
<br>
<%=htmlwrite("html14")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
