#!/bin/bash

# Enables nagiosadmin in case the admins disable it and delete themselves.

BASEDIR=$(dirname $(readlink -f $0))

# Import data
eval $(php $BASEDIR/import_fusionconfig.php)

# Create SQL file (so that it doesn't show up in the history)
if [ -f file1 ]; then
    rm file1
fi
echo "update users set enabled=1 where user_id='1';" >> file1
echo "update meta set meta_value=0 where obj_type='1' and obj_id='1' and meta_key='failed_2fa_attempts';" >> file1

tr -d '\n' < file1 > file2
echo "" >> file2
rm file1


# Execute SQL
mysql -h $cfg__database__fusion__host -u $cfg__database__fusion__user --password="$cfg__database__fusion__pass" $cfg__database__fusion__dbname < file2
rm file2

echo "User with user_id=1 re-enabled successfully!"
echo ""