<!--#include file="../Start.asp"-->
<!--#include file="../Include/PowerEasy.MD5.asp"-->
<%
'**************************************************************
' Software name: PowerEasy SiteWeaver
' Web: http://www.powereasy.net
' Copyright (C) 2005－2009 佛山市动易网络科技有限公司 版权所有
'**************************************************************

'强制浏览器重新访问服务器下载页面，而不是从缓存读取页面
'主要是使随机出现的图片数字随机
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"

If Action = "Login" Then
    Call ChkLogin
ElseIf Action = "Logout" Then
    Call Logout
Else
    Call main
End If
If FoundErr = True Then
    Call WriteErrMsg
End If
Call CloseConn

Sub main()
    Response.Write "<html>" & vbCrLf
    Response.Write "<head>" & vbCrLf
    Response.Write "<title>管理员登录</title>" & vbCrLf
    Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbCrLf
	Response.Write "<meta http-equiv=""x-ua-compatible"" content=""ie=7"" />" & vbCrLf
    Response.Write "<link href=""Admin_Login.css"" rel=""stylesheet"" type=""text/css"" />" & vbCrLf
	Response.Write "<script language='JavaScript' src='../images/softkeyboard.js'></script>" & vbCrLf
    Response.Write "<script language=javascript>" & vbCrLf
    Response.Write "<!--" & vbCrLf
    Response.Write "var closestr=0;" & vbCrLf
    Response.Write "function SetFocus() {" & vbCrLf
    Response.Write "if(document.Login.UserName.value == '')" & vbCrLf
    Response.Write "  document.Login.UserName.focus();" & vbCrLf
    Response.Write "else" & vbCrLf
    Response.Write "  document.Login.UserName.select();" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "function CheckForm() {" & vbCrLf
    Response.Write "  if(document.Login.UserName.value == '') {" & vbCrLf
    Response.Write "    alert('请输入用户名！');" & vbCrLf
    Response.Write "    document.Login.UserName.focus();" & vbCrLf
    Response.Write "    return false;" & vbCrLf
    Response.Write "  }" & vbCrLf
    Response.Write "  if(document.Login.password.value == '') {" & vbCrLf
    Response.Write "    alert('请输入密码！');" & vbCrLf
    Response.Write "    document.Login.password.focus();" & vbCrLf
    Response.Write "    return false;" & vbCrLf
    Response.Write "  }" & vbCrLf
    Response.Write "  if (document.Login.CheckCode.value == '') {" & vbCrLf
    Response.Write "    alert ('请输入您的验证码！');" & vbCrLf
    Response.Write "    document.Login.CheckCode.focus();" & vbCrLf
    Response.Write "    return false;" & vbCrLf
    Response.Write "  }" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "function CheckBrowser() {" & vbCrLf
    Response.Write "  var app=navigator.appName;" & vbCrLf
    Response.Write "  var verStr=navigator.appVersion;" & vbCrLf
    Response.Write "  if(app.indexOf('Netscape') != -1) {" & vbCrLf
    Response.Write "    alert('赛奇友情提示：\n    你使用的是Netscape、Firefox或者其他非IE浏览器，可能会导致无法使用后台的部分功能。建议您使用 IE6.0 或以上版本。');" & vbCrLf
    Response.Write "  } else if(app.indexOf('Microsoft') != -1) {" & vbCrLf
    Response.Write "    if (verStr.indexOf('MSIE 3.0')!=-1 || verStr.indexOf('MSIE 4.0') != -1 || verStr.indexOf('MSIE 5.0') != -1 || verStr.indexOf('MSIE 5.1') != -1)" & vbCrLf
    Response.Write "      alert('赛奇友情提示：\n    您的浏览器版本太低，可能会导致无法使用后台的部分功能。建议您使用 IE6.0 或以上版本。');" & vbCrLf
    Response.Write "  }" & vbCrLf
    Response.Write "}" & vbCrLf
    Response.Write "function refreshimg(){document.all.checkcode.src='../Inc/CheckCode.asp?'+Math.random();}" & vbCrLf
    Response.Write "//-->" & vbCrLf
    Response.Write "</script>" & vbCrLf
    Response.Write "</head>" & vbCrLf
    Response.Write "<body>" & vbCrLf
    Response.Write "<dl class=""login_dl"">" & vbCrLf
    Response.Write "<dd>" & vbCrLf
	Response.Write "<form name=""Login"" action=""Admin_Login.asp"" method=""post"" target=""_parent"" onSubmit=""return CheckForm();"">" & vbCrLf
    Response.Write "<ul>" & vbCrLf
    Response.Write "<li><span>用户名：</span><input name=""UserName"" type=""text"" /></li>" & vbCrLf
    Response.Write "<li><span>密　码：</span><input name=""password""  type=""password"" maxlength=""20"" type=""text"" /></li>" & vbCrLf
    Response.Write "<li class=""yzm""><span>验证码：</span><input name=""CheckCode"" size=""6"" maxlength=""6"" /><a href=""javascript:refreshimg()"" title=""看不清楚，换个图片""><img id=""checkcode"" src=""../Inc/CheckCode.asp""  /></a></li>" & vbCrLf
    Response.Write "</ul>" & vbCrLf
    Response.Write "</dd>" & vbCrLf
    Response.Write "<dt><input name=""submit"" type=""image"" src=""images/btn_form.gif"" value=""点击登陆""><input type=""hidden"" name=""Action"" value=""Login"" /></dt>" & vbCrLf
	Response.Write "</form>" & vbCrLf
    Response.Write "</dl>" & vbCrLf
    Response.Write "</body>" & vbCrLf
    Response.Write "</html>" & vbCrLf
End Sub

Sub ChkLogin()
    Dim sql, rs
    Dim UserName, Password, CheckCode, RndPassword, AdminLoginCode
    UserName = ReplaceBadChar(Trim(Request("UserName")))
    Password = ReplaceBadChar(Trim(Request("Password")))
    CheckCode = LCase(ReplaceBadChar(Trim(Request("CheckCode"))))
    AdminLoginCode = Trim(Request("AdminLoginCode"))

    If CSng(ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion) < 5.6 Then
        FoundErr = True
        ErrMsg = ErrMsg & "<li>服务器脚本解释引擎（VBScript）版本过低，请联系您的空间商或服务器管理员更新。</li>"
        ErrMsg = ErrMsg & "<li><a href='http://www.microsoft.com/downloads/release.asp?ReleaseID=33136' target='_blank'><font color='green'>脚本解释引擎下载地址</font></a></li>"
    End If

    If UserName = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>用户名不能为空！</li>"
    End If
    If Password = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>密码不能为空！</li>"
    End If
    If CheckCode = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>验证码不能为空！</li>"
    End If
    If Trim(Session("CheckCode")) = "" Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>你在管理登录停留的时间过长，导致验证码失效。请重新返回登录页面进行登录。</li>"
    End If
    If CheckCode <> Session("CheckCode") Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>您输入的验证码和系统产生的不一致，请重新输入。</li>"
    End If
    If EnableSiteManageCode = True And AdminLoginCode <> SiteManageCode Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>您输入的后台管理认证码不对，请重新输入。</li>"
    End If
    If FoundErr = True Then
        Exit Sub
    End If
    
    ComeUrl = Trim(Request.ServerVariables("HTTP_REFERER"))

    Password = MD5(Password, 16)
    Set rs = Server.CreateObject("adodb.recordset")
    sql = "select * from SQ_Admin where Password='" & Password & "' and AdminName='" & UserName & "'"
    rs.Open sql, Conn, 1, 3
    If rs.bof And rs.EOF Then
        FoundErr = True
        ErrMsg = ErrMsg & "<br><li>用户名或密码错误！！！</li>"
    Else
        If Password <> rs("Password") Then
            FoundErr = True
            ErrMsg = ErrMsg & "<br><li>用户名或密码错误！！！</li>"
        End If
    End If
    If FoundErr = True Then
        Call InsertLog(1, -1, UserName, UserTrueIP, "登录失败", ComeUrl, "")
        Session("AdminName") = ""
        Session("AdminPassword") = ""
        Session("RndPassword") = ""
        rs.Close
        Set rs = Nothing
        Exit Sub
    End If
    UserName = rs("UserName")
    RndPassword = GetRndPassword(16)
    rs("LastLoginIP") = UserTrueIP
    rs("LastLoginTime") = Now()
    rs("LoginTimes") = rs("LoginTimes") + 1
    rs("RndPassword") = RndPassword
    rs.Update
    Call InsertLog(1, 0, UserName, UserTrueIP, "登录成功", ComeUrl, "")

    InstallDir = GetInstallDir(Trim(Request.ServerVariables("SCRIPT_NAME")), 1)
    Site_Sn = Replace(Replace(LCase(Request.ServerVariables("SERVER_NAME") & InstallDir), "/", ""), ".", "")
    Response.Cookies(Site_Sn)("AdminName") = rs("AdminName")
    Response.Cookies(Site_Sn)("AdminPassword") = rs("Password")
    Response.Cookies(Site_Sn)("RndPassword") = RndPassword
    Response.Cookies(Site_Sn)("AdminLoginCode") = AdminLoginCode
    rs.Close

    sql = "select UserID,UserPassword,LastPassword,LastLoginIP,LastLoginTime,LoginTimes from SQ_User where UserName='" & UserName & "'"
    rs.Open sql, Conn, 1, 3
    If Not (rs.bof And rs.EOF) Then
        rs("LastPassword") = RndPassword
        rs("LastLoginIP") = UserTrueIP
        rs("LastLoginTime") = Now()
        rs("LoginTimes") = rs("LoginTimes") + 1
        rs.Update
        Response.Cookies(Site_Sn)("UserName") = UserName
        Response.Cookies(Site_Sn)("UserPassword") = rs("UserPassword")
        Response.Cookies(Site_Sn)("LastPassword") = RndPassword
        Session("UserID") = rs("UserID")
    End If
    rs.Close
    Set rs = Nothing

    Call CloseConn
    Response.Redirect "Admin_Index.asp"
End Sub

Sub Logout()
    Conn.Execute ("update SQ_Admin set LastLogoutTime=" & SQ_Now & "  where AdminName='" & ReplaceBadChar(Trim(Request.Cookies(Site_Sn)("AdminName"))) & "'")
    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") = ""
    Call CloseConn
    Response.Redirect "../Index.asp"
End Sub

'****************************************************
'过程名：WriteErrMsg
'作  用：显示错误提示信息
'参  数：无
'****************************************************
Sub WriteErrMsg()
    Response.Write "<html><head><title>错误信息</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
    Response.Write "<link href='Admin_Style.css' rel='stylesheet' type='text/css'></head><body>" & vbCrLf
    Response.Write "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbCrLf
    Response.Write "  <tr align='center'><td height='22' class='title'><strong>错误信息</strong></td></tr>" & vbCrLf
    Response.Write "  <tr><td height='100' class='tdbg' valign='top'><b>产生错误的可能原因：</b><br>" & ErrMsg & "</td></tr>" & vbCrLf
    Response.Write "  <tr align='center'><td class='tdbg'><a href='Admin_Login.asp'>&lt;&lt; 返回登录页面</a></td></tr>" & vbCrLf
    Response.Write "</table>" & vbCrLf
    Response.Write "</body></html>" & vbCrLf
End Sub

Sub InsertLog(LogType, ChannelID, UserName, UserIP, LogContent, ScriptName, PostString)
    Dim sqlLog, rsLog
    sqlLog = "select top 1 * from SQ_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") = UserName
    rsLog("UserIP") = UserIP
    rsLog("LogContent") = LogContent
    rsLog("ScriptName") = ScriptName
    rsLog("PostString") = PostString
    rsLog.Update
    rsLog.Close
    Set rsLog = Nothing
End Sub

'**************************************************
'函数名：GetInstallDir
'作  用：如果是当前页面在管理后台或者用户后台,就取他上一级的目录为系统安装路径,如果当前页面在根目录下,就取当前路径
'参  数：ScriptName ----路径名称
'        ParentLevel ---- 1 系统安装路径,0 当前路径
'返回值：返回路径
'**************************************************
Function GetInstallDir(ByVal ScriptName, ParentLevel)
    Dim i, strTemp
    GetInstallDir = "/"
    If ScriptName = "" Or IsNull(ScriptName) Then Exit Function
    If ParentLevel > 1 Then ParentLevel = 1
    If ParentLevel = 0 Then
        strTemp = Left(ScriptName, InStrRev(ScriptName, "/"))
    ElseIf ParentLevel = 1 Then
        i = InStrRev(ScriptName, "/") - 1
        If i < 1 Then i = 1
        strTemp = Left(ScriptName, InStrRev(ScriptName, "/", i))
    End If
    If Right(strTemp, 1) <> "/" Then strTemp = strTemp & "/"
    GetInstallDir = strTemp
End Function
%>
