From 3744d31bb39c88ebb1f697302deec7f1b0d32b26 Mon Sep 17 00:00:00 2001 From: Mafoo Date: Sat, 29 Jul 2017 20:59:40 +0100 Subject: [PATCH] Enhance - add reset_admin_password.sh (#102) will look for all instances of system_username from config.sh in the database and update it's password --- centos/resources/reset_admin_password.sh | 33 +++++++++++++++++++++++ debian/resources/reset_admin_password.sh | 33 +++++++++++++++++++++++ devuan/resources/reset_admin_password.sh | 33 +++++++++++++++++++++++ freebsd/resources/reset_admin_password.sh | 33 +++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100755 centos/resources/reset_admin_password.sh create mode 100755 debian/resources/reset_admin_password.sh create mode 100755 devuan/resources/reset_admin_password.sh create mode 100755 freebsd/resources/reset_admin_password.sh diff --git a/centos/resources/reset_admin_password.sh b/centos/resources/reset_admin_password.sh new file mode 100755 index 0000000..148655a --- /dev/null +++ b/centos/resources/reset_admin_password.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +#move to script directory so all relative paths work +cd "$(dirname "$0")" + +#includes +. ./config.sh +. ./colors.sh +. ./environment.sh + +#count the users +admin_users=$(sudo -u postgres psql fusionpbx -Atc "select count(*) from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + +if [ .$admin_users = .'0' ]; then + error "i could not find the user '$system_username' in the database, check your resources/config.sh is correct" +elif [ .$admin_users = .'' ]; then + error "something went wrong, see errors above"; +else + admin_uuids=$(sudo -u postgres psql fusionpbx -Atc "select v_users.user_uuid from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + for admin_uuid in $admin_uuids; do + user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php); + if [ .$system_password = .'random' ]; then + user_password=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g') + else + user_password=$system_password + fi + password_hash=$(php -r "echo md5('$user_salt$user_password');"); + sudo -u postgres psql fusionpbx -c "update v_users SET password='$password_hash', salt='$user_salt' where user_uuid='$admin_uuid'" + admin_domain=$(sudo -u postgres psql fusionpbx -Atc "select domain_name from v_users JOIN v_domains USING (domain_uuid) where username='$system_username'") + verbose " $system_username@$admin_domain has had it's password reset." + verbose " password: $user_password" + done +fi diff --git a/debian/resources/reset_admin_password.sh b/debian/resources/reset_admin_password.sh new file mode 100755 index 0000000..148655a --- /dev/null +++ b/debian/resources/reset_admin_password.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +#move to script directory so all relative paths work +cd "$(dirname "$0")" + +#includes +. ./config.sh +. ./colors.sh +. ./environment.sh + +#count the users +admin_users=$(sudo -u postgres psql fusionpbx -Atc "select count(*) from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + +if [ .$admin_users = .'0' ]; then + error "i could not find the user '$system_username' in the database, check your resources/config.sh is correct" +elif [ .$admin_users = .'' ]; then + error "something went wrong, see errors above"; +else + admin_uuids=$(sudo -u postgres psql fusionpbx -Atc "select v_users.user_uuid from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + for admin_uuid in $admin_uuids; do + user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php); + if [ .$system_password = .'random' ]; then + user_password=$(dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 | sed 's/[=\+//]//g') + else + user_password=$system_password + fi + password_hash=$(php -r "echo md5('$user_salt$user_password');"); + sudo -u postgres psql fusionpbx -c "update v_users SET password='$password_hash', salt='$user_salt' where user_uuid='$admin_uuid'" + admin_domain=$(sudo -u postgres psql fusionpbx -Atc "select domain_name from v_users JOIN v_domains USING (domain_uuid) where username='$system_username'") + verbose " $system_username@$admin_domain has had it's password reset." + verbose " password: $user_password" + done +fi diff --git a/devuan/resources/reset_admin_password.sh b/devuan/resources/reset_admin_password.sh new file mode 100755 index 0000000..531c9f6 --- /dev/null +++ b/devuan/resources/reset_admin_password.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +#move to script directory so all relative paths work +cd "$(dirname "$0")" + +#includes +. ./config.sh +. ./colors.sh +. ./environment.sh + +#count the users +admin_users=$(sudo -u postgres psql fusionpbx -Atc "select count(*) from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + +if [ .$admin_users = .'0' ]; then + error "i could not find the user '$system_username' in the database, check your resources/config.sh is correct" +elif [ .$admin_users = .'' ]; then + error "something went wrong, see errors above"; +else + admin_uuids=$(sudo -u postgres psql fusionpbx -Atc "select v_users.user_uuid from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + for admin_uuid in $admin_uuids; do + user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php); + if [ .$system_password = .'random' ]; then + user_password="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 12 | xargs)" + else + user_password=$system_password + fi + password_hash=$(php -r "echo md5('$user_salt$user_password');"); + sudo -u postgres psql fusionpbx -c "update v_users SET password='$password_hash', salt='$user_salt' where user_uuid='$admin_uuid'" + admin_domain=$(sudo -u postgres psql fusionpbx -Atc "select domain_name from v_users JOIN v_domains USING (domain_uuid) where username='$system_username'") + verbose " $system_username@$admin_domain has had it's password reset." + verbose " password: $user_password" + done +fi diff --git a/freebsd/resources/reset_admin_password.sh b/freebsd/resources/reset_admin_password.sh new file mode 100755 index 0000000..012d8ae --- /dev/null +++ b/freebsd/resources/reset_admin_password.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +#move to script directory so all relative paths work +cd "$(dirname "$0")" + +#includes +. ./config.sh +. ./colors.sh +. ./environment.sh + +#count the users +admin_users=$(sudo -u postgres psql fusionpbx -Atc "select count(*) from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + +if [ .$admin_users = .'0' ]; then + error "i could not find the user '$system_username' in the database, check your resources/config.sh is correct" +elif [ .$admin_users = .'' ]; then + error "something went wrong, see errors above"; +else + admin_uuids=$(sudo -u postgres psql fusionpbx -Atc "select v_users.user_uuid from v_users JOIN v_group_users USING (domain_uuid) where username='$system_username' and group_name = 'superadmin'") + for admin_uuid in $admin_uuids; do + user_salt=$(/usr/bin/php /var/www/fusionpbx/resources/uuid.php); + if [ .$system_password = .'random' ]; then + user_password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20) + else + user_password=$system_password + fi + password_hash=$(php -r "echo md5('$user_salt$user_password');"); + sudo -u postgres psql fusionpbx -c "update v_users SET password='$password_hash', salt='$user_salt' where user_uuid='$admin_uuid'" + admin_domain=$(sudo -u postgres psql fusionpbx -Atc "select domain_name from v_users JOIN v_domains USING (domain_uuid) where username='$system_username'") + verbose " $system_username@$admin_domain has had it's password reset." + verbose " password: $user_password" + done +fi