Created
September 3, 2013 13:13
-
-
Save ssstonebraker/6423730 to your computer and use it in GitHub Desktop.
Function to install AuditConsole
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################################### | |
# Exit if program echo does not exist (this allows us to do one line if statements) | |
[ ! -x "$(which echo)" ] && exit 1 | |
######################################## | |
# pretty printing functions | |
function print_status { echo -e "\x1B[01;34m[*]\x1B[0m $1"; } | |
function print_good { echo -e "\x1B[01;32m[*]\x1B[0m $1"; } | |
function print_error { echo -e "\x1B[01;31m[*]\x1B[0m $1"; } | |
function print_notification { echo -e "\x1B[01;33m[*]\x1B[0m $1"; } | |
function printline { hr=------------------------------------------------------------------------------------------------------------------------------- | |
printf '%s\n' "${hr:0:${COLUMNS:-$(tput cols)}}" | |
} | |
#################################### | |
# print message and exit program | |
function die { print_error "$1" >&2;exit 1; } | |
######################################## | |
#Make sure only root can run our script | |
function proceed_if_root { if [[ $EUID -ne 0 ]]; then die "This script must be run as root"; fi } | |
function install_openjdk6() | |
{ | |
apt-get purge -y openjdk* | |
apt-get install openjdk-6-jre-headless | |
################################################ | |
#Set java enviornment variable | |
################################################ | |
grep -q 'JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/' /etc/profile \ | |
|| sudo sh -c "echo 'JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/' >> /etc/profile" | |
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/ | |
ln -s /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-openjdk | |
# source new variables | |
. /etc/profile | |
################################################ | |
} | |
function install_mod_security_audit_console() | |
{ | |
#This will install auditconsole (used with mod_security to view rules/logs) | |
curl -s -O http://download.jwall.org/debian/chris.gpg | |
apt-key add chris.gpg | |
append_line "deb http://download.jwall.org/debian/ jwall main" /etc/apt/sources.list | |
apt-get update | |
#install java 6 | |
install_openjdk6 | |
#install audit console | |
apt-get install -y auditconsole || print_error "auditconsole failed to install" | |
#start on boot | |
apt-get install -y chkconfig | |
ln -s /usr/lib/insserv/insserv /sbin/insserv | |
chkconfig auditconsole 345 | |
#Download and install MySQL Connnector | |
current_directory=`pwd` | |
curl -L 'http://www.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.25.tar.gz/from/http://mysql.he.net/' | \ | |
tar xz && print_good "Downloaded and extracted MySQL Connector" || print_error "Failed to download MySQL Connector" | |
mysqljar="$current_directory/mysql-connector-java-5.1.25/mysql-connector-java-5.1.25-bin.jar" | |
if [ -e $mysqljar ]; then | |
mv $mysqljar /opt/AuditConsole/lib/mysql-connector-java-5.1.25-bin.jar | |
chown jwall:jwall /opt/AuditConsole/lib/mysql-connector-java-5.1.25-bin.jar | |
print_status "MySQL Connector Installed" | |
rm -Rf mysqljar | |
print_status "Restarting Audit Console" | |
service auditconsole restart | |
else | |
print_error "Failed to install MySQL Connector" | |
fi | |
apt-get install -y binutils | |
wacPassword=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 14 | tr -d '\n'; echo` | |
print_status "DB: AuditConsoleDB" | |
print_status "user: wacUser" | |
print_status "pass: $wacPassword" | |
#We ask the user for the root mysql user's password 3 times, one for each task. | |
print_notification "The next several steps will need you to enter the mysql root user password." | |
#1. If the database exists, we blow it away to ensure a clean install. | |
while true; do | |
print_notification "Enter the mysql root user password to create the AuditConsole database." | |
print_notification "If you already have a database named AuditConsoleDB, this WILL drop that database!" | |
mysql -u root -p -e "drop database if exists AuditConsoleDB; create database if not exists AuditConsoleDB; GRANT ALL ON AuditConsoleDB.* to wacUser@localhost IDENTIFIED BY '$wacPassword'; FLUSH PRIVILEGES; show databases;" | |
if [ $? != 0 ]; then | |
print_error "the command did NOT complete successfully. Please see $logfile, confirm the root mysql user password, and try again." | |
continue | |
else | |
print_good "AuditConsoleDB database created!" | |
break | |
fi | |
done | |
mkdir /home/jwall | |
chown -R jwall:jwall /home/jwall | |
install_jwall_tools | |
echo "config file at: /opt/AuditConsole/conf/AuditConsole.xml" | |
jwall console-db-check /opt/AuditConsole | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment