diff --git a/setup/so-common-functions b/setup/so-common-functions new file mode 100644 index 000000000..b80fc4920 --- /dev/null +++ b/setup/so-common-functions @@ -0,0 +1,69 @@ +#!/bin/bash + +source './so-variables' + +# Helper functions + +filter_unused_nics() { + # Set the main NIC as the default grep search string + local grep_string="$MNIC" + + # If we call this function and NICs have already been assigned to the bond interface then add them to the grep search string + if [[ $BNICS ]]; then + for BONDNIC in "${BNICS[@]}"; do + grep_string="$grep_string\|$BONDNIC" + done + fi + + # Finally, set filtered_nics to any NICs we aren't using (and ignore interfaces that aren't of use) + export filtered_nics + filtered_nics=$(ip link | grep -vwe "$grep_string" | awk -F: '$0 !~ "lo|vir|veth|br|docker|wl|^[^0-9]"{print $2}') +} + +calculate_useable_cores() { + + # Calculate reasonable core usage + local cores_for_bro=$(( CPUCORES/2 - 1 )) + local lb_procs_round + lb_procs_round=$(printf "%.0f\n" $cores_for_bro) + + export lb_procs + if [ "$lb_procs_round" -lt 1 ]; then lb_procs=1; else lb_procs=$lb_procs_round; fi +} + +set_defaul_log_size() { + + local disk_dir="/" + if [ -d /nsm ]; then + disk_dir="/nsm" + fi + local disk_size_kb + disk_size_kb=$(df $disk_dir |grep -v "^Filesystem" | awk '{print $2}') + local percentage=85 + local disk_size + disk_size=$(( disk_size_kb * 1000 )) + local percentage_disk_space + percentage_disk_space=$(( disk_size * (percentage / 100) )) + + export log_size_limit=$(( percentage_disk_space / 1000000000 )) +} + +ls_heapsize() { + + if [ "$total_mem" -ge 32000 ]; then + LS_HEAP_SIZE='1000m' + return + fi + + case "$install_type" in + 'MASTERSEARCH' | 'HEAVYNODE' | 'HELIXSENSOR') + LS_HEAP_SIZE='1000m' + ;; + 'EVAL') + LS_HEAP_SIZE='700m' + ;; + *) + LS_HEAP_SIZE='500m' + ;; + esac +} \ No newline at end of file diff --git a/setup/so-functions b/setup/so-functions index 2fea2e98d..3d27df17b 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -15,19 +15,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -SCRIPTDIR=$(dirname "$0") -source "$SCRIPTDIR/so-whiptail" -SOVERSION=1.2.1 +cd "$(dirname "$0")" || exit 255 +source "./so-whiptail" +source "./so-variables" +source "./so-common-functions" +so_version=1.2.1 + accept_salt_key_local() { - echo "Accept the key locally on the master" >> "$SETUPLOG" 2>&1 + echo "Accept the key locally on the master" >> "$setup_log" 2>&1 # Accept the key locally on the master salt-key -ya "$MINION_ID" } accept_salt_key_remote() { - echo "Accept the key remotely on the master" >> "$SETUPLOG" 2>&1 + echo "Accept the key remotely on the master" >> "$setup_log" 2>&1 # Delete the key just in case. ssh -i /root/.ssh/so.key soremote@"$MSRV" sudo salt-key -d "$MINION_ID" -y salt-call state.apply ca @@ -44,7 +47,7 @@ add_admin_user() { } add_master_hostfile() { - echo "Checking if I can resolve master. If not add to hosts file" >> "$SETUPLOG" 2>&1 + echo "Checking if I can resolve master. If not add to hosts file" >> "$setup_log" 2>&1 # Pop up an input to get the IP address MSRVIP=$(whiptail --title "Security Onion Setup" --inputbox \ "Enter your Master Server IP Address" 10 60 X.X.X.X 3>&1 1>&2 2>&3) @@ -65,7 +68,7 @@ so_add_user() { local home_dir=$4 if [ "$5" ]; then local pass=$5; fi - echo "Add $username user" >> "$SETUPLOG" 2>&1 + echo "Add $username user" >> "$setup_log" 2>&1 groupadd --gid "$gid" "$username" useradd --uid "$uid" --gid "$gid" --home-dir "$home_dir" "$username" @@ -187,16 +190,6 @@ bro_logs_enabled() { fi } -calculate_useable_cores() { - - # Calculate reasonable core usage - local cores_for_bro=$(( CPUCORES/2 - 1 )) - local lb_procs_round - lb_procs_round=$(printf "%.0f\n" $cores_for_bro) - - if [ "$lb_procs_round" -lt 1 ]; then LBPROCS=1; else LBPROCS=$lb_procs_round; fi -} - check_admin_pass() { check_pass_match "$ADMINPASS1" "$ADMINPASS2" "APMATCH" } @@ -671,19 +664,6 @@ generate_passwords(){ KRATOSKEY=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 20 | head -n 1) } -get_log_size_limit() { - - local DISK_DIR="/" - if [ -d /nsm ]; then - DISK_DIR="/nsm" - fi - DISK_SIZE_K=$(df $DISK_DIR |grep -v "^Filesystem" | awk '{print $2}') - PERCENTAGE=85 - DISK_SIZE=$(( DISK_SIZE_K * 1000 )) - PERCENTAGE_DISK_SPACE=$(( DISK_SIZE * PERCENTAGE / 100 )) - LOG_SIZE_LIMIT=$(( PERCENTAGE_DISK_SPACE / 1000000000 )) - -} get_main_ip() { # Get the main IP address the box is using @@ -746,26 +726,6 @@ install_master() { } -ls_heapsize() { - - if [ "$TOTAL_MEM" -ge 32000 ]; then - LS_HEAP_SIZE='1000m' - return - fi - - case "$INSTALLTYPE" in - 'MASTERSEARCH' | 'HEAVYNODE' | 'HELIXSENSOR') - LS_HEAP_SIZE='1000m' - ;; - 'EVAL') - LS_HEAP_SIZE='700m' - ;; - *) - LS_HEAP_SIZE='500m' - ;; - esac -} - master_pillar() { local pillar_file=$temp_install_dir/pillar/minions/$MINION_ID.sls diff --git a/setup/so-whiptail b/setup/so-whiptail index 54e479605..24aa1ad22 100755 --- a/setup/so-whiptail +++ b/setup/so-whiptail @@ -16,6 +16,7 @@ # along with this program. If not, see . source "./so-variables" +source "./so-common-functions" whiptail_basic_bro() {