4371 |
26 Oct 12 |
olle |
#!/bin/bash |
3577 |
11 Mar 10 |
gregory |
2 |
PS1="ProSE: " |
3577 |
11 Mar 10 |
gregory |
3 |
|
3577 |
11 Mar 10 |
gregory |
4 |
function help() |
3577 |
11 Mar 10 |
gregory |
5 |
{ |
3577 |
11 Mar 10 |
gregory |
6 |
echo "passwd USER Change password of USER" |
3577 |
11 Mar 10 |
gregory |
7 |
} |
3577 |
11 Mar 10 |
gregory |
8 |
|
3577 |
11 Mar 10 |
gregory |
9 |
function hide() |
3577 |
11 Mar 10 |
gregory |
10 |
{ |
3577 |
11 Mar 10 |
gregory |
11 |
stty -echo |
3577 |
11 Mar 10 |
gregory |
12 |
} |
3577 |
11 Mar 10 |
gregory |
13 |
|
3577 |
11 Mar 10 |
gregory |
14 |
function unhide() |
3577 |
11 Mar 10 |
gregory |
15 |
{ |
3577 |
11 Mar 10 |
gregory |
16 |
stty echo |
3577 |
11 Mar 10 |
gregory |
17 |
} |
3577 |
11 Mar 10 |
gregory |
18 |
|
3577 |
11 Mar 10 |
gregory |
19 |
function passwd() |
3577 |
11 Mar 10 |
gregory |
20 |
{ |
3577 |
11 Mar 10 |
gregory |
21 |
uid=`mysql -b proteios -e "select id from Users where login='$1'"|sed s/id//g` |
3578 |
11 Mar 10 |
gregory |
22 |
if [ -z $uid ] || [ "$uid" == "" ]; then |
3578 |
11 Mar 10 |
gregory |
23 |
echo "No such user $1" >> /dev/stderr |
3577 |
11 Mar 10 |
gregory |
24 |
else |
3578 |
11 Mar 10 |
gregory |
25 |
hide |
3578 |
11 Mar 10 |
gregory |
26 |
read -p "New $1 password: " p1; echo |
3578 |
11 Mar 10 |
gregory |
27 |
read -p "Repeat $1 password: " p2; echo |
3578 |
11 Mar 10 |
gregory |
28 |
unhide |
3578 |
11 Mar 10 |
gregory |
29 |
echo |
3578 |
11 Mar 10 |
gregory |
30 |
if [ "$p1" == "$p2" ]; then |
3578 |
11 Mar 10 |
gregory |
31 |
md5=`echo -n $p1 | md5sum | awk '{print $1}'` |
3578 |
11 Mar 10 |
gregory |
32 |
mysql -b proteios -e "update Passwords set md5password='$md5' where id = $uid" |
3578 |
11 Mar 10 |
gregory |
33 |
echo "$1 password changed" |
3578 |
11 Mar 10 |
gregory |
34 |
else |
3578 |
11 Mar 10 |
gregory |
35 |
echo "Failed: passwords do not match" |
3578 |
11 Mar 10 |
gregory |
36 |
fi |
3577 |
11 Mar 10 |
gregory |
37 |
fi |
4371 |
26 Oct 12 |
olle |
38 |
} |