Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 View Source Code and Edit with no FTP
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Helterskelter
Junior Member

United Kingdom
331 Posts

Posted - 03 December 2004 :  19:08:01  Show Profile  Visit Helterskelter's Homepage  Send Helterskelter an ICQ Message
This cool code i found at brinkster.com by Yahavbr

allows you to edit your web page, no matter if it's html, asp, xml, etc etc

This is great to make those silly little changes with out haveing to load you FTP program's etc etc.......
unless you luckly enough to host you own site and thus no need for this code.

All I've done is is edit inc_header to include the link under admin options so only admin has the link.


in Inc_header.asp find (mine is line 537,538 SHN modded site)

Response.Write " <tr>" & vbNewLine & _
" <td align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strFooterFontSize & """><a href=""admin_home.asp""" & dWStatus("Access the Forum Admin Functions...") & " tabindex=""-1"">Admin Options</a>



Then replace it with


Response.Write " <tr>" & vbNewLine & _
" <td align=""center""><font face=""" & strDefaultFontFace & """ size=""" & strFooterFontSize & """><a href=""admin_home.asp""" & dWStatus("Access the Forum Admin Functions...") & " tabindex=""-1"">Admin Options</a><br><A href=""admin_edit.asp"">Edit This Page</A>"


Then save the following code as "admin_edit.asp", and upload to your forum


<%
Option Explicit
Response.Buffer=True

'authorized username/password:
Public const ADMIN_USERNAME="admin"
Public const ADMIN_PASSWORD="admin"

'store this page name for later use
Public pageName
pageName=Request.ServerVariables("Script_Name")

'which page we have to edit?
Public pageToEdit
pageToEdit=Request.Form("pageToEdit")
If Len(pageToEdit)<1 Then
pageToEdit=Request.ServerVariables("HTTP_REFERER")
End If

'check if new contents been submitted:
If Request.Form("edit")="true" Then SaveFile()

'check if admin already logged in:
If Session("AdminLogged")="true" Then
PerformEdit()
End If
'validate username/password:
If Validation() Then
PerformEdit()
End If

'getting here means un-authorized user!
Response.Write("<H3><Font color=red>You are not authorized to use this page.</Font></H3>")
Response.Write("<A href='javascript:history.back();'>Return to previous page.</A>")
Response.END

Function Validation()
Dim username, password
Validation=False
username=LCase(Request.Form("username"))
If Len(username)<1 Then
AskForDetails()
End If
password=Request.Form("password")
If (username=LCase(ADMIN_USERNAME)) And (password=ADMIN_PASSWORD) Then Validation=True
End Function

Function AskForDetails()
Response.Write("<H3>This page required username and password.</H3>")
Response.Write("<Form action="""&pageName&""" method=""POST"">")
Response.Write("<Input type=hidden name=""pageToEdit"" value="""&pageToEdit&""">")
Response.Write("Username: <Input type=text name=""username""><BR>")
Response.Write("Password: <Input type=password name=""password""><BR><BR>")
Response.Write("<Input type=submit>")
Response.Write("</Form>")
Response.END
End Function

Function PerformEdit()
Session("AdminLogged")="true"
Dim fso, objFile
Dim strFilePath, strFileContents
Dim iRowsCount, iColsCount
strFilePath=GrabPath(pageToEdit)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strFilePath) Then
Set objFile=fso.OpenTextFile(strFilePath, 1) 'forReading
strFileContents=objFile.ReadAll
objFile.Close
Set objFile=Nothing
iRowsCount=GetRowsCount(strFileContents)
iColsCount=GetColsCount(strFileContents)
' strFileContents=Replace(strFileContents, Chr(34), Chr(34)&Chr(34))
If iRowsCount<15 Then iRowsCount=15
If iColsCount<20 Then iColsCount=20
Response.Write("<H3>Editing <Font color=blue>"&pageToEdit&"</Font>:</H3>")
Response.Write("<Table border=1><TR><TD>")
Response.Write("<H3><U>YOU MUST SAVE YOUR FILE BEFORE THE COUNTER BELOW REACH ZERO:</U></H3>")
Response.Write("<Form name='counterForm' onsubmit='return false;'>")
Response.Write("<Input type=text size=6 name='seconds' value='"&(Session.Timeout*60)&"' DISABLED><BR>")
Response.Write("<H5>(after this time passes, your session will expire)</H5>")
Response.Write("</Form>")
Response.Write("</TD></TR></Table>")
WriteCounterScript()
Response.Write("<Form action="""&pageName&""" method=""POST"">")
Response.Write("<Input type=hidden name=""edit"" value=""true"">")
Response.Write("<Input type=hidden name=""pageToEdit"" value="""&pageToEdit&""">")
Response.Write("<Input type=hidden name=""pagePath"" value="""&strFilePath&""">")
Response.Write("<Textarea name=""fileContents"" rows="&(iRowsCount+1)&" cols="&(iColsCount+1)&" >"&strFileContents&"</Textarea><BR><BR>")
Response.Write("<Center>")
Response.Write("<Input type=submit value=""Save File""><BR>")
Response.Write("<A href="""&pageToEdit&""">Cancel, and return to "&pageToEdit&"</A>")
Response.Write("</Center>")
Response.Write("</Form>")
Else 
Response.Write("<H3><Font color=red>Requested file, <B>"&strFilePath&"</B>, does not exist on the Server.</Font></H3>")
End If
Set fso=Nothing
Response.END
End Function

Function GrabPath(strAddress)
Dim strHost, iHostIndex, iHostLength
strHost=Request.ServerVariables("HTTP_HOST")
iHostIndex=InStr(strAddress, strHost)
If iHostIndex=0 Then
Response.Write("<H3><Font color=red>You can edit only pages of this site!</Font></H3>")
Response.END
End If
iHostLength=Len(strHost)
GrabPath=Server.MapPath(Mid(strAddress, iHostIndex+iHostLength, Len(strAddress)))
End Function

Function GetRowsCount(str)
Dim arrLines
arrLines=Split(str, VBCrLf)
GetRowsCount=UBound(arrLines)+1
'free memory:
Erase arrLines
End Function

Function GetColsCount(str)
Dim arrLines, x, iMaxLength
iMaxLength=0
arrLines=Split(str, VBCrLf)
For x=0 To UBound(arrLines)
If Len(arrLines(x))>iMaxLength Then
iMaxLength=Len(arrLines(x))
End If
Next
GetColsCount=iMaxLength
'free memory:
Erase arrLines
End Function

Function SaveFile()
If Session("AdminLogged")="" Then
Response.Write("<H3><Font color=red>Session expired, page not saved.</Font></H3>")
Exit Function
End If
Dim fso, objFile, strPath
Dim strContents
strPath=Request.Form("pagePath")
strContents=Request.Form("fileContents")
If Len(strContents)<1 Then
Response.Write("<H3><Font color=red>You can't delete this file.</Font></H3>")
Exit Function
End If
Set fso=Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strPath) Then
Set objFile=fso.CreateTextFile(strPath)
objFile.Write(strContents)
objFile.Close
Set objFile=Nothing
Response.Write("<H3><Font color=blue>File Saved Successfully.</Font></H3>")
Else 
Response.Write("<H3><Font color=red>File does not exist! You can't create new files.</Font></H3>")
End If
Set fso=Nothing
End Function

Function WriteCounterScript()
Response.Write("<script>")
Response.Write(" setTimeout(""Tick();"", 1000);")
Response.Write(" function Tick()")
Response.Write(" {")
Response.Write(" if (!document.all) return false;")
Response.Write(" var iSeconds=parseInt(document.counterForm.seconds.value);")
Response.Write(" var iMinutes=(iSeconds/60);")
Response.Write(" if ((iSeconds < 350)&&((iSeconds%60) == 0))")
Response.Write(" alert(""Warning! Only ""+iMinutes+"" minutes left to save you file."");")
Response.Write(" if (iSeconds <= 0) return false;")
Response.Write(" document.counterForm.seconds.value = (iSeconds-1)+'';")
Response.Write(" setTimeout(""Tick();"", 1000);")
Response.Write(" return true;")
Response.Write(" }")
Response.Write("</script>")
End Function
%>


The admin name and password is hardcoded so you will have to edit this to your options, but i'm sure someone can link with database.

Default being
admin
admin


Dave.
Senior Member

USA
1037 Posts

Posted - 03 December 2004 :  21:41:25  Show Profile
This would require that you set read/write access to the IUSR_<MachineName> account to your entire web folder to allow you to save.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.18 seconds. Powered By: Snitz Forums 2000 Version 3.4.07