Bug 13143

Summary: Add a tool to show a Koha's password
Product: Koha Reporter: Mason James <mtj>
Component: Command-line UtilitiesAssignee: Mason James <mtj>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: brendan, liz, mirko, mtompset, robin
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - follow up - usability improvements
Bug 13143: Followup - Correct the pause message
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - follow up - usability improvements
Bug 13143: Followup - Correct the pause message
Bug 13143 - Detect if the password is in a pipe
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - follow up - usability improvements
Bug 13143: Followup - Correct the pause message
Bug 13143 - Detect if the password is in a pipe
Bug 13143 - Add a tool to show a Koha's password
Bug 13143 - follow up - usability improvements
Bug 13143: Followup - Correct the pause message
Bug 13143 - Detect if the password is in a pipe

Description Mason James 2014-10-24 17:54:04 UTC
add a useful koha-passwd command, to show a password for a Koha instance
Comment 1 Mason James 2014-10-24 18:05:33 UTC Comment hidden (obsolete)
Comment 2 Mason James 2014-10-24 18:13:08 UTC Comment hidden (obsolete)
Comment 3 Mason James 2014-10-24 18:15:42 UTC Comment hidden (obsolete)
Comment 4 Mason James 2014-10-24 18:19:09 UTC Comment hidden (obsolete)
Comment 5 Robin Sheat 2014-10-31 00:18:08 UTC
This is good and useful, though some suggestions:

it needs a manpage.

if it's at a terminal (you can detect this, somehow) it should perhaps wait for a keypress and clear the screen unless you provide some command line arg.

The second one is just a thought, and isn't required.
Comment 6 Liz Rea 2014-10-31 01:06:55 UTC
Hi Mason,

The idea of this is great, it'll be a great addition to the suite of scripts for making koha administration easier. One thing I noticed, we now have common functions for debian scripts in the debian/scripts/koha-functions.sh for things like "get_instance" - it would probably be good to use that function instead of duplicating it in your script.

Cheers,
Liz
Comment 7 Mark Tompsett 2014-10-31 01:51:16 UTC
(In reply to Mason James from comment #4)
> Created attachment 32687 [details] [review] [review]
> Bug 13143 - Add a tool to show a Koha's password
> 
> to test...
>  # koha-passwd
>  # koha-passwd xxxxx
>  # koha-passwd koha1
>  # koha-passwd koha1 koha2 koha3

Try running as non-root user, it will fail.
Comment 8 Mason James 2014-10-31 02:16:08 UTC Comment hidden (obsolete)
Comment 9 Mason James 2014-10-31 02:23:31 UTC
(In reply to M. Tompsett from comment #7)
> (In reply to Mason James from comment #4)
> > Created attachment 32687 [details] [review] [review] [review]
> > Bug 13143 - Add a tool to show a Koha's password
> > 
> > to test...
> >  # koha-passwd
> >  # koha-passwd xxxxx
> >  # koha-passwd koha1
> >  # koha-passwd koha1 koha2 koha3
> 
> Try running as non-root user, it will fail.


all /usr/sbin/koha-* tools fail when executed by a non-root user

this is normal behaviour, not a bug
Comment 10 Mason James 2014-10-31 02:25:32 UTC
(In reply to Mason James from comment #9)
> (In reply to M. Tompsett from comment #7)
> > (In reply to Mason James from comment #4)
> > > Created attachment 32687 [details] [review] [review] [review] [review]
> > > Bug 13143 - Add a tool to show a Koha's password
> > > 
> > > to test...
> > >  # koha-passwd
> > >  # koha-passwd xxxxx
> > >  # koha-passwd koha1
> > >  # koha-passwd koha1 koha2 koha3
> > 
> > Try running as non-root user, it will fail.
> 
> 
> all /usr/sbin/koha-* tools fail when executed by a non-root user
> 
> this is normal behaviour, not a bug

oop, sorry - thats incorrect ^
Comment 11 Mason James 2014-10-31 02:54:38 UTC
(In reply to M. Tompsett from comment #7)
> (In reply to Mason James from comment #4)
> > Created attachment 32687 [details] [review] [review] [review]
> > Bug 13143 - Add a tool to show a Koha's password
> > 
> > to test...
> >  # koha-passwd
> >  # koha-passwd xxxxx
> >  # koha-passwd koha1
> >  # koha-passwd koha1 koha2 koha3
> 
> Try running as non-root user, it will fail.


if you run it as a valid koha user, and ask for your instance's password - it does correctly return your passwd

for everything else, it is expected to fail


root@xen1:~# koha-shell -l fka
fka-koha@xen1:~$ /usr/sbin/koha-passwd fka
narfnarf69
Comment 12 Mason James 2014-10-31 02:57:45 UTC
(In reply to Liz Rea from comment #6)
> Hi Mason,
> 
> The idea of this is great, it'll be a great addition to the suite of scripts
> for making koha administration easier. One thing I noticed, we now have
> common functions for debian scripts in the debian/scripts/koha-functions.sh
> for things like "get_instance" - it would probably be good to use that
> function instead of duplicating it in your script.
> 
> Cheers,
> Liz


thanks, i attached a new patch that fixes this problem
Comment 13 Liz Rea 2014-10-31 03:48:18 UTC Comment hidden (obsolete)
Comment 14 Mark Tompsett 2014-11-26 21:28:01 UTC Comment hidden (obsolete)
Comment 15 Mark Tompsett 2014-11-26 21:29:12 UTC Comment hidden (obsolete)
Comment 16 Mark Tompsett 2014-11-26 21:29:23 UTC Comment hidden (obsolete)
Comment 17 Mirko Tietgen 2015-03-03 23:58:07 UTC Comment hidden (obsolete)
Comment 18 Robin Sheat 2015-03-05 04:59:31 UTC
My issue is that the pausing thing means it can't be used within a script.

It shouldn't say "password for x is y", it should just output the password, and it should only block if it's outputting to a terminal, otherwise it'll block forever.

A test for this is here:

http://stackoverflow.com/questions/911168/how-to-detect-if-my-shell-script-is-running-through-a-pipe

running koha-passwd instance | cat should output the password and then finish without issuing a clear or anything. This makes it easy for people who need the password as part of some other shell script.

Additionally, it'd probably be good (although I wouldn't consider it a blocker) to make a function in koha-functions.sh to fetch the password and use that, that way other scripts in the koha-* set can use that (if you're really keen you can change them to use it, but certainly don't consider than necessary.)
Comment 19 Liz Rea 2015-07-07 01:08:55 UTC Comment hidden (obsolete)
Comment 20 Liz Rea 2015-07-07 03:06:53 UTC
Note that you'll need the whole set of patches to test this. :)
Comment 21 Mark Tompsett 2016-01-19 19:31:04 UTC Comment hidden (obsolete)
Comment 22 Mark Tompsett 2016-01-19 19:31:11 UTC Comment hidden (obsolete)
Comment 23 Mark Tompsett 2016-01-19 19:31:20 UTC Comment hidden (obsolete)
Comment 24 Mark Tompsett 2016-01-19 19:31:42 UTC Comment hidden (obsolete)
Comment 25 Mark Tompsett 2016-01-19 19:32:29 UTC
Also corrected a rebase issue caused by the release of plack while I was at it.
Comment 26 Jonathan Druart 2016-01-20 10:49:15 UTC
Created attachment 46985 [details] [review]
Bug 13143 - Add a tool to show a Koha's password

to test...

1/ run without any args, and get some help
 # koha-passwd
Displays a Koha instance's password.

Usage: /usr/sbin/koha-passwd instancename1 instancename2...

Missing instance name...

2/ run with a bad instance, get an error
 # koha-passwd xxxxx
Unknown instance xxxxx

3/ run with a correct instance, get a password
 # koha-passwd koha1
foofoo69

4/ run with many instances, get many passwords
 # koha-passwd koha1 koha2 koha3
foofoo69
foofoo68
foofoo67

Signed-off-by: Mason James <mtj@kohaaloha.com>

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 27 Jonathan Druart 2016-01-20 10:49:18 UTC
Created attachment 46986 [details] [review]
Bug 13143 - follow up - usability improvements

* makes sure output is not on the line with the prompt
* adds ability to clear screen after password display

Same test plan as for original bug.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 28 Jonathan Druart 2016-01-20 10:49:22 UTC
Created attachment 46987 [details] [review]
Bug 13143: Followup - Correct the pause message

'read anykey' actually requires enter under sh.
This patch changes the string from:
    'Press any key to clear the screen...'
to
    'Press enter to clear the screen...'

TEST PLAN
---------
1) Apply the first two patches
2) Trigger the script.
2) Press 'q' or anything other than enter when prompted.
   --- You could type a whole sentence! Oops!
3) Press enter.
4) Apply this patch
5) Trigger the script.
6) Be happy that you aren't told any key will work.
7) run koha qa tools

Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>

http://bugs.koha-community.org/show_bug.cgi?id=13141

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 29 Jonathan Druart 2016-01-20 10:49:26 UTC
Created attachment 46988 [details] [review]
Bug 13143 - Detect if the password is in a pipe

1. cd kohaclone/debian/scripts
2. sudo koha-passwd instance | cat
   Output should be password only
3. sudo koha-passwd instance
   Output should be "Password for $instance is: $password"

Does this get at what you were wanting, Robin?

NOTE:
$ cd ~
$ sudo mkdir /etc/koha
$ sudo mkdir /etc/koha/sites
$ sudo mkdir /etc/koha/sites/library
$ sudo ln -s ~/koha-dev/etc/koha-conf.xml /etc/koha/sites/library/koha-conf.xml
$ sudo mkdir /usr/share/koha
$ sudo ln -s ~/kohaclone/debian/scripts /usr/share/koha/bin

This will fake out your system enough to get koha-passwd to run in your git
system. Since you are using your git system, no need for the sudo's in
steps 2 & 3. And no need to roll a custom build to test it.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 30 Brendan Gallagher 2016-01-27 06:28:17 UTC
Pushed to Master - Should be in the May 2016 release.  Thanks!