On Feb 12, 2004, at 8:58 AM, Timothy C. Bohen wrote:


 
Anyone willing to send me a script that I can use?


Sure, here's mine written in Perl. It knows enough to check the timestamps so it doesn't fetch files when unecessary, keeps a backup copy, and does everything in a safe manner such as to not leave your system in an unusable state at any time. It relies on the fact that the rename() function is atomic. I don't make that guarantee on non-unix systems.

All you need to do is set the directory location for your rule file, and your license key information from Sniffer. It assumes snf2check.exe is in that same directory, and you have the Perl modules LWP::UserAgent and HTTP::Request::Common installed.


--cut here-- #! /usr/bin/perl -wT use strict;

# fetch the updated rules file from SortMonster's web site and safely
# update the local copy if it passes self-integrity test.  keep one old
# file as backup.

# Time-stamp: "23 October 2003, 11:10:36 ([EMAIL PROTECTED])"

# private license/key pair
my ($license,$key) = qw(abcdefg a1b2c3d4e5f6g7h8);

# directory where to put the resulting file. snf2check should be there too
my $dir = '/var/amavis/sniffer';


# credentials for remote site
my ($login,$password) = qw(sniffer ki11sp8m);

###
### The rest should not require any changes.
###

my $host = 'www.sortmonster.net:80';
# file to fetch
my $url = "http://$host/Sniffer/Updates/${license}.snf";;

$ENV{PATH} = '';

chdir($dir) or die "unable to change directory to $dir";

use LWP::UserAgent;
use HTTP::Request::Common;

my $tmpfile = "${license}.tmp.$$";

$SIG{INT} = $SIG{TERM} = sub { die "killed."; };
$SIG{__DIE__} = sub { unlink $tmpfile; };

my $ua = new LWP::UserAgent or die "unable to create user agent";

$ua->credentials($host,'SortMonster',$login,$password);

my $response = $ua->request(HTTP::Request::Common::HEAD($url));
die "Error while stating ", $response->request->uri,
  " -- ", $response->status_line, "\nAborting"
  unless $response->is_success;

# check if newer than our copy...
if ( -f "${license}.snf" ) {
  my $current_age = (stat "${license}.snf")[9];
  if ($response->last_modified <= $current_age) {
    # remote file older, no point fetching it again
    exit(0);
  }
}

# now stick the result into a temp file
$response = $ua->request(HTTP::Request::Common::GET($url),$tmpfile);
die "Error while getting ", $response->request->uri,
  " -- ", $response->status_line, "\nAborting"
  unless $response->is_success;

system('./snf2check.exe',$tmpfile,$key) == 0
  or die "failure to execute snf2check: $!";

my $exitvalue = $? >> 8;
my $sig = $? & 127;

if ($exitvalue or $sig) {
  die "error running snf2check: exit $exitvalue\n";
} else {
  # keep old file just in case...
  unlink "${license}.snf.old";
  link "${license}.snf","${license}.snf.old";

  rename $tmpfile, "${license}.snf";
}

exit(0);

This E-Mail came from the [EMAIL PROTECTED] mailing list. For information and (un)subscription instructions go to http://www.sortmonster.com/MessageSniffer/Help/Help.html

Reply via email to