日期:2009-12-20  浏览次数:20929 次

<%
'' Site validator 1.0.0
'' Very simple concept, run this script on your server, it records the file details to an
'' XML file which you download and store. Then, when you come back to make changes you can
'' run the XML file back through this script and it will tell you if any of the files have
'' been modified. Quite simple really.
'' Requires XML parser version 3 to work really. Also needs access to the FileSystemObject.
Dim objRequest, objFSO, sXML, objXML, objNode, objFile, lDifferences, sVersion, sDate

sVersion = "1.0.0"

Response.Expires = -1

Set objRequest = New ProxyRequest

if UCase(objRequest("action")) = "UPLOAD" then
Response.ContentType = "text/html"
%>
<HTML>
<HEAD>
<TITLE>ASPValidate, Site validator <%=sVersion%></TITLE>
</HEAD>
<BODY>
<h1>ASPValidate, Site validator <%=sVersion%></h1>
<h2>Author: Chris Read (<a href="mailtmrjolly@bigpond.net.au">Mail</a>, <a href="http://users.bigpond.net.au/mrjolly.">Web</a>)</h2>
<p>Validation results</p>
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objXML = Server.CreateObject("MSXML2.DOMDocument")
objXML.async = False

sXML = objRequest("xmlupload")

objXML.loadXML objRequest.ASCIIToUNICODE(sXML)

lDifferences = 0

'' Now we go through the XML entries and validate each one against that on the server
For Each objNode in objXML.documentElement.childNodes
 on error resume next
 Set objFile = objFSO.GetFile(objNode.getAttribute("path"))
 if err.number <> 0 then
  '' Problem with the file
  Response.Write "<b>"
  Response.Write objNode.getAttribute("path") & "<br>"
  Response.Write "^^^^ FILE HAS BEEN REMOVED<br>"
  Response.Write "</b>"
 else
  if CStr(objFile.DateLastModified) <> objNode.getAttribute("modified") or CStr(objFile.Size) <> objNode.getAttribute("size") then
   Response.Write "<b>"
   Response.Write objNode.getAttribute("path") & "<br>^^^^ Changed, "
   Response.Write "original: " & objNode.getAttribute("modified") & " modified: " & objFile.DateLastModified & ", "
   Response.Write "was " & objNode.getAttribute("size") & " bytes - now " & CStr(objFile.Size) & " bytes<br>"
   Response.Write "</b>"
   lDifferences = lDifferences + 1
  elseif objRequest("view") <> "" then
   Response.Write objNode.getAttribute("path") & "- File has not changed<br>"
  end if
 end if
 on error goto 0
Next
if lDifferences = 0 then
 Response.Write "<p>The site matches the last update</p>"
else
 Response.Write "<p>" & lDifferences & " difference(s) detected in the above files</p>"
end if
%>
<a href="aspvalidate.asp">Back to the main page</a>
</BODY>
</HTML>
<%
Response.End
elseif UCase(objRequest.QueryString("action")) = "XML" then
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

sXML = "<?xml version=''1.0''?>" & vbCRLF
sXML = sXML & "<!-- Generated by Site Validator " & sVersion & " -->" & vbCRLF
sXML = sXML & "<!-- Author: Chris Read -->" & vbCRLF
sXML = sXML & "<site>" & vbCRLF

sXML = sXML & ProcessFolder(Server.MapPath("/"))

sXML = sXML & "</site>" & vbCRLF

sDate = Year(Date()) & "-" & Month(Date()) & "-" & Day(Date())

Response.ContentType = "text/xml"
Response.AddHeader "Content-Disposition","attachment; filename=site" & sDate & ".xml;"
Response.Write sXML
Response.End
else
Response.ContentType = "text/html"
%>
<HTML>
<HEAD>
<TITLE>ASPValidate, Site validator <%=sVersion%&