-
Notifications
You must be signed in to change notification settings - Fork 5
/
nems-passwd
executable file
·80 lines (65 loc) · 2.35 KB
/
nems-passwd
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
ver=$(/usr/local/bin/nems-info nemsver)
platform=$(/usr/local/bin/nems-info platform)
init=$(/usr/local/bin/nems-info init)
tmpdir=`mktemp -d -p /usr/local/share/`
username=$(/usr/local/bin/nems-info username)
echo ""
echo -e "\e[1mNEMS Linux Change Password\e[0m"
echo ""
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root" 2>&1
exit 1
else
if [[ $init = 1 ]]; then
echo -e "Changing password for user: \e[1m$username\e[0m (CTRL-C to abort)"
read -r -p "Continue? [y/N] " beta
echo ""
if [[ $beta =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Proceeding..."
else
echo "Aborted."
exit 1
fi
else
echo
echo "Your NEMS Server is not yet initialized, so password cannot be changed."
echo
exit 1
fi
echo -e "\e[0m"
while true; do
read -s -p "New Password: " password
echo
read -s -p "New Password (again): " password2
echo
[ "$password" = "nemsadmin" ] && password="-" && echo "You are not allowed to use that password."
[ "$password" = "raspberry" ] && password="-" && echo "You are not allowed to use that password."
[ "$password" = "" ] && password="-" && echo "You can't leave the password blank."
[ "$password" = "$password2" ] && break
echo "Please try again"
done
echo ""
# In case this is a re-initialization, delete and then re-add this user
/bin/sed -i~ '/$username/d' /var/www/htpasswd
echo $password | /usr/bin/htpasswd -B -c -i /var/www/htpasswd $username
# Set the user password
echo -e "$password\n$password" | passwd $username >$tmpdir/init 2>&1
# Samba config
# Change Samba User
echo -e "$password\n$password" | smbpasswd -s -a $username
systemctl restart smbd
if (( $(awk 'BEGIN {print ("'$ver'" >= "'1.3'")}') )); then
# Configure NagVis user
if (( $(awk 'BEGIN {print ("'$ver'" >= "'1.4'")}') )); then
cp -f /root/nems/nems-migrator/data/1.4/nagvis/auth.db /etc/nagvis/etc/
else
cp -f /root/nems/nems-migrator/data/nagvis/auth.db /etc/nagvis/etc/
fi
chown www-data:www-data /etc/nagvis/etc/auth.db
# Modify the password for NagVis
sqlite3 /etc/nagvis/etc/auth.db "UPDATE users SET password='$(echo -n '29d58ead6a65f5c00342ae03cdc6d26565e20954'$password | sha1sum | awk '{print $1}')' WHERE name='$username'";
fi
echo "Done. You need to use your new password for NEMS Linux from now on."
fi
echo