<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request("username")=""  or RegExpTest("[^A-Za-z0-9]",Request("username")) Then
	ef=True
	ec="请输入用户名！"
ElseIf Request("cdntype")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Not IsNumeric(Request("cdntype"))  Then
	ef=True
	ec="非法产品类型！"
ElseIf Request.Form ("cdnname")="" Then
	ef=True
	ec="请设置cdn名！"
ElseIf Len(Request.Form ("cdnname"))<3 Then
	ef=True
	ec="cdn名长度不能小于3位！"
ElseIf Trim(LCase(Request.Form ("cdnname")))="self" or Trim(LCase(Request.Form ("cdnname")))="adm" Or Trim(LCase(Request.Form ("cdnname")))="administrator" Or Trim(LCase(Request.Form ("cdnname")))="freehost" Or Trim(LCase(Request.Form ("cdnname")))="proxy" Then
	ef=True
	ec="您输入的cdn户名为保留用户名，请换一个cdn名"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("cdnname")) Then
	ef=True
	ec="cdn名中有非法字符！"
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_cdnProductlist where id='"&Request("cdntype")&"'"
			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
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_cdnProductlist_AGN where id='"&dshost ("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
if not agnserverid.Eof then

isAgncdnSer=false

end if
end if
end If

if not ef then
If Request.Form ("year")<>999 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_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
	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_cdn where ftpname='"&trim(Request.Form ("cdnname"))&"'"
	dsph.Open Sql,conn,1,1
if not dsph.Eof then
	ef=True
	ec="您输入的cdn名已存在，请另外输入一个！"
end if
dsph.close
end If




if not ef then

dim starttime,temptime,pdtype,isAgnHostSer
isAgnHostSer=isAgncdnSer
pdtype=dshost("cdntype")
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_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)
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
Userpaymoney=dshost("usermoney")
forpayyear=Request.Form ("year")
set RsUserds=ds
Useragentname=ds("agent1")
forpaytype="cdn产品"
forpayid=dshost("id")
logfor="开通新建(AG)"
pubisagnSer=isAgncdnSer
AgnRunasUser=false
DoPayMoney
end if

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

cdnname=lcase(trim(Request.Form ("cdnname")))
cdnpassword=trim(Request.Form ("cdnpassword"))
'dsph("cdnname")=cdnname
'dsph("cdnpassword")=cdnpassword

'dsph("vhdpath")=replace(dsserver("homedir")&"\"&dsph("cdnname")&".vhd","\\","\")

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("allowdomain")=dshost("allowdomain")
dsph("CDNMaxMb")=dshost("CDNMaxMb")

dsph("Bindserverid1")=dshost("Bindserverid1")
dsph("Bindserverid2")=dshost("Bindserverid2")

dsph("Ftpname")=LCase(Trim(Request.Form("cdnname")))
dsph("Ftppassword")=Request.Form("cdnpassword")

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

dsph.update
'dsph.close

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

FreeHost_oplog session("agentusername"),"信息","代理区，代理开通CDN产品:("&CDNname&") "


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

If Application("smsCDNopen")=True And (ds("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=ds("username")
mobi=Trim(ds("mobi"))
smsContent=Application("smsCDNopencon")
'恭喜！您的邮箱产品已开通了！用户名 ：#用户名#产品类型 ：#产品类型#到期时间是 ：#到期时间#您的帐户余款是 ：#金额# 元
smsContent=Replace(smsContent,"#用户名#",ds("username"))
smsContent=Replace(smsContent,"#产品类型#",dsph("CDNtype"))
smsContent=Replace(smsContent,"#到期时间#",formatdatetime(dsph("endtime"),1))
smsContent=Replace(smsContent,"#金额#",newuser_money)
ret=SendSms(mobi,smsContent,0,Now,"")
End if

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


'dim Subject,body
'cdnopen
'ret=Send2Mail(conn,ds("username"),Subject,body)
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>　开通cdn
<%=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">新cdn添加成功，以下是相关的资料：</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">　　　 cdn名是：</font></td>
    <td colspan="3"><%=cdnname%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000"> 　　　 cdn密码是：</font></td>
    <td colspan="3"><%=cdnpassword%></td>
  </tr>
  <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%>
