<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostEmail.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunction.asp"-->
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
Function CLen(HzStr)
L = len(HzStr)
For n=1 to L
If Asc(mid( HzStr,n,1))<0 Then HzNum = HzNum + 1
Next
Clen = L + HzNum
End Function
for each item in Request.Form
if instr(Request.Form(item),"'")>0 then response.Redirect "e.asp?e=出错，请不要输入'字符："&Request.Form(item) 
if instr(Request.Form(item),"&")>0 then response.Redirect "e.asp?e=出错，请不要输入&字符："&Request.Form(item) 
if CLen(Request.Form(item))>50 then response.Redirect "e.asp?e=出错，请不要输入超出50个字母或25个汉字："&Request.Form(item)&" 字数为："&CLen(Request.Form(item))
next

If Request.Form ("username")="" or RegExpTest("[^A-Za-z0-9]",Request.Form ("username")) or Instr(1, Request.Form ("username"), "'", 1)>0 or Instr(1, Request.Form ("username"), "-", 1)>0 or Instr(1, Request.Form ("username"), " ", 1)>0 or Instr(1, Request.Form ("username"), "&", 1)>0 or Instr(1, Request.Form ("username"), ".", 1)>0 or Instr(1, Request.Form ("username"), "_", 1)>0 or len(Trim(Request.Form ("username")))<3 Then
	ef=True
	ec="代理名没有写/或代理名中有非法字符/代理名称长度小于3位"
ElseIf Request.Form ("Vcode")<>session("Vcode") or session("Vcode")="" Then
	ef=True
	ec="验证码不正确！"
'ElseIf Lcase(trim(Request.Form ("username")))="freehost" Then
'	ef=True
'	ec="系统保留的用户名不能申请！"
ElseIf RegExpTest("[^\u4e00-\u9fa5]",Request("coun")) Then
	ef=True
	ec="国家中有非法字符！"
ElseIf RegExpTest("[^\u4e00-\u9fa5]",Request("prv")) Then
	ef=True
	ec="省份中有非法字符！"
ElseIf RegExpTest("[^\u4e00-\u9fa5]",Request("city")) Then
	ef=True
	ec="城市中有非法字符！"
ElseIf Request.Form ("password")="" or len(Request.Form ("password"))<6 Then
	ef=True
	ec="密码没填/或密码长度不足6位！"
ElseIf Request.Form ("password")<>Request.Form ("repassword") Then
	ef=True
	ec="重复输入的密码不一致！"
ElseIf len(Request.Form ("postid"))>7 Then
	ef=True
	ec="邮编出错！"
ElseIf len(Request.Form ("truename"))<2 or RegExpTest("[A-Za-z0-9]",Request.Form ("truename")) Then
	ef=True
	ec="请提供准确的姓名！"
ElseIf RegExpTest("[^\u4e00-\u9fa5]",Request("truename")) Then
	ef=True
	ec="姓名中有非法字符！"
ElseIf len(Request.Form ("mobi"))<>11 Or  not IsNumeric(Request("mobi")) Then
	ef=True
	ec="请提供准确的手机号码！"
elseif Request("email")="" or RegExpTest("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$",Request("email"))=false then
	ef=True
	ec="邮箱不正确！"
elseIf checkscript(Request.Form ("qq")) Then
	ef=True
	ec="QQ有非法字符！如<>script"
elseIf checkscript(Request.Form ("postid")) Then
	ef=True
	ec="postid有非法字符！如<>script"
elseIf checkscript(Request.Form ("truename")) Then
	ef=True
	ec="truename有非法字符！如<>script"
elseIf checkscript(Request.Form ("contact")) Then
	ef=True
	ec="contact有非法字符！如<>script"
elseIf checkscript(Request.Form ("tel")) Then
	ef=True
	ec="tel有非法字符！如<>script"
elseIf checkscript(Request.Form ("fax")) Then
	ef=True
	ec="fax有非法字符！如<>script"
elseIf checkscript(Request.Form ("perid")) Then
	ef=True
	ec="perid有非法字符！如<>script"
elseIf checkscript(Request.Form ("prv")) Then
	ef=True
	ec="prv有非法字符！如<>script"
elseIf checkscript(Request.Form ("city")) Then
	ef=True
	ec="city有非法字符！如<>script"
elseIf checkscript(Request.Form ("address")) Then
	ef=True
	ec="address有非法字符！如<>script"
end if

If not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
'agent test
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_Admuser where superuser='"&Request.Form ("username")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsreg.Open Sql,conn,1,3
If not dsreg.Eof Then
		ef=True
		ec="这个用户名已经被别人注册了，请另外换一个用户名吧！"
end if
dsreg.close
'user test
Set dsreg = 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
		dsreg.Open Sql,conn,1,3
If not dsreg.Eof Then
		ef=True
		ec="这个用户名已经被别人注册了，请另外换一个用户名吧！"
end if
dsreg.close
'agent test
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_AGENT where username='"&Request.Form ("username")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsreg.Open Sql,conn,1,3
If not dsreg.Eof Then
		ef=True
		ec="这个用户名已经被别人注册了，请另外换一个用户名吧！"
end if

end if


If not ef then
if Application("emailmustone")=true Then
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_AGENT where email='"&Request.Form ("email")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsreg.Open Sql,conn,1,3
If not dsreg.Eof Then
		ef=True
		ec="这个邮箱已被别人使用了，一个邮箱只能用来注册一个用户名！"
end if
end If
end If

If not ef then
if Application("smsmustone")=true Then
Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_AGENT where mobi='"&Request.Form ("mobi")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsreg.Open Sql,conn,1,3
If not dsreg.Eof Then
		ef=True
		ec="这个手机号码已被别人使用了，一个手机号码只能用来注册一个用户名！"
end if
end If
end If


If not ef then
dsreg.AddNew
dsreg("username")=LCASE(trim(Request.Form ("username")))
dsreg("password")=md5(trim(Request.Form ("password")))
dsreg("email")=Request.Form ("email")
dsreg("truename")=Request.Form ("truename")
dsreg("etruename")=Request.Form ("etruename")
dsreg("coun")=Request.Form ("coun")
dsreg("ecoun")=Request.Form ("ecoun")
dsreg("prv")=Request.Form ("prv")
dsreg("eprv")=Request.Form ("eprv")
dsreg("city")=Request.Form ("city")
dsreg("ecity")=Request.Form ("ecity")
dsreg("address")=Request.Form ("address")
dsreg("eaddress")=Request.Form ("eaddress")
dsreg("postid")=Request.Form ("postid")
dsreg("tel")=Request.Form ("tel")
dsreg("qq")=Request.Form ("qq")
dsreg("perid")=Request.Form ("perid")
dsreg("fax")=Request.Form ("fax")
dsreg("regtime")=NOW
dsreg("lastuse")=NOW
dsreg("regip")=Request.ServerVariables("REMOTE_ADDR")

dsreg("contact")=Request.Form ("contact")
dsreg("mobi")=Request.Form ("mobi")
dsreg("Domain_Agent_md5_6")=md5(LCase(dsreg("username"))&"7i24.com"&dsreg("password"))


if request("kefunow")<>"" then
Set dskefu = Server.CreateObject("ADODB.Recordset")	
	Sql="Select id from FreeHost.FreeHost_KeFu where kefumd5='"&md5(trim(request("kefunow")))&"'"
	dskefu.Open Sql,conn,1,1
if not dskefu.Eof then
dsreg("kefunow")=Request.Form ("kefunow")
end if
dskefu.close
end if

dsreg("usermoney")="0.00"

dsreg("hostphcount")=0
dsreg("emailphcount")=0
dsreg("domainphcount")=0

dsreg("agenttype")="n"
dsreg("haveupdate")="y"'3.0
if session("agentname")="" then
dsreg("agent1")="n"
else
dsreg("agent1")=session("agentname")
end if
dsreg("agent2")="n"
If session("agentusername")<>"" and LCASE(trim(dsreg("agent1")))<>LCASE(trim(session("agentusername"))) Then dsreg("agent1")=session("agentusername") 

if LCASE(trim(dsreg("agent1")))=LCASE(trim(dsreg("username"))) then dsreg("agent1")="n"


dsreg.Update

dim Subject,body
EmailAgentRegister
ret=Send2Mail(conn,dsreg("username"),Subject,body)


dsreg.Update
session("Vcode")=""
'dsreg.Requery
'ID=dsreg("id")
dsreg.Close
set dsreg=Nothing


Set dsreg = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_USER where username='"&Request.Form ("username")&"'"
dsreg.Open Sql,conn,1,3
dsreg.AddNew
dsreg("username")=LCASE(trim(Request.Form ("username")))
dsreg("password")=md5(Request.Form ("password"))
dsreg("email")=Request.Form ("email")
dsreg("truename")=Request.Form ("truename")
dsreg("etruename")=Request.Form ("etruename")
dsreg("coun")=Request.Form ("coun")
dsreg("ecoun")=Request.Form ("ecoun")
dsreg("prv")=Request.Form ("prv")
dsreg("eprv")=Request.Form ("eprv")
dsreg("city")=Request.Form ("city")
dsreg("ecity")=Request.Form ("ecity")
dsreg("address")=Request.Form ("address")
dsreg("eaddress")=Request.Form ("eaddress")
dsreg("postid")=Request.Form ("postid")
dsreg("tel")=Request.Form ("tel")
dsreg("qq")=Request.Form ("qq")
dsreg("perid")=Request.Form ("perid")
dsreg("fax")=Request.Form ("fax")

dsreg("contact")=Request.Form ("contact")
dsreg("mobi")=Request.Form ("mobi")


dsreg("regtime")=NOW
dsreg("lastuse")=NOW
dsreg("regip")=Request.ServerVariables("REMOTE_ADDR")
If Request.ServerVariables("HTTP_FreeHostAPIIP")<>"" Then dsreg("regip")=Request.ServerVariables("HTTP_FreeHostAPIIP")

dsreg("usermoney")="0.00"

dsreg("hostphcount")=0
dsreg("emailphcount")=0
dsreg("domainphcount")=0
dsreg("haveupdate")="y"'3.0

dsreg("agent2")="n"
dsreg("agent1")=dsreg("username")

'If Not Application("mustcheckid")=True Then
dsreg("emailR")=Request.Form ("email")
dsreg("truenameR")=Request.Form ("truename")
dsreg("prvR")=Request.Form ("prv")
dsreg("cityR")=Request.Form ("city")
dsreg("addressR")=Request.Form ("address")
dsreg("postidR")=Request.Form ("postid")
dsreg("telR")=Request.Form ("tel")
dsreg("qqR")=Request.Form ("qq")
dsreg("peridR")=Request.Form ("perid")
dsreg("faxR")=Request.Form ("fax")
dsreg("contactR")=Request.Form ("contact")
dsreg("mobiR")=Request.Form ("mobi")

if request("kefunow")<>"" then
Set dskefu = Server.CreateObject("ADODB.Recordset")	
	Sql="Select id from FreeHost.FreeHost_KeFu where kefumd5='"&md5(trim(request("kefunow")))&"'"
	dskefu.Open Sql,conn,1,1
if not dskefu.Eof then
dsreg("kefunow")=Request.Form ("kefunow")
end if
dskefu.close
end if
'End if


If Application("smsreg")=True And (dsreg("agent1")="n" Or Application("agncangetsms")=True) Then
Dim username
username=dsreg("username")
mobi=Trim(dsreg("mobi"))
smsContent=Application("smsregcon")
'尊敬的 #真名# ，恭喜您成为 #发件人# 的新会员，同时感谢您对 #发件人# 的关注与支持并欢迎您使用 #发件人# 的产品与服务。用户名 ：#用户名#  密码 ：#密码#
smsContent=Replace(smsContent,"#真名#",dsreg("truename"))
smsContent=Replace(smsContent,"#用户名#",dsreg("username"))
smsContent=Replace(smsContent,"#发件人#",session("Mail_fromName"))
smsContent=Replace(smsContent,"#密码#",Request.Form ("password"))
ret=SendSms(mobi,smsContent,0,Now,"")
End if


dsreg.Update


conn.Close
set conn=nothing
end if

If not ef then%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
代理注册
<%=htmlwrite("html6")%>
<br>
<br>
<table width="100%"  border="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td width="9%" height="30" rowspan="2" bgcolor="#FFFFFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="22%" height="179" align="center" bgcolor="#eeeeee"><font color="#CC6600"><img src="../style/img/5.jpg" width="81" height="94"></font></td>
        <td align="center" bgcolor="#eeeeee"><font color="#CC6600">恭喜！注册成功了！<a href="/style/info/contact.asp">请联系管理员审批您的代理资格&gt;&gt;&gt;</a></font></td>
        </tr>
    </table>    </td>
  </tr>
</table>
<%=htmlwrite("html7")%><%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if
function strLen(str)
  dim i,l,t,c
  l=len(str)
  t=l
  for i=1 to l
      c=asc(mid(str,i,1))
      if c<0 then c=c+65536
      if c>255 then 
        t=t+1
      end if
  next
  strLen=t
end function
Function RegExpTest(patrn, strng)
  Dim regEx
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = False
  RegExpTest = regEx.Test(strng)
End Function 
%>
