<!--#include file="conn.asp"-->
<!--#include file=cookies.asp-->
<% 
dim webname
dim ipid,ipcls
  Set rs = Server.CreateObject("ADODB.RecordSet")
	sql="Select * from stopip"
	Rs.open sql,conn,1,3
ipid=Request.QueryString("id")
ipcls=Request.QueryString("cls")
Select case ipcls
case ""

case "del"
	conn.execute("Delete  From stopip Where id="&ipid)
case "jd0"
    conn.execute("Update stopip set viw=0 Where id="&ipid)
case "jd1"
    conn.execute("Update stopip set viw=1 Where id="&ipid)
case "jd2"
     conn.execute("Update stopip set viw=2 Where id="&ipid)
end Select

if Request.Form("Submit")="提交" then
dim oneip,endip
oneip=trim(Request.Form("oneip"))
endip=trim(Request.Form("endip"))
call ynip(oneip)
call ynip(endip)
    Set rs = Server.CreateObject("ADODB.RecordSet")
	sql="Select * from stopip"
	Rs.open sql,conn,2,3
	Rs.addnew
	      rs("oneip")=cip(oneip)
		  rs("endip")=cip(endip)
		  rs("ip1")=oneip
		  rs("ip2")=endip
		  rs("rdate")=now()
		  rs("viw")=1
	rs.update
	rs.close
end if
 stop_ip= Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
If  stop_ip= "" Then  stop_ip= Request.ServerVariables("REMOTE_ADDR")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>IP访问管理器</title>
<style type="text/css">
<!--
.unnamed1 {
	font-size: 12px;
	line-height: 20px;
}
-->
</style>
<link href="inc_style.css" rel="stylesheet" type="text/css">
</head>

<body>
<form name="form1" method="post" action="">
  <table width="70%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
    <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29"colspan="3"  class="tdbar"> 
        <div align="center"><%=stop_ip%> </div></td>
    </tr>
    <tr> 
      <td width="19%" bgcolor="#F2F4F9"><div align="right">IP段:</div></td>
      <td width="30%" bgcolor="#F2F4F9"><input name="oneip" type="text" id="oneip"></td>
      <td width="51%" bgcolor="#F2F4F9"><input name="endip" type="text" id="endip"></td>
    </tr>
    <tr> 
      <td  class="tdbar1">　</td>
      <td colspan="2"  class="tdbar1"><input type="submit" name="Submit" value="提交"></td>
    </tr>
  </table>
  <br>
</form>
<%  Set rs = Server.CreateObject("ADODB.RecordSet")
	sql="Select * from stopip"
	Rs.open sql,conn,1,3
%>
<table width="70%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29" bgcolor="#C5D5E4"  class="tdbar"> 
        <div align="center">被封IP信息</div></TD>
    </TR>
    <TR> 
      <TD  align=middle valign="top" > <table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" bordercolorlight="#c5cfe0" bordercolordark="#FFFFFF" bgcolor="#C5D5E4"  style="font-size:12px; letter-spacing:1px;">
        <tr align="center" bgcolor="#FFFFFF" height="20"> 
<td align="center" height="29"  class="tdbar1">状态</td>
            <td  class="tdbar1">起始</td>
          <td  class="tdbar1">终止</td>
      <td  class="tdbar1">时间</td>
            <td  class="tdbar1">操作</td>
          </tr>
          <tr> 
            <td height="2" colspan="5" bgcolor="#E4F2FA" class="jd_title"></td>
          </tr>
          <%			ipi=0
do while not rs.eof 
ipi=ipi+1 %>
          <tr>
            <td bgcolor="#F2F4F9">
              <% 
			  if rs("viw")=1 then
			  Response.write("<font color='#FF9900'>")
			  end if
			  if rs("viw")=0 then
			  Response.write("<font color='#009900'>")
			  end if
			   if rs("viw")=2 then
			  Response.write("<font color='#FF0000'>")
			  end if
              Response.write("●</font>")
			  %>
            </td>
            <td bgcolor="#F2F4F9"><%=rs("ip1")%></td>
            <td bgcolor="#F2F4F9"><%=rs("ip2")%></td>
            <td bgcolor="#F2F4F9"><%=rs("rdate")%></td>
            <td bgcolor="#F2F4F9"><a href="admin_stop_ip.asp?cls=del&id=<%=rs("id")%>" onClick="return confirm('删除一个IP段？！\n\n该操作不可恢复！可以设为开通,保留这个段.\n\n要删除请按[确定]\n\n不小心按错按[取消]反回！')">
			<span style="text-decoration: none">删除</span></a> 
              <a href="admin_stop_ip.asp?cls=jd0&id=<%=rs("id")%>">
			<span style="text-decoration: none">开通</span></a>&nbsp; 
              <a href="admin_stop_ip.asp?cls=jd2&id=<%=rs("id")%>">
			<span style="text-decoration: none">禁止访问</span></a> 
            </td>
          </tr>
          <tr> 
            <td height="1" class="jd_title" colspan="5" bgcolor="#E4F2FA"></td>
          </tr>
          <% 
		rs.movenext
    	loop
		rs.close
		set rs=nothing
		%>
          <tr> 
            <td colspan="5"  class="tdbar1">　</td>
          </tr>
          <tr> 
            <td colspan="5" bgcolor="#F2F4F9"><div align="center"><font color="#009900">●开通 </font>&nbsp;<font color="#FF0000">●禁止访问</font></div></td>
          </tr>
        </table>
</TD>
    </TR>
  </TBODY>
</TABLE>

</body>
 </html>
<% ' IP算法
function cip(sip)
	tip=cstr(sip)
	sip1=left(tip,cint(instr(tip,".")-1))
	tip=mid(tip,cint(instr(tip,".")+1))
	sip2=left(tip,cint(instr(tip,".")-1))
	tip=mid(tip,cint(instr(tip,".")+1))
	sip3=left(tip,cint(instr(tip,".")-1))
	sip4=mid(tip,cint(instr(tip,".")+1))
	if cint(sip1)<128 then
		cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)
	else
		cip=cint(sip1)*256*256*256+cint(sip2)*256*256+cint(sip3)*256+cint(sip4)-4294967296
	end if
end function

sub eorr()
			         Response.Write "<script language=javascript>alert(""请输入正确的IP"");location.href=""admin_stop_ip.asp"";</script>"
		             Response.End
end sub
sub ynip(uip)
         dim tip
		 tip = split(uip,".") 
		  if not IsArray(tip) then call eorr()
          if UBound(tip)<3 then call eorr()
          if Not IsNumeric(tip(0)) or  Not IsNumeric(tip(1)) or  Not IsNumeric(tip(2)) or Not IsNumeric(tip(3)) then call eorr()
		  if cint(tip(0))>255 or cint(tip(1))>255 or cint(tip(2))>255 or cint(tip(3))>255 then call eorr()
end sub
%>