Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added username/ password verification #60

Merged
merged 3 commits into from May 8, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -139,10 +139,41 @@ compareVersions ()
echo '0'
}

checkLogglyServersAccessiblilty()
{
echo "Checking if https://www.loggly.com is reachable"
if [ $(curl -s --head --request GET https://www.loggly.com | grep "200 OK" | wc -l) == 1 ]; then
echo "INFO: https://www.loggly.com is reachable"
else
logMsgToConfigSysLog "WARNING" "WARNING: https://www.loggly.com is not reachable. Please check your network and firewall settings. Continuing to configure Loggly on your system..."
fi

echo "Checking if https://$LOGGLY_ACCOUNT.loggly.com is reachable"
if [ $(curl -s --head --request GET https://$LOGGLY_ACCOUNT.loggly.com/login | grep "200 OK" | wc -l) == 1 ]; then
echo "INFO: https://$LOGGLY_ACCOUNT.loggly.com reachable"
else
logMsgToConfigSysLog "WARNING" "WARNING: https://$LOGGLY_ACCOUNT.loggly.com is not reachable. Please check your network and firewall settings. Continuing to configure Loggly on your system..."
fi

echo "Checking if logs-01.loggly.com is reachable"
if [ $(ping -c 1 logs-01.loggly.com | grep "1 packets transmitted, 1 received, 0% packet loss" | wc -l) == 1 ]; then

This comment has been minimized.

@vinhn

vinhn May 8, 2014

Many of these urls should be defined as variables/constants at the top of the script, instead of being embedded into these functions. Users who care about security will definitely look at this script before they actually execute it. A nicely constructed script that gives clear visibility into what it is doing will automatically win over trust on a user's part. A complex script will do the exact opposite and can increase the chance of it not being used.

echo "INFO: logs-01.loggly.com is reachable"
else
logMsgToConfigSysLog "WARNING" "WARNING: logs-01.loggly.com is not reachable. Please check your network and firewall settings. Continuing to configure Loggly on your system..."
fi
if [ $(curl -s -u $LOGGLY_USERNAME:$LOGGLY_PASSWORD http://$LOGGLY_ACCOUNT.loggly.com/apiv2/customer | grep "Unauthorized" | wc -l) == 1 ]; then

This comment has been minimized.

@vinhn

vinhn May 8, 2014

Ok to send password in clear text over unencrypted connection? Should this be over https instead?

This comment has been minimized.

@mchaudhary

mchaudhary May 8, 2014
Contributor

Great catch. This should be over https. I will fix it.

logMsgToConfigSysLog "ERROR" "ERROR: Invalid Loggly username or password"
exit 1
fi

}

configureLoggly()
{
setVariables
logMsgToConfigSysLog "INFO" "INFO: Initiating Configure Loggly"
checkLogglyServersAccessiblilty

INITIAL_MSGSEARCH_COUNT=0
FINAL_MSGSEARCH_COUNT=0

@@ -235,7 +266,7 @@ fi
#ROTATABLE
#fi

restartTomcat
#restartTomcat

# Create rsyslog dir if doesn't exist, Modify the rsyslog directory if exist
if [ -d "$SYSLOG_DIR" ]; then
@@ -267,7 +298,7 @@ queryParam="tag%3Atomcat&from=-15m&until=now&size=1"
searchAndFetch tomcatinitialLogCount "$queryParam"
# restart the syslog service.
restartsyslog
echo "INFO: Restarting tomcat one more time..."
echo "INFO: Restarting tomcat to generate logs for verification..."
restartTomcat
searchAndFetch tomcatLatestLogCount "$queryParam"

@@ -278,12 +309,12 @@ while [ "$tomcatLatestLogCount" -le "$tomcatinitialLogCount" ]; do
echo "######### waiting for 30 secs......"
sleep 30
echo "######## Done waiting. verifying again..."
echo "Try # $counter of total 10"
echo "Try # $counter of total $maxCounter"
searchAndFetch tomcatLatestLogCount "$queryParam"
echo "Again Fetch: initial count $tomcatinitialLogCount : latest count : $tomcatLatestLogCount counter: $counter max counter: $maxCounter"
let counter=$counter+1
if [ "$counter" -gt "$maxCounter" ]; then
logMsgToConfigSysLog "ERROR" "ERROR: Tomcat logs did not make to Loggly in stipulated time. Please retry"
logMsgToConfigSysLog "ERROR" "ERROR: Tomcat logs did not make to Loggly in stipulated time. Please check your token & network/firewall settings and retry"
exit 1
fi
done
@@ -408,6 +439,8 @@ debug()
{
setVariables
logMsgToConfigSysLog "INFO" "INFO: Initiating debug"
checkLogglyServersAccessiblilty

#if [ -f loggly_tcpdump.log ]; then
# sudo rm -rf loggly_tcpdump.log
#fi
@@ -456,7 +489,7 @@ debug()
echo "Again Fetch: initial count $initialCount : final count : $finalCount counter: $counter max counter: $maxCounter"
let counter=$counter+1
if [ "$counter" -gt "$maxCounter" ]; then
logMsgToConfigSysLog "ERROR" "ERROR: Tomcat logs did not make to Loggly in stipulated time. Please retry"
logMsgToConfigSysLog "ERROR" "ERROR: Tomcat logs did not make to Loggly in stipulated time. Please check your token & network/firewall settings and retry"
exit 1
fi
done
@@ -478,7 +511,7 @@ searchAndFetch()
result=$(wget -qO- /dev/stdout --user "$LOGGLY_USERNAME" --password "$LOGGLY_PASSWORD" "$url")
#echo "Result of wget invoke $result"
if [ -z "$result" ]; then
logMsgToConfigSysLog "ERROR" "ERROR: Please check your network connectivity & ensure Loggly subdomain, username and password is specified/correct"
logMsgToConfigSysLog "ERROR" "ERROR: Please check your network/firewall settings & ensure Loggly subdomain, username and password is specified correctly"
exit 1
fi
id=$(echo "$result" | grep -v "{" | grep id | awk '{print $2}')
@@ -507,7 +540,7 @@ searchAndFetch()
usage()
{
cat << EOF
usage: ltomcatsetup [-a loggly auth account or subdomain] [-t loggly token] [-u username] [-p password (optional)] [-d to debug (optional)] [-ch catalina home (optional)]
usage: ltomcatsetup [-a loggly auth account or subdomain] [-t loggly token] [-u username] [-p password (optional)] [-ch catalina home (optional)]
usage: ltomcatsetup [-r to rollback] [-ch catalina home (optional)]
usage: ltomcatsetup [-h for help]
EOF
@@ -518,6 +551,9 @@ restartsyslog()
{
echo "Restarting the rsyslog service..."
sudo service rsyslog restart
if [ $? -ne 0 ]; then
logMsgToConfigSysLog "WARNING" "WARNING: rsyslog did not restart gracefully. Please restart rsyslog manually"
fi
}

restartTomcat()
@@ -528,15 +564,27 @@ restartTomcat()
if [ -f /etc/init.d/$SERVICE ]; then
echo "INFO: $SERVICE is running as service"
sudo service $SERVICE restart
if [ $? -ne 0 ]; then
logMsgToConfigSysLog "WARNING" "WARNING: Tomcat did not restart gracefully. Log rotation may not be disabled. Please restart tomcat manually"
fi
else
echo "INFO: $SERVICE is not running as service..."
# To be commented only for test
echo "INFO: Shutting down tomcat..."
$LOGGLY_CATALINA_HOME/bin/shutdown.sh
echo "INFO: Done shutting down tomcat!"
sudo $LOGGLY_CATALINA_HOME/bin/shutdown.sh
if [ $? -ne 0 ]; then
logMsgToConfigSysLog "WARNING" "WARNING: Tomcat did not shut down gracefully"
else
echo "INFO: Done shutting down tomcat!"
fi

echo "INFO: Starting up tomcat..."
$LOGGLY_CATALINA_HOME/bin/startup.sh
echo "INFO: Tomcat is up and running"
sudo $LOGGLY_CATALINA_HOME/bin/startup.sh
if [ $? -ne 0 ]; then
logMsgToConfigSysLog "WARNING" "WARNING: Tomcat did not start up down gracefully"
else
echo "INFO: Tomcat is up and running"
fi
fi
fi
}
@@ -602,9 +650,9 @@ while [ "$1" != "" ]; do
-p | --password ) shift
LOGGLY_PASSWORD=$1
;;
-d | --debug )
LOGGLY_DEBUG="true"
;;
#-d | --debug )
# LOGGLY_DEBUG="true"
# ;;
-r | --rollback )
LOGGLY_ROLLBACK="true"
;;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.