Classes that manipulate XML

Source: Internet
Author: User
Tags add date end mail net servervariables version xml parser

' Site Validator 1.0.0
' Very simple concept, run this script on your server, it records the "file details to"
' XML file which you download and store. Then, when your come back to make changes can
"Run the XML file back through this script and it'll 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"
<title>aspvalidate, Site Validator <%=sVersion%></TITLE>
<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" XML entries and validate each one against this 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>"
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 &am P ", "
Response.Write "was" & Objnode.getattribute ("Size") & "Bytes-now" & CStr (objfile.size) & "Bytes<b R> "
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
If ldifferences = 0 Then
Response.Write "<p>the site matches the last update</p>"
Response.Write "<p>" & Ldifferences & "difference (s) detected in the above files</p>"
End If
<a href= "aspvalidate.asp" >back to the main page</a>
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.ContentType = "Text/html"
<title>aspvalidate, Site Validator <%=sVersion%></TITLE>
<p>this script would scan your entire Web site from the root folder, and a record of the file sizes and last modified date s for all ASP pages.
This is saved as XML. Then, at a later date, where you need to make adjustments or check anything, and you can load the XML into
This script again and it ' ll tell you which files have changed and when.</p>
Checksum all ASP files in this site and generate an XML Checksum file<br>
<a href= "Aspvalidate.asp?action=xml&html=0" >right-click here and select "Save as" to download for ASP files </a><br>
<a href= "Aspvalidate.asp?action=xml&html=1" >right-click here and select "Save as" to download for ASP and HTML F Iles</a><br>
<form action= "aspvalidate.asp" method= "post" enctype= "Multipart/form-data" Id=form1 name=form1>
Upload XML File of checksums and validate it against this site<br>
File: <input type=file name=xmlupload><br>
Show all results: <input Type=checkbox name=view><br>
<input type=submit name=action value= "Upload" >
End If

' Bit of ' recursion to traverse the folder structure building XML
Function ProcessFolder (Sfolder)
Dim objfolder, Objroot, objfile, Stemp, slastmodified, ssize

Set objroot = Objfso.getfolder (Sfolder)

Stemp = ""

For each objfile in Objroot.files,4 = ". asp" or (right (,5) = ". html" or right (,4) = ". htm") and Request ("HT ML ") = 1)) and InStr (Sfolder &" "&," _vti_cnf ") = 0 Then
Slastmodified = objfile.datelastmodified
Ssize = Objfile.size
Stemp = stemp & "<file path=" "& Sfolder &" "& &" ' modified= ' "" & Slastmodifie D & "' Size= '" "& Ssize &" '/> "& VbCRLF
End If

For each objfolder in Objroot.subfolders
Stemp = stemp & ProcessFolder (Sfolder & "" &

Set objfolder = Nothing

ProcessFolder = stemp
End Function

' Reques object proxy for uploads.
Class Proxyrequest
Public ClientCertificate
Public Cookies
Public Form
Public querystring
Public ServerVariables
Public TotalBytes

Private M_item

Public Default Property Get Item (Sindex)
Item = M_item (Sindex)
End Property

Private Sbinarytext

Public Function BinaryRead (ltotalbytes)
BinaryRead = LeftB (sbinarytext,ltotalbytes)
End Function

Private Sub parserequest ()
Dim Sdelimeter
Dim Lkeylength
Dim Lblockend
Dim Sblock
Dim stemp
Dim Sfield
Dim Lstart
Dim Llength
Dim sFileName
Dim Scontenttype
Dim scontent
Sblock = Sbinarytext
Lkeylength = InstrB (1,SBLOCK,CHRB (&h0d))-1
If lkeylength > 0 Then
Sdelimeter = LeftB (sblock,lkeylength)
Lblockend = 0
While Lblockend >= 0
' Chop off the key, including the cr/lf pair
Sblock = RIGHTB (Sblock,lenb (Sblock)-(lblockend + lkeylength + 2))
Lblockend = InStrB (1,sblock,sdelimeter)-1
If Lblockend >= 0 Then
Stemp = LeftB (sblock,lblockend-2)
Lstart = InStrB (1,stemp,unicodetoascii ("name=")) + 6
Llength = InStrB (LSTART,STEMP,CHRB)-Lstart
Sfield = MidB (stemp,lstart,llength)
Lstart = InStrB (1,stemp,unicodetoascii ("filename=")) + 10
Llength = InStrB (LSTART,STEMP,CHRB)-Lstart
If Lstart > Then
sFileName = MidB (stemp,lstart,llength)
Lstart = InStrB (1,stemp,unicodetoascii ("Content-type:")) + 14
Llength = InStrB (LSTART,STEMP,CHRB (&h0d))-Lstart
Scontenttype = MidB (stemp,lstart,llength)
sFileName = ""
Scontenttype = ""
End If
Lstart = InStrB (1,stemp,unicodetoascii (VbCRLF & VbCRLF)) + 4
Llength = LenB (stemp)-Lstart + 1
Scontent = MidB (stemp,lstart,llength)
If Asciitounicode (sfilename) <> "" Then
M_item.add Asciitounicode (Sfield), scontent
M_item.add Asciitounicode (Sfield) & "_filename", Asciitounicode (sFileName)
M_item.add Asciitounicode (Sfield) & "_contenttype", Asciitounicode (Scontenttype)
M_item.add Asciitounicode (Sfield), Asciitounicode (scontent)
End If
End If
End If
End Sub

Public Function unicodetoascii (stext)
Dim ltemp
Dim objstream
Set objstream = Server.CreateObject ("ADODB. Stream ")
For ltemp = 1 to Len (stext)
Objstream.writetext ChrB (ASC (stext,ltemp,1))
objstream.position = 0
Unicodetoascii = Objstream.readtext
End Function

Public Function Asciitounicode (stext)
' Do this with the stream, avoiding VBScript string concatenation, which are slow to say the least
Dim ltemp
Dim objstream
Set objstream = Server.CreateObject ("ADODB. Stream ")

For ltemp = 1 to LenB (stext)
Objstream.writetext MidB (Stext, Ltemp, 1) & ChrB (0), 0
objstream.position = 0
Asciitounicode = Objstream.readtext
End Function

Private Sub Class_Initialize ()
Set M_item = Server.CreateObject ("Scripting.Dictionary")
Set ClientCertificate = request.clientcertificate
Set Cookies = Request.Cookies
Set Form = Request.Form
Set querystring = Request.QueryString
Set ServerVariables = Request.ServerVariables
TotalBytes = Request.TotalBytes
Sbinarytext = Request.BinaryRead (request.totalbytes)
End Sub

Private Sub Class_Terminate ()
Set ClientCertificate = Nothing
Set Cookies = Nothing
Set Form = Nothing
Set querystring = Nothing
Set ServerVariables = Nothing
End Sub
End Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.