<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock

set cschat=server.createobject("ffcschat.cssbchat")
my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))

myname=cschat.myname
room_id=cschat.room_id

votes=application( ConstStr & "_votes")
if (votes(0)<>0 and votes(1)=myname) then my_level=1
cschat.FilterStr = Application(ConstStr & "_saysfilterstr")
forwhat=left(cschat.trdb(request("forwhat")),40)
cmdYes=request("cmdYes")
Set Conn=Server.CreateObject("ADODB.Connection")
conn.open Application( ConstStr & "_connstr")

if my_level=0 then
  errText="你还没有登录到聊天室！"
elseif cmdYes<>"解锁" and cmdYes<>"封锁" then
  errText="你想要干什么？"
elseif my_level-application( ConstStr & "_l_lockip")<0 then
  errText="你暂时还没有"&cmdYes&"IP的权力！"
elseif forwhat="" then
  errText="不注明原因，你想乱来啊？"
else
  ip=request("ip")
  if IsNumeric(request("howlong")) then
    howlong=cint(request("howlong"))*60
    if howlong-application( ConstStr & "_iplocktime")<0 then howlong=application( ConstStr & "_iplocktime")
  else
    howlong=application( ConstStr & "_iplocktime")
  end if
  ipnum=replace(replace(replace(replace(replace(ip,".",""),"*",""),"?",""),"%",""),"_","")
  if not IsNumeric(ipnum) then
    errText="IP地址格式错误！"
  elseif len(ip)>16 then
    errText="有这么长的IP地址吗？！"
  elseif len(ipnum)<4 then
    errText="IP地址至少包含4位数字！"
  else
    sql="SELECT * FROM ip_lock WHERE ip='"&ip&"'"
    set Rs=conn.Execute(sql)
    if cmdYes="解锁" then
      if Rs.eof or Rs.bof then
        errText="你想解锁ip"&ip&",但"&ip&"并没有被封锁！"
      elseif my_level-rs("act_level")<0 then
        errText="你想解锁ip"&ip&",但封锁此ip的用户权力比你更高！"
      else
        stype=13
        occ_end=">解除对IP%%的封锁"
        conn.Execute("delete from ip_lock WHERE ip='"&ip&"'")
      end if
    elseif cmdYes="封锁" then
      if rs.eof or rs.bof then
      elseif my_level-rs("act_level")<0 then
        errText="此ip地址已经被比你权力更高的用户封锁了！"
      else
        conn.Execute("DELETE FROM ip_lock WHERE ip='"&ip&"'")
      end if
      if errText="" then
        stype=3
        occ_end=">封锁了IP%%"
        ip=replace(replace(ip,"*","%"),"?","_")
        out_time=dateAdd("n",howlong,now())
        conn.Execute("INSERT INTO ip_lock (ip,end_time,act_level) VALUES ('"&ip&"','"&out_time&"',"&my_level&")")
      end if
    end if
    rs.close
    set rs=nothing
  end if
end if
if errText="" then
  if my_level-application( ConstStr & "_superlevel")=0 then myname="管理员"
  room_name=cschat.GetListValue(Application(ConstStr & "_room_list"), room_id, 0)
  
  occ_env=room_name&">"&myname&">"&Request.ServerVariables("REMOTE_ADDR")&">"&ip&"> >"&forwhat&occ_end
  conn.Execute("INSERT INTO record (stype,occ_time,occ_env) VALUES ("&stype&",'"&now()&"','"&occ_env&"')")
  say_mess=split(application( ConstStr & "_lockipshow"),"::")

  say_mess(0)=replace(say_mess(0),"$IP",ip)
  say_mess(0)=replace(say_mess(0),"$F",forwhat)
  say_mess(0)=replace(say_mess(0),"$OP",cmdYes)

  says = Application(ConstStr & "_says")
  current = Application(ConstStr & "_current")
  cschat.newsay myname,"大家",0,room_id,say_mess(0),say_mess(1),say_mess(2),-2,says,current
  Application(ConstStr & "_says") = says
  Application(ConstStr & "_current") = current
  
  errText="你成功地"&cmdYes&"了IP(<font color=green>"&ip&"</font>)!"
end if
set cschat=nothing
application.unlock
conn.close
set conn=nothing
response.redirect("showerr.asp?errtext="&ErrText)%>