<%
'乘风多用户计数器
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，没有放在程序里，请自己上网站上查看
%>
<%
If Action="userloginsave" Then
Response.Charset= "gbk"

UserName=ChkStr(Request("UserName"),1)
Pwd=ChkStr(Request("Pwd"),1)
Cookies_Time=ChkStr(Request("Cookies_Time"),2)
CheckCode=ChkStr(Request("CheckCode"),1)

If UserName="" Then
 Response.Write "请输入用户名称!"
 Response.End
End If
 
If Pwd="" Then
 Response.Write "请输入用户密码!"
 Response.End
End If

If Cookies_Time="" Then
 Response.Write "请选择保留Cookies时间!"
 Response.End
End If

If CheckCode="" Then
 Response.Write "请输入验证码!"
 Response.End
End If

If LCase(Session("ValidCode"))<>LCase(CheckCode) Then
 Response.Write "验证码输入错误!"
 Response.End
End If

If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Then
 Ip = ChkStr(Request.ServerVariables("REMOTE_ADDR"),1)
Else
 Ip = ChkStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1)
 If InStr(Ip, ",") > 0 Then Ip = ChkStr(Left(Ip, InStr(Ip, ",") - 1),1)
End If

CFCountUserCookie=Md5(UserName&Pwd&SysCode,2)


Set Rs=Server.CreateObject("Adodb.RecordSet")
Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
Rs.Open Sql,Conn,3,2

IF Rs.eof and Rs.bof Then
 Response.Write "用户不存在!"
 Response.End
End If

IF Rs("Pwd")<>Md5(Pwd&Rs("Salt"),2) Then
 Response.Write "用户密码错误!"
 Response.End
End If

Rs("LoginIp")=Ip
Rs("LoginTotal")=Rs("LoginTotal")+1
Rs("LastLoginTime")=Now()
Rs("UserCode")=CFCountUserCookie
Rs.Update
Rs.Close

Session("CFCountUser")=UserName

If Cookies_Time>0 Then
 Response.Cookies("CFCountUserCookie")=CFCountUserCookie
 Response.Cookies("CFCountUserCookie").expires=Dateadd("n",Cookies_Time,Now())
End If

Response.Cookies("CFCountCraCookie")=1
Response.Cookies("CFCountCraCookie").expires=Dateadd("d",3650,Now())

Response.Write "登录成功!"
Response.End
End If


IF Action="adminloginsave" Then
Response.Charset= "gbk"

Admin=ChkStr(Request("Admin"),1)
Pwd=ChkStr(Request("Pwd"),1)
Cookies_Time=ChkStr(Request("Cookies_Time"),2)
CheckCode=ChkStr(Request("CheckCode"),1)

If Admin="" Then
 Response.Write "请输入管理员名称!"
 Response.End
End If
 
If Pwd="" Then
 Response.Write "请输入管理员密码!"
 Response.End
End If

If Cookies_Time="" Then
 Response.Write "请选择保留Cookies时间!"
 Response.End
End If

If CheckCode="" Then
 Response.Write "请输入验证码!"
 Response.End
End If

If LCase(Session("ValidCode"))<>LCase(CheckCode) Then
 Response.Write "验证码输入错误!"
 Response.End
End If


If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Then
 Ip = ChkStr(Request.ServerVariables("REMOTE_ADDR"),1)
Else
 Ip = ChkStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1)
 If InStr(Ip, ",") > 0 Then Ip = ChkStr(Left(Ip, InStr(Ip, ",") - 1),1)
End If

CFCountAdminCookie=Md5(Admin&Pwd&SysCode,2)

Set Rs = Server.CreateObject("ADODB.Recordset")
Sql="Select * From CFCount_Admin where Admin='"&Admin&"'"
rs.open sql,conn,3,2

IF Rs.eof and Rs.bof Then
 Response.Write "管理员名称不存在!"
 Response.End
End If

IF Rs("Pwd")<>Md5(Pwd&Rs("Salt"),2) Then
 Response.Write "管理员密码错误!"
 Response.End
End If

Rs("LoingIp")=Ip
Rs("LoginTotal")=Rs("LoginTotal")+1
Rs("LastLoginTime")=Now()
Rs("AdminCode")=CFCountAdminCookie
Rs.Update
Rs.Close

Session("CFCountAdmin")="ok"

If Cookies_Time>0 Then
 Response.Cookies("CFCountAdminCookie")=CFCountAdminCookie
 Response.Cookies("CFCountAdminCookie").expires=Dateadd("n",Cookies_Time,Now())
End If

Response.Cookies("CFCountCraCookie")=1
Response.Cookies("CFCountCraCookie").expires=Dateadd("d",3650,Now())

Response.Write "登录成功!"
Response.End
End If


If Action="usernamechecksave" Then
 Response.Charset= "gbk"

 UserName=ChkStr(Request("UserName"),1)
 If UserName="" Then
  Response.Write "<br>请输入要检测的用户名!"
  Response.End
 End if

 Set Rs= Server.CreateObject("ADODB.Recordset")
 Sql="Select Count(*) From CFCount_User Where UserName='"&UserName&"'"
 Rs.Open Sql,Conn,1,1
 If Rs(0)=0 Then
  Response.Write "<br>恭喜，此用户名还没有被注册!"
 Else
  Response.Write "<br><font color='#ff0000'>对不起，此用户名已经被别人注册了!</font>"
 End if  

 Response.End
End If


If Action="checkcodechecksave" Then
 Response.Charset= "gbk"

 CheckCode=ChkStr(Request("CheckCode"),1)

 If CheckCode="" Then
  Response.Write "<br>错误,请输入验证码!"
  Response.End
 End If

 If LCase(Session("ValidCode"))<>LCase(CheckCode) Then
  Response.Write "验证码输入错误!"
  Response.End
 End If

 Response.Write "输入验证码正确!"
 Response.End
End if


If Action="userregsave" Then

 If RsSet("RegState")=0 Then Call AlertBack("此计数器系统已经暂停新用户注册!",1)

 UserName=GoBack(ChkStr(Trim(Request("UserName")),1),"请填入注册用户名!")
 Call CheckInput_Letter(UserName)
 Pwd=GoBack(ChkStr(Request("Pwd"),1),"请填入密码!")
 Pwd2=GoBack(ChkStr(Request("Pwd2"),1),"请再次填入密码!")

 PasswordAsk=ChkStr(Request("PasswordAsk"),1)
 PasswordAnswer=ChkStr(Request("PasswordAnswer"),1)
 
 Email=GoBack(ChkStr(Request("Email"),1),"请输入E-mail!")
 
 QQ=ChkStr(Request("QQ"),1)
 PageName=GoBack(ChkStr(Request("PageName"),1),"请填入主页名称!")
 PageUrl=GoBack(ChkStr(Request("PageUrl"),1),"请填入主页网址!")
 
 QuickStyle=CInt(ChkStr(Request("QuickStyle"),2))
 TjOpen=ChkStr(Request("TjOpen"),2)
 ShowTotal=CLng(ChkStr(Request("ShowTotal"),2))
 
 If TjOpen="" Then TjOpen=0
 
 If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Then
  Ip = ChkStr(Request.ServerVariables("REMOTE_ADDR"),1)
 Else
  Ip = ChkStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1)
  If InStr(Ip, ",") > 0 Then Ip = ChkStr(Left(Ip, InStr(Ip, ",") - 1),1)
 End If

 If RsSet("RegCheckCodeOpen") = -1 Then
  CheckCode=Trim(Request("CheckCode")) 
  If LCase(Session("ValidCode"))<>LCase(CheckCode) Then Call AlertUrl("四位数字的验证码输入错误!","?")
 End If
 
 If Pwd<>Pwd2 Then Call AlertBack("填入的密码不一致，请重新输入一遍!",1)

 Salt=Md5(Pwd&SysCode,2)
 
 Set Rs=Server.CreateObject("Adodb.RecordSet")
 Sql="Select Count(1) From CFCount_User Where LoginIp='" & Ip & "' And Datediff('n',AddTime,now())<1440"
 Rs.Open Sql,Conn,1,1
 If Rs(0)>RsSet("SameIpRegTotal") Then Call AlertBack("同一IP一天内注册数量过多!",1)
 
 Set Rs=Server.CreateObject("Adodb.RecordSet")
 Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
 Rs.Open Sql,Conn,3,2
 If Not Rs.Eof Then
  Call AlertBack("此用户名已经被别人注册,请换名!",1)
 Else
 Rs.AddNew
 Rs("UserName")=UserName
 Rs("Pwd")=Md5(Pwd&Salt,2)
 Rs("Pwd_View")=Md5(Pwd&Salt,2)
 If PwdAsk<>"" Then Rs("PwdAsk")=PwdAsk
 If PwdAnswer<>"" Then Rs("PwdAnswer")=Md5(PwdAnswer&Salt,2)
 Rs("Salt")=Salt
 Rs("Email")=Email
 Rs("QQ")=QQ
 Rs("PageName")=PageName
 Rs("PageUrl")=PageUrl
 Rs("ShowTotal")=ShowTotal
 Rs("TjOpen")=TjOpen
 Rs("UserCode")=Md5(UserName&Pwd&SysCode,2)
 Rs.Update
 Rs.Close
 End If

 If QuickStyle=1 Or QuickStyle=4 Then
  CounterShow=-1
  ShowType=1
  CounterHiddenPic=2
  CounterSite=3
 End if

 If QuickStyle=2 Or QuickStyle=5 Then
  CounterShow=0
  ShowType=1
  CounterHiddenPic=2
  CounterSite=3
 End if
 
 If QuickStyle=3 Or QuickStyle=6 Then
  CounterShow=0
  ShowType=2
  CounterHiddenPic=1
  CounterSite=3
 End if
 
 If QuickStyle=7 Then
  CounterShow=0
  ShowType=2
  CounterHiddenPic=0
  CounterSite=3
 End if
 
 If QuickStyle=4 Or QuickStyle=5 Or QuickStyle=6 Then
  TjOpen=-1
  TjOpen_2=-1
 Else
  TjOpen_2=0
 End If
 
  CFCountUserCookie=Md5(UserName&Pwd&SysCode,2)

  Set Rs=Server.CreateObject("Adodb.RecordSet")
  Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
  Rs.Open Sql,Conn,3,2
  Rs("CounterShow")=CounterShow
  Rs("ShowType")=ShowType
  Rs("CounterHiddenPic")=CounterHiddenPic
  Rs("CounterSite")=CounterSite
  Rs("OnlineShow")=TjOpen_2
  Rs("TodayShow")=TjOpen_2
  Rs("TodayIpShow")=TjOpen_2
  Rs("IpShow")=TjOpen_2
  Rs("VisitShow")=TjOpen_2
  Rs("TjOpen")=TjOpen
  Rs("SurveyOpen")=TjOpen
  Rs("TodayLyOpen")=TjOpen
  Rs("OnlineOpen")=TjOpen
  Rs("TodayHourOpen")=TjOpen
  Rs("EveryDayOpen")=TjOpen
  Rs("UserCode")=CFCountUserCookie
  Rs.Update


 Response.Cookies("CFCountUserCookie")=CFCountUserCookie
 Response.Cookies("CFCountUserCookie").expires=Dateadd("n",60,Now())

 Response.Cookies("CFCountCraCookie")=1
 Response.Cookies("CFCountCraCookie").expires=Dateadd("d",3650,Now())

 Session("CFCountUser")=UserName

Call AlertUrl("注册成功,转到计数器代码获取页!","User.asp?Action=webcodeget")

End If




If Action="answermodifypwd" Then
UserName=ChkStr(request("UserName"),1)
PwdAnswer=ChkStr(request("PwdAnswer"),1)


Set Rs= Server.CreateObject("ADODB.Recordset")
Sql="select * from CFCount_User where UserName='"&UserName&"'"
Rs.Open Sql,Conn,1,1
If Not Rs.Eof Then
 If Rs("PwdAnswer")<>Md5(PwdAnswer&Rs("Salt"),2) Then
  Call AlertUrl("回答答案有误！","?")
 End If
Else
 Call AlertUrl("用户名不存在！",HttpPath(5))
End If

Response.Redirect "?Action=pwdmodify&UserCode="&Rs("UserCode")

End If

If Action="pwdmodifysave" Then
Pwd=GoBack(ChkStr(Request("Pwd"),1),"请输入密码!")
Pwd2=GoBack(ChkStr(Request("Pwd2"),1),"请输入重复密码!")

UserName=GoBack(ChkStr(Request("UserName"),1),"用户名不能为空")
MakeTime=GoBack(ChkStr(Request("MakeTime"),2),"生成时间不能为空")
CheckCode=GoBack(ChkStr(Request("CheckCode"),1),"验证码不能为空")

If Pwd<>Pwd2 Then Call AlertBack("两次输入的密码不一致！",1)

If Abs(DateDiff("s", "1970-1-1", Now) - MakeTime) > 15 * 60 Then Call AlertBack("链接只在15分钟内有效,已经过了时效!", 1)

Set Rs=Server.CreateObject("Adodb.RecordSet")
Sql="Select * From CFCount_User Where UserName='" &UserName& "'"
Rs.Open Sql,Conn,3,2

If Rs.Eof And Rs.Bof Then
 Call AlertBack("用户名不存在!",1)
Else
 If Md5(UserName & MakeTime & Rs("Pwd"), 2) <> CheckCode Then Call AlertBack("验证码错误或链接已失效!", 1)
 If Md5(Pwd & Rs("Salt"), 2) = Rs("Pwd") Then Call AlertBack("新密码不能和原来的设置相同!", 1)
 
 Rs("Pwd")=Md5(Pwd & Rs("Salt"), 2)
 Rs.Update
End If

Call AlertUrl("修改成功，请牢记你的新密码",HttpPath(5))
End If



If Action="gbookaddsave" Then
 UserName=ChkStr(Request("UserName"),1)
 Content=ChkStr(Request("Content"),1)
 Contact=ChkStr(Request("Contact"),1)
 Ly=Left(ChkStr(URLDecode(Request("Ly")),1),255)
 CurrWeb=Left(ChkStr(URLDecode(Request("CurrWeb")),1),255)

  
 If Content="" Then Call AlertClose("请输入留言内容")
 If Contact="" Then Call AlertClose("请输入联系方式")
 
 If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" Then
  Ip = ChkStr(Request.ServerVariables("REMOTE_ADDR"),1)
 Else
  Ip = ChkStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1)
  If InStr(Ip, ",") > 0 Then Ip = ChkStr(Left(Ip, InStr(Ip, ",") - 1),1)
 End If
 
Set Rs=Server.CreateObject("Adodb.RecordSet")
Sql="Select Count(1) From CFCount_Gbook Where Ip='" & Ip & "' And Datediff('n',AddTime,now())<1440"
Rs.Open Sql,Conn,1,1
If Rs(0)>10 Then Call AlertBack("同一IP一天内最多留言10条!",1)

Sql="Select * From CFCount_Gbook Where UserName='"&UserName&"' And Content='"&Content&"' And Contact='"&Contact&"' And DateDiff('d',AddTime,Now())=0"
Rs.Open Sql,Conn,3,2
If Not Rs.Eof Then
 Call AlertClose("请不要留相同的留言")
Else
 Rs.AddNew
 Rs("UserName")=UserName
 Rs("Content")=Content
 Rs("Contact")=Contact
 Rs("Ly")=Ly
 Rs("CurrWeb")=CurrWeb
 Rs("Ip")=Ip
 Rs.Update
End If

Call AlertClose("留言成功a")

End If


'查看用户登录
If Action="viewuserlogin" Then
 UserName=GoBack(ChkStr(Request("UserName"),1),"请输入用户名称")
 Pwd_View=GoBack(ChkStr(Request("Pwd_View"),1),"请输入独立查看密码")

 Set Rs=Server.CreateObject("Adodb.RecordSet")
 Sql="Select * From CFCount_User Where UserName='"&UserName&"'"
 Rs.Open Sql,Conn,1,1


 If Rs.Eof And Rs.Bof Then Call AlertBack("没有此注册用户!",1)

 If Rs("Pwd_View")<>Md5(Pwd_View&Rs("Salt"),2) Then Call AlertBack("独立查看密码错误!",1)
 
 Session("CFCountUser_View")=UserName

 Response.Cookies("CFCountCraCookie")=1
 Response.Cookies("CFCountCraCookie").expires=Dateadd("d",3650,Now())

 Response.Redirect "User.asp"
End If
%>