Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need script to write to XML doc

Status
Not open for further replies.

bingoldsby

Technical User
Jan 24, 2002
68
0
0
US
In another discussion on this board
(I have been trying to find a way to take the output of an HTML form (one field - email address) and add it into a section of an existing XML document. That doc is a whitelist - part of an email filter set in xml.

I don't want programming advice (I'm not a perl programmer and couldn't use it). I need the whole perl script, which will look for a specific line like this:

<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>

...or just the part "zyxxxyz," and replace it with that same line + cr/lf + that line again, but with the email address gathered from the form field in place of the zyxxxyz.

I have been trying to use a perl script which will search and replace text in any text document (which xml is), using a form which contains the text to search for (that whole "expression" line) contained in a hidden input form field, but the punctuation of the xml line interferes with the html in the form and everything breaks after that.

My guess is that the form should only gather the email address, send it to the script, and the script find the same line each time and make the addition, then rewrite the rest of the xml file. There is no efficiency issue what-so-ever, as the addition of an email address to the xml whitelist will only be done form the local network at our organization (Union Gospel Mission - Yakima, WA) and only occassionally at that.

If someone has a solution, I'd deeply appreciate having it. My next approach is to offer money. (But don't forget, we're a non-profit charitable organization - with little extra money to spend).

Hope this explanation is clear enough.

Thanks,

Brian
 
What is zyxxxyz? Is it an email address with an AT symbol in it?

The problem doesn't sound complicated but I could use more information about the input and output.

Are you trying to get this line
<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>

to

<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>cr/lf

?

Thanks
Bruce

 
Hi, Bruce,

Thanks for the reply. The zyxxxyz has no significance except to be something in the line that can be identified for a search and not likely to be used by a spammer which would cause it to be passed by the filters (that's what the line does at that place in the xml file). My gobbledegook is valid as a string in that position and does not have to be a qualified email address or domain name.

My thinking is that the search & replace would be done on the whole line and when found, that line would be rewritten (so as to be left behind to search for again) and added to that line, would be a cr/lf (to get onto a new line) and the addition of a similar line with the new actual email address.

Maybe this scheme is not needed by a script, but rather the original line left alone and a new line inserted for the writing of the new email address.

The thread which referenced in the above message contains the contents of the xml file. The beginning of the Email address section has that line in it.

Is that more clear? As you can tell, I don't have programming-like thinking on this, so that's why I have asked for help.

Thanks again,

Brian
 
Ok so you want to search for a line like

<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>

and replace it with

zyxxxyz

?

What about $str =~ s/<expression[^\>]*>([^\<]*)\<\/expression\>/$1\n\r/g;

This line should search a string and remove the xml stuff and replace with just the content.

I'd like to see some real examples from the file to make sure I understand what you are after.

This example was written off the top of my head and is completely untested.

Thanks
Bruce
 
Bruce,

I'm sorry that you miss the point. The user fills in the form with an email address that is to be added to the whitelist, which is an xml document.

1. I put the line in with the zyxxxyz because it is valid xml code and will not mess up the parsing.

2. It is there at the point that I want to insert another line just like it - which contains a valid email address, but there only to use to search for something that will not change. (yes, I could have used the line above it)

3. The inserted email address comming from the input of the HTML form which has called the script.

In the first part of this discussion, I said I couldn't use programming suggestions. I still can't. I need the entire Perl script written for me.

Thank you for your time.

Brian
 
Here's a script that was written by a fellow on another one of the boards at this site - the xml board.

He has provided me with a modified form and the perl script. I can't get it to work and he can't test what he's written as he doesn't have Perl installed.

Can someone look at this and see if any sense of it can be made.

As it is configured now, the form should just pass the email address to the cgi script and the script finds the file and writes the line. I don't know enought to validate this or know if it's written correctly. Perhaps someone here can.

#!c:\perl\bin\perl.exe

# The following accepts the data from the form and splits it into its component parts

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

# Read XML file to array of strings

$xml_file="c:\program files\merak\whitelist_test.xml";
open(XML, $xml_file) || die("Could not open file!");
@xml=<XML>;
close(XML);

# Write XML back to file, adding email

open(XML,">>$xml_file") || die("Cannot Open File");
foreach $line (@xml) {
print XML $line;
if ($line == "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">zyxxxyz</expression>") {
print XML "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">$FORM{email}</expression>"
}
}
close(XML);

# Write the thank you page

print "Content-type: text/html\n\n";

print <<EndStart;

<html>
<head>
<title>Thank You</title>
</head>

<body bgcolor="#ffffff" text="#000000">

<h1>Thank You</h1>

<p>Your email address has been stored.</p>

</body>
</html>

EndStart

Thanks for any help. I'll include the html form if needed.

Brian
 
If you attach the form I'll run it here

I think I can finally see what you want to do

The file produced should be

<XML>
<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>
<expression casesensitive="no" type="regex" onmatch="score += 1">someone@somewhere.com</expression>
<expression casesensitive="no" type="regex" onmatch="score += 1">user@website.com</expression>
</XML>


Bruce
 
Yes, that looks right.

The form... and thanks.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
  <head>
    <title>Enter the title of your XHTML document here</title>
    <style type="text/css">
body {
  margin : 0px 0px 0px 0px;
}
#left {
  float: left;
  width: 10%;
  height: 100%;
  background-color: gray;
}
#main {
  float: left;
  padding: 10px;
}
#main h1 {
  text-align: center;
  font-size: small;
}
.center {
  text-align: center;
}  
    </style>
  </head>
  <body>
    <div id="left">&#160;</div>
    <div id="main">
      <h1>Whitelist Editor</h1>
      <form action="whitelist_editor.cgi" method="post">
        <p>This page can be used to add email addresses to the "WHITELIST"</p>
        <p>
          <strong>Each address must be added one at a time.</strong>
        </p>
        <p>
          <label for="email">Email Address:</label>
          <input id="email" type="text" name="email" />
        </p>
        <p class="center">
          <input type="submit" value="Add Address" />
        </p>
      </form>
    </div>
  </body>
</html>
 
Just incase... here is the xml file it is set up to operate on.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<filters>
		<filter name="primary">
			<log>
				<option type="match true" />
				<option type="rules with match" />
				<option type="execution" />
			</log>
			<results default="accept">
				<result key="accept">
					<return>0</return>
					<copy enabled="no" createdir="no">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,
&quot;{smtp:rcpt_to_domain}&quot;,&quot;accept&quot;,&quot;default&quot;,
&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\\{smtp:rcpt_to_domain}\{smtp:rcpt_to_mailbox}\\{source:filename}{smtp:recipient_id}.txt&quot;
\r\n">c:\regexflt\accepted\{yyyy}-{mm}\log.txt</copy>
					<imap enabled="no" createdir="no">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
				</result>
				<result key="accept_do_nothing">
					<return>0</return>
				</result>
				<result key="mark">
					<return>0</return>
					<copy enabled="no" createdir="no">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,&quot;
{smtp:rcpt_to_domain}&quot;,&quot;mark&quot;,&quot;whitelist&quot;,
&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\\{smtp:rcpt_to_domain}\{smtp:rcpt_to_mailbox}\\{source:filename}{smtp:recipient_id}.txt&quot;
\r\n">c:\regexflt\accepted\{yyyy}-{mm}\log.txt</copy>
					<imap enabled="no" createdir="no">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
					<modifysource enabled="no">
					  <header enabled="no" action=
"add" item="X-RegEx-Filter" value="regex_whitelist.xml" />
					  <header enabled="no" action=
"add" item="X-RegEx-Filter-Title" value="{result:rule:title}" comment=
"Not yet implemented" />
					  <header enabled="no" action=
"add" item="X-RegEx-Filter-UID" value="{result:rule:uid}" comment=
"Not yet implemented" />
					</modifysource>
				</result>
				<result key="mark_high">
					<return>0</return>
					<copy enabled="no" createdir="no">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,
&quot;{smtp:rcpt_to_domain}&quot;,&quot;mark_high&quot;,&quot;
whitelist&quot;,&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\{smtp:rcpt_to_domain}\\{smtp:rcpt_to_mailbox}\\{source:filename}
{smtp:recipient_id}.txt&quot;\r\n">c:\regexflt\accepted\{yyyy}-{mm}log.txt</copy>
					<imap enabled="no" createdir="no">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
					<modifysource enabled="yes">
					  <header enabled="no" action=
"add" item="X-RegEx-Filter" value="regex_whitelist.xml" />
					  <header enabled="no" action="replaceoradd" item="Importance" value="High" />
					  <header enabled="no" action="replaceoradd" item="X-Priority" value="1 (Highest)" />
					  <header enabled="no" action=
"add" item="X-RegEx-Filter-Title" value="{result:rule:title}" comment=
"Not yet implemented" />
					  <header enabled="no" action=
"add" item="X-RegEx-Filter-UID" value="{result:rule:uid}" comment="Not yet
 implemented" />
					</modifysource>
				</result>
			</results>
			<parser>
				<maxlines>10000</maxlines>
				<maxbuffer>500000</maxbuffer>
				<quickresult>yes</quickresult>
			</parser>
			<rules>
				<rule result="accept_do_nothing">
					<title>Whitelist MAIL FROM (do nothing)</title>
					<comment>Allow all email from these
 addresses (outbound mailing lists)</comment>
					<scope>
						<mailfrom>all</mailfrom>
					</scope>
					<expressions oninit="score=0" logic="return score > 0">
						<expression casesensitive="no" type="regex" onmatch="score += 1">clinic@yugm\.org</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">lcv@yugm\.org</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">lighthouseshoppe@yugm\.org</expression>
					</expressions>
				</rule>
				<rule result="mark_high">
					<title>Secret phrase</title>
					<comment>Secret phrase to force email to be accepted unconditionally. Any email containing one of these phrases will be accepted.</comment>
					<scope>
						<header>all</header>
					</scope>
					<expressions oninit="score=0" logic="return score > 0">
						<expression casesensitive="no" type="regex" onmatch="score += 1" comment="Secret phrase or word">prayer</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1" comment="Secret phrase or word">\[accept\]</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1" comment="Secret phrase or word">\[AGRM-LIST\]</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1" comment="Secret phrase or word">\[DEVELOPMENT\]</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1" comment="Secret phrase or word">board meeting</expression>
					</expressions>
				</rule>
				<rule result="mark">
					<title>Whitelist MAIL FROM</title>
					<comment>Allow all email from these addresses</comment>
					<scope>
						<mailfrom>all</mailfrom>
					</scope>
		<expressions oninit="score=0" logic="return score > 0">
	<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">register4less\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">pc@max\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">Dave\.Benefiel@avenuea-razorfish\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">bcms@auna\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ssg2359@comcast\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">HavenatYakima@aol\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ericstoothoff@charter\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">gbliss@blisspages\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">teresa@thehomestead\.info</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">mopar@gorge\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">jodi_sargent81@yahoo\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">johnhatfield@comcast\.net></expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">jonathan@zav\.om\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">martinlopez1957@msn\.co</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ericstoothoff@charter\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">familiesnorthwest\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">diersinc\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">envelopeconverting\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">pastordennis@yakimatbc\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">digitalriver\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">xpedx\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ipaper\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">danieleburrow@yahoo\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">hsabank\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">FloydPeg@aol\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">f-prot\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">\bugm\.org\b</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">patricia_2005@earthlink\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">Christloves9@aol\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">timelesstexts\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">pat dodd</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">rescuecollege\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">chris@servantchurch\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">digikey\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">Christloves9@aol\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">nsadownick@bellintl\.ca</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">abbotts\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">accs\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">biblestudylessons\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">billygraham\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">chaplainjim</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">christianbook\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">culver@spiritone\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">danieleburrow@earthlink\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">designedhometheater\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">desiringgod\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">editpadpro\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">editwrx\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">feinsteinfoundation\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">fern@rockisland\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ga\.wa\.gov</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">goldwinggadgets\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">gospelway\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">griff208@charter\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">hp\.com</expression>regexbuddy.com
	<expression casesensitive="no" type="regex" onmatch="score += 1">hrcaerica@hm\.honda\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">icewarp\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">charter\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">Linda@pedersonbros\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">lindsund@comcast\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">lists.cciusa\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">lists.gospelcom\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">lmhsoft\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">lynnnathe@msn\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">martinlopez1957@msn\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">mcafee\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">mikeeclark@hotmail\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">nwinfo\.net</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">online-bible-college\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">onPhilanthropy\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">paypal\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">pilgrim@gracegems\.org</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">raldrich@owt\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">rcpddp@hotmail\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">Register4less\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">rejoyce3@msn\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">reply\.ebay\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">rob@powerviewsystems\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">simpledns\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">sosexchange1</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">ssutton@edcc\.edu</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">taspro6support</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">tharp_m@televar\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">walkintheword\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">weightwatchers\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score += 1">xecute\.com</expression>
	<expression casesensitive="no" type="regex" onmatch="score -= 1">service@paypal\.com</expression>
		</expressions>
				</rule>
				<rule result="mark">
					<title>Whitelist RCPT TO</title>
					<comment>Allow all email from these addresses (can be used to effectively disable filtering to specific users/domains, though the index is a better way to do this</comment>
					<scope>
						<rcptto>all</rcptto>
					</scope>
					<expressions oninit="score=0" logic="return score > 0">
					</expressions>
				</rule>
				<rule result="mark">
					<title>Whitelist body</title>
					<comment>Whitelist based on these expressions being in the body of an email</comment>
					<scope>
						<body>all</body>
					</scope>
					<expressions oninit="score=0" logic="return score > 0">
			<expression casesensitive="no" type="regex" onmatch="score += 1">EVHS1985</expression>
					</expressions>
				</rule>
			</rules>
		</filter>
		<filter name="secondary">
			<log>
				<option type="match true" />
				<option type="rules with match" />
				<option type="execution" />
			</log>
			<results default="accept">
				<result key="accept">
					<return>0</return>
					<copy enabled="no" createdir="no">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,
&quot;{smtp:rcpt_to_domain}&quot;,&quot;accept&quot;,&quot;default&quot;,
&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\\{smtp:rcpt_to_domain}\{smtp:rcpt_to_mailbox}\\{smtp:rcpt_to_domain}\\{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt&quot;\r\n">c:\regexflt\accepted{yyyy}-{mm}\log.txt</copy>
					<imap enabled="no" createdir="yes">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
				</result>
				<result key="mark">
					<return>0</return>
					<copy enabled="no" createdir="yes">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,&quot;
{smtp:rcpt_to_domain}&quot;,&quot;mark&quot;,&quot;whitelist&quot;,
&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\\{smtp:rcpt_to_domain}\{smtp:rcpt_to_mailbox}\\{smtp:rcpt_to_domain}\\{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt&quot;\r\n">c:\regexflt\accepted{yyyy}-{mm}\log.txt</copy>
					<imap enabled="no" createdir="yes">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
					<modifysource enabled="yes">
					  <header enabled="yes" action="add" item="X-RegEx-Filter" value="regex_whitelist.xml" />
					  <header enabled="no" action="add" item="X-RegEx-Filter-Title" value="{result:rule:title}" comment="Not yet implemented" />
					  <header enabled="no" action="add" item="X-RegEx-Filter-UID" value="{result:rule:uid}" comment="Not yet implemented" />
					</modifysource>
				</result>
				<result key="mark_high">
					<return>0</return>
					<copy enabled="no" createdir="yes">c:\regexflt\accepted\{yyyy}-{mm}\{smtp:rcpt_to_domain}{smtp:rcpt_to_mailbox}\{source:filename}{smtp:recipient_id}.txt</copy>
					<copy enabled="no" operation="append" mail="no" append="&quot;{smtp:client_ip}&quot;,&quot;{smtp:helo}&quot;,&quot;
{smtp:mail_from}&quot;,&quot;{smtp:rcpt_to}&quot;,&quot;{mm}/{dd}/{yyyy} {HH}:{MM}:{SS}&quot;,&quot;{smtp:mail_from_mailbox}&quot;,&quot;
{smtp:mail_from_domain}&quot;,&quot;{smtp:rcpt_to_mailbox}&quot;,
&quot;{smtp:rcpt_to_domain}&quot;,&quot;mark_high&quot;,&quot;
whitelist&quot;,&quot;c:\\regexflt\\accepted\\{yyyy}-{mm}\{smtp:rcpt_to_domain}\\{smtp:rcpt_to_mailbox}\\{source:filename}
{smtp:recipient_id}.txt&quot;\r\n">c:\regexflt\accepted\{yyyy}-{mm}log.txt</copy>
					<imap enabled="no" createdir="yes">c:\Program Files\Merak\mail\2150.com\rejectedmail\RegEx Accepted\{source:filename}{smtp:recipient_id}.imap</imap>
					<http enabled="no">[URL unfurl="true"]http://localhost/2150/regexflt_test.asp</http>[/URL]
					<modifysource enabled="yes">
					  <header enabled="yes" action="add" item="X-RegEx-Filter" value="regex_whitelist.xml" />
					  <header enabled="yes" action="replaceoradd" item="Importance" value="High" />
					  <header enabled="yes" action="replaceoradd" item="X-Priority" value="1 (Highest)" />
					  <header enabled="no" action="add" item="X-RegEx-Filter-Title" value="{result:rule:title}" comment="Not yet implemented" />
					  <header enabled="no" action="add" item="X-RegEx-Filter-UID" value="{result:rule:uid}" comment="Not yet implemented" />
					</modifysource>
				</result>
			</results>
			<parser>
				<maxlines>1000</maxlines>
				<maxbuffer>10000</maxbuffer>
				<quickresult>yes</quickresult>
			</parser>
			<rules>
				<rule result="mark">
					<title>Whitelist subject</title>
					<comment>Exclude subject lines with a date at the end or with "order"/"confirm"/"reservation" in them to catch online orders and reservations that append an order # that otherwise would flag immediately as SPAM.</comment>
					<scope>
						<header>all</header>
					</scope>
					<expressions oninit="score=0" logic="return score > 0">
						<expression casesensitive="no" type="regex" onmatch="score -= 10" comment="If viagra is in the subject, don't allow whitelist subjects to work">^subject:.+\bv[iI1]agra\b</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Exclude any from address with 'advize'">^from:.+advize</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Exclude any subject with 'debt'">^subject:.+debt</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it starts with 'you can'">^subject:.+\byou can order\b</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'diet'">^subject:.+\bdiet</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'drugs'">^subject:.+\bdrugs</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'log in'">^subject:.+\blog +in</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'medication'">^subject:.+\bmedication</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'meds'">^subject:.+\bmeds</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'offer confirmation'">^subject:.+\boffer +confirmation</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'order approved'">^subject:.+\border +approved</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'penis'">^subject:.+pen[iIl1]s</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'porno'">^subject:.+p[oO0]rn[oO0]</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'virgin'">^subject:.+\bv[iI1]rg[iI1]n</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'waiting on your'">^subject:.+\bwaiting +on +your</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'we want'">^subject:.+\bwe +want</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'xanax'">^subject:.+\bxanax</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'order' if it has 'you can order'">^subject:.+\byou +can +order</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">^subject:.+\border\b</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'confirm' if it has 'your information'">^subject:.+\byour +information</expression>
						<expression casesensitive="no" type="regex" onmatch="score -= 1" comment="Don't whitelist based on 'confirm' if it has 'as seen on">^subject:.+\bas +seen +on</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">^subject:.+\bconfirmation</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">^subject:.+\breservation</expression>
						<expression casesensitive="no" type="regex" onmatch="score += 1">^subject:.+\bshipment</expression>
					</expressions>
				</rule>
			</rules>
		</filter>
	</filters>
</configuration>
 
Ok I can see your problem I think

In the program

if ($line == "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">zyxxxyz</expression>") {
print XML "<expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">$FORM{email}</expression>"

Now if I look at the XML file I see

<expression casesensitive="no" type="regex" onmatch="score += 1">zyxxxyz</expression>

The problem is the line has either spaces or a tab at the start of the line. You need to check the file and see if it's spaces or a tab or something else

Try using

if ($line == " <expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">zyxxxyz</expression>") {
print XML " <expression casesensitive=\"no\" type=\"regex\" onmatch=\"score += 1\">$FORM{email}</expression>"

Where the spaces are the same as whats in the XML file

Bruce
 
Thanks, Bruce,

That's pretty elementary, of course, and I didn't think about it.

I'm just getting started this morning and will give it a try.

Brian
 
No... the form/script still does nothing. No server error messages (either returned, or in the Apache log files) and no changes to the XML file either.

I changed the xml file and removed the tabs in front of that search line. I also have been looking at the xml files properties and it shows only the file being modified at the time I changed those line, and no updates as I try to run the script. Seems like if the file is being opened and written to and saved, there should me indications of it in file properties.

I'm looking for some way to debug the script on my own - it's short and not too complicated for a beginner. But if you know of some easy lines to add which would indicate whether the xml file is being opened or not - or being rewritten and saved or not, please help me with that.

Brian
 
One further thing, when I load the form via the webserver (Apache Win) across the network and run it, I get a popup dialog box with the message "c is not a registered protocol"

That, using Firefox. IE6 just does nothing, or shows nothing.
 
Ok Whats the operating system on the server?

The line

#!c:\perl\bin\perl.exe

refers to a windows server

This line is custom for each machine depending on where the perl files are kept

My linux server uses the line

#!/usr/bin/perl

Try using my line if it's linux

Bruce
 
Bruce,

Please read my previous post (just above your last one) which clearly indicates that I am using Apache on Windows.

My shebang line is correct. I am using it in several other Perl scripts which run successfully on that server.

So far I have had a bit of success discovering where a problem lies in the script.

I am going to continue this in another discussion and try to make everything as completely clear and explanitory as I can.

Thanks and stay tuned.

Brian

 
I don't want programming advice (I'm not a perl programmer and couldn't use it). I need the whole perl script,

This is a place for people who want to learn. There are commercial offerings for people who just want complete solutions.

f

[&quot;]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.[&quot;]
--Maur
 
Fish,

I just read the etiquite and protocol requirements for this board late last night. I understand now the mistake that I have made in asking for a complete solution. Unfortuanately I have been unable to find anything close to what I need as a commercial product, or anyone who wants to make a buck from me.

I hope this doesn't wreck my chances of getting continued help here. This is a small piece of work, I'm sure, and I'm trying like hell to learn enough to get it going. But I'm in way over my head and am now thinking I better stick to my piano playing, just continue to open the xml files and add email addresses as needed, and leave the learning of this stuff to those who are much smarter than I.

As long as I've been trying to figure this thing out, it's been nothing but a big fat dissappointment.

Sorry for the intrusison here.

Brian
 
it might work, but this line:

if ($line == "

is using the numeric comparison operator "==" when it should be using the string comparison operator "eq"

if ($line eq "

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top