<%Option Explicit%>
<!--#include file="conn.asp"-->
<%
DoWhat="后台管理"
dim action,modify
IsErr=False
action=request.querystring("action")
if int(session("times"))>=times then
	DoWhat=DoWhat & "登陆失败"
	WhatErr="<LI>您已经连续五次登陆失败，请稍候再试！</LI>"
	ToUrl="default.asp"
else	
	if session("admin")=True then
		modify=request.querystring("modify")
		select case modify
			case "loginout"
				DoWhat=DoWhat & "退出成功"
				session("admin")=False
			case "adminpassd"
				call ModifyAdmin()
			case "config"
				call ModifyConfig()
			case "fastdata"
				call Clearly()
				WhatErr=WhatErr & "<LI>" & CompactDB(server.mappath(Db))
			case "delly"
				call ModifyDelly()
			case "cleardata"
				call Clearly()
			case "badwords"
				call ModifyBadwords()
			case "addstopip"
				call AddStopIp()
			case "zipdata"
				WhatErr="<LI>" & CompactDB(server.mappath(Db))
			case else
				IsErr=True
		end select
	else
		IsErr=True
	end if
	if action="login" and not session("admin") then 
		call login()
		IsErr=False
		ToUrl=session("BackUrl")
	end if
end if

sub AdminBody()		'后台管理界面
%>
<table width="780" border="1" cellspacing="1" cellpadding="5" align="center" bordercolor="#FFFFFF">
<tr bordercolor="#DEE5EF">
	<td width="100%" colspan=2 align=right>
		<a href="default.asp"><img src="images/home.gif" border=0 alt="返回首页"></a> 
		<a href="upfile.asp"><img src="images/newpage.gif" border=0 alt="签写留言"></a>
		<a href="?modify=loginout"><img src="images/loginout.gif" border=0 alt="退出登陆"></a>
	</td>
</tr>
<tr>
	<td height=15 bgcolor="#DEE5EF" colspan=2 align=center> 
		<img src="images/team.gif" border=0> <B>留 言 簿 后 台 管 理</B>
	</td>
</tr>
<tr>
	<td width="18%" height=30 bgcolor="#DEE5EF" valign="top">
		<table width="100%" border="1" cellspacing="2" cellpadding="2" bordercolor="#FFFFFF">
			<tr><td><B>[<a href="?">管理首页</a>] [<a href="?modify=loginout">退出</a>]</B></td></tr>
			<tr><td> ◎ <a href="?action=adminpassd">账号管理</a></td></tr>
			<tr><td> ◎ <a href="?action=config">基本设置</a></td></tr>
			<tr><td> ◎ <a href="?action=badwords">脏话过滤</a></td></tr>
			<tr><td> ◎ <a href="?action=delly">数据管理</a></td></tr>
			<tr><td> ◎ <a href="?action=stopip">ＩＰ限制</a></td></tr>
			<tr><td> ◎ <a href="?action=help">使用说明</a></td></tr>
			<tr><td><B>[版权信息]</B><BR>版权所有：<a href="http://my.hnjdzy.net/feelings" target=_blank>飞凌酷网<BR>
			(Feelings.Ku.Net)</a><BR>支持论坛：<a href="http://my.hnjdzy.net/feelings/bbs" target=_blank>飞凌酷网</a></td></tr>
		</table>
	</td>
    <td width="82%" colspan=2 bgcolor="#FFFFFF" valign=Top align=Center>
	    <table width="100%" cellspacing="2" cellpadding="2"  border="1" bordercolor="#DEE5EF">
	     <%if action="adminpassd" then%>
	     <tr><td colspan=2><B>帐号管理：</B>可更改管理帐号或密码，密码经Md5加密存放，确保安全。</td></tr>
	     <FORM METHOD=POST ACTION="?modify=adminpassd" name="adminpassdform">
	     <tr><td align=right>用户名：<td><input type=text name="username" size=20 maxlength=20 value="<%=session("postname")%>"> 至少6个字符，不修改请留空</td></tr>
	     <tr><td align=right>密 &nbsp;码：<td><input type=password name="userpassd1" size=20 maxlength=20> 至少6个字符，不修改请留空</td></tr>
	     <tr><td align=right>确认密码：<td><input type=password name="userpassd2" size=20 maxlength=20> 再输入一遍密码以确认</td></tr>
	     <tr><td> </td><td><input type="submit" name="send" value=" 确 定 "> <input type="reset" name="reset" value=" 清 除 "></td></tr>
	     </FORM>
	     <%elseif action="config" then%>
	     <FORM METHOD=POST ACTION="?modify=config" name="configform">
	     <tr><td align=right>您的网站名称：<td><input type=text name="LybName" size=30 maxlength=20 value="<%=LybName%>"></td></tr>
	     <tr><td align=right>您的主页地址：<td><input type=text name="HomePage" size=30 maxlength=220 value="<%=HomePage%>"> 没有请留空；</td></tr>	     
	     <tr><td align=right>网页描述：<td><input type=text name="Descrip" size=30 maxlength=80 value="<%=Descrip%>"> 网页的描述信息；</td></tr>
	     <tr><td align=right>网页关键字：<td><input type=text name="KeyWord" size=30 maxlength=80 value="<%=KeyWord%>"> 用于引擎搜索的关键字词，用英文逗号“,”隔开；</td></tr>
	     <tr><td align=right>首页广播内容：<td><input type=text name="MainNote" size=30 maxlength=200 value="<%=MainNote%>"> 显示于首页顶部的滚动信息；</td></tr>
	     <tr><td align=right>版权注册信息：<td><input type=text name="CopyRight" size=30 maxlength=200 value="<%=CopyRight%>"> 显示于页面底部的版权信息；</td></tr>
	     <tr><td align=right>首页显示留言条数：<td><input type=text name="HomePageNO" size=2 maxlength=2 value="<%=HomePageNO%>"> 请填入1-30之间的数字； 建议20</td></tr>
	     <tr><td align=right>热门话题最低回复：<td><input type=text name="HotPageNO" size=2 maxlength=2 value="<%=HotPageNO%>"> 请填入1-30之间的数字； 建议10</td></tr>
	     <tr><td align=right>文件上传目录：<td><input type=text name="UpJpgFile" size=30 maxlength=220 value="<%=UpJpgFile%>">  用于存放上传文件的目录；</td></tr>
	     <tr><td align=right>上传文件大小：<td><input type=text name="fsize" size=5 maxlength=5 value="<%=fsize%>">  允许上传文件的大小，单位：KB；</td></tr>
	     <tr><td align=right>上传文件类型：<td><input type=text name="AbleFileExt" size=30 maxlength=220 value="<%=AbleFileExt%>">  允许上传的文件类型；用英文分号“;”隔开</td></tr>
	     <tr><td> </td><td><input type="submit" name="send" value=" 确 定 "> <input type="reset" name="reset" value=" 重 写 "></td></tr>
	     </FORM>
	     <%elseif action="delly" then%>
	     <tr><td colspan=2><B>留言删除：</B>可删除符合指定条件的主题，勾选“全部删除”则清空所有留言数据！</td></tr>
	      <FORM METHOD=POST ACTION="?action=delly&modify=delly" name="dellyform">
	     <tr><td align=right>人气低于：<td><input type=text name="PeopleDot" size=2 maxlength=5> 将删除人气低于此值的主题</td></tr>
	     <tr><td align=right>回复低于：<td><input type=text name="PeopleRe" size=2 maxlength=5> 将删除回复低于此值的主题</td></tr>
	     <tr><td align=right>过期时效：<td><select name="LyYear" size=1><option SELECTED value="">年</option><%for ii=2004 to Year(Now())
	     response.write "<option value=" & ii & ">" & ii & "</option>"
	     next%></select>年 <select name="LyMonth" size=1><option SELECTED value="">月</option><%for ii=1 to 12
	     response.write "<option value=" & ii & ">" & ii & "</option>"
	     next%></select>月 <select name="LyDay" size=1><option SELECTED value="">日</option><%for ii=1 to 31
	     response.write "<option value=" & ii & ">" & ii & "</option>"
	     next%></select>日 将删除在此日期之前发表的主题</td></tr>
	     <tr><td align=center>全部删除<input type=checkbox name="DelAll" value=1 onclick="{if(this.checked==true){if(confirm('确认清空所有留言数据？')){return true;}return false;}}"></td>
	     <td><input type="submit" name="submit" value=" 确 定 删 除 "></td></tr>
	     </FORM>
	     <tr><td colspan=2 height=30> </td></tr>
	     <form name="cleardataform" method=post action="?modify=cleardata">
	      <tr><td align=center><input type=submit name="cleardatasubmit" value="清理数据库"></td> <td>清除无效数据，建议每隔一段时间运行一次。</td></tr>
	     </form>
	     <form name="zipdataform" method=post action="?modify=zipdata">
	      <tr><td align=center><input type=submit name="zipdatasubmit" value="压缩数据库"></td> <td>压缩当前数据库，请在数据库未被使用时运行。</td></tr>
	     </form>
	     <%elseif action="badwords" then
	     Dim AllBadWord
				EachBadWords=Split(BadWords,"|")
				EachBadWords1=Split(BadWords1,"|")
	     For ii=Lbound(EachBadWords) to Ubound(EachBadWords)-1
	     	AllBadWord=AllBadWord & EachBadWords(ii) & "=" & EachBadWords1(ii) & VBCrlf
	     Next
	     	AllBadWord=AllBadWord & EachBadWords(Ubound(EachBadWords)) & "=" & EachBadWords1(Ubound(EachBadWords))
	     %>
	     <tr><td><B>字符过滤：</B>过滤字符设定规则为 要过滤的字符=过滤后的字符 ，每个过滤字符用回车分割开。</td></tr>	     
	     <FORM name="BadWordsForm" method=POST action="?action=badwords&modify=badwords">
	     <tr><td><textarea name="BadWords" cols="80" rows="12"><%=AllBadWord%></textarea></td></tr>
	     <tr><td> <input type=submit name="submit" value="提 交"></td></tr>
	     </FORM>
	     <%elseif action="stopip" then%>
	     <tr><td><B>ＩＰ限制：</B>可阻挡使用该IP的客户端浏览留言簿；每个IP用回车分割开。</td></tr>
	     <FORM name="IpDisable" method=POST action="?action=stopip&modify=addstopip">
	     <tr><td><textarea name="ipcontent" cols="60" rows="12"><%=Replace(IpDisable,"|",VBCrlf)%></textarea></td></tr>
	     <tr><td> <input type=submit name="submit" value="提 交"></td></tr>
	     </FORM>
	     <%elseif action="help" then%>
	     <tr><td align=center><B>《“飞凌酷网”留言系统v4.2单用户版》使用说明</B></td></tr>
	     <tr><td> &nbsp; &nbsp; 系统的界面和功能仿论坛（BBS），但任何人可以留言，也可以回复他人的留言；
	     留言内容拥有强大的UBB标签支持，从安全方面考虑，不开放HTML标签的支持； 为实现所有功能，请确认服务器已开放FSO支持；FSO相关帮助请查阅微软相关网站；</td></tr>
	     <tr><td>站长可以登陆留言系统后台进行设置和管理，目前包括如下功能：</td></tr><tr><td>
	     <LI><a href="?action=adminpassd">帐号管理</a> 可以更改管理员帐号或密码；</LI>
	     <LI><a href="?action=config">基本设置</a> 可以对留言板的基本参数进行设置；</LI>
	     <LI><a href="?action=badwords">脏话过滤</a> 可以对留言内容的某些字词进行过滤；</LI>
	     <LI><a href="?action=delly">数据管理</a> 可以对留言进行指定删除操作，并对数据库进行相应的清理和压缩维护；</LI>
	     <LI><a href="?action=stopip">ＩＰ限制</a> 可以添加多个限制IP，每个IP用回车分隔；当客户端的IP符合限制条件时将被禁止浏览留言簿；</LI>
	     </td></tr><tr><td>站长可在前台操作：留言逐条删除、留言主题（解除）固顶、留言编辑、查看留言者来源、（解除）限制留言者IP。</td></tr>
	     <tr><td>更多请访问：<a href="http://my.hnjdzy.net/feelings" target=_blank>http://my.hnjdzy.net/feelings</a></td></tr>
	     <%else%>
	     <tr><td align=center><B>欢迎使用《“飞凌酷网”留言系统》</B></td></tr>
	     <tr><td>本系统由飞凌酷网(Feelings.ku.net)授权给 <B><%=LybName%></B> 使用，版本：Version4.2 Build 050502</td></tr>
	     <tr><td>服务器类型：<%=Request.ServerVariables("OS")%>(IP:<%=Request.ServerVariables("LOCAL_ADDR")%>)
	      脚本解释引擎：<%=ScriptEngine & "/"& ScriptEngineMajorVersion &"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
	     </td></tr><tr><td>站点物理路径：<%=request.ServerVariables("APPL_PHYSICAL_PATH")%> 数据库地址：<a href=<%=Db%> target=_blank><%=Db%></a></td></tr>
	     <tr><td height=15> </td></tr><form name="fastdataform" method=post action="?modify=fastdata">
	     	<tr><td><input type=submit name="fastdatasubmit" value="数据库快速维护"> 清除无效数据并对数据库进行压缩，请在数据库未被使用时运行。</td></tr>
	     </form><tr><td height=15> </td></tr>
	     <tr><td>在使用时，如有什么不明白的地方，请查看《<a href="?action=help">使用说明</a>》。</td></tr>
	     <tr><td>如发现程序中存在问题，请及时和我们联系，谢谢！</td></tr>
	     <tr><td>EMAIL：<a href="mailto:zjmotion@163.com">zjmotion@163.com</a> 
	     网站：<a href="http://my.hnjdzy.net/feelings" target=_blank>http://my.hnjdzy.net/feelings</a></td></tr>
	     <%end if%>
	    </table>
    </td>
  </tr>
</table>
<%end sub

sub ModifyAdmin()		'帐号管理
	Dim name,passd1,passd2
	Dim isnameerr,ispassderr
	isnameerr=False
	ispassderr=False
	name=Trim(request.form("username"))
	name=Replace(Lcase(name),"'","")
	passd1=Trim(request.form("userpassd1"))
	passd2=Trim(request.form("userpassd2"))
	passd1=Replace(passd1,"'","")
			SqlData="Select Top 1 administrator,password From Admin"
			Rs.open SqlData,Conn,1,3
			if Not Rs.Eof and Not Rs.Bof then
				if (len(name)>=6) then
					Rs(0)=name
					session("postname")=name
				else
					isnameerr=True
				end if
				if (len(passd1)>=6) and (passd1=passd2) then Rs(1)=md5(passd1) else ispassderr=True
				if (Not isnameerr) or (Not ispassderr) then Rs.update
			end if
			Rs.close
			Set Rs=Nothing
			Conn.close
			Set Conn=Nothing
	DoWhat="帐号管理操作成功"
	if Not isnameerr then	WhatErr="<LI><font color=red>帐号被修改</font>，" else WhatErr="<LI>帐号未被修改，"
	if Not ispassderr then WhatErr=WhatErr & "<font color=red>密码被修改</font>；</LI>" else WhatErr=WhatErr & "密码未被修改；</LI>"
end sub

sub ModifyConfig()		'基本设置
	LybName=replace(request.form("LybName"),"'","&#39;")
	HomePage=replace(request.form("HomePage"),"'","")
	KeyWord=replace(request.form("KeyWord"),"'","&#39;")
	Descrip=replace(request.form("Descrip"),"'","&#39;")
	MainNote=replace(request.form("MainNote"),"'","&#39;")
	CopyRight=replace(request.form("CopyRight"),"'","&#39;")
	UpJpgFile=replace(request.form("UpJpgFile"),"'","")
	AbleFileExt=replace(request.form("AbleFileExt"),"'","")
	HomePageNO=request.form("HomePageNO")
	HotPageNO=request.form("HotPageNO")
	fsize=request.form("fsize")
	if isempty(HomePageNO) or (not isnumeric(HomePageNO)) then 
		HomePageNO=1
	elseif cint(HomePageNO)<1 or cint(HomePageNO)>30 then 
		HomePageNO=1
	end if
	if isempty(HotPageNO) or (not isnumeric(HotPageNO)) then 
		HomePageNO=1
	elseif cint(HotPageNO)<1 or cint(HotPageNO)>30 then 
		HomePageNO=1
	end if
	if isempty(fsize) or (not isnumeric(fsize)) then fsize=200
	if HomePage>"" and left(HomePage,7)<>"http://" then HomePage="http://" & HomePage
	SqlData="update Config set LybName='" & LybName & "',HomePage='" & HomePage & "',keyword='" & KeyWord & "',descrip='" & Descrip & "',"&_
					"MainNote='" & MainNote & "',copyright='" & CopyRight & "',UpJpgFile='" & UpJpgFile & "',AbleFileExt='" & AbleFileExt & "',"&_
					"homepageno=" & HomePageNO & ",hotpageno=" & HotPageNO & ",fsize=" & fsize
	Conn.Execute(SqlData)
	DoWhat="基本设置成功"
end sub

sub ModifyBadwords()	'脏话过滤
Dim BadWordsContent,LeftBadWord,RightBadWord,RowBadWord,ColBadWord
BadWordsContent=replace(request.form("BadWords"),"'","&#39;")
if BadWordsContent="" then
	LeftBadWord="L|"
	RightBadWord="R|"
else
	RowBadWord=Split(BadWordsContent,VBCrlf)
	For ii=Lbound(RowBadWord) to Ubound(RowBadWord)
		ColBadWord=Split(RowBadWord(ii),"=")
		LeftBadWord=LeftBadWord & "|" & ColBadWord(0)
		RightBadWord=RightBadWord & "|" & ColBadWord(1)
	Next
end if
Conn.Execute("update Config set Badwords='" & Mid(LeftBadWord,2) & "',Badwords1='" & Mid(RightBadWord,2) & "'")
DoWhat="脏话过滤设置成功"
end sub

sub AddStopIp()	'IP限制
Dim IpContent
IpContent=replace(request.form("ipcontent"),"'","")
IpContent=replace(IpContent,VBCrlf,"|")
If Right(IpContent,1)<>"|" Then IpContent=IpContent & "|"
Conn.Execute("update Config set IpDisable='" & IpContent & "'")
DoWhat="ＩＰ限制设置成功"
end sub

sub ModifyDelly()		'留言管理
	DoWhat="留言删除管理"
	if request.form("DelAll")=1 then
		Conn.execute("delete from Data")		
		WhatErr="<LI>已清空所有留言！</LI>"
	else
		Dim PeopleDot,PeopleRe,LyYear,LyMonth,LyDay
		PeoPleDot=Trim(Request.form("PeopleDot"))
		PeoPleRe=Trim(Request.form("PeopleRe"))
		LyYear=Trim(Request.form("LyYear"))
		LyMonth=Trim(Request.form("LyMonth"))
		LyDay=Trim(Request.form("LyDay"))
		if (PeoPleDot>"" and Isnumeric(PeoPleDot)) then	
			Conn.execute("delete from Data where SubMainNumber=0 and counter<" & Cint(PeoPleDot))			
			WhatErr="<LI>已删除所有人气值低于" & PeoPleDot & "的主题！</LI>"
		end if
		if (PeoPleRe>"" and Isnumeric(PeoPleRe)) then	
			Conn.execute("delete from Data where SubMainNumber=0 and report<" & Cint(PeoPleRe))
			WhatErr=WhatErr & "<LI>已删除所有回复值低于" & PeoPleRe & "的主题！</LI>"
		end if
		if LyYear>"" and LyMonth>"" and LyDay>"" and Isnumeric(LyYear) and Isnumeric(LyMonth) and Isnumeric(LyDay) then
			Dim DelDate
			DelDate	=Cstr(LyYear)+Cstr(LyMonth)+Cstr(LyDay)
			Conn.execute("delete from Data where SubMainNumber=0 and (Cstr(Year(writetime))+Cstr(Month(writetime))+Cstr(Day(writetime)))<" & DelDate)
			WhatErr=WhatErr & "<LI>已删除所有在" & LyYear & "年" & LyMonth & "月" & LyDay & "日之前发表的主题！</LI>"
		end if
	end if
end sub

sub Clearly()	'清空无效数据
	DoWhat="清理数据库"
	Rs.Open "select SubMainNumber from Data where SubMainNumber>0",conn,1,1
	if (Rs.eof and Rs.bof) then
		WhatErr="<LI>没有找到无效的留言数据；</LI>"
	else
		Dim RsC,i
		i=0
		Set RsC=Server.CreateObject("ADODB.Recordset")
		Do While Not Rs.eof
			RsC.Open "select id from Data where id=" & Rs(0),conn,1,1
			if (RsC.eof and RsC.bof) then
				Conn.execute("delete from Data where SubMainNumber=" & Rs(0))
				i=i+1
			end if
			RsC.close
		Rs.movenext
		loop
		WhatErr="<LI>删除了" & i & "条无效数据；</LI>"
	end if
	Rs.close
	Set Rs=nothing
	Set RsC=nothing
	Conn.close
	Set Conn=nothing
end sub

Function CompactDB(dbPath)
Dim fso,Engine,strDBPath,JET_3X
strDBPath=left(dbPath,instrrev(dbPath,"\"))
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists(dbPath) Then
	fso.CopyFile dbpath,strDBPath & "temp.mdb"
	Set Engine=CreateObject("JRO.JetEngine")
	Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
	"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
	fso.CopyFile strDBPath & "temp1.mdb",dbpath
	fso.DeleteFile(strDBPath & "temp.mdb")
	fso.DeleteFile(strDBPath & "temp1.mdb")
	Set fso=nothing
	Set Engine=nothing
	CompactDB="你的数据库" & dbpath & ", 已经压缩成功!"
Else
	CompactDB="数据库名称或路径不正确，请重试!"
End If
End Function

call HeadHtml()		'网页头函数
if (Not IsErr) then
	call FounderErr()
else
	if session("admin") then
		call AdminBody()
	else		
		call LoginBody()
		if session("times")=0 then session("BackUrl")=ToUrl
	end if
end if
call FootHtml()		'网页尾函数
%>
