#!/bin/sh

# Configuration script for the Autopsy Forensics Browser
#
# Brian Carrier [carrier@cerias.purdue.edu]
#
#  $Revision: 0.2 $
#
# Copyright (c) 2001 by Brian Carrier.  All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote
#    products derived from this software without specific prior written
#    permission.
#
#
# THIS SOFTWARE IS NOT AFFILIATED WITH PURDUE UNIVERSITY OR THE CENTER FOR
# EDUCATION IN INFORMATION ASSURANCE AND SECURITY (CERIAS) AND THEY BEAR
# NO RESPONSIBILITY FOR ITS USE OR MISUSE.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR ANY PARTICULAR PURPOSE.
# IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, OR PROFITS OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# Current version
ver=1.01

# Directories to search in
dirs='/bin/ /usr/bin/ /usr/ccs/bin/ /usr/ucb/bin/ /usr/local/bin/ /sbin/ /usr/sbin/ /usr/local/sbin/'


echo ""
echo "   Autopsy Forensic Browser v.$ver Installation"
echo ""

#############################################################################
# Setup Perl locations
#############################################################################

# Find perl
found=0;
for d in $dirs
  do if (test -x ${d}perl) 
    then echo "perl found: ${d}perl";
    echo "#!${d}perl -wT" > ./config.tmp;
    found=1; 
    break; 
  fi;
done

# If it wasn't found, then prompt for it.
if (test $found -eq 0) then
  echo 'ERROR: perl not found';
  echo 'Enter Location:';
  read perlexe;
  if (test -x $perlexe) 
    then echo "#!$perlexe -wT" > ./config.tmp;
  else
    echo "file not found";
    exit 1;
  fi
fi

# Write autopsyfunc.pm
if (test -f ./autopsyfunc.pm) then
  echo "autopsyfunc.pm already exists, overwrite? (y/n):";
  read rep;
  if (test $rep = "y") then
    cat ./config.tmp aux/autopsyfunc.pm.base > ./autopsyfunc.pm;
  else 
    echo '  original version was kept';
  fi
else
  cat ./config.tmp aux/autopsyfunc.pm.base > ./autopsyfunc.pm;
fi


# Get current working directory for lib
echo "use lib '$PWD';" >> ./config.tmp

# Write autopsy
if (test -f ./autopsy) then
  echo "autopsy already exists, overwrite? (y/n):";
  read rep;
  if (test $rep = "y") then
    cat ./config.tmp aux/autopsy.base > ./autopsy
  else 
    echo '  original version was kept';
  fi
else
  cat ./config.tmp aux/autopsy.base > ./autopsy
fi
chmod 0700 ./autopsy

# cleanup
rm -f ./config.tmp


#############################################################################
# create conf.pl
#############################################################################
conf='conf.pl'

if (test -f $conf) then
  echo "$conf already exists, overwrite? (y/n):";
  read rep;
  if (test $rep = "n") then
    exit 0;
  fi
fi

# STANDARD STUFF
echo \$VER = \'$ver\'\; > $conf
echo \$PROGNAME = \'autopsy\'\; >> $conf
echo \$NAME = \'autopsy\'\; >> $conf
echo \$HOME_PAGE = \'http://www.cerias.purdue.edu/homes/carrier/forensics/\'\; >> $conf

#
# DEFAULT USER SETTINGS
#
echo '' >> $conf
echo '' >> $conf
echo '# User Settings' >> $conf
echo '' >> $conf
echo '# when set to 1, the server will stop after it receives no' >> $conf
echo '# connections for STIMEOUT seconds. ' >> $conf
echo '$USE_STIMEOUT = 0;' >> $conf
echo '$STIMEOUT = 3600;'>> $conf    

echo '' >> $conf
echo '# number of seconds that child waits for input from client' >> $conf
echo '$CTIMEOUT = 15;' >> $conf

echo '' >> $conf
echo '#Set to 1 for cookie authentication' >> $conf
echo '$USE_COOKIE = 1;' >> $conf
echo '#file where cookie is saved' >> $conf
echo "\$COOKIE_FILE = '.autopsy.cook';" >> $conf

echo '' >> $conf
echo '# set to 1 for logging, 0 for none' >> $conf
echo '$USE_LOG = 1;' >> $conf
echo '# Log connections and errors' >> $conf
echo "\$LOG_FILE = 'autopsy.log';" >> $conf



#
# FIND THE UTILITIES
#
echo '' >> $conf
echo '' >> $conf
echo '# System Utilities' >> $conf

#
# MD5
#
found=0;
for d in $dirs
  do if (test -x ${d}md5sum) 
    then echo \$MD5_EXE = \'${d}md5sum\'\; >> $conf; 
    echo "MD5 found: ${d}md5sum";
    found=1; 
    break; 
  fi;
done

# Look for md5 if md5sum was not found
if (test $found -eq 0) then
  for b in $dirs
    do if (test -x ${b}md5) 
      then echo \$MD5_EXE = \'${b}md5\'\; >> $conf; 
      echo "MD5 found: ${b}md5";
      found=1; 
      break; 
    fi;
  done;
fi

# Prompt if neither was found
if (test $found -eq 0) then
  echo "ERROR: MD5 (md5 nor md5sum) utility not found";
  echo "Enter Location:";
  read md5exe;
  if (test -x $md5exe) 
    then echo \$MD5_EXE = \'$md5exe\'\; >> $conf; 
  else
    echo "file not found"
  fi
fi

#
# STRINGS
#
found=0
for d in $dirs 
  do if (test -x ${d}strings) then
    echo \$STRINGS_EXE = \'${d}strings\'\; >> $conf; 
    echo "strings found: ${d}strings";
    found=1; 
    break; 
  fi;
done

# Prompt if not found
if (test $found -eq 0) then
  echo 'ERROR: strings utility not found';
  echo 'Enter Location:';
  read strexe;
  if (test -x $strexe) 
    then echo \$STRINGS_EXE = \'$strexe\'\; >> $conf; 
  else
    echo 'file not found'
  fi
fi

#
# GREP
#
found=0
for d in $dirs 
  do if (test -x ${d}grep) then
    echo \$GREP_EXE = \'${d}grep\'\; >> $conf; 
    echo "grep found: ${d}grep";
    found=1; 
    break; 
  fi;
done

# Prompt if not found
if (test $found -eq 0) then
  echo 'ERROR: grep utility not found';
  echo 'Enter Location:';
  read grepexe;
  if (test -x $grepexe) 
    then echo \$GREP_EXE = \'$grepexe\'\; >> $conf; 
  else
    echo 'file not found'
  fi
fi


#############################################################################
# TCT & TCTUTILs
#############################################################################

echo '' >> $conf
echo '' >> $conf
echo '# Directories' >> $conf

# TCT
echo ''
echo 'Enter TCT Directory:'
while (test 1 -eq 1) 
  do read tctdir;
  if (test -x ${tctdir}/bin/icat) then
    echo '  TCT bin directory was found';
    echo \$TCTDIR = \'${tctdir}/bin/\'\; >> $conf;
    break;
  else
    echo 'TCT was not found (try again):';
  fi;
done

# TCTUTILs
echo ''
echo 'Enter TCTUTILs Directory:'
while (test 1 -eq 1) 
  do read tctudir;
  if (test -x ${tctudir}/bin/fls) then
    echo '  TCTUTILs bin directory was found';
    echo \$TCTUTILDIR = \'${tctudir}/bin/\'\; >> $conf;
    break;
  else
    echo 'TCTUTILs was not found (try again):';
  fi;
done

#############################################################################
# MORGUE
#############################################################################
mdone=0
echo ''
echo 'Enter Morgue Directory:'
read morgdir;
if (test -d ${morgdir}) then
  echo "  $morgdir already exists"
else
  echo '';
  echo "$morgdir does not exist"
  while (test 1 -eq 1) do
    echo 'Shall I create it for you? (y/n):';
    read rep;

    if (test $rep = "y") then
      mkdir $morgdir;
      chmod 0700 $morgdir;
      cp aux/fsmorgue $morgdir;
      cp aux/zoneinfo $morgdir;
      mdone=1;
      break;

    elif (test $rep = "n") then
      mdone=1;
      break;
    fi

  done
fi

echo \$MORGDIR = \'${morgdir}\'\; >> $conf;

if (test $mdone -eq 0) then
  if (test -f $morgdir/fsmorgue) then
    echo "  $morgdir/fsmorgue already exists"
  else
    echo '';
    echo "$morgdir/fsmorgue does not exist"
    while (test 1 -eq 1) do
      echo "Shall I create it for you? (y/n):";
      read rep;

      if (test $rep = "y") then
        cp aux/fsmorgue $morgdir;
        break;
      elif (test $rep = "n") then
        break;
      fi
    done
  fi

  if (test -f $morgdir/zoneinfo) then
    echo "  $morgdir/zoneinfo already exists"
  else
    echo '';
    echo "$morgdir/zoneinfo does not exist"
    while (test 1 -eq 1) do
      echo "Shall I create it for you? (y/n):";
      read rep;

      if (test $rep = "y") then
        cp aux/zoneinfo $morgdir;
        break;
      elif (test $rep = "n") then
        break;
      fi
    done
  fi
fi

#############################################################################
# INSTALLATION DIRECTORY
#############################################################################
echo \$INSTALLDIR = \'$PWD/\'\; >> $conf; 

#############################################################################
# INVESTIGATOR
#############################################################################
echo '';
echo 'Enter Default Investigator Name (for the Autopsy Reports):'
read inves
echo '' >> $conf
echo '' >> $conf
echo '# Investigator' >> $conf
echo \$INVESTIG = \'$inves\'\; >> $conf;


#############################################################################
# CLEANUP
#############################################################################
echo ''
echo "Settings saved to $conf"
echo ''

