From 640c7f9ac9f15cbfb5229e6736fd58824a6b7a44 Mon Sep 17 00:00:00 2001 From: Steve Clement Date: Wed, 27 Feb 2019 07:58:46 +0530 Subject: [PATCH] chg: [tools] misp-workers.service need to be able to be installed on a stick MISP install (Ubuntu) other flavours want to be marked as such. (and in a seperate directory, ideally, etc/systemd/system) chg: [tools] Backup script todo added chg: [tools] worker start script todo and fix me added --- INSTALL/misp-workers.service | 8 +++--- app/Console/worker/start.sh | 20 +++++++++++++-- tools/misp-backup/misp-backup.sh | 42 +++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/INSTALL/misp-workers.service b/INSTALL/misp-workers.service index 679095149..cac35a125 100644 --- a/INSTALL/misp-workers.service +++ b/INSTALL/misp-workers.service @@ -1,14 +1,14 @@ [Unit] Description=misp-workers -After=network.target apache2.service +After=network.target remote-fs.target nss-lookup.target httpd.service [Service] Type=forking KillMode=none User=www-data -Group=misp-server -ExecStart=/bin/bash -c "/opt/misp-server/misp/app/Console/worker/start.sh" -ExecStop=/bin/bash -c "/opt/misp-server/misp/app/Console/cake CakeResque.CakeResque stop --all" +Group=www-data +ExecStart=/bin/bash -c "/var/www/MISP/app/Console/worker/start.sh" +ExecStop=/bin/bash -c "/var/www/MISP/app/Console/cake CakeResque.CakeResque stop --all" WorkingDirectory=%h Restart=on-failure diff --git a/app/Console/worker/start.sh b/app/Console/worker/start.sh index 9b958614d..27230a0ad 100755 --- a/app/Console/worker/start.sh +++ b/app/Console/worker/start.sh @@ -1,13 +1,29 @@ #!/usr/bin/env bash +# TODO: Improve script to bring workers up that are not. + +# Extract base directory where this script is and cd into it +cd "${0%/*}" + # Check if run as root if [ "$EUID" -eq 0 ]; then echo "Please DO NOT run the worker script as root" exit 1 fi -# Extract base directory where this script is and cd into it -cd "${0%/*}" +##[[ $(../cake CakeResque.CakeResque stop --all |grep "not permitted" ; echo $?) != 1 ]] && echo "Either you have no permissions or CakeResque is not installed/configured" && exit 1 + +## FIXME: PIDs seem off by 1 +# Check which workers are currently running +WORKERS_PID=$(ps a |grep CakeResque |grep -v grep |cut -f 1 -d\ ) + +if [[ ! -z $WORKERS_PID ]]; then + for p in $WORKERS_PID; do + WORKER_RUNNING=$(ps $p |grep CakeRes|grep -v grep |grep -o -e "QUEUE=.[a-z]*" |cut -f2 -d\') + #echo "Worker $WORKER_RUNNING with PID $p" + done +fi + ../cake CakeResque.CakeResque stop --all ../cake CakeResque.CakeResque start --interval 5 --queue default ../cake CakeResque.CakeResque start --interval 5 --queue prio diff --git a/tools/misp-backup/misp-backup.sh b/tools/misp-backup/misp-backup.sh index 98ba9e7d3..e1fe5ee36 100755 --- a/tools/misp-backup/misp-backup.sh +++ b/tools/misp-backup/misp-backup.sh @@ -2,13 +2,16 @@ #!/bin/sh ## $Id: misp-backup.sh 07.04.2016 $ ## -## script to backup MISP on debian/ubuntu 14.04.1 +## script to backup MISP on debian/ubuntu 18.04.1 ## ## Authored by daverstephens@gmail.com ## https://github.com/daverstephens/The-SOC-Shop ## ## added some more studd by @alexanderjaeger ## https://github.com/deralexxx/misp-backup +## +## more amendments by @SteveClement +## ## ## This script can be used to backup a complete MISP @@ -16,7 +19,7 @@ ## built system. This is not intended as an upgrade script ## to move between MISP versions - But it might work ;). ## -## Tested against MISP 2.4.96 +## Tested against MISP 2.4.101 ## ## Run the script as the standard user with the command below ## @@ -24,9 +27,37 @@ ## vi misp-backup.conf # adjust values ## sudo sh -x misp-backup.sh 2>&1 | tee misp-backup.log ## -## Time to set some variables +## TODO: Target directory, rudimentary free space check: stat -f --format="%a" OutputDirName +## TODO: Make sure no directories are blank ## +## Functions + +# Dynamic horizontal spacer +space () { + if [[ "$NO_PROGRESS" == "1" ]]; then + return + fi + # Check terminal width + num=`tput cols` + for i in `seq 1 $num`; do + echo -n "-" + done + echo "" +} + +# Make sure the target has enough free space +checkDiskFree () { + threshhold=90 + free=$(df -l --sync --output=pcent $1 |tail -1|cut -f 1 -d% | tr -d \ ) + if [ $free > $threshhold ]; then + echo "Your destination folder is $threshhold% full." + exit 1 + fi +} + +## Time to set some variables +## FILE=./misp-backup.conf @@ -74,6 +105,10 @@ AdminEmail=$(grep -o -P "(?<='contact' => ').*(?=')" $MISPPath/app/Config/config GnuPGEmail=$(sed -n -e '/GnuPG/,$p' $MISPPath/app/Config/config.php|grep -o -P "(?<='email' => ').*(?=')") GnuPGHomeDir=$(grep -o -P "(?<='homedir' => ').*(?=')" $MISPPath/app/Config/config.php) GnuPGPass=$(grep -o -P "(?<='password' => ').*(?=')" $MISPPath/app/Config/config.php) + +## Folders to be checked for useable space: OutputDirName +## To be checked for emptiness: all? + # Create backup files TmpDir="$(mktemp --tmpdir=$OutputDirName -d)" cp -r $GnuPGHomeDir/* $TmpDir/ @@ -81,6 +116,7 @@ echo "copy of org images and other custom images" cp -r $MISPPath/app/webroot/img/orgs $TmpDir/ cp -r $MISPPath/app/webroot/img/custom $TmpDir/ cp -r $MISPPath/app/files $TmpDir + # MISP Config files mkdir -p $TmpDir/Config cp $MISPPath/app/Config/bootstrap.php $TmpDir/Config