<%session("pe")="pe"%>
<!--#include file="Conn.asp" -->
<!--#include file="inc/hl_md5.asp" -->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/UpiConfig.asp"-->
<!--#include file="Admin/Admin_ChkCode.asp"-->
<%
Set rsConfig=server.CreateObject("ADODB.Recordset")
	    sqlConfig="select * from PE_config" 
	    rsConfig.open sqlConfig,conn,1,1
	    InstallDir = rsConfig("InstallDir")
		rsConfig.close
		set rsConfig=nothing
Site_Sn = Replace(Replace(LCase(Request.ServerVariables("SERVER_NAME") & InstallDir), "/", ""), ".", "")

Dim HLMd5Info,UpiMd5Info,TrueIP,RndPassword

UpiMd5Info = UCase(Trim(Request("Md5Info")))
Action = Trim(Request("action"))
username = ReplaceBadChar(Trim(Request("name")))
userpassword = ReplaceBadChar(Trim(Request("pass")))
If Len(userpassword) = 32 Then userpassword = Mid(userpassword,9,16)
UpiSaveCookies = Trim(Request("save"))
TrueIP = Trim(Request.ServerVariables("HTTP_X_FORWARDED_FOR"))
If TrueIP = "" Then TrueIP = Request.ServerVariables("REMOTE_ADDR")
RndPassword = GetRndPassword(16)
If Action="LogoutUser" Then Call LogoutUser()
			   
If Not (Action = "" or username = "" or UpiMd5Info = "") And HLAdminIntegration=True Then
	   Md5OLD=0          '兼容PHP整合中文同步设置
 	   HLMd5Info = MD5(username&AdminSecurityKey,32)
	If UpiMd5Info <> UCase(HLMd5Info) Then	
	   Md5OLD=1          '不兼容PHP整合中文同步设置
 	   HLMd5Info = MD5(username&AdminSecurityKey,32)
	   If UpiMd5Info <> UCase(HLMd5Info) Then
	      Response.End()
	   End IF
	End IF	
	
	Select Case Action
		Case "AddUser"
			Call AddUser()			
		Case "LoginUser"
			Call LoginUser()
		Case "LogoutUser"
			Call LogoutUser()
		Case "ModifyInfo"
			Call ModifyUserInfo()		
		Case "DelUser"
			Call DelUser()
	End Select
End If

Sub AddUser()
    sqlReg = "select * from PE_Admin where AdminName='"&username&"'"
            Set rsReg = Server.CreateObject("adodb.recordset")
            rsReg.Open sqlReg,Conn,1,3
			response.Write sqlReg
             If rsReg.eof then           
                    rsReg.addnew
		    rsReg("AdminName") = username
		    rsReg("UserName") = username
		    rsReg("Purview")=1
                    rsReg("Password") = userpassword
                    rsReg("LastLoginIP") = TrueIP
                    rsReg("LastLoginTime") = now()
                    rsReg("LoginTimes") = 0
                    rsReg("RndPassword")= RndPassword
		    rsReg.update
            End if
 rsReg.close
 set rsReg=nothing
End Sub '注册新用户

Sub LoginUser()
Response.Write "hi"
Set rspe=server.CreateObject("ADODB.Recordset")   
    sqlpe="select * from PE_Admin where AdminName='"&username&"' and Password='"&userpassword&"'"
   	    rspe.open sqlpe,conn,1,3
    If not rspe.eof Then
    	rspe("AdminName")=username
	rspe("Password")=userpassword
        rspe("LastLoginIP") = TrueIP
        rspe("LastLoginTime") = Now()
        rspe("LoginTimes") = rspe("LoginTimes") + 1
        rspe("RndPassword") = RndPassword
	rspe.update
	rspe.close
	set rspe=nothing
	ComeUrl = Trim(Request.ServerVariables("HTTP_REFERER"))
	Call InsertLog(1, 0, UserName, TrueIP, "成功登陆", ComeUrl, "")
	Response.Cookies(Site_Sn)("AdminName")=username 
        Response.Cookies(Site_Sn)("AdminPassword") =userpassword
        Response.Cookies(Site_Sn)("RndPassword") = RndPassword
	Response.Cookies(Site_Sn)("AdminLoginCode") = SiteManageCode
    End IF
	
End Sub '登陆用户

Sub LogoutUser()

Set rspe=server.CreateObject("ADODB.Recordset")   
    sqlpe="select * from PE_Admin where AdminName='"& ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("AdminName"))) & "'"
   	    rspe.open sqlpe,conn,1,3
		rspe("LastLogoutTime")= Now()
        rspe.update
		rspe.close
		set rspe=nothing
    Response.Cookies(Site_Sn)("AdminName") = ""
    Response.Cookies(Site_Sn)("AdminPassword") = ""
    Response.Cookies(Site_Sn)("RndPassword") = ""
    Response.Cookies(Site_Sn)("UserName") = ""
    Response.Cookies(Site_Sn)("UserPassword") = ""
    Response.Cookies(Site_Sn)("LastPassword") = ""
    Response.Cookies(Site_Sn)("UnreadMsg") = ""
    Response.Redirect "../Index.asp"
End Sub '注销登陆


Sub ModifyUserInfo()
Dim tempSQL
On Error Resume Next
set rspe=server.CreateObject("ADODB.Recordset")
    tempSQL="select Password from PE_Admin where AdminName='"&username&"'"
	rspe.open tempSQL,conn,1,3
	rspe("Password")=userpassword
	rspe.update
	rspe.close
	set rspe=nothing
End Sub

Sub DelUser()
set rs=server.CreateObject("ADODB.RecordSet")
set rs=conn.execute("delete * from PE_Admin where AdminName ='"&username&"'") 
rs.close
set rs=nothing
conn.close
set conn=nothing

End Sub

'------------------------------------------------------------

Sub InsertLog(LogType, ChannelID, UserName, UserIP, LogContent, ScriptName, PostString)
           Dim sqlLog, rsLog
           sqlLog = "select * from PE_Log"            
           Set rsLog = Server.CreateObject("Adodb.RecordSet")
           rsLog.Open sqlLog, Conn, 1, 3
           rsLog.addnew
           rsLog("LogType") = LogType
           rsLog("ChannelID") = ChannelID
           rsLog("LogTime") = Now()
           rsLog("UserName") = UserId
           rsLog("UserIP") = TrueIP
           rsLog("LogContent") = LogContent
           rsLog("ScriptName") = ScriptName
           rsLog("PostString") = PostString
           rsLog.Update
           rsLog.Close
           Set rsLog = Nothing
       End Sub 
	   
Function GetRndPassword(PasswordLen)
    Dim Ran, i, strPassword
    strPassword = ""
    For i = 1 To PasswordLen
        Randomize
        Ran = CInt(Rnd * 2)
        Randomize
        If Ran = 0 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & UCase(Chr(Ran))
        ElseIf Ran = 1 Then
            Ran = CInt(Rnd * 9)
            strPassword = strPassword & Ran
        ElseIf Ran = 2 Then
            Ran = CInt(Rnd * 25) + 97
            strPassword = strPassword & Chr(Ran)
        End If
    Next
    GetRndPassword = strPassword
End Function

'**************************************************
'函数名：ReplaceBadChar
'作  用：过滤非法的SQL字符
'参  数：strChar-----要过滤的字符
'返回值：过滤后的字符
'**************************************************
Function ReplaceBadChar(strChar)
    If strChar = "" Or IsNull(strChar) Then
        ReplaceBadChar = ""
        Exit Function
    End If
    Dim strBadChar, arrBadChar, tempChar, i
    strBadChar = "',%,^,&,?,(,),<,>,[,],{,},/,\,;,:," & Chr(34) & "," & Chr(0) & ""
    arrBadChar = Split(strBadChar, ",")
    tempChar = strChar
    For i = 0 To UBound(arrBadChar)
        tempChar = Replace(tempChar, arrBadChar(i), "")
    Next
    ReplaceBadChar = tempChar
End Function

Function PE_CLng(ByVal str1)
    If IsNumeric(str1) Then
        PE_CLng = CLng(str1)
    Else
        PE_CLng = 0
    End If
End Function

Function PE_CDbl(ByVal str1)
    If IsNumeric(str1) Then
        PE_CDbl = CDbl(str1)
    Else
        PE_CDbl = 0
    End If
End Function

%>
<%
'==================================================
'恒浪网站整合管理系统V4.05 请保留此版权信息~
'Powered by HoWave.net
'
'邮箱: websky888@126.com		
'ＱＱ: 615939753				
'网站: www.howave.net			www.jsp163.com
'论坛: bbs.howave.net			bbs.jsp163.com
'
'Copyright (C) 2006 HoWave.Net All Rights Reserved.
'==================================================
%>