<!-- #include file="../conn.asp" -->
<!-- #include file="../cls_main.asp" -->
<% MyDbPath = "../"
dim obj
set obj = New admin_lockIP
	call obj.AspInit()
set obj = nothing

Class admin_lockIP
	Private isEdit, MaxPerPage, Mesky
	Private Sub Class_Initialize()
		Set Mesky = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		Set Mesky = Nothing
	End Sub
	Public Sub AspInit()
		Response.Write "<HTML><HEAD><TITLE>IP限制管理</TITLE>" & vbCrLf
		Response.Write "<META http-equiv=Content-Type content=""text/html; charset=gb2312"">" & vbCrLf
		Response.Write "<LINK href=""admin.css"" type=text/css rel=stylesheet>" & vbCrLf
		Response.Write "</HEAD>" & vbCrLf
		Response.Write "<BODY leftMargin=1 topMargin=2>" & vbCrLf
		
		MaxPerPage = 25
	
			If Mesky.adminName = "" Then
				Mesky.strMsg = "<li>非法操作：登录超时或你没有以管理员身份登录系统，<a href=""admin_login.asp"" target=_top>点此进入管理员登录界面</a>。"
				Call Mesky.SystemMsg
			ElseIf Mesky.checkPermission(Mesky.adminName, 0) = False Then
				Mesky.strMsg = "<li>非法操作：你没有权限进行此项操作，请联系管理员！"
				Call Mesky.SystemMsg
			Else
				Call Main
			End If
		Response.Write "</BODY></HTML>" & vbCrLf
	End Sub

	Private Sub Main()
		Select Case Request("action")
		Case "add"
			Call addIP
		Case "saveadd"
			Call SaveAdd
		Case "delIP"
			Call delIP
		Case Else
			Call showList
		End Select
	End Sub
	Private Sub SaveAdd()
		Dim sip, str1, str2, str3, str4, num_1, num_2
		sip = CStr(Request.Form("ip1"))
		'dot=instr(ip,".")-1
		'response.write dot
		str1 = Left(sip, CInt(InStr(sip, ".") - 1))
		sip = Mid(sip, CInt(InStr(sip, ".")) + 1)
		str2 = Left(sip, CInt(InStr(sip, ".")) - 1)
		sip = Mid(sip, CInt(InStr(sip, ".")) + 1)
		str3 = Left(sip, CInt(InStr(sip, ".")) - 1)
		str4 = Mid(sip, CInt(InStr(sip, ".")) + 1)
		num_1 = CInt(str1) * 256 * 256 * 256 + CInt(str2) * 256 * 256 + CInt(str3) * 256 + CInt(str4) - 1
	
		sip = CStr(Request.Form("ip2"))
		str1 = Left(sip, InStr(sip, ".") - 1)
		sip = Mid(sip, InStr(sip, ".") + 1)
		str2 = Left(sip, InStr(sip, ".") - 1)
		sip = Mid(sip, InStr(sip, ".") + 1)
		str3 = Left(sip, InStr(sip, ".") - 1)
		str4 = Mid(sip, InStr(sip, ".") + 1)
		num_2 = CInt(str1) * 256 * 256 * 256 + CInt(str2) * 256 * 256 + CInt(str3) * 256 + CInt(str4) - 1
		'response.write num_1  & "," &  num_2
		'response.end
		Dim Rs, sql
		If Not IsObject(Conn) Then ConnectionDatabase
		Set Rs = Server.CreateObject("adodb.recordset")
		sql = "select * from Mesky_LockIP"
		Rs.open sql, Conn, 1, 3
		Rs.AddNew
		Rs("ip1") = num_1
		Rs("ip2") = num_2
		Rs("sip1") = Request.Form("ip1")
		Rs("sip2") = Request.Form("ip2")
		Rs.Update
		Rs.Close
		Set Rs = Nothing
		Mesky.strMsg = "<li>添加限制访问的IP操作成功！</li>"
		Call Mesky.SystemMsg
		If IsObject(Conn) Then CloseConn
	End Sub
	
	Private Sub delIP()
		Mesky.Execute ("delete from Mesky_LockIP where id =" & CLng(Request.QueryString("delID")))
		Mesky.strMsg = "<li>删除限制访问的IP操作成功！</li>"
		Call Mesky.SystemMsg
	End Sub
	
	Private Sub addIP()
		Dim userip, ips, GetIp1, GetIp2
		If Request("userip") <> "" Then
			userip = Request("userip")
			ips = Split(userip, ".")
			GetIp1 = ips(0) & "." & ips(1) & "." & ips(2) & ".1"
			GetIp2 = ips(0) & "." & ips(1) & "." & ips(2) & ".255"
		Else
			userip = ""
			GetIp1 = ""
			GetIp2 = ""
		End If
		
		Response.Write " <fieldset><legend>添加限制访问的 IP：</legend>" & vbCrLf
		Response.Write "    <table width=""100%"" border=""0"" align=""center"" cellpadding=""3"" cellspacing=""1"">" & vbCrLf
		Response.Write "        <form action=""admin_LockIP.asp"" method=""post"">" & vbCrLf
		Response.Write "        <input name=""action"" type=""hidden"" id=""action"" value=""saveadd"">" & vbCrLf
		Response.Write "          <tr class=tdbg2>" & vbCrLf
		Response.Write "            <td align=""right"">" & vbCrLf
		Response.Write "            起始 IP</td>" & vbCrLf
		Response.Write "            <td><input type=""text"" name=""ip1"" size=""30"" value=""" & GetIp1 & """> 如：202.152.12.1</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=tdbg3>" & vbCrLf
		Response.Write "            <td align=""right"">结尾 IP</td>" & vbCrLf
		Response.Write "            <td><input type=""text"" name=""ip2"" size=""30"" value=""" & GetIp2 & """> 如：202.152.12.255</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "          <tr class=tdbg2>" & vbCrLf
		Response.Write "            <td align=""right""></td>" & vbCrLf
		Response.Write "            <td><input type=""submit"" name=""Submit"" value="" 提 交 ""></td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Response.Write "        </form>" & vbCrLf
		Response.Write " </table></fieldset>" & vbCrLf
	End Sub
	Private Sub showList()
		Dim currentPage, page_count, Pcount
		Dim totalrec, endpage
		If Not IsEmpty(Request("page")) Then
				currentPage = CInt(Request("page"))
		Else
				currentPage = 1
		End If
		Dim Rs, sql, i
		If Not IsObject(Conn) Then ConnectionDatabase
	
		Response.Write "<fieldset><legend>访问IP限制管理：[<a href=""?action=add"">添加</a>]</legend>" & vbCrLf
		Response.Write " <table width=""100%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"">" & vbCrLf
		Response.Write "          <tr class=""tdbg2"">" & vbCrLf
		Response.Write "            <td width=""15%"" align=""center"" height=""20""><B>ID号</B></td>" & vbCrLf
		Response.Write "            <td width=""35%"" align=""center""><B>起始IP</B></td>" & vbCrLf
		Response.Write "            <td width=""35%"" align=""center""><B>结尾IP</B></td>" & vbCrLf
		Response.Write "            <td width=""15%"" align=""center""><B>删除</B></td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
	
	
		sql = "select id,sip1,sip2 from Mesky_LockIP order by id desc"
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.open sql, Conn, 1, 1
		If Rs.EOF And Rs.BOF Then
	
		Response.Write "          <tr class=""tdbg3"">" & vbCrLf
		Response.Write "            <td width=""100%"" colspan=4>还没有任何允许访问IP数据。</td>" & vbCrLf
		Response.Write "          </tr>" & vbCrLf
		Else
			Rs.PageSize = MaxPerPage
			Rs.AbsolutePage = currentPage
			page_count = 0
			totalrec = Rs.recordcount
			While (Not Rs.EOF) And (Not page_count = MaxPerPage)
	
			Response.Write "          <tr class=""tdbg3"">" & vbCrLf
			Response.Write "            <td width=""15%"" align=""center"" height=""20"">" & Rs("id") & "</td>" & vbCrLf
			Response.Write "            <td width=""35%"" align=""center"">" & Rs("sip1") & "</td>" & vbCrLf
			Response.Write "            <td width=""35%"" align=""center"">" & Rs("sip2") & "</td>" & vbCrLf
			Response.Write "            <td width=""15%"" align=""center""><a href=""?action=delIP&delID=" & CStr(Rs("ID")) & """>删除</a></td>" & vbCrLf
			Response.Write "          </tr>" & vbCrLf
	
	
			page_count = page_count + 1
			Rs.MoveNext
			Wend
			Response.Write "          <tr class=""tdbg2"">" & vbCrLf
			Response.Write "            <td colspan=4 align=center>分页：" & vbCrLf
	
			Pcount = Rs.PageCount
			If currentPage > 4 Then
			Response.Write "<a href=""?page=1"">[1]</a> ..."
			End If
			If Pcount > currentPage + 3 Then
			endpage = currentPage + 3
			Else
			endpage = Pcount
			End If
			For i = currentPage - 3 To endpage
			If Not i < 1 Then
				If i = CLng(currentPage) Then
				Response.Write " <font color=red>[" & i & "]</font>"
				Else
				Response.Write " <a href=""?page=" & i & """>[" & i & "]</a>"
				End If
			End If
			Next
			If currentPage + 3 < Pcount Then
			Response.Write "... <a href=""?page=" & Pcount & """>[" & Pcount & "]</a>"
			End If
			Response.Write "    </td></tr>" & vbCrLf
		End If
		Rs.Close
		Set Rs = Nothing
		
		Response.Write "</FORM> </table> </fieldset>" & vbCrLf
	End Sub

End Class %>