Lines 2-7
Link Here
|
2 |
# |
2 |
# |
3 |
# koha-reset-passwd -- reset password for a user in a Koha instance |
3 |
# koha-reset-passwd -- reset password for a user in a Koha instance |
4 |
# Copyright 2010 Catalyst IT, Ltd |
4 |
# Copyright 2010 Catalyst IT, Ltd |
|
|
5 |
# Copyright 2019 Theke Solutions |
5 |
# |
6 |
# |
6 |
# This program is free software: you can redistribute it and/or modify |
7 |
# This program is free software: you can redistribute it and/or modify |
7 |
# it under the terms of the GNU General Public License as published by |
8 |
# it under the terms of the GNU General Public License as published by |
Lines 27-58
else
Link Here
|
27 |
exit 1 |
28 |
exit 1 |
28 |
fi |
29 |
fi |
29 |
|
30 |
|
30 |
pwdigest() { |
31 |
usage() |
31 |
echo -n "$1" | |
32 |
{ |
32 |
perl -e 'use Digest::MD5 qw(md5_base64); |
33 |
local scriptname=$0 |
33 |
while (<>) { print md5_base64($_), "\n"; }' |
34 |
cat <<EOF |
|
|
35 |
Resets the password for the specified user on the Koha instance. |
36 |
|
37 |
Usage: $scriptname instancename userid |
38 |
|
39 |
Note: The generated password will be printed. |
40 |
EOF |
34 |
} |
41 |
} |
35 |
|
42 |
|
|
|
43 |
set_password() |
44 |
{ |
45 |
local instancename=$1 |
46 |
local userid=$2 |
47 |
local password=$(pwgen 12 1) |
36 |
|
48 |
|
37 |
[ $# -lt 2 ] && die "Usage: $0 instancename username..." |
49 |
# Optionally use alternative paths for a dev install |
38 |
instance="$1" |
50 |
adjust_paths_dev_install $1 |
39 |
shift |
51 |
|
|
|
52 |
if [ "$DEV_INSTALL" = "" ]; then |
53 |
KOHA_BINDIR=$KOHA_HOME/bin |
54 |
else |
55 |
KOHA_BINDIR=$KOHA_HOME/misc |
56 |
fi |
57 |
|
58 |
if sudo -u "$instancename-koha" -H \ |
59 |
env PERL5LIB=$PERL5LIB \ |
60 |
KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \ |
61 |
$KOHA_BINDIR/admin/set_password.pl --userid $userid --password $password ; then |
40 |
|
62 |
|
41 |
temp="$(mktemp)" |
63 |
echo "$userid $password" |
|
|
64 |
return 0 |
65 |
else |
66 |
return 1 |
67 |
fi |
68 |
} |
69 |
|
70 |
if [ $# -lt 2 ]; then |
71 |
usage |
72 |
die "Wrong parameters" |
73 |
fi |
42 |
|
74 |
|
43 |
cat <<eof > "$temp" |
75 |
instance="$1" |
44 |
use koha_$instance; |
76 |
shift |
45 |
eof |
|
|
46 |
|
77 |
|
47 |
for userid in "$@" |
78 |
for userid in "$@" |
48 |
do |
79 |
do |
49 |
password="$(pwgen 12 1)" |
80 |
set_password $instance $userid |
50 |
digest="$(pwdigest $password)" |
|
|
51 |
echo "$userid $password" |
52 |
echo "UPDATE borrowers SET password = '$digest' WHERE userid = '$userid';" \ |
53 |
>> "$temp" |
54 |
done |
81 |
done |
55 |
|
82 |
|
56 |
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf < "$temp" |
83 |
exit 0 |
57 |
|
|
|
58 |
rm "$temp" |
59 |
- |
|
|