<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMoney.asp"-->
<%
If session("username")="" And session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。如果您没有登陆，请您先登陆。"
ElseIf Not Application("usenetcnhost")=true then
	ef=True
	ec="管理员设置了不允许开万网主机！"
ElseIf Request.Form ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Request.Form ("domain")="" Then
	ef=True
	ec="域名不能为空！"
ElseIf Request.Form ("os")="" Then
	ef=True
	ec="请选择操作系统类型！"
ElseIf Request.Form ("idc")="" 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应该是数字！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
elseIf checkscript(Request.Form ("userremindinfo")) Then
	ef=True
	ec="备注有非法字符！如<>script"
end If

if not ef Then
OriDomain= Request.Form("domain")
If OriDomain<>"" then
 
OriDomain=ComX.idntoac_7i24_com(Cstr(OriDomain))
If OriDomain="" or RegExpTest("[^.A-Za-z0-9--]",OriDomain) Then
	ef=True
	ec="域名非法！"

End if
OriDomain=ComX.actoidc_7i24_com(Cstr(OriDomain))
Enddomaintypeid=GetDomaintype(OriDomain)
End if
End If

if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")

username=session("username")
If session("agentusername")<>"" Then
username=session("agentusername")
End If

	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where username='"&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 dsNetCNpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_NetCNProductlist where id='"&Request.Form ("id")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsNetCNpdlist.Open Sql,conn,1,1
if dsNetCNpdlist.Eof then
	ef=True
	ec="产品不存在！"

else
productid=dsNetCNpdlist ("productid")
ServerlistID=dsNetCNpdlist ("ServerlistID")
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_NetCNProductlist_AGN where id='"&dsNetCNpdlist ("id")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then
if agnserverid ("ServerlistID")<>0 then
ServerlistID=agnserverid ("ServerlistID")
isAgnNetCNSer=true
else
isAgnNetCNSer=false
end if
end if
end if
end if

if not ef Then
If productid="host_xiangyun_1" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_2" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_3" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_4" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_6" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_7" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
If productid="host_xiangyun_12" And Request.Form ("os")<>"host_xiangyun" Then
	ef=True
	ec="此类型产品只能选云类型操作系统！"
End If
end if


if not ef then
If Request.Form ("year")<>999 and Request.Form ("year")<>dsNetCNpdlist("PAY_Month") and Request.Form ("year")<>dsNetCNpdlist("PAY_Season")  and Request.Form ("year")<>dsNetCNpdlist("PAY_halfyear") and Request.Form ("year")<>1 and Request.Form ("year")<>dsNetCNpdlist("PAY_2year") and Request.Form ("year")<>dsNetCNpdlist("PAY_3year") and Request.Form ("year")<>dsNetCNpdlist("PAY_4year") and Request.Form ("year")<>dsNetCNpdlist("PAY_5year") Then
	ef=True
	ec="请选择时间！"
end If
end if

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

if not ef then
if dsNetCNpdlist("canbyenduser")="n" And session("agentname")="n" then
	ef=True
	ec="本产品不允许最终用户开通！"
end if
end If

if not ef then
if dsNetCNpdlist("canbyagnenduser")="n" And session("agentname")<>"n" then
	ef=True
	ec="本产品不允许用户开通！"
end if
end If

if not ef then
if dsNetCNpdlist("canbyagn")="n" And session("AgnRunasUser")=true then
	ef=True
	ec="本产品不允许代理开通！"
end if
end if


if not ef then
if Request.Form ("year")=999 then
	ef=True
	ec="很抱歉,本产品不可以试用！"
end if
end If

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

if not ef then
if Request.Form ("year")=dsNetCNpdlist("PAY_Season") and dsNetCNpdlist("canseason")="n" then
	ef=True
	ec="很抱歉,本产品不可以季付！"
end if
end if
if not ef then
if Request.Form ("year")=dsNetCNpdlist("PAY_halfyear") and dsNetCNpdlist("canhalfyear")="n" then
	ef=True
	ec="很抱歉,本产品不可以半年付！"
end if
end if


if not ef Then


os=request("os")
If productid="host_xiangyun_1" Then OS=productid
If productid="host_xiangyun_2" Then OS=productid
If productid="host_xiangyun_3" Then OS=productid
If productid="host_xiangyun_4" Then OS=productid
If productid="host_xiangyun_6" Then OS=productid
If productid="host_xiangyun_7" Then OS=productid
If productid="host_xiangyun_12" Then OS=productid

dim starttime,temptime,pdtype,isAgnHostSer
isAgnHostSer=isAgnNetCNSer
pdtype=dsNetCNpdlist("productid")
starttime=Now
'结束时间
y=Request.Form ("year")
if y=1 then temptime=dateadd("yyyy",1,now)
if y=dsNetCNpdlist("PAY_2year") then temptime=dateadd("yyyy",2,now)
if y=dsNetCNpdlist("PAY_3year") then temptime=dateadd("yyyy",3,now)
if y=dsNetCNpdlist("PAY_4year") then temptime=dateadd("yyyy",4,now)
if y=dsNetCNpdlist("PAY_5year") then temptime=dateadd("yyyy",5,now)
if y=dsNetCNpdlist("PAY_Month") then temptime=dateadd("y",31,now)
if y=dsNetCNpdlist("PAY_Season") then temptime=dateadd("y",92,now)
if y=dsNetCNpdlist("PAY_halfyear") then temptime=dateadd("y",182,now)
if y=999 then
temptime=dateadd("y",Application("testtime"),now)
dim isfortest
isfortest=true
end if

dim ef,ec,Userpaymoney,forpaytype,olduser_money,moneych,newuser_money,oldagn_money,mymoneych,newagn_money,Useragentname,agent_UP,agent_thisgree_cost,agent_this_name,logfor,pubisagnSer,AgnRunasUser,RsDlist
set RsDlist=dsNetCNpdlist
Userpaymoney=dsNetCNpdlist("usermoney")
forpayyear=Request.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="万网主机产品"
forpayid=dsNetCNpdlist("id")
logfor="自动开通新建万网主机产品"
pubisagnSer=isAgnNetCNSer
AgnRunasUser=session("AgnRunasUser")

If session("agentusername")<>"" Then
AgnRunasUser=True
End If

DoPayMoneyIDC
end If




if not ef then
Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_NetCN where username='"&username&"'"
	dsph.Open Sql,conn,1,3
dsph.AddNew
dsph("username")=ds ("username")
dsph("Ftpname")="未设置"
'dsph("Ftppasswordword")=Ftppasswordword
'dsph("volume")=request("volume")
'dsph("ipaddress")=request("ipaddress")
'dsph("dbname")=request("dbname")
'dsph("dbpassword")=request("dbpassword")
dsph("starttime")=starttime
dsph("endtime")=temptime
dsph("Domain")=Trim(request("Domain"))
dsph("category")="host"
dsph("productid")=dsNetCNpdlist("productid")
dsph("os")=OS
dsph("idc")=request("idc")
dsph("vyear")=request("year")
'dsph("amount")=request("amount")
dsph("status")="等待处理"
if ds("agent1")<>"n" then
dsph("agent1")=ds("agent1")
else
dsph("agent1")="n"
end If
dsph("agent2")="n"
dsph.update

'log
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_NetCN 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


			userid=Application("Domain_Agent_username_5")			'万网数字ID
			password		=Application("Domain_Agent_password_5")		'万网数字ID密码
			email			=Application("Domain_Agent_username_5_emamil")	'万网注册email
			vtime			= FormatDate(now())
			userstr			=md5(userid&password&email&vtime)

			category		="host"
			productid		=dsph("productid")
			action			="activate"
			
			vsendStr		="userid="&userid&"&userstr="&userstr&"&vtime="&vtime
			
			vsendStr		=vsendStr&"&category="&category
			vsendStr		=vsendStr&"&productid="&productid
			vsendStr		=vsendStr&"&action="&action
			
			vsendStr		=vsendStr&"&domain="&server.URLEncode(Trim(request("Domain")))

If dsph("vyear")=dsNetCNpdlist("PAY_Month") Then vsendStr		=vsendStr&"&vmonth=1"
If dsph("vyear")=dsNetCNpdlist("PAY_Season") Then vsendStr		=vsendStr&"&vmonth=3"
If dsph("vyear")=dsNetCNpdlist("PAY_halfyear") Then vsendStr		=vsendStr&"&vmonth=6"
If dsph("vyear")>0.9 Then vsendStr		=vsendStr&"&vyear="&dsph("vyear")

			vsendStr		=vsendStr&"&os="&server.URLEncode(OS)
			vsendStr		=vsendStr&"&idc="&server.URLEncode(request("idc"))
			retdns=LIT_RetrunStr("http://api.hichina.com/wwwnetcn.aspx",vsendStr)

dsph("retdns")=retdns
dsph.update

If retdns="" then
	ef=True
	ec="操作失败，可能的原因是您服务器连接万网的网络不正常"
	retdns=ec
	FreeHost_oplog session("username"),"失败","开通万网主机时由于网络不正常等原因操作失败:"&dsph("Domain")
'	dsph.cancel
end If

end if

If Not ef Then



			dim returncodevalue,failreason,sucdate,deaddate,hostadminid,hostpassword,volume,ipaddress,dbname,dbpassword
			xmlvalue(retdns)
			If Instr(retdns,"200")<=0 Then
				retdns= "返回状态码:"&returncodevalue&" 原因:"&failreason
				ef=True
				ec=retdns
				FreeHost_oplog session("username"),"失败","万网主机:"&dsph("id")&"<br>"&retdns
			Else
				FreeHost_oplog session("username"),"信息","万网主机："&retdns&":"&dsph("id")
			End If		
		


end if

If Not ef Then


dsph("ftpname")=hostadminid
dsph("Ftppassword")=hostpassword
dsph("endtime")=deaddate
dsph("volume")=volume
dsph("ipaddress")=ipaddress
'dsph("dbname")=dbname
'dsph("dbpassword")=dbpassword
dsph("status")="正常"
dsph.Update


If Application("smshostopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smshostopencon")
'恭喜！您的虚拟主机已开通了！用户名 ：#用户名# FTP地址：#FTP地址#服务器IP ：#IP#FTP用户名 ：#FTP#FTP密码 ：#FTP密码#到期时间是 ：#到期时间#您的帐户余款是 ：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#FTP地址#",dsph("domain"))
smsContent=Replace(smsContent,"#IP#",dsph("ipaddress"))
smsContent=Replace(smsContent,"#FTP#",dsph("ftpname"))
smsContent=Replace(smsContent,"#FTP密码#",dsph("Ftppassword"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if





if session("agentusername")<>"" Then%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
<%else%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>
<%End if%>
　 万网主机类自助开通
<%if session("agentusername")<>"" Then%>
<%=htmlwrite("html6")%>
<%else%>
<%=htmlwrite("html3")%>
<%End if%>

<br>
<br>
<br>
<table width="60%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td height="37" colspan="2" bgcolor="#999999"><font color="#000000">　　　</font><font color="#990000"><font color="#FF0000">恭喜您，开通成功，以下是您的资料：</font></font></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#999999">
    <td width="46%" height="37" align="right" bgcolor="#eeeeee">用户的原金额：</td>
    <td width="54%" height="37" align="left" bgcolor="#eeeeee">　<%=olduser_money%>元</td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="37" align="right" bgcolor="#eeeeee">用户金额变化：</td>
    <td height="37" align="left"><font color=red>　<%=moneych%>元</font></td>
  </tr>
  <tr align="center" bordercolor="#000000" bgcolor="#eeeeee">
    <td height="40" align="right">用户的新金额：</td>
    <td height="40" align="left">　<%=newuser_money%>元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="37" align="right"><font color="#000000">　　　 FTP登陆用户名是：</font></td>
    <td colspan="3"><%=dsph("ftpname")%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="37" align="right"><font color="#000000"> 　　　 FTP密码是：</font></td>
    <td colspan="3"><%=dsph("Ftppassword")%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="42" align="right"><font color="#000000">　　　 </font><font color="#000000">用户的网址为：</font></td>
    <td height="42"><font color="#000000"><a href="http://<%=dsph("Domain")%>" target=_blank><font color="#000000">http://<%=dsph("Domain")%></font></a></font></td>
    <td height="42">&nbsp;</td>
    <td height="42">&nbsp;</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="40" align="right"><font color="#000000"> 　　　 用户的FTP地址是：</font></td>
    <td height="40"><font color="#000000"><font color=red><%=dsph("ipaddress")%></font></font></td>
    <td height="40">&nbsp;</td>
    <td height="40">&nbsp;</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#EEEEEE">
    <td height="37" align="right"><font color="#000000"> 　　　 到期时间是:</font></td>
    <td colspan="3"><%=temptime%></td>
  </tr>
</table>
<br>
<br>
<br>
<br>

<br>
<%if session("agentusername")<>"" Then%>
<%=htmlwrite("html7")%>
<%else%>
<%=htmlwrite("html4")%>
<%End if%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
