%@Language = VBScript%>
<%Option Explicit%>
<%
'Begin buffering the HTML so that no data is sent to the client browser until all processing is finished on the servers end.
Response.Buffer = True
%>
<%
DIM postsArray() 'array of posts from text file
DIM postCount 'number of posts in total file
DIM i 'repeatedly used counting variable
DIM perform 'action the file is intended to perform
DIM fileLocation 'location of post file relative to this script file
DIM headerLocation 'location of content that is displayed at the top of each page relative to this script file
DIM headerContents 'contents of the header file
DIM newHeaderContents 'new contents of the header file
DIM footerLocation 'location of content that is displayed at the bottom of each page relative to this script file
DIM footerContents 'contents of the footer file
DIM newFooterContents 'new contents of the footer file
DIM deleteLocation 'location of deleted posts file relative to this script file
DIM postsPerPage 'amount of posts displayed on each page
DIM tableWidth 'width of table containing form and heading
Dim tableBg, personalInformationBg, msgBg, buttonBg 'Colors
DIM filePath 'path to file
DIM fileString 'FSO object
DIM theFile
DIM allPosts 'all the posts from text file (also doubles up for other similar variables)
DIM person 'users name
DIM message 'message typed by user
DIM email 'users email
DIM msn 'users msn address
DIM aim 'users aim account
DIM yahoo 'users yahoo account
DIM icq 'users ICQ UIN
DIM homepage 'users homepage
DIM datetime 'date and time (in String format) that user posted
DIM postedDatetime 'date and time (in String format) that user originally posted (used when editing a file, so users of site can still see when a post was originally posted
DIM password 'password for gaining access to admin areas
DIM pwd 'form entered password
DIM act 'action to be performed when in admin area
DIM postNumber 'id number of post to be edited/deleted
DIM submit 'variable for what button pressed
DIM signature 'signature appended to edited posts
DIM signatureToggle 'holds value defining whether a signature is placed in a posts message after editing
DIM importantText 'string holding hex for color of any important text that must stand out ( e.g. error messages, etc)
'get date and time from server
datetime=FormatDateTime(Date, 1) & " " & FormatDateTime(Now, 3)
'------------------------------------------------------------------------'
'-------------------------------READ HERE!-------------------------------'
' '
'NOTE: REMOVING COMMENTS MAY CAUSE THE SCRIPT TO CEASE OPERATING SINCE '
' THE ADMIN FUNCTION LOOKS FOR PARTICULAR COMMENTS!!! '
' '
'AUTHOR: Leigh McCulloch (http://www.shokem.com/) '
'Refer to file 'COPYING' for license. '
'Refer to file 'INSTALL' for installation instructions. '
'Refer to file 'ChangeLog' for release history and changes. '
' '
'To edit the header and footer of both pages, edit the files header.asp '
'and footer.asp. '
' '
'password for administration areas '
password="123" '
' '
'amount of posts displayed on each page '
postsPerPage=10 '
' '
'signature displayed below posts that have been edited. '
'set signature to "" if not wanting to display a signature '
signature=" (EDITED by Admin: " & datetime & ")" '
' '
'guestbook database file location, relative to this file '
'header file location and footer file location '
'for unix/linux server: must have '/' in front of file name '
'for windows server: must have '\' in front of file name '
fileLocation="/guestbook.txt" '
headerLocation="/header.asp" '
footerLocation="/footer.asp" '
' '
'deleted entries database file location, relative to this file '
'for unix/linux server: must have '/' in front of file name '
'for windows server: must have '\' in front of file name '
deleteLocation="/guestbook-deleted.txt" '(NOT YET IMPLMENTED) '
' '
'width of table containing form and heading for Sign Guestbook page '
tableWidth="400" '
' '
'Colors, in hex (Run on server first to see which color is which.) '
tableBg="FFFFFF" 'bg color of whole table and heading (not page bg) '
personalInformationBg="FFD96C" 'bg color for personal information box's '
msgBg="FFAA00" 'bg color for message text area box '
buttonBg="3ED85B" 'bg color for 'submit' button's box '
importantText="FF0000" 'text color for error messages, etc '
' '
' '
'-------------------------------||-CODE-||-------------------------------'
'-------------------------------\/------\/-------------------------------'
'set variables containing arguments
newHeaderContents = Request.Form("newHeaderContents")
newFooterContents = Request.Form("newFooterContents")
perform = replace(Request("perform"),"""",""")
signatureToggle = replace(Request("signatureToggle"),"""",""")
submit = replace(Request.Form("Submit"),"""",""")
act = replace(Request.Form("act"),"""",""")
pwd = replace(Request.Form("pwd"),"""",""")
postNumber = replace(Request.Form("postNumber"),"""",""")
email = replace(Request.Form("EMail"),"""",""")
msn = replace(Request.Form("MSN"),"""",""")
aim = replace(Request.Form("AIM"),"""",""")
yahoo = replace(Request.Form("Yahoo"),"""",""")
icq = replace(Request.Form("ICQ"),"""",""")
If (replace(Request.Form("Homepage"),"""",""")) = "http://" THEN
homepage = ""
ELSE
homepage = replace(Request.Form("Homepage"),"""",""")
END IF
If replace(Request.Form("Message"),"""",""") = "" THEN
message = "No Message"
ELSE
message = replace(Request.Form("Message"),"""",""")
END IF
If replace(Request.Form("Person"),"""",""") = "" THEN
person = "unkown"
ELSE
person = replace(Request.Form("Person"),"""",""")
END IF
'replace '^' with '^' - changed by Leigh McCulloch, 2002-11-05
person = replace(person,"^","^")
email = replace(email,"^","^")
msn = replace(msn,"^","^")
aim = replace(aim,"^","^")
yahoo = replace(yahoo,"^","^")
icq = replace(icq,"^","^")
homepage = replace(homepage,"^","^")
message = replace(message,"^","^")
'replace '|' with '|' - added by Leigh McCulloch, 2002-11-05
person = replace(person,"|","|")
email = replace(email,"|","|")
msn = replace(msn,"|","|")
aim = replace(aim,"|","|")
yahoo = replace(yahoo,"|","|")
icq = replace(icq,"|","|")
homepage = replace(homepage,"|","|")
message = replace(message,"|","|")
'check whether the user has logged in
IF ((NOT (Session("guestbookAgent") = "SKGB" AND (Session("pwd") = "SKGB" & postsPerPage & tableWidth & password & tableBg & personalInformationBg & msgBg & buttonBg & "SKGB"))) AND perform="admin") THEN
perform="login"
END IF
'read guestbook text file
IF (perform="post" OR perform="view" OR perform="details" OR (perform="admin" AND (act= "" OR ((act="restoreBackup" OR act="createBackup" OR act="options") AND NOT submit="Cancel") OR act="save" OR act="delete"))) THEN
'specify the file containing the posts
filePath=server.mappath(".") & fileLocation
'NOTE: Because adding post to beginning of file, can't use 'append' feature, must rewrite file.
'open the file for reading
Set fileString = CreateObject("Scripting.FileSystemObject")
IF (perform="admin" AND act="restoreBackup") THEN
IF fileString.FileExists(filePath & ".backup")=true THEN
Set theFile = fileString.OpenTextFile((filePath & ".backup"), 1, False)
'store all the posts in a variable and then close
allPosts = theFile.readall
theFile.Close
END IF
ELSEIF (perform="admin" AND act="options") THEN
filePath = server.mappath(".") & headerLocation
Set theFile = fileString.OpenTextFile(filePath, 1, False)
headerContents = theFile.readall
theFile.Close
filePath = server.mappath(".") & footerLocation
Set theFile = fileString.OpenTextFile(filePath, 1, False)
footerContents = theFile.readall
theFile.Close
ELSE
Set theFile = fileString.OpenTextFile(filePath, 1, True)
'store all the posts in a variable and then close
allPosts = theFile.readall
theFile.Close
END IF
END IF
IF (perform="admin" AND submit="Cancel") THEN
Response.Clear
Response.Redirect("?perform=admin")
ELSEIF perform="post" THEN
'open the file for writing
Set fileString = Server.CreateObject("Scripting.FileSystemObject")
Set theFile = fileString.OpenTextFile(filePath, 2, True)
'Write the contents of the text file
theFile.WriteLine(person)
theFile.WriteLine("|" & datetime)
theFile.WriteLine("|" & email)
theFile.WriteLine("|" & homepage)
theFile.WriteLine("|" & message & "^")
theFile.WriteBlankLines(1)
theFile.WriteLine(allPosts)
'Close the file and remove objects
theFile.Close
set theFile=nothing
set fileString=nothing
Response.Clear
Response.redirect("?perform=view")
ELSEIF (perform="admin" AND act="restore") THEN
Response.write("Restore From Recovery Backup File
")
Response.write("If you click 'OK', the current file will be deleted and replaced with the backup file.
The backup file is created each time a post is edited or deleted with the 'Administration' page. It is not created when users sign the guestbook, or when any other changes are made with the 'Administration' page (e.g. appearance changes, etc). It's only purpose is to serve as a resource if this script fails whilst you are editing or deleting a post.
NOTE: Once you click 'OK' the backup guestbook file will be copied over replacing the current guestbook file. The current guestbook file will be lost, and irrecoverable.
")
Response.write("
")
Response.write("
How To Make Effective Backups
")
Response.write("Click the button below to read this section.
")
Response.write("")
ELSEIF (perform="admin" AND act="backup") THEN
Response.write("Create Backup of Guestbook Post File
")
Response.write("If you click 'OK', the current backup file will be deleted and replaced with the current guestbook file.
The backup file is created each time a post is edited or deleted with the 'Administration' page. So this next time this happens, this file you are creating now will be overwritten. It is not however created when users sign the guestbook, or when any other changes are made with the 'Administration' page (e.g. appearance changes, etc). Similarily this backup will only hold the contents of the guestbook posts file, and not any other settings.
NOTE: Once you click 'OK' the backup guestbook file will be replaced with the current guestbook posts file. The current backup file will be lost, and irrecoverable.
")
Response.write("")
Response.write("
How To Make Effective Backups
")
Response.write("As you would notice, the backup features of this script only provide for those who have encounted problems while editing or deleting posts. The reason for this is because it would be pointless to create backups onto the same server as this script.
The role of a backup of this kind, is to provide a source of information, if the server with the original file, goes down or is somehow caused to lose data. Considering any backup functions would create a backup file onto the same server as original file, if the server went down you would lose both the original and the backup - defeating the purpose of it.
For this reason I suggest manual backup of files be used. Depending on how often people submit posts to this guestbook, a backup should be created every two days. This can be done by copying the file off the server (using FTP or HTTP is your server allows it) to another location. If a failure occurs, the backup file can then be used.
")
Response.write("")
ELSEIF (perform="admin" AND act="restoreBackup") THEN
IF fileString.FileExists(filePath)=true THEN
fileString.DeleteFile(filePath)
END IF
IF fileString.FileExists(filePath & ".backup")=true THEN
Set theFile = fileString.OpenTextFile(filePath, 2, True)
theFile.WriteLine(allPosts)
theFile.Close
Response.Clear
Response.redirect("?perform=admin")
ELSE
Response.write("ERROR: No Recovery Backup File exists in the same directory as this script file. If you feel this is incorrect, re-read the information on the previous page.")
END IF
ELSEIF (perform="admin" AND act="createBackup") THEN
IF fileString.FileExists(filePath & ".backup")=true THEN
fileString.DeleteFile(filePath & ".backup")
END IF
Set theFile = fileString.OpenTextFile((filePath & ".backup"), 2, True)
theFile.WriteLine(allPosts)
theFile.Close
Response.Clear
Response.redirect("?perform=admin")
ELSEIF (perform="admin" AND (act="save" OR act="delete")) THEN
'make backup of guestbook text file
'this is extremely necessary in this case,
'since if the script was to hav an error after deleting the file,
'and before rewriting it, all posts would be lost.
Set theFile = fileString.OpenTextFile((filePath & ".backup"), 2, True)
theFile.WriteLine(allPosts)
theFile.Close
'determine how many posts in total guestbook
postCount = 0
FOR i = 1 to len(allPosts)
IF mid(allPosts,i,1) = "^" THEN
postCount = postCount + 1
END IF
NEXT
'determine true post number from postNumber
postNumber = ((postCount+1)-postNumber)
REDIM postsArray(postCount-1) 'set array length
'place posts into seperate array index's instead of one String
FOR i=0 to postCount-1
postsArray(i) = left(allPosts,instr(allPosts, "^"))
allPosts = mid(allPosts,instr(allPosts, "^")+1)
NEXT
'create objest
Set fileString = Server.CreateObject("Scripting.FileSystemObject")
'remove the current guestbook file.
'This is necessary since some servers handle this operation differently.
'Because the file is getting smaller in length when deleting, some servers will retain
'anything not written over. And so will cause errors in the 'view' and other pages.
fileString.DeleteFile(filePath)
'create new file for edited guestbook entries
Set theFile = fileString.OpenTextFile(filePath, 2, True)
'write posts back to the index file FOR i=0 to postCount-1
IF (act="delete" AND i=postNumber-1) THEN
'write to deleted entries file (NOT YET IMPLEMENTED)
ELSEIF (act="save" AND i=postNumber-1) THEN
'get original post datetime
pipe = instr(postsArray(i),"|")
postsArray(i) = mid(postsArray(i),pipe + 1)
pipe = instr(postsArray(i),"|")
postedDatetime = left(postsArray(i),pipe - 1)
'write new values
theFile.WriteLine(person)
theFile.WriteLine("|" & postedDatetime)
theFile.WriteLine("|" & email)
theFile.WriteLine("|" & homepage)
theFile.Write("|" & message)
IF (NOT signature="" AND signatureToggle="1") THEN
theFile.Write(vbCrLf & vbCrLf)
theFile.WriteLine(signature)
END IF
theFile.Write("^")
theFile.WriteBlankLines(1)
ELSE
theFile.WriteLine(postsArray(i))
END IF
NEXT
'Close the file and remove objects
theFile.Close
set theFile=nothing
set fileString=nothing
Response.Clear
Response.Redirect("?perform=admin")
ELSEIF (perform="admin" AND (act="options" OR act="advoptions")) THEN
IF act="advoptions" THEN
Response.write("Advanced Options")
Response.write("
")
Response.write(" NOTE: Depending on the caching habits of your hosting server. The above scripts may take up to 20 minutes to change appearance. ")
Response.write(" Posts Per Page: " & postsPerPage)
Response.write(" Signature: " & signature)
Response.write(" (Inserted after edited posts)")
Response.write(" Table Width: " & tableWidth & " pixels")
Response.write(" (Sign Guestbook page only)")
Response.write("
Colors:")
Response.write(" Text Color: Must be edited in the header file.")
Response.write(" Table Background: #" & tableBg)
Response.write(" Personal Information Background: #" & personalInformationBg)
Response.write(" Message Area Background: #" & msgBg)
Response.write(" Submit Button Background: #" & buttonBg)
Response.write(" (Sign Guestbook page only)")
Response.write(" Important Text Color: #" & importantText)
END IF
Response.write("
NOT YET IMPLEMENTED These variables can be edited manually in the 'READ THIS!' section this script file (e.g. guestbook.asp).")
ELSEIF (perform="admin" AND (act="writeHeader" OR act="writeFooter")) THEN
IF act="writeHeader" THEN
filePath = server.mappath(".") & headerLocation
ELSE
filePath = server.mappath(".") & footerLocation
END IF
Set fileString = Server.CreateObject("Scripting.FileSystemObject")
fileString.DeleteFile(filePath)
Set theFile = fileString.OpenTextFile(filePath, 2, True)
IF act="writeHeader" THEN
theFile.Write(newHeaderContents)
ELSE
theFile.Write(newFooterContents)
END IF
theFile.Close
set theFile=nothing
set fileString=nothing
Response.Clear
Response.redirect("?perform=admin")
ELSEIF (perform="admin" AND act="logout") THEN
Session("guestbookAgent") = ""
Session("pwd") = ""
Response.Clear
Response.Redirect("?perform=admin")
ELSEIF (perform="login" AND act="checkPassword") THEN
IF pwd = password THEN
Session("guestbookAgent") = "SKGB"
Session("pwd") = "SKGB" & postsPerPage & tableWidth & password & tableBg & personalInformationBg & msgBg & buttonBg & "SKGB"
Response.Clear
Response.Redirect("?perform=admin")
ELSE
Response.Clear
Response.Redirect("?perform=login")
END IF
ELSEIF (perform="login") THEN 'added by Leigh McCulloch, 2002-11-09
Response.write(FormatDateTime(Date, 1) & " " & FormatDateTime(Now, 3))
Response.write("
Administration Login
")
Response.write("Please enter the Administration password below.
")
Response.write("")
ELSEIF ((perform="view") OR (perform="details") OR (perform="admin")) THEN
DIM pageNumber 'page number to display of guestbook
DIM maxNumberOfPossiblePosts 'maximum number of possible posts that could be held on the amount of pages
DIM difference 'difference between first post on page, and last post on page
DIM firstPostNumber 'number of first post on page
DIM lastPostNumber 'number of last post on page
DIM pageList 'list of page's available
DIM totalPages 'total amount of pages
DIM pipe 'pipeline used in variable assignment
DIM bracketNumber 'number that starts for each square bracket in the pageList
DIM distanceFromTensValue 'distance from the closest 'tens' value
pageNumber = Request("p")
IF pageNumber="" THEN
pageNumber=1 'if no page number selected, set to page 1 (latest posts)
END IF
'determine how many posts in total guestbook
postCount = 0
FOR i = 1 to len(allPosts)
IF mid(allPosts,i,1) = "^" THEN
postCount = postCount + 1
END IF
NEXT
'determine first and last post numbers to be published on current page
maxNumberOfPossiblePosts=pageNumber*postsPerPage 'maximum number of possible posts that could be held on the amount of pages
difference=((postCount/postsPerPage)-((-Int(-(postCount/postsPerPage-1)))-1))*postsPerPage-postsPerPage 'difference between first and last post number for page
IF postCount-1>=maxNumberOfPossiblePosts-postsPerPage THEN
IF (maxNumberOfPossiblePosts-postsPerPage+difference)<< "
END IF
totalPages=(-Int(-(postCount/postsPerPage-1)))
IF totalPages=postCount/postsPerPage THEN
totalPages=totalPages-1
END IF
FOR i=0 TO totalPages
bracketNumber = (-Int(-(totalPages/10)))*10-i
distanceFromTensValue = (-Int(-(totalPages/10)))*10-totalPages-1
IF (-Int(-((totalPages-(i-1))/10)))=(-Int(-((totalPages-(pageNumber-1-1))/10))) THEN
IF i=pageNumber-1 THEN
pageList=pageList & "["
pageList=pageList & (-Int(-(postCount/postsPerPage-i)))
pageList=pageList & "]"
ELSE
pageList=pageList & ""
pageList=pageList & (-Int(-(postCount/postsPerPage-i)))
pageList=pageList & ""
END IF
IF i=totalPages THEN
ELSE
pageList=pageList & " "
END IF
ELSE
i=i+9
bracketNumber = (-Int(-(totalPages/10)))*10-i-distanceFromTensValue
IF (bracketNumber+9)>totalPages THEN
bracketNumber = totalPages-8
END IF
pageList=pageList & "[" & (bracketNumber+9) & "-"
IF bracketNumber<=1 THEN
pageList=pageList & "1]"
ELSEIF bracketNumber+9=totalPages+1 THEN
pageList=pageList & (bracketNumber+distanceFromTensValue) & "] "
i=i-distanceFromTensValue
ELSE
pageList=pageList & (bracketNumber) & "] "
END IF
END IF
NEXT
IF (pageNumber-1)>=totalPages THEN
pageList=pageList & " >>"
ELSE '
pageList=pageList & " >>"
END IF
'write html for heading and top of table
Response.write("
")
Response.write("
")
Response.write("
")
Response.write("
")
Response.write("
")
Response.write("
Guestbook: ")
IF perform="admin" THEN
Response.write("Administration")
ELSE
Response.write("Read the Guestbook")
END IF
Response.write(": Page " & (-Int(-(postCount/postsPerPage-(pageNumber-1)))))
Response.write("
")
'write form linking to 'advanced options' editing - added by Leigh McCulloch, 2002-11-09
IF perform = "admin" THEN
Response.write("")
Response.write("")
Response.write("")
END IF
'write link to 'sign guestbook' page
Response.write("Sign the Guestbook
")
'write page list links
Response.write(pageList)
Response.write("
")
'write start of table
Response.write("
")
'create variables and write them inside html
FOR i=firstPostNumber to lastPostNumber-1
allPosts = postsArray(i)
'replace '<', '>' with '<', '>' - added by Leigh McCulloch, 2002-11-04
allPosts = replace(allPosts,">",">")
allPosts = replace(allPosts,"<","<")
'Person
pipe = instr(allPosts,"|")
person = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'Date and Time
pipe = instr(allPosts,"|")
datetime = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'EMAIL
pipe = instr(allPosts,"|")
email = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'MSN
pipe = instr(allPosts,"|")
msn = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'AIM
pipe = instr(allPosts,"|")
aim = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'Yahoo!
pipe = instr(allPosts,"|")
yahoo = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'ICQ
pipe = instr(allPosts,"|")
icq = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'Homepage
pipe = instr(allPosts,"|")
homepage = left(allPosts,pipe - 1)
allPosts = mid(allPosts,pipe + 1)
'Message
allPosts = trim(allPosts)
IF perform="admin" THEN
message = allPosts
ELSE
message = replace(allPosts,vbcrlf," ")
END IF
'write to html for posts viewing/editing
IF perform="admin" THEN
Response.write("")
NEXT
'write end of table
response.write("
")
'write page list links
Response.write(pageList)
'write end of other tables
response.write("
")
END IF
'-------------------------------/\------/\-------------------------------'
'-------------------------------||-CODE-||-------------------------------'
'-------------------------------||------||-------------------------------'
%>
<% 'To support and respect the Author (Leigh McCulloch), please do not remove the code below.
Response.write("