<!--#include file="conn.asp"-->
<!--#include file="inc/config.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="../include/Lebi_Config.asp"-->
<!--#include file="../include/Lebi_md5.asp"-->
<%
'*****************************************
'* 软件名称 乐彼多语言网店系统(56770 EShop)
'* 软件开发 http://www.56770.com
'* 版权所有 http://www.56770.com
'* 文件名称 Admin_login.asp
'* 最后更新 2012-03-12 by 56770.kingdge
'*****************************************
If Eshop_Lebi_name <> "" Then
		Set rs = conn.execute("select menutype from [Lebi_adminuser] where admin_name='"& Eshop_Lebi_name &"'")
		If Not rs.eof Then 
				Select Case rs(0)
				Case "0" url = "manage.asp"
				Case "1" url = "manage_vertical.asp"
				End Select 
				response.redirect url
		End If 
		rs.close : Set rs = Nothing 
End If
if request("action")="login" then
		admin_name=safereplace(trim(request("admin_name")))
		admin_pass=md5(safereplace(trim(request("admin_pass"))))
		verifycode= safereplace(trim(request("verifycode")))
		admin_ip = safereplace(trim(request("admin_ip")))
		admin_loginip = request.servervariables("remote_addr")
		url = LCase(safereplace(request("url")))
		If InStr(url,"http") > 0 Then url = ""
		if admin_name="" or admin_pass="" then
				Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('帐号名称或密码错误！');history.go(-1);</script>")
				response.end
		end If
		If admin_ip="0.0.0.0" And request.cookies(cookiesname&"_logincheck")("error") = "1" Then
				if verifycode <> cstr(Session("verifycode"))then
						Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('验证码错误！');location.href='admin_login.asp';</script>")
						response.end
				end If
		End If
		response.cookies(cookiesname&"_logincheck")("admin_name") = admin_name
		rem <-{检测是否已执行安装向导 2009-9-29 by 56770.kingdge
		AdminNum = conn.execute("select count(id) from [Lebi_adminuser]")(0)
		AdminNum = checknum(AdminNum,0)
		If AdminNum = 0 Then
				Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('当前尚未有创建网站管理员，请先执行乐彼网店系统安装向导！');document.location.href='../Install/Install.asp';</script>")
				response.End
		End If
		rem }->
		set rs=server.createobject("adodb.recordset")
		sql="select * from [Lebi_adminuser] where admin_name='"&admin_name&"' and admin_pass='"&admin_pass&"'"
		rs.open sql, conn, 1, 3
		if rs.eof Then
				response.cookies(cookiesname&"_logincheck")("error") = "1"
				Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('帐号名称或密码错误！');location.href='admin_login.asp';</script>")
				response.End
		elseIf Rs("a_state") = 1 Then
				Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('您的帐号被锁定！');history.go(-1);</script>")
				response.end
		elseIf InStr(Rs("AcceptIP"),".")>0 and ChkLoginIP(Rs("AcceptIP"),admin_ip)=False Then
				Write_Lebi_Eshop("<script LANGUAGE='javascript'>alert('您的IP不允许登陆！');history.go(-1);</script>")
				response.end
		Else
				menutype = rs("menutype")
				rs("LastLogin") = Now()
				rs("LastLoginIP") = admin_loginip
				rs("logins") = rs("logins") + 1
				rs("RndPass") = md5(admin_pass)
				rs.update
				response.cookies(cookiesname&"_logincheck")("error") = "0"
				response.cookies(cookiesname)("admin_name") = rs("admin_name")
				response.cookies(cookiesname)("admin_pass") = rs("RndPass")
				response.cookies(cookiesname)("flag") = Rs("flag")
				response.cookies(cookiesname)("pflag") = Rs("pflag")
				response.cookies(cookiesname)("loginip") = admin_loginip
				response.cookies(cookiesname).Expires = Date() + 1
				Session(cookiesname&"_admin"&"admin_name") = rs("admin_name")
				Session(cookiesname&"_admin"&"admin_pass") = rs("RndPass")
				Session(cookiesname&"_admin"&"flag") = Rs("flag")
				Session(cookiesname&"_admin"&"pflag") = Rs("pflag")
				Session(cookiesname&"_admin"&"loginip") = admin_loginip
'			    Response.Cookies(cookiesname).path = Eshop_url
				conn.execute("insert into [Lebi_admin_log](l_name,l_logintime,l_loginip)values('"& rs("admin_name") &"',"& sqlnowstring &",'"& admin_loginip &"')")
		End If
		rs.close
		set rs=Nothing
		response.cookies(cookiesname&"_logincheck").Expires = Date() + 365
		If url = "" Then 
				Select Case menutype
				Case "0" url = "manage.asp"
				Case "1" url = "manage_vertical.asp"
				End Select 
				response.redirect url
		Else
				If InStr(url,"union/") > 0 Then url = Eshop_url & url
				response.redirect url	
		End If 
end If
If weblogin="0" Then
		If Trim(ArrData(0)) <> "" Then logo = "<img src=""../"& ArrData(0) &""" />"
		Temp = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"" ""http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"">"&_
				"<HTML xmlns=""http://www.w3.org/1999/xhtml"">"&_
				"<HEAD>"&_
				"<TITLE>"& ArrData(2) &" 后台管理</TITLE>"&_
				"<META content=""IE=EmULateIE7"" http-equiv=""X-UA-Compatible"">"&_
				"<META content=""text/html; charset=UTF-8"" http-equiv=""content-type"">"&_
				"<LINK rel=icon type=""image/x-icon"" href=""http://www.56770.com/favicon.ico"" media=""screen"">"&_
				"<LINK rel=""shortcut icon"" type=""image/x-icon"" href=""http://www.56770.com/favicon.ico"" media=""screen"">"&_
				"<META name=""author"" content=""56770 Eshop"">"&_
				"<LINK rel=""stylesheet"" type=""text/css"" href="""& Eshop_url & AdminPath &"/images/login.css"" media=""screen"">"&_
				"<script type=""text/javascript"">function get_Code() {var CodeFile = ""../"& codepath&""";if(document.getElementById(""verifycodeimg""))document.getElementById(""verifycodeimg"").innerHTML = '<img src=""'+CodeFile+'?t='+Math.random()+'"" alt=""点击刷新验证码"" style=""cursor:pointer;height:15px;border:0;vertical-align:middle;"" onclick=""this.src=\''+CodeFile+'?t=\'+Math.random()"" />'}</script>"&_
				"</HEAD>"&_
				"<BODY>"&_
				"<DIV class=""main"">"&_
				"<FORM method=""POST"" action=""?action=login"">"&_
				"<DIV class=""logo"">"& logo &"</DIV>"&_
				"<DIV class=""login-form"">"&_
				"<UL>"&_
				"<LI><SPAN>用户名</SPAN><input type=""text"" name=""admin_name"" maxlength=""25"" class=""input-name"" value="""& request.cookies(cookiesname&"_logincheck")("admin_name") &""" /></li>"&_
				"<LI><SPAN>密&nbsp;&nbsp;码</SPAN><input type=""password"" name=""admin_pass"" maxlength=""25"" class=""input-name"" /></li>"
		If request.cookies(cookiesname&"_logincheck")("error") = "1" Then 
				Temp = Temp &"<LI><SPAN>验证码</SPAN><input type=""text"" name=""verifycode"" maxlength=""10"" class=""input-code"" onfocus=""get_Code();return true;"" />&nbsp;<em id=""verifycodeimg""></em></li>"
		End If 
		Temp = Temp &"</UL>"&_
				"<DIV class=""submit""><input type=""hidden"" name=""admin_ip"" value=""0.0.0.0"" /><input type=""hidden"" name=""url"" value="""& safereplace(request.querystring("url")) &""" /><input type=""image"" src=""images/login/submit.jpg"" name=""submit"" value=""登陆"" /></DIV>"
		If request.cookies(cookiesname&"_logincheck")("error") <> "1" Then 
				Temp = Temp &"<UL><LI></li></UL>"
		End If 
		Temp = Temp &"</DIV>"&_
				"</FORM>"&_
				"<DIV class=""both""></DIV>"&_
				"<DIV class=""copy""><p>"& ArrData(1) &"</p></DIV>"&_
				"<DIV class=""both""></DIV></DIV>"&_
				"</BODY>"&_
				"</HTML>"
		Write_Lebi_Eshop(Temp)
		Get_Usersurl()
End If
Function ChkLoginIP(AcceptIP,ChkIp)
		Dim i,LoginIP,TempIP
		ChkLoginIP = False
		If Instr("|"&AcceptIP&"|","|"&ChkIp&"|") Then ChkLoginIP = True : Exit Function
		LoginIP = Split(ChkIp,".")
		TempIP = LoginIP(0)&"."&LoginIP(1)&"."&LoginIP(2)&".*"
		If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
		TempIP = LoginIP(0)&"."&LoginIP(1)&".*.*"
		If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
		TempIP = LoginIP(0)&".*.*.*"
		If Instr("|"&AcceptIP&"|","|"&TempIP&"|") Then ChkLoginIP = True : Exit Function
End Function
Sub Write_Lebi_Eshop(value)
		Response.Write(value)
End Sub
%>