Spam Filter ISP Support Forum

  New Posts New Posts RSS Feed - Web page to modify SpamFilter.ini and rel
  FAQ FAQ  Forum Search   Register Register  Login Login

Web page to modify SpamFilter.ini and rel

 Post Reply Post Reply
Author
JeffHildebrand View Drop Down
Newbie
Newbie


Joined: 26 January 2005
Location: United States
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote JeffHildebrand Quote  Post ReplyReply Direct Link To This Post Topic: Web page to modify SpamFilter.ini and rel
    Posted: 01 November 2006 at 7:03pm

This is a very simple page for remote viewing and editing of your SpamFilter.ini and related .txt files.  It will create a backup of your current file when you save any changes, it will also show you a history of any changes so you may view any of the old settings and copy them.  It is best to run this on an authenticated web site, with appropriate permissions set on the files.

To Install:
- Copy the asp code below and create SpamConfig.asp on your webserver
- Create the directory ..\Spamfilter\OldSettings, for backups and logs in your Spamfilter installation directory
- Modify root paths as desired, default = C:\Program files\Spamfilter...

 

*code below, copy and paste into - SpamConfig.asp*

<html>
<body>
<%
'  USE AT YOUR OWN RISK.  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'  Intended use:
'   This asp page is designed to edit SpamFilter.ini and any .txt files located in the SpamFilter directory, it also keeps a running backup and log of any changes made through this page.
' Additional Information:
'   Highly recommended to only use this page on a website with authentication enabled, and applicable file security set appropriately to authorized users; i.e. WWWUSER should have not access to your SpamFilter directory.
'   Default root paths are hard coded here for additional security, this should only allow .txt files and SpamFilter.ini in that directory to be modified.
'   dirbackup is used to keep an archive of any changes made through this asp page (default setting requires the creation of the a folder OldSettings in the Spamfilter installation directory)
'   History of any changes is also kept in the dirbackup folder by adding ".log" to the end of the edited file, with links to display the backupfile.

 dirspam="C:\Program Files\SpamFilter\"
 dirbackup="C:\Program Files\SpamFilter\OldSettings\"
 filespam = "SpamFilter.ini"

'  check if file was carried over from form, if not check parameter sent to asp with ?file=, if still not found use SpamFilter.ini from above
 fileedit = request.form("fileedit")
 if fileedit="" then
  fileedit = request.querystring("file")
 end if
 if fileedit = "" then
  fileedit = filespam
 else
  if (right(fileedit,4)<>".txt") and (fileedit <> filespam) then
   fileedit = fileedit & ".txt"      'allow only .txt and spamfilter.ini edits
  end if
 end if
 set fs=Server.CreateObject("Scripting.FileSystemObject")
 
' Check if a showbackup file was request with showbackup=(backupfile)
 showbackup=request.querystring("showbackup")
 if showbackup<>"" then
  if fs.FileExists(dirbackup & showbackup) then
   ' read backup file
   set FName=fs.OpenTextFile(dirbackup & showbackup,1,  False , -2) 
   bkupContents = FName.ReadAll
   FName.Close 
  end if
 end if 
 if request.form("editing")="true" then
  Contents = request.form("Contents") 
  backupfile = "SFBU-" & year(now()) & right("0" & month(now()),2) & right("0" & day(now()),2) & "-" & right("0"  & hour(now()),2) & right("0" & minute(now()),2) & right("0" & second(now()),2) & "-"& fileedit
  'backup original file if it exists
  if fs.FileExists(dirspam & fileedit) then
   ' read original file
   set FName=fs.OpenTextFile(dirspam & fileedit,1,  False , -2) 
   bkupContents = FName.ReadAll
   FName.Close 
   ' write changes
   set FName=fs.OpenTextFile(dirbackup & backupfile,2,true)
   FName.writeline bkupContents
   FName.Close
   response.write("File Backed up to:" & dirbackup & backupfile & "<br>")
   'write out html log of edits
   set FName=fs.OpenTextFile(dirbackup & fileedit & ".log",8,true)
   htmlline="<a href=Spamconfig.asp?file=" & fileedit & "&showbackup=" & backupfile & ">" & backupfile &"</a><br>" & vbcrlf
   FName.writeline htmlLine
   FName.Close   
  end if
  ' write out the changes to the file
  set FName=fs.OpenTextFile(dirspam & fileedit,2,true)
  FName.writeline Contents
  FName.Close
  response.write("File Saved:" & dirspam & fileedit)
 else
  'read file
  if fs.FileExists(dirspam & fileedit) then
   set FName=fs.OpenTextFile(dirspam & fileedit,1,  False , -2) 
   Contents = FName.ReadAll
   FName.Close
  else
   response.write("New File:" & dirspam & fileedit)
  end if
 end if
%>
<form method="POST" action="SpamConfig.asp">
 <input type=hidden name="editing" value="true">
    <input type=hidden name="fileedit" value="<%=fileedit%>">
    <table border="0" cellpadding="0" cellspacing="0" width="780">
    <tr><td><%=fileedit%></td>
<% if showbackup<>"" then %>
 <td>  <%=showbackup%> </td>
<% end if %> 
   
 </tr>
<% if showbackup<>"" then %>
    <tr>
    <td>
    <textarea rows="44" name="Contents" cols="50"><%=contents%></textarea>
   </td>
 <td> 
  <textarea rows="44" name="Contents" cols="50" readonly="true"><%=bkupContents%></textarea>
 </td>
 </tr> 
<% else %> 
    <tr>
    <td>
    <textarea rows="44" name="Contents" cols="100"><%=contents%></textarea>
   </td>
 </tr> 
<% end if %> 
 </table>
  <table border="0" cellpadding="0" cellspacing="0" width="380">
    <tr>
      <td width="278"><p><input type="submit" value="Back" name="B1" onclick="javascript:history.back()"> </td>
      <td width="294"><p align="center"><input type="reset" value="Reset" name="B2"></p></td>
      <td width="275"><p align="right"><input type="submit" value="Save" name="B3"></p></td>
    </tr>
  </table>
</form>
<p>
Related files detected in <a href="SpamConfig.asp"><%=dirspam & filespam%></a>.
</p>
<ul>
<%
 'read default spamfilter.ini settings if needed for linksfile
  if fileedit <> filespam then
   if fs.FileExists(dirspam & filespam) then
    set FName=fs.OpenTextFile(dirspam & filespam,1,  False , -2) 
    Contents = FName.ReadAll
    FName.Close
   else
    response.write("SpamFilter.ini missing:" & dirspam & fileedit)
    response.end
   end if
  end if

' parse spamfilter.ini to scan for any filename= and provide links to edit them
 strContents = contents
 intFN = instr(strContents,"FileName=")
 while (intFN>1)
  intStart=1
   for intI=intFN to 1 step -1
    if mid(strContents,intI,2)=vbcrlf then
     intStart=intI+2
     intI=0
    end if
   next
   intEnd = instr(intFN,strContents,vbcrlf)
   strDesc = mid(strContents, intStart, intFN - intStart + 9)
   strName = mid(strContents,intFN + 9, intEnd -  intFN - 9)
   strLink = strName
   'remove any pathing, to only allow editing in defined spam filter directory
   for intI=len(strName) to 1 step -1
    if mid(strName,intI,1)="\" then
     strLink = mid(strName,intI+1,len(strName)-IntI)
     intI=0
    end if
   next
   
   if strname <>"" then
%>
   <li> <%=strDesc%><a href="SpamConfig.asp?file=<%=strLink%>"><%=strNa me%></a></li>
<%
   end if         &nbs p;         &nbs p;       
   strContents = mid(strContents,intEnd+1,65000)
   intFN = instr(strContents,"FileName=")
 wend  
 
 %>
 
 </ul>
 
 
 Backup File History
<ul>
 <%
 
'  Read any history log and display it
  if fs.FileExists(dirbackup & fileedit & ".log") then
   ' read log file
   set FName=fs.OpenTextFile(dirbackup & fileedit & ".log",1,  False , -2) 
   logContents = FName.ReadAll
   FName.Close 
   response.write(logContents)
  end if

'cleanup file handles
 
 set FName=nothing
 set fs=nothing 

%>

</ul>

</body>
</html>

 

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0.055 seconds.