-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreset-openstack-users-password.sh
More file actions
46 lines (39 loc) · 1.51 KB
/
reset-openstack-users-password.sh
File metadata and controls
46 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Make sure needed commands exist
command -v openstack >/dev/null 2>&1 || { echo >&2 "openstack command not found. Aborting."; exit 1; }
command -v curl >/dev/null 2>&1 || { echo >&2 "curl command not found. Aborting."; exit 1; }
command -v tr >/dev/null 2>&1 || { echo >&2 "tr command not found. Aborting."; exit 1; }
command -v head >/dev/null 2>&1 || { echo >&2 "head command not found. Aborting."; exit 1; }
EMAILPATH="$1"
OPENRC="/root/openrc"
# Source in an OpenStack admin user's openrc file
if [ -r "$OPENRC" ]; then
. $OPENRC
else
echo "$OPENRC not found. Aborting."
exit 1
fi
# Print script usage if not enough arguments
if [ "$#" -ne "1" ]; then
echo "Usage: $0 <ABSOLUTE PATH TO EMAIL LIST>"
echo
exit 1
fi
while read i; do
EMAIL=$i
USERNAME=$(echo $i | cut -d'@' -f 1)
PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
# Check if user exists
if openstack user show $USERNAME > /dev/null 2>&1; then
# If user exists, change password
openstack user set --password $PASSWORD $USERNAME
# POST the generated password to password sharing website
PASSWORDLINK=$(curl -sS -X POST -d '{"password":"'"$PASSWORD"'"}' -H "Content-Type:application/json" https://passwd.thornelabs.net/api | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["web"]')
echo "Username: $USERNAME"
echo "Email: $EMAIL"
echo "Password: $PASSWORDLINK"
echo
else
echo "User doesn't exist"
fi
done <$EMAILPATH