#!/bin/bash

# lab-grade-https

# This script is for grading the https portion of rh254 lab X.

# It does the following:
# determines the hostname of the user's serverX
# checks the SSL cert from https://serverX.example.com 
# and verifies that it is correct and signed by the CA on 
# instructor.example.com.

IPA=$(hostname -i | cut -d. -f4)

# determines the hostname of the user's serverX
if  links -dump http://server${IPA}.example.com &>/dev/null; then
    echo "http://server${IPA}.example.com: (name) PASS"	    
else
    echo "http://server${IPA}.example.com: (name) FAIL"
    echo ""
    echo "Please check your configuration and try again."
    exit 1
fi

# checks the SSL cert from https://serverX.example.com
# (fails if cert is self-signed)
if  wget -nv --secure-protocol=auto --no-check-certificate https://server${IPA}.example.com 2>&1 | grep -q "Self-signed"; then
    echo "https://server${IPA}.example.com: (SSL) FAIL"
    echo ""
    echo "Please check your configuration and try again."
else
    echo "https://server${IPA}.example.com: (SSL) PASS"
fi
