View | Details | Raw Unified | Return to bug 37025
Collapse All | Expand All

(-)a/debian/docs/koha-common.xml (+7 lines)
Lines 233-238 Link Here
233
          <para>This command behaves something like su(1), but provides you with a shell as the koha user, and with the environment pointing to the right places.</para>
233
          <para>This command behaves something like su(1), but provides you with a shell as the koha user, and with the environment pointing to the right places.</para>
234
        </listitem>
234
        </listitem>
235
      </varlistentry>
235
      </varlistentry>
236
237
      <varlistentry>
238
        <term><option>koha-api-keys</option></term>
239
        <listitem>
240
          <para>Create an api key for a given patron on a koha instance or delete one based on its client id.</para>
241
        </listitem>
242
      </varlistentry>
236
    </variablelist>
243
    </variablelist>
237
    </refsect2>
244
    </refsect2>
238
  </refsect1>
245
  </refsect1>
(-)a/debian/koha-common.install (+1 lines)
Lines 7-12 debian/unavailable.html usr/share/koha/intranet/htdocs Link Here
7
debian/unavailable.html                     usr/share/koha/opac/htdocs
7
debian/unavailable.html                     usr/share/koha/opac/htdocs
8
debian/templates/*                          etc/koha
8
debian/templates/*                          etc/koha
9
debian/scripts/koha-functions.sh            usr/share/koha/bin
9
debian/scripts/koha-functions.sh            usr/share/koha/bin
10
debian/scripts/koha-api-keys                usr/sbin
10
debian/scripts/koha-create                  usr/sbin
11
debian/scripts/koha-create                  usr/sbin
11
debian/scripts/koha-create-dirs             usr/sbin
12
debian/scripts/koha-create-dirs             usr/sbin
12
debian/scripts/koha-disable                 usr/sbin
13
debian/scripts/koha-disable                 usr/sbin
(-)a/debian/scripts/koha-api-keys (-1 / +98 lines)
Line 0 Link Here
0
- 
1
#!/bin/bash
2
#
3
# koha-api-keys: generate or delete api keys for a given patron and
4
#   koha instance.
5
# Copyright 2024 LMSCloud GmbH
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
set -e
21
umask 0077
22
23
# include helper functions
24
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
25
    . "/usr/share/koha/bin/koha-functions.sh"
26
else
27
    echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
28
    exit 1
29
fi
30
31
usage() {
32
    local scriptname=$0
33
    cat <<EOF
34
Generate, or delete api keys for specified patron.
35
36
Usage: $scriptname generate|delete [ description ] [ borrowernumber ] [ instancename ]
37
38
EOF
39
}
40
41
op="$1"
42
43
[ "$#" -ge 2 ] || (
44
    usage
45
    die 'Missing required arguments.'
46
)
47
48
if [ "$op" == 'generate' ]; then
49
    if [ "$#" -eq 3 ]; then
50
        description=$(openssl rand -hex 16)
51
        borrowernumber="$2"
52
        instance="$3"
53
    fi
54
55
    if [ "$#" -eq 4 ]; then
56
        description="$2"
57
        borrowernumber="$3"
58
        instance="$4"
59
    fi
60
61
    is_instance "$instance" || (
62
        usage
63
        die "Unknown instance '$instance'"
64
    )
65
66
    if ! perl -MKoha::Patrons -e "Koha::Patrons->find($borrowernumber) or die;" 2>/dev/null; then
67
        die "Unknown borrowernumber: '$borrowernumber'"
68
    fi
69
70
    {
71
        read -r client_id
72
        read -r secret
73
    } < <(
74
        perl -MKoha::ApiKeys -e "my \$key = Koha::ApiKey->new( { patron_id => $borrowernumber, description => '$description' } )->store; printf \"%s\n%s\n\", \$key->client_id, \$key->plain_text_secret;"
75
    )
76
77
    printf "Client ID:\t%s\nClient Secret:\t%s\n" "$client_id" "$secret"
78
79
    exit 0
80
fi
81
82
if [ "$op" == 'delete' ]; then
83
    instance="$2"
84
    is_instance "$instance" || (
85
        usage
86
        die "Unknown instance '$instance'"
87
    )
88
89
    read -rp "Client ID to delete: " client_id
90
    if ! perl -MKoha::ApiKeys -e "Koha::ApiKeys->find('$client_id')->delete or die;" 2>/dev/null; then
91
        die "Unknown client id: '$client_id'"
92
    fi
93
94
    exit 0
95
fi
96
97
usage
98
die "Invalid operation: '$op'"

Return to bug 37025