<!--#include file=conn.asp-->
<!--#include file=config.asp-->
<!--#include file=const.asp-->
<!--#include file=char.asp-->
<!--#include file=inc/Ms_admin.asp-->
<!--#include file=Md5.asp-->
<%
 '=========================================================
' File: admin_loginx.asp
' Version:3.0
' Date: 2005-9-17
' Script Written by xmrxw
'=========================================================
' Copyright (C) 2004,2005 Xmrxw.Com All rights reserved.
' Web: http://www.xmrxw.com,http://www.xmzxw.com
' Email: info@mssky.com,super@mssky.com
' QQ：10689579　Msn：zdlmicr@hotmail.com
'=========================================================
response.buffer=true
stats="管理登录"
call Admin_Login()''后台登录
if founderr=true then
	call Mslove_error()
end if
Sub Admin_Login()
	If (UserGroupID>1 and UserID>0) or Master or UserID>0 Then
		Master = True
	Else
		Master = False
	End If
	If Not Master Then Response.write "您不是系统管理员！"
	If Master And Session("flag")<>"" Then Response.Redirect ""&Adminpath&"index.asp"
	If Request("action")="chklogin" Then
		Chk_Login()
	Else
		Login_Main()
	End If
End Sub

sub Login_Main()
Dim version
	If IsSqlDataBase = 1 Then version="SQL 版" Else version="ACCESS 版"%>
<style type=text/css>
body {
	background:#CAD7F7; font-size: 12px; margin-top:0px;
	SCROLLBAR-FACE-COLOR: #799AE1; SCROLLBAR-HIGHLIGHT-COLOR: #799AE1; 
	SCROLLBAR-SHADOW-COLOR: #799AE1; SCROLLBAR-DARKSHADOW-COLOR: #799AE1; 
	SCROLLBAR-3DLIGHT-COLOR: #799AE1; SCROLLBAR-ARROW-COLOR: #FFFFFF;
	SCROLLBAR-TRACK-COLOR: #AABFEC;
}
TD {
	FONT-SIZE: 12px
}
INPUT {
	BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 12px; BORDER-BOTTOM-WIDTH: 1px; BORDER-RIGHT-WIDTH: 1px
}
TD.forumHeaderBackgroundAlternate {
	BACKGROUND-IMAGE: url(images/manage/admin_top_bg.gif); COLOR: #000000; BACKGROUND-COLOR: #799ae1
}
TD.forumRow {
	PADDING-RIGHT: 3px; PADDING-LEFT: 3px; BACKGROUND: #F1F3F5; PADDING-BOTTOM: 3px; PADDING-TOP: 3px
}
TH {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; BACKGROUND-IMAGE: url(images/manage/admin_bg_1.gif); COLOR: white; BACKGROUND-COLOR: #4455aa
}
TD.forumRowHighlight {
	PADDING-RIGHT: 3px; PADDING-LEFT: 3px; BACKGROUND: #E4EDF9; PADDING-BOTTOM: 3px; PADDING-TOP: 3px
}
</style>
<p>&nbsp;</p>
<p>&nbsp;</p>
  <table cellpadding="1" cellspacing="0" border="0" align=center style="border: outset 3px;width:0;">
  <form action="?action=chklogin" method="post">
<tr>
	<td>
	<table style="width:500" border=0 cellspacing=0 cellpadding=3 align=center class=tablefoot>
		<tr><th valign=middle colspan=2 height=25><%=webname%>管理登录</th></tr>
	</table>
	<table style="width:500" border=0 cellspacing=0 cellpadding=3 align=center class=tablefoot>
	<tr>
	<td valign=middle colspan=2 align=center class=forumRowHighlight style="background-image: url(images/admin_loginbg.gif);" height="75">
		<table border="0" width="100%" height="100%">
		<tr>
		<td width="61%" height="100%" rowspan="3"></td>
		<td width="39%" height="0"></td>
		</tr>
		<tr>
		<td height="" valign=top><BR><a href="index.asp"><b><%=webname%></b></a><br>版本：Mslove v3.0 <%If UserID>0 Then Response.Write Version%><br>
                    注册：<%=UpcodeID%></td>
		</tr>
		<tr><td height=""></td></tr>
		</table>
	</td>
	</tr>
	</table>
	<table style="width:500" border=0 cellspacing=0 cellpadding=3 align=center>
	<tr>
	<td valign=middle colspan=2 align=center class=forumRowHighlight height=4></td>
	</tr>
	<%If UserID=0 Or UserGroupID>1 Then%>
	<tr>
	<td valign=middle class=forumRow width="30%" align=right><b>前台用户名：</b></td>
	<td valign=middle class=forumRow><Input name=adduser type=text value=""></td></tr>
	<tr>
	<td valign=middle class=forumRow align=right><b>前台密码：</b></font></td>
	<td valign=middle class=forumRow><Input name=password2 type=password></td></tr>
	<%End If%>
	<tr>
	<td valign=middle class=forumRow width="30%" align=right><b>用户名：</b></td>
	<td valign=middle class=forumRow><Input name=username type=text></td></tr>
	<tr>
	<td valign=middle class=forumRow align=right><b>密　码：</b></font></td>
	<td valign=middle class=forumRow><Input name=password type=password></td></tr>
	<tr>
	<td valign=middle class=forumRow align=right><b>附加码：</b></td>
	<td valign=middle class=forumRow><input type="text" name="codestr" maxlength="4" size="4">
              &nbsp;请输入 <img src="Getcode.asp"></td>
          </tr>
	<tr>
	<td valign=middle colspan=2 align=center class=forumRowHighlight><input class=button type=submit name=submit value="登 录"></td>
	</tr>
	</table>
	</td>
</tr>
</form>
</table>
</body>
</html>
<%End Sub

sub Chk_Login()
Dim ip
	Dim UserName
	Dim PassWord
	UserName=checkStr(Request("username"))
	PassWord=md5(request("password"),16)
	If Request("codestr")="" Then
		errmsg=errmsg+"<br>"+"<li>请返回输入确认码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		FoundErr=True
	Elseif Session("getcode")="9999" then
		Session("getcode")=""
	Elseif Session("getcode")="" then
		errmsg=errmsg+"<br>"+"<li>请不要重复提交，如需重新登录请返回登录页面。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		FoundErr=True
	ElseIf Cstr(Session("getcode"))<>Cstr(Trim(Request("codestr"))) Then
		errmsg=errmsg+"<br>"+"<li>您输入的确认码和系统产生的不一致，请重新输入。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		FoundErr=True
	End If
	Session("getcode")=""
	if UserName="" Or PassWord="" Then
		errmsg=errmsg+"<br>"+"<li>请输入您的用户名或密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		FoundErr=True
	End If
	ip=UserTrueIP
	If MemberName=""  Or Request("adduser") <>"" Then 
		MemberName=Checkstr(Request("adduser"))
	Else
		MemberName=MemberName
	End If
	if FoundErr=True then exit sub
	Set Rs=Conn.Execute("Select a.*,u.UserPassword,u.UserGroupID From "&Admintable&" a Inner Join Ms_User u On a.AddUser=u.UserName Where a.UserName='"&username&"' And a.AddUser='"&MemberName&"'")
	If Rs.Eof and Rs.Bof Then
		Rs.Close
		Set Rs=Nothing
		errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
		FoundErr=True
		Exit Sub
	else
		If Rs("AcceptIP")<>"" And ChkIPLogin=1 Then
			If ChkLoginIP(Rs("AcceptIP"),ip)=False Then
				errmsg=errmsg+"<br>"+"<li>你不是合法的后台管理员。请<a href=admin_login.asp>重新输入</a>您的密码。"
				FoundErr=True
				Exit Sub
			End If
		End If
		If Trim(Rs("password"))<>PassWord then
			errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"
			FoundErr=True
			Exit Sub
		Else
			If MemberName=""  Or Request("adduser") <>"" Then 
				If Trim(Rs("userpassword"))<>md5(Request("password2"),16) Then
					errmsg=errmsg+"<br>"+"<li>您输入的用户名和密码不正确或者您不是系统管理员。请<a href=admin_login.asp>重新输入</a>您的密码。<b>返回后请刷新登录页面后重新输入正确的信息。</b>"		
					FoundErr=True
					Exit Sub
				End If
			End If
		end if
		Conn.Execute("Update "&admintable&" Set LastLogin="&SqlNowString&",LastLoginIP='"&ip&"' Where UserName='"&UserName&"'")
					Session("flag")=Rs("flag")
					Session.Timeout=45
					Session("MemberName")=MemberName
					Response.Redirect ""&Adminpath&"index.asp"
					
	Rs.Close
	Set Rs=Nothing
	end if
end sub

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%>