<%@ 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("admau")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
elseIf session("canadmCDNadd")="" 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 not IsNumeric(Request("CDNtype"))  Then
	ef=True
	ec="ID应该是数字！"
'ElseIf Request.Form ("ServerlistID")="" Then
'	ef=True
'	ec="请选择服务器！"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("Ftpname")) or Instr(1, Request.Form ("Ftpname"), "'", 1)>0 or Instr(1, Request.Form ("Ftpname"), "-", 1)>0 or Instr(1, Request.Form ("Ftpname"), " ", 1)>0 or Instr(1, Request.Form ("Ftpname"), "&", 1)>0 or Instr(1, Request.Form ("Ftpname"), ".", 1)>0 or Instr(1, Request.Form ("Ftpname"), "_", 1)>0 Then
	ef=True
	ec="CDN用户名中有非法字符！"
ElseIf Trim(LCase(Request ("Ftpname")))="self" or Trim(LCase(Request ("Ftpname")))="adm" or Trim(LCase(Request ("Ftpname")))="admin" or Trim(LCase(Request ("Ftpname")))="sefreehost" Or Trim(LCase(Request ("Ftpname")))="administrator" Or Trim(LCase(Request ("Ftpname")))="freehost" Or Trim(LCase(Request ("Ftpname")))="proxy" Or Trim(LCase(Request ("Ftpname")))="windows" Or Trim(LCase(Request ("Ftpname")))="system32" Then
	ef=True
	ec="您输入的CDN用户名为保留用户名，请换一个ftp用户名"
ElseIf RegExpTest("[^A-Za-z0-9]",Request.Form ("Ftppassword"))  or Request.Form ("Ftppassword")="123456" or Request.Form ("Ftppassword")="12345"  or len(Request.Form ("Ftppassword"))<4 Then
	ef=True
	ec="CDN密码有非法字符，只能是字母与数字/密码没填/或密码过于简单！"
ElseIf not IsNumeric(Request.Form ("ServerlistID"))  Then
	ef=True
	ec="服务器ID应该是数字！"
ElseIf not IsNumeric(Request.Form ("year"))  Then
	ef=True
	ec="时间应该是数字！"
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 dsCDNpdlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_CDNProductlist where id='"&Request.Form ("CDNtype")&"'"
	if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsCDNpdlist.Open Sql,conn,1,1
if dsCDNpdlist.Eof then
	ef=True
	ec="产品不存在！"
end if
end If

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


if not ef then
If Request.Form ("usermoney")="" Then
cost=dsCDNpdlist("usermoney")
cost=cost*Request.Form ("year")
if Request.Form ("year")=999 then cost=0
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！"
end if
else
cost=Clng(Request.Form ("usermoney"))
if cost>ds("usermoney") then
	ef=True
	ec="很抱歉,用户的余额不足！"
end if
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 ("Ftpname"))&"'"
	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

'开始扣费
olduser_money=ds("usermoney")
moneych=0
ds("usermoney") =ds("usermoney") -cost
moneych=-cost
ds.update

newuser_money=ds("usermoney")


	Set dsph = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Product_CDN"
	dsph.Open Sql,conn,1,3
starttime=Now
'结束时间
y=Request.Form ("year")
if y=1 then temptime=dateadd("yyyy",1,now)
if y=dsCDNpdlist("PAY_2year") then temptime=dateadd("yyyy",2,now)
if y=dsCDNpdlist("PAY_3year") then temptime=dateadd("yyyy",3,now)
if y=dsCDNpdlist("PAY_4year") then temptime=dateadd("yyyy",4,now)
if y=dsCDNpdlist("PAY_5year") then temptime=dateadd("yyyy",5,now)
if y=dsCDNpdlist("PAY_Month") then temptime=dateadd("y",31,now)
if y=dsCDNpdlist("PAY_Season") then temptime=dateadd("y",92,now)
if y=dsCDNpdlist("PAY_halfyear") then temptime=dateadd("y",182,now)
if y=999 then
temptime=dateadd("y",Application("testtime"),now)
end if
if request.Form ("endtime")<>"" then temptime=request.Form ("endtime")
dsph.addnew
dsph("username")=ds("username")
dsph("CDNtype")=dsCDNpdlist("CDNtype")
dsph("starttime")=starttime
dsph("endtime")=temptime
if y=999 then
dsph("istest")="y"
dim isfortest
isfortest=true
else
dsph("istest")="n"
end if

temptime=dsph("endtime")

dsph("allowdomain")=dsCDNpdlist("allowdomain")
dsph("CDNMaxMb")=dsCDNpdlist("CDNMaxMb")

dsph("Bindserverid1")=dsCDNpdlist("Bindserverid1")
dsph("Bindserverid2")=dsCDNpdlist("Bindserverid2")
CDNname=LCase(Trim(Request.Form("Ftpname")))
dsph("Ftpname")=LCase(Trim(Request.Form("Ftpname")))
dsph("Ftppassword")=Request.Form("Ftppassword")

if Request.Form("allowdomain")<>"" then dsph("allowdomain")=Request.Form("allowdomain")
if Request.Form("CDNMaxMb")<>"" then dsph("CDNMaxMb")=Request.Form("CDNMaxMb")


dsph("status")="正常"

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_CDN where starttime='"&starttime&"' and username='"&ds("username")&"'"
	dsph.Open Sql,conn,1,1
pdtype=dsph("CDNtype")
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"),"管理员新建cdn","管理员新建cdn","cdn产品",dsph("id"),pingzheng,type1,bank,haveget,havecheck

FreeHost_oplog session("admusername"),"信息","管理区，管理员开通CDN产品:("&CDNname&") "

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)

%>
<!--#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 width="83"><table height="59"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="7" background="img/midtop.gif">&nbsp;</td>
            <td width="60" align="center" valign="middle" background="img/r3.jpg" id="tableTop1" style="Cursor:hand"><a href="admCDN.asp"><font color="#FFFFFF">CDN管理</font></a><a href="systeminfo.asp"></a><a href="logininfo.asp"></a></td>
            <td width="5" background="img/midtop2.gif">&nbsp;</td>
          </tr>
      </table></TD>
      <TD width="83">&nbsp;</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">
<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">CDN添加成功，以下是相关的资料</font></font></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td width="47%" height="30"><font color="#000000"> 　　　 用户的原金额：</font></td>
    <td width="53%" colspan="3"><%=olduser_money%> 元</td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="41"><font color="#000000">　　　 用户的金额变化：</font></td>
    <td colspan="3"><font color=red><%=moneych%> 元</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"><%=temptime%></td>
  </tr>
  <tr bordercolor="#000000" bgcolor="#E4EAF2">
    <td height="37"><font color="#000000">　　　 </font>为CDN绑定域名：</td>
    <td colspan="3"><a href="handCDN1.asp?username=<%=dsph("username")%>">绑定CDN域名</a></td>
  </tr>

  <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%>
