<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'===================================

'程序配置
'=========================================================
'设置访问密码，默认是lake2。如不修改，后果自负！！！！！！
Password = "lake2"   
'脚本超时时间，单位秒；如果网站空间文件很多的话就设置长些。默认90秒
Server.ScriptTimeout = 90
'设置要检查文件的扩展名，小写。如果检查所有文件则填“*”
DimFileExt = "asp,aspx,cer,asa,cdx,shtml,shtm,stm,htm,html"
'=========================================================



If Request.Form("radiobutton")<>"" And Session("InfoSec")<>"" Then
	If Request.Form("radiobutton")="0" then
		Str="@本文件由“ASP文件安全检查”程序生成；请妥善保存，以备后用"&vbcrlf&"@"&Now&vbcrlf&"@FileType:"&DimFileExt&vbcrlf
		Call ShowAllFile(Server.MapPath("."),0)
		Call DownFile()
	ElseIf Request.Form("radiobutton")="1" Then
			Set FE = CreateObject("Scripting.FileSystemObject")
			If FE.FileExists(Server.MapPath(".")&"\"&Request.Form("name2")) = False Then
					Response.Write("没有发现文件<font color=red>"&Request.Form("name2")&"</font>！请先将以前提取的网站文件上传到本程序目录!")
					Response.End()
			End If
			Set FE =  Nothing
		Call ShowAllFile(Server.MapPath("."),1)
		Report = True
		If x="" Then
			Result = "没有发现异常文件！时间："&Now
		Else
			Result = "发现异常文件<font color=""Red"">"&x&"</font>个，请注意了！时间："&Now
		End If
	Else
		Response.Write("错误：参数丢失！")
		Response.End()
	End If
End If


'遍历处理path及其子目录所有文件
Sub ShowAllFile(Path , Flag)
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set f = FSO.GetFolder(Path)
	Set fc2 = f.files
	For Each myfile in fc2
		If CheckExt(FSO.GetExtensionName(path&"\"&myfile.name)) Then
			If path<>Server.MapPath(".") Then
					Temp = Replace( Path , Server.MapPath(".")&"\" , "")&"\"
			End If
			If Flag=0 Then
					Str=Str&Temp&myfile.name&"@"&myfile.Size&"@"&myfile.DateLastModified&vbcrlf
			Else
					Call Compe( Temp&myfile.name , myfile.Size , myfile.DateLastModified )
			End If
		End If
	Next
	Set fc = f.SubFolders
	For Each f1 in fc
		ShowAllFile path&"\"&f1.name , Flag
    Next
	Set FSO = Nothing
End Sub

'检查文件后缀，如果与预定的匹配即返回TRUE
Function CheckExt(FileExt)
	If DimFileExt = "*" Then
		CheckExt = True
		Exit Function
	End If
	Ext = Split(DimFileExt,",")
	For i = 0 To Ubound(Ext)
		If Lcase(FileExt) = Ext(i) Then 
			CheckExt = True
			Exit Function
		End If
	Next
End Function

'下载数据
Sub DownFile()
	Response.AddHeader "Content-Disposition", "attachment; filename="&Request.Form("name1")
	Response.ContentType="application/ms-download"
	Response.Write(Str)
	Response.End()
End Sub

'比较文件找不同
Sub Compe(FName , FSize , FTime)
	exist=0
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set ts = FSO.OpenTextFile(Server.MapPath(".")&"\"&Request.Form("name2"), 1 , False)
	Do While (ts.AtEndOfStream = False)
			Content = ts.ReadLine
			If Left(Content,1)<>"@" And Lcase(FName)=Lcase(GetContent( Content , 1 )) Then
					exist = 1
					If Cstr(FSize) <> GetContent( Content , 2 ) Or Cstr(Ftime) <> GetContent( Content , 3 ) Then
						Str2=Str2&"<tr><td>"&FName&"</td><td  align=""center"">"&FSize&"/"&GetContent( Content , 2 )&"</td><td align=""center"">"&FTime&"/"&GetContent( Content , 3 )&"</td></tr>"&vbCrLF
						x = x + 1 
					End If
					Exit Do
			End If
	Loop
	If ts.AtEndOfStream = True And exist = 0 Then 
			Str2=Str2&"<tr><td>"&FName&"</td><td align=""center""  colspan=""3"">这个是上次提取信息后出现的文件</td></tr>"&vbCrLF
			x = x + 1 
	End If
	ts.close
	Set FSO = Nothing
End Sub

'得到文本里的内容
Function GetContent( Content , Num )
	temp = Split( Content , "@" )
	GetContent = temp(Num-1)
End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link href="Common/Style.css" rel="stylesheet" type="text/css">
<div id="All">
<div id="ShowMain">
  <div class="TitleBar">通过丰富的配置,您可以建立一个属于您自己的播客家园.</div>
  <div id="TabContent">
    <div class="ShowSimpleCon">
<DIV id=All>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP文件安全检查 1.0</title>
</head>
<body>
<table width="100%"  border="1" align="center" bordercolor="#000000">

<%	If Report = False Then	%>

  <tr>
    <td  colspan="3">
<%
If Session("InfoSec")<>"" Then
%>
	<form name="form1" method="post" action="">
  <p>
    <br>
    <input name="radiobutton" type="radio" class="TextBox" value="0">
  提取当前文件信息到这个文件：
  <input name="name1" type="text" class="TextBox" id="name1" value="网站文件信息.txt"> 
  （如果网站文件比较多的话就耐心一点）
</p>
  <p>  
    <input name="radiobutton" type="radio" class="TextBox" value="1">
    使用以前提取的信息进行检查：
    <input name="name2" type="text" class="TextBox" id="name2" value="网站文件信息.txt">
（需要把以前的信息文件传到所在目录）     </p>
  <p>     
    &nbsp;&nbsp;&nbsp;&nbsp;<input name="Submit" type="submit" class="buttom" value="提交"  onClick="alert('若网站文件很多，可能会花些时间。耐心一点吧，安全第一啊\n若出现脚本超时错误，就增加配置里的脚本超时时间');">
    <input name="ReSet" type="reset" class="buttom" id="ReSet" value="重置">
</p>
</form>
<%	Else	%>
	<form name="form1" method="post" action="">
     输入密码：
     <input name="pass" type="password" class="TextBox">
     &nbsp;
     <input name="Submit" type="submit" class="buttom" value="提交">
  </form>
<%	End If	%>
	</td>
  </tr>
<%	Else	%> 
    <tr>
    <td colspan="3"><div align="center">检查结果：<%=Result%></div></td>
  </tr>
  <tr>
    <td width="31%"><div align="center">异常文件（路径相对于本文件）</div></td>
    <td width="26%"><div align="center">文件现在的大小/原来的大小</div></td>
    <td width="43%"><div align="center">文件现在的修改时间/原来的修改时间</div></td>
  </tr>
  <%=Str2%>
<%	End If	%> 
   <tr>
 

</TD>
    </TR>
  </TBODY>
</TABLE>
<div align="center"><br>

</div>
</body>
</html>
  </div>
    <div style="clear:both"></div>
  </div>
</div>
<div class="FooterDiv">
<p class="Text"><span>Copyright &copy; 2006-2007 <a href="Http://Www.WuhU263.Cn/" target="_blank">芜湖播客家园</a> 版权所有. 并保留一切权利.</p>
</div>
</div>
</body>
</html>