Ad-Aware SE Pro (or personal) file definition update

 

Note from the Ad-Aware web site: "As of April 1st 2009, we no longer support Ad-Aware SE definition files". The prescription below will hence no longer work as there will be no definition file sources available. Hope you enjoyed and were helped by this short script up to that time ...


 

For those who are still using Ad-Aware SE Pro or personal but as all of us discoverred that the Integrated WebUpdates Tools of the definitions is no longer working through the auto-update, here is a script which will help you installing the new definitions as they are provided.

Ad-Aware SE Main windowAd-Aware SE Integrated WebUpdate Tools window

Hope it will help Ad-Aware SE users ...

 

 

#!/usr/local/bin/perl

#
# (c) J. Lauret July 2008-2009, GPL
#
# This script contacts the LavaSoft update center, checks if updates
# are available for the Ad-Aware SE definition files, downloads and
# install the update if needed. It is a replacement for the automated
# updates for Ad-Aware SE (product support for definitions continues
# but the update center mechanism was broken).
#
# This script is meant to run under cygwin on Windows.
#
# Variables used (and you will need to change) are:
#   $ARCH   An archive directory for the downloaded packages specified as
#           cygwin-path syntax.
#           *** YOU HAVE TO DEFINE THIS ONE FOR SURE ***
#
#   $TRGTD  Target directory where your Ad-Aware SE product is installed
#           There should be no need to change this unless you have it
#           installed on another drive than the C: drive
#
#   $ENAM   Lavasoft package name for the definitions (assumed to be
#           $ENAM.zip)
#   $BNAM   The base name of the definition files to be downloaded and
#           archived on your disk (no need to change unless you really
#           do not like the name I picked). If not defined, will default
#           to $ENAM
#
# In case
#   $SRC    Source and base URL where the defs.zip can be found.
#
#

use URI;
use File::Copy;
use lib "/home/jlauret/lib";
use CygWin;

$URL  = "http://www.lavasoft.com/support/securitycenter/blog/";    # up to 2009
$URL  = "http://www.lavasoft.com/mylavasoft/securitycenter/blog/"; # 2009 server

$FLNM = "/tmp/ad-aware.securitycenter.html";
$CURL = "/usr/bin/curl";
$WGET = "/usr/bin/wget";
$UNZIP= "/usr/bin/unzip";
$SRC  = "http://download.lavasoft.com/public";


# Expected name of download - extension always expected as .zip
$ENAM = "defs";

# Archive director for all downloads (copy)
$ARCH = "/cygdrive/f/Documents and Settings/jlauret/My Documents/Packages/Ad-Aware/";

# Target directory where it should go
$TRGTD= "/cygdrive/c/Program Files/Lavasoft/Ad-Aware SE Professional/";

# Base name for archive file anme - if empty, will be the same
# name than ENAM with version appended
$BNAM = "Ad-Aware-defs";


# --- No modifs needed below ----

#extract base URL for information
$uri = URI->new($URL);
$BASE  = $uri->host;
print "Looking at $BASE for updates\n";

# check variables
$BNAM = ENAM if ($BNAM eq "");



system("$CURL $URL >&$FLNM");

$ref = $ver = "";

if ( -e $FLNM ){
  open(FI,$FLNM);
  $fetch =0;
  while ( defined($line = <FI>) ){
    # pre 2009
    if ($line =~ m/filename-se/){
      $fetch = 1;
      $next;
    } elsif ($line =~ m/Download Current Definition File for Ad-Aware SE/){
      # 2009 Drupal server string parsing
      $fetch = 1;
    }
    if ( $fetch ){
      if ( $line =~ m/(<a href=)(.*)(>SE)(.*)( <.*)/){
        $fetch = 0;
        $ref   = $2;
        $ver   = "SE".$4;
        last;
      } elsif ( $line =~ m/(<a href=\")(.*)(\" title=\"Download)(.*)/){
        # 2009 Drupal server
        # Obviously this step may be skipped but don't know how they
        # will change later so leave logic as-is
        $tmp   = $2;
        $tmp   =~ s/\/.*\?f=//; # print " TODO [$tmp] may be a version\n";

        $ref   = "http://download.lavasoft.com/public/defs.zip";
        # $ver   = "SE-$tmp";
        $ver   = "SE";

      }
    }
  }
  close(FI);
}


if ($ver eq "" && $ref eq ""){
  die "Could not parse version and fetch URL\n";

} elsif ( $ver eq ""){
  die "Found fetcher URL $ref with no version info. Skipping.\n";

} else{
  unlink($FLNM);
  # all is OK
 
  if ( $ver eq "SE"){
    # if you want to use checksum instead, set ver to "SE" and this
    # block will do the rest. However, a download of defs.zip will
    # be needed each time.
    print " Found reference and will need checksum\n";
    print " Fetching from $SRC/$ENAM.zip\n";

    unlink("$ENAM.zip") if ( -e "$ENAM.zip");
    system("$WGET $SRC/$ENAM.zip");
    die "Failed to download $ENAM.zip\n" if ( ! -e "$ENAM.zip");

    chomp($tmp = `md5sum $ENAM.zip`);
    $ver = (split(" ",$tmp))[0];

    if ( -e "$ARCH/$BNAM-$ver.zip" ){
      print "You have the latest definition version $ver\n";
      exit;
    } else {
      print "Setting version to $ver\n";
    }

  } else {
    if ( ! -e "$ARCH/$BNAM-$ver.zip" ){
      print " Found $ver . We do not have $BNAM-$ver.zip\n";
      print " Fetching from $SRC/$ENAM.zip\n";

      unlink("$ENAM.zip") if ( -e "$ENAM.zip");
      system("$WGET $SRC/$ENAM.zip");
      die "Failed to download $ENAM.zip\n" if ( ! -e "$ENAM.zip");

    } else {
      print "You have the latest definition version $ver\n";
      exit;
    }
  }


  $BASE = "/tmp/$$";                         # re-usde of variable
                                             # now a working directory
  mkdir($BASE);
  $FLNM = "/tmp/ad-aware-se-install.csh";    # temp csh script now

  open(FO,">$FLNM");
  print FO 
    "#!/bin/csh\n",
    "/bin/cp $ENAM.zip $BASE/\n",
    "cd $BASE\n",
    "$UNZIP $ENAM.zip\n";
  close(FO);
  chmod( oct('0755'), $FLNM);
  print " Unziping $ENAM.zip ($ver)\n";
  system($FLNM);

  if ( !-e "$BASE/$ENAM.ref"){
    print 
      "Failed to find $ENAM.ref in downloaded package.".
      "Please, review content\n";
    system("/bin/ls -al $BASE/");
    die "\n";
  } else {
    # rename old defs
    if ( -e "$TRGTD/$ENAM.ref.old"){
      print " Deleting previous old definition\n";
      unlink("$TRGTD/$ENAM.ref.old");
    }
    if ( -e "$TRGTD/$ENAM.ref"){
      print " Moving current definition to .old\n";
      rename("$TRGTD/$ENAM.ref","$TRGTD/$ENAM.ref.old");
    }
    
    # install new files
    print " Copying new definition\n";
    if ( ! copy("$BASE/$ENAM.ref","$TRGTD/$ENAM.ref")){
      print " Warning: Did not succeed in installing new definitions\n";
      if ( -e "$TRGTD/$ENAM.ref.old" && ! -e "$TRGTD/$ENAM.ref"){
        print " Re-installing previous definitions\n";
        rename("$TRGTD/$ENAM.ref.old","$TRGTD/$ENAM.ref");
      }
    } else {
      # was a success, proceed
      print " Saving archive copy\n";
      if ( copy("$BASE/$ENAM.zip","$ARCH/$BNAM-$ver.zip") ){
        print " Archive copy is made as $BNAM-$ver.zip\n";
      } else {
        print " Warning: Failed to copy into archive directory\n";
      }
    }
    # cleanup
    system("/bin/rm -fr $BASE") if ( -e $BASE);
    unlink("$ENAM.zip")         if ( -e "$ENAM.zip");
    unlink($FLNM)               if ( -e $FLNM);
  }
}