2019-11-25 22:58:18 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
MISP_APP_CONFIG_PATH=/var/www/MISP/app/Config
|
|
|
|
[ -z "$MYSQL_HOST" ] && MYSQL_HOST=db
|
|
|
|
[ -z "$MYSQL_PORT" ] && MYSQL_PORT=3306
|
|
|
|
[ -z "$MYSQL_USER" ] && MYSQL_USER=misp
|
|
|
|
[ -z "$MYSQL_PASSWORD" ] && MYSQL_PASSWORD=example
|
|
|
|
[ -z "$MYSQL_DATABASE" ] && MYSQL_DATABASE=misp
|
|
|
|
[ -z "$REDIS_FQDN" ] && REDIS_FQDN=redis
|
|
|
|
[ -z "$MYSQLCMD" ] && MYSQLCMD="mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -P $MYSQL_PORT -h $MYSQL_HOST -r -N $MYSQL_DATABASE"
|
|
|
|
|
|
|
|
ENTRYPOINT_PID_FILE="/entrypoint_apache.install"
|
|
|
|
[ ! -f $ENTRYPOINT_PID_FILE ] && touch $ENTRYPOINT_PID_FILE
|
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
setup_cake_config(){
|
|
|
|
sed -i "s/'host' => 'localhost'.*/'host' => '$REDIS_FQDN', \/\/ Redis server hostname/" "/var/www/MISP/app/Plugin/CakeResque/Config/config.php"
|
|
|
|
}
|
|
|
|
|
2019-11-25 22:58:18 +01:00
|
|
|
init_misp_config(){
|
2020-02-28 00:10:39 +01:00
|
|
|
[ -f $MISP_APP_CONFIG_PATH/bootstrap.php ] || cp $MISP_APP_CONFIG_PATH.dist/bootstrap.default.php $MISP_APP_CONFIG_PATH/bootstrap.php
|
|
|
|
[ -f $MISP_APP_CONFIG_PATH/database.php ] || cp $MISP_APP_CONFIG_PATH.dist/database.default.php $MISP_APP_CONFIG_PATH/database.php
|
|
|
|
[ -f $MISP_APP_CONFIG_PATH/core.php ] || cp $MISP_APP_CONFIG_PATH.dist/core.default.php $MISP_APP_CONFIG_PATH/core.php
|
|
|
|
[ -f $MISP_APP_CONFIG_PATH/config.php ] || cp $MISP_APP_CONFIG_PATH.dist/config.default.php $MISP_APP_CONFIG_PATH/config.php
|
|
|
|
[ -f $MISP_APP_CONFIG_PATH/email.php ] || cp $MISP_APP_CONFIG_PATH.dist/email.php $MISP_APP_CONFIG_PATH/email.php
|
|
|
|
[ -f $MISP_APP_CONFIG_PATH/routes.php ] || cp $MISP_APP_CONFIG_PATH.dist/routes.php $MISP_APP_CONFIG_PATH/routes.php
|
2019-11-25 22:58:18 +01:00
|
|
|
|
|
|
|
echo "Configure MISP | Set DB User, Password and Host in database.php"
|
|
|
|
sed -i "s/localhost/$MYSQL_HOST/" $MISP_APP_CONFIG_PATH/database.php
|
|
|
|
sed -i "s/db\s*login/$MYSQL_USER/" $MISP_APP_CONFIG_PATH/database.php
|
|
|
|
sed -i "s/db\s*password/$MYSQL_PASSWORD/" $MISP_APP_CONFIG_PATH/database.php
|
2020-01-29 21:15:17 +01:00
|
|
|
|
|
|
|
echo "Configure sane defaults"
|
2020-02-19 15:30:43 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "MISP.redis_host" "$REDIS_FQDN"
|
2020-02-12 15:37:23 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "MISP.baseurl" "$HOSTNAME"
|
2020-02-12 14:55:16 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "MISP.python_bin" $(which python3)
|
|
|
|
|
2020-02-19 16:57:02 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_redis_host" "$REDIS_FQDN"
|
2020-02-28 00:14:59 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.ZeroMQ_enable" true
|
2020-02-12 14:55:16 +01:00
|
|
|
|
2020-02-19 16:57:02 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Enrichment_services_enable" true
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Enrichment_services_url" "http://misp-modules"
|
|
|
|
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Import_services_enable" true
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Import_services_url" "http://misp-modules"
|
|
|
|
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Export_services_enable" true
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Export_services_url" "http://misp-modules"
|
|
|
|
|
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "Plugin.Cortex_services_enable" false
|
2019-11-25 22:58:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
init_misp_files(){
|
|
|
|
if [ ! -f /var/www/MISP/app/files/INIT ]; then
|
|
|
|
cp -R /var/www/MISP/app/files.dist/* /var/www/MISP/app/files
|
|
|
|
touch /var/www/MISP/app/files/INIT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:47:26 +01:00
|
|
|
init_ssl() {
|
2020-02-25 03:09:08 +01:00
|
|
|
if [[ (! -f /etc/ssl/certs/cert.pem) || (! -f /etc/ssl/certs/key.pem) ]];
|
|
|
|
then
|
|
|
|
cd /etc/ssl/certs
|
2020-01-29 20:47:26 +01:00
|
|
|
openssl req -x509 -subj '/CN=localhost' -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
init_mysql(){
|
2019-11-25 22:58:18 +01:00
|
|
|
# Test when MySQL is ready....
|
|
|
|
# wait for Database come ready
|
|
|
|
isDBup () {
|
|
|
|
echo "SHOW STATUS" | $MYSQLCMD 1>/dev/null
|
|
|
|
echo $?
|
|
|
|
}
|
2019-11-28 23:46:30 +01:00
|
|
|
|
2019-11-25 22:58:18 +01:00
|
|
|
RETRY=100
|
|
|
|
until [ $(isDBup) -eq 0 ] || [ $RETRY -le 0 ] ; do
|
|
|
|
echo "Waiting for database to come up"
|
|
|
|
sleep 5
|
2020-02-12 15:37:23 +01:00
|
|
|
RETRY=$(( RETRY - 1))
|
2019-11-25 22:58:18 +01:00
|
|
|
done
|
|
|
|
if [ $RETRY -le 0 ]; then
|
|
|
|
>&2 echo "Error: Could not connect to Database on $MYSQL_HOST:$MYSQL_PORT"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
$MYSQLCMD < /var/www/MISP/INSTALL/MYSQL.sql
|
2019-11-25 22:58:18 +01:00
|
|
|
}
|
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
# Things we should do when we have the INITIALIZE Env Flag
|
|
|
|
if [[ "$INIT" == true ]]; then
|
|
|
|
echo "Import MySQL scheme..." && init_mysql
|
|
|
|
echo "Setup MISP files dir..." && init_misp_files
|
2020-01-29 20:47:26 +01:00
|
|
|
echo "Ensure SSL certs exist..." && init_ssl
|
2019-11-28 23:46:30 +01:00
|
|
|
fi
|
2019-11-25 22:58:18 +01:00
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
# Things that should ALWAYS happen
|
|
|
|
echo "Configure Cake | Change Redis host to $REDIS_FQDN ... " && setup_cake_config
|
2020-02-28 00:14:59 +01:00
|
|
|
|
|
|
|
# Things we should do if we're configuring MISP via ENV
|
|
|
|
echo "Configure MISP | Initialize misp base config..." && init_misp_config
|
|
|
|
|
2019-11-28 23:46:30 +01:00
|
|
|
echo "Configure MISP | Enforce permissions ..."
|
|
|
|
echo "... chown -R www-data.www-data /var/www/MISP ..." && find /var/www/MISP -not -user www-data -exec chown www-data.www-data {} +
|
|
|
|
echo "... chmod -R 0750 /var/www/MISP ..." && find /var/www/MISP -perm 550 -type f -exec chmod 0550 {} + && find /var/www/MISP -perm 770 -type d -exec chmod 0770 {} +
|
|
|
|
echo "... chmod -R g+ws /var/www/MISP/app/tmp ..." && chmod -R g+ws /var/www/MISP/app/tmp
|
|
|
|
echo "... chmod -R g+ws /var/www/MISP/app/files ..." && chmod -R g+ws /var/www/MISP/app/files
|
|
|
|
echo "... chmod -R g+ws /var/www/MISP/app/files/scripts/tmp ..." && chmod -R g+ws /var/www/MISP/app/files/scripts/tmp
|
2019-11-25 22:58:18 +01:00
|
|
|
|
|
|
|
# delete pid file
|
|
|
|
[ -f $ENTRYPOINT_PID_FILE ] && rm $ENTRYPOINT_PID_FILE
|
|
|
|
|
2020-02-21 16:14:43 +01:00
|
|
|
# Work around https://github.com/MISP/MISP/issues/5608
|
|
|
|
if [[ ! -f /var/www/MISP/PyMISP/pymisp/data/describeTypes.json ]]; then
|
|
|
|
mkdir -p /var/www/MISP/PyMISP/pymisp/data/
|
|
|
|
ln -s /usr/local/lib/python3.7/dist-packages/pymisp/data/describeTypes.json /var/www/MISP/PyMISP/pymisp/data/describeTypes.json
|
|
|
|
fi
|
|
|
|
|
2020-02-27 21:28:21 +01:00
|
|
|
if [[ "$NOREDIR" == true ]]; then
|
|
|
|
ln -s /etc/nginx/sites-available/misp80-noredir /etc/nginx/sites-enabled/misp80
|
|
|
|
else
|
|
|
|
ln -s /etc/nginx/sites-available/misp80 /etc/nginx/sites-enabled/misp80
|
|
|
|
fi
|
|
|
|
|
2020-02-20 02:21:49 +01:00
|
|
|
# Start NGINX
|
|
|
|
nginx -g 'daemon off;'
|