#!/bin/bash

# lab-grade-dropbox

# This script is to be run on desktopX
# determines the hostname of serverX
# checks that ftp service is running on serverX and can be reached from desktopX
# anonymous uploads work to ftp://serverX/dropbox works
# the contents of ftp://serverX/dropbox cannot be listed
#
#  MODIFICATION HISTORY
#    2010.12.01 George Hacker <ghacker@redhat.com>
#       Fixed 'ls dropbox' logic, save file with a unique name (hosts.$$)

. /usr/local/lib/labtool.shlib
IPA=$GLS_ENROLLMENT

# determines the hostname of serverX
host server${IPA}.example.com | grep address

# checks that ftp service is running on serverX 
# and can be reached from desktopX
if  lftp -e "ls; bye" server${IPA}.example.com &>/dev/null; then
    echo "ftp://server${IPA}.example.com: (service) PASS"	    
else
    echo "ftp://server${IPA}.example.com: (service) FAIL"
    echo ""
    echo "Please check your configuration and try again."
    exit 1
fi

# check if anonymous uploads to ftp://serverX/dropbox work
if  lftp -e "cd /dropbox; put /etc/hosts -o hosts.$$; bye" server${IPA}.example.com &>/dev/null; then
    echo "ftp://server${IPA}.example.com/dropbox: (anon upload) PASS"	    
else
    echo "ftp://server${IPA}.example.com/dropbox: (anon upload) FAIL"
    echo ""
    echo "Please check your configuration and try again."
    exit 1
fi

# the contents of ftp://serverX/dropbox cannot be listed
if  [ $( lftp -e "ls /dropbox/*; bye" server${IPA}.example.com 2> /dev/null | wc -l ) -gt 0 ] ; then
    echo "ftp://server${IPA}.example.com/dropbox: (ls /dropbox/*) FAIL"
    echo "Please check your configuration and try again."	    
else
    echo "ftp://server${IPA}.example.com/dropbox: (ls /dropbox/*) PASS"
    echo ""
    exit 1
fi
