#!/usr/bin/perl

# money.pl
# This script searches a subnet for BO servers listening on the default port,
# then searches their C: drive for Microsoft Money files.
# If M$ Money files are found, it will sugget an alternative financial package


# Use the boscript module
use boscript;

# Find a subnet to scan
print "Enter subnet to scan: ";
my $subnet = <STDIN>; chomp $subnet;

# Standard initialization
boscript::initialize();

# Since it's an example, we want to see what's going on...
boscript::set_verbose();

# If the sweep is successful, we'll look at the ouput of the sweep command..
unless(boscript::sweep($subnet)){
  # Read the command output into $result
  $result = boscript::gettext();
  
  # Split the result into lines
  @resultlist = split /\n/, $result;
  
  foreach $line (@resultlist){
    # Split each line into it's constituent variables....
    # Pings return in ! delimited fields
    ($dummy1, $host, $port, $dummy2, $serverversion, $machinename) =
      split /!/, $line;
      
    # Usually the port has trailing white space
    chomp $port;
    
    print "Found a machine at $host port $port.\n";
    
    # Now that we know the host, we can set this.
    # Technically, we could have set the port before the scan, because
    # it won't change from the scanned port.
    boscript::set_host("$host");
    boscript::set_port("$port");

    # Find is a long command... let's raise the timeout value.
    boscript::raise_timeout(25);
    
    # Look for Microsoft Money files.
    boscript::find("*.mny", "c:\\");
    
    # Get the results of the search.  The find command will always return
    # at least two lines.  One the says 'starting search..' and the final
    # line that says 'search ended' (or something like that)
    # The actual found files go in-between.  So, we just count the number
    # of lines to see if we found some.
    # If we wanted to do more, we could just examine @result2
    $result = boscript::gettext();
    @resultlist2 = split /\n/, $result;
    if($#resultlist2 > 2){
      print "Found money files!\n";
      
      # Some sage advice.
      boscript::dialog("You should use Quicken", "A word to the wise");
    }
    else{
      # durnit.
      print "Didnt find any money files.\n";
    }
  }
}

