Minor cleanups and add hostid2 value for uploads

This commit is contained in:
Michael Boelen 2016-05-24 11:28:08 +02:00
parent 47748c8fd8
commit d2c82adc98

View File

@ -22,7 +22,7 @@
# #
################################################################################# #################################################################################
# #
PROGRAM_VERSION="104" PROGRAM_VERSION="105"
# Data upload destination # Data upload destination
if [ "${UPLOAD_SERVER}" = "" ]; then UPLOAD_SERVER="portal.cisofy.com"; fi if [ "${UPLOAD_SERVER}" = "" ]; then UPLOAD_SERVER="portal.cisofy.com"; fi
@ -44,11 +44,10 @@
SETTINGS_FILE="${PROFILE}" SETTINGS_FILE="${PROFILE}"
# Only output text to stdout if DEBUG mode is not used # Only output text to stdout if DEBUG mode is not used
output() Output() {
{ if [ ${DEBUG} -eq 1 ]; then echo "$1"; fi
if [ ${DEBUG} -eq 1 ]; then echo "$1"; fi }
}
##################################################################################### #####################################################################################
# #
@ -56,8 +55,8 @@ output()
# #
##################################################################################### #####################################################################################
output "Lynis Enterprise data uploader starting" Output "Lynis Enterprise data uploader starting"
output "Settings file: ${SETTINGS_FILE}" Output "Settings file: ${SETTINGS_FILE}"
# Check if we can find curl # Check if we can find curl
# Suggestion: If you want to keep the system hardened, copying the binary from a trusted source is a good alternative. # Suggestion: If you want to keep the system hardened, copying the binary from a trusted source is a good alternative.
@ -74,7 +73,7 @@ output "Settings file: ${SETTINGS_FILE}"
LogText "Error: no license key was specified in the profile (${PROFILE})" LogText "Error: no license key was specified in the profile (${PROFILE})"
ExitFatal ExitFatal
else else
output "License key = ${LICENSE_KEY}" Output "License key = ${LICENSE_KEY}"
fi fi
@ -87,7 +86,7 @@ output "Settings file: ${SETTINGS_FILE}"
# Check report file # Check report file
if [ -f ${REPORTFILE} ]; then if [ -f ${REPORTFILE} ]; then
output "${WHITE}Report file found.${NORMAL} Starting with connectivity check.." Output "${WHITE}Report file found.${NORMAL} Starting with connectivity check.."
if [ ! "${UPLOAD_PROXY_SERVER}" = "" ]; then if [ ! "${UPLOAD_PROXY_SERVER}" = "" ]; then
LogText "Upload: Proxy is configured: ${UPLOAD_SERVER}" LogText "Upload: Proxy is configured: ${UPLOAD_SERVER}"
@ -120,7 +119,7 @@ output "Settings file: ${SETTINGS_FILE}"
# Quit if license is not valid, to reduce load on both client and server. # Quit if license is not valid, to reduce load on both client and server.
LogText "Command used: ${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "collector_version=${PROGRAM_VERSION}" ${LICENSE_SERVER_URL} 2> /dev/null" LogText "Command used: ${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "collector_version=${PROGRAM_VERSION}" ${LICENSE_SERVER_URL} 2> /dev/null"
UPLOAD=`${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "collector_version=${PROGRAM_VERSION}" ${LICENSE_SERVER_URL} 2> /dev/null` UPLOAD=$(${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "collector_version=${PROGRAM_VERSION}" ${LICENSE_SERVER_URL} 2> /dev/null)
EXITCODE=$? EXITCODE=$?
LogText "Exit code: ${EXITCODE}" LogText "Exit code: ${EXITCODE}"
if [ ${EXITCODE} -gt 0 ]; then if [ ${EXITCODE} -gt 0 ]; then
@ -164,9 +163,9 @@ output "Settings file: ${SETTINGS_FILE}"
LogText "Result: quitting, can't check license" LogText "Result: quitting, can't check license"
ExitFatal ExitFatal
fi fi
UPLOAD_CODE=`echo ${UPLOAD} | head -n 1 | awk '{ if ($1=="Response") { print $2 }}'` UPLOAD_CODE=$(echo ${UPLOAD} | head -n 1 | awk '{ if ($1=="Response") { print $2 }}')
if [ "${UPLOAD_CODE}" = "100" ]; then if [ "${UPLOAD_CODE}" = "100" ]; then
output "${WHITE}License is valid${NORMAL}" Output "${WHITE}License is valid${NORMAL}"
LogText "Result: license is valid" LogText "Result: license is valid"
else else
LogText "Result: error while checking license" LogText "Result: error while checking license"
@ -183,18 +182,18 @@ output "Settings file: ${SETTINGS_FILE}"
echo "" echo ""
echo "URL: ${LICENSE_SERVER_URL}" echo "URL: ${LICENSE_SERVER_URL}"
echo "Key: ${LICENSE_KEY}" echo "Key: ${LICENSE_KEY}"
output "Debug information: ${UPLOAD}" Output "Debug information: ${UPLOAD}"
# Quit # Quit
ExitFatal ExitFatal
fi fi
# Extract the hostid from the parse file
HOSTID=`awk -F= '/^hostid=/ { print $2 }' ${REPORTFILE}` # Check for host IDs
if [ ! "${HOSTID}" = "" ]; then if [ ! "${HOSTID}" = "" -a ! "${HOSTID2}" = "" ]; then
output "${WHITE}Found hostid: ${HOSTID}${NORMAL}" Output "${WHITE}Found hostid: ${HOSTID}${NORMAL}"
# Try to connect # Try to connect
output "Uploading data.." Output "Uploading data.."
LogText "Command used: ${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode \"data@${REPORTFILE}\" --data-urlencode \"licensekey=${LICENSE_KEY}\" --data-urlencode \"hostid=${HOSTID}\" ${UPLOAD_URL}" LogText "Command used: ${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode \"data@${REPORTFILE}\" --data-urlencode \"licensekey=${LICENSE_KEY}\" --data-urlencode \"hostid=${HOSTID}\" ${UPLOAD_URL}"
UPLOAD=`${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "data@${REPORTFILE}" --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "hostid=${HOSTID}" ${UPLOAD_URL} 2> /dev/null` UPLOAD=$(${CURLBINARY}${CURL_OPTIONS} -s -S --data-urlencode "data@${REPORTFILE}" --data-urlencode "licensekey=${LICENSE_KEY}" --data-urlencode "hostid=${HOSTID}"" --data-urlencode "hostid2=${HOSTID2}" ${UPLOAD_URL} 2> /dev/null)
EXITCODE=$? EXITCODE=$?
LogText "Exit code: ${EXITCODE}" LogText "Exit code: ${EXITCODE}"
if [ ${EXITCODE} -gt 0 ]; then if [ ${EXITCODE} -gt 0 ]; then
@ -218,12 +217,12 @@ output "Settings file: ${SETTINGS_FILE}"
Display --indent 2 --text "Data upload status" --result OK --color GREEN Display --indent 2 --text "Data upload status" --result OK --color GREEN
fi fi
else else
echo "${RED}Error${NORMAL}: No hostid found in report file. Can not upload report file." echo "${RED}Error${NORMAL}: No hostid and/or hostid2 found. Can not upload report file."
# Quit # Quit
ExitFatal ExitFatal
fi fi
else else
output "${YELLOW}No report file found to upload.${NORMAL}" Output "${YELLOW}No report file found to upload.${NORMAL}"
ExitFatal ExitFatal
fi fi