PHP/shell script]

brad brad at ispn.net
Fri Aug 15 19:08:45 CDT 2003


Thanks Paul!

My script starts by receiving from the form mail the $email and the
action=0/1.  I first check the action to set whether it is going to try
to append 'RELAY' or '550 REJECT'.

if ($action=="1") {
        $status="550tREJECT - We Do Not Accept SPAM!";
} else {
        $status="RELAY";
}

This seems to work fine.

Based on the posts by Rob and Brian, I need to parse the user entry here
for security.  I have looked at string manipulation and regular
expressions, but it's over my head at this point.

Now I need to check the access file for a match.  I have tried 

$page = implode ('', file ('/etc/mail/access2'));

if (preg_match("/b$emailb/i","$page")){
      print "That address is already blocked.<br><br>";
      }else{      print "No Matches Found, Good To Go!<br><br>";

A co-worker found an example that we think is similar, but I don't
understand it.  The problem with this I think is that if someone enters
an entire domain like spammer.org it will see a previous entry of
loser at spammer.org and think it is a match.  To be honest I don't
understand what the above code is doing.  I would like to add to this
part of the script the ability to return not only that a match was
found, but whether it has a block or allow associated with it.  Maybe
after I learn more I could expand on that to allow user interaction to
change the entry instead of just ending because a match was found.

Again with the help of a co-worker I have a chunk that seems toc work
fine at opening the access file and appending $email with the associated
action.

      $out = fopen("/etc/mail/access2", "a");
      print "Adding Your Entry...<br><br>";
      fputs($out,"$emailt");
      fputs($out,"$statusn");
      fclose($out);

Shamefully, I am so new to this that I don't understand the fputs.  I
assume that fopen is a function that opens a file and the 'a' is open
with append access, and that is built into a larger function assigned as
the variable $out?  It does seem to work though.

Lastly, the script needs to run makemap.  I know from the command line
that if you have a double entry, or a syntax error in the access file,
makemap will complain.  I am not sure if it still build the parts that
it can or not, but I need for the script to return text to the user
indicating whether makemap succeeded or failed and maybe what it
complained about if it failed.  I see that I can use the flag -r and it
will not complain about dupes, but I am not sure if it just overwrites
the original entry or not.  I don't think that is what I want.  I have
tried exec(), shell_exec(), and command, but I don't think I was using
them properly as none seemed to work.  Here is where I am most confused.

Thanks again for the help!

Paul wrote:

> This shouldn't be so tough. I have quite a bit of PHP experience, so
> I should be able to give you a hand.
> 
> Basically, you can do all of this in PHP, pretty much - INCLUDING
> the checking of the file for the email address.
> 
> Why don't you email me back some more details about the project and
> I will give you a better reply. Feel free to do that on the list or
> to me personally.
> 




More information about the Kclug mailing list