Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the keepassxc-cli session based #3224

Closed
qwc opened this issue Jun 4, 2019 · 7 comments · Fixed by #3426

Comments

@qwc
Copy link

@qwc qwc commented Jun 4, 2019

Summary

The current behaviour of the cli is that you have to issue a command at a time and input the password for your database everytime you issue your command.
I would like to have that session based.

Desired Behavior

So, if you issue keepassxc-cli, you start a CLI session where you may open a database, enter the password for it, and then work on the database, just like the GUI after all.
And after you type "close" or "quit" the database is closed again and the session terminated.
Also a timeout to automatically close the CLI session might be a good idea, but should be configurable.

Context

Well, I'm living on the console with huge tmux sessions, local and on my server, where I would also like to access my credentials for different things. And after all it's cool that KeePassXC provides a CLI, but to always type in your 25-30 character password with every command issued is damn annoying.

@qwc qwc added the new feature label Jun 4, 2019
@sjamesr

This comment has been minimized.

Copy link
Contributor

@sjamesr sjamesr commented Jul 30, 2019

I'm working on a prototype of a readline-based solution, where you'd do something like:

$ keepassxc-cli open passwords.kdbx
Insert password to unlock /home/whatever/passwords.kdbx: <password>
> ls
Banking/
Internet/

The commands understood by the cli shell would be the same as those understood by keepassxc-cli itself.

Subclasses of Command would have a new optional method suggest (or something similar), allowing them the opportunity to offer tab completion suggestions.

For systems without readline, the fallback would just be to read from standard input with no fancy features such as editing, history, tab completion, etc.

Would this be of interest?

@droidmonkey

This comment has been minimized.

Copy link
Member

@droidmonkey droidmonkey commented Jul 30, 2019

It would make more sense to add a command "shell" which would drop you into this interface. Then you could use the standard commands from there.

@sjamesr

This comment has been minimized.

Copy link
Contributor

@sjamesr sjamesr commented Jul 31, 2019

shell seems like a fine name for this command too.

I’d like to reuse the existing command parsing code as much as possible. However, QCommandLineParser requires a QStringList of arguments. Since the existing commands rely on the shell to split strings, the shell command is probably going to implement splitting differently. This might cause surprises.

Do you have a better idea about how to navigate this issue?

@droidmonkey

This comment has been minimized.

Copy link
Member

@droidmonkey droidmonkey commented Jul 31, 2019

Sorry I missed that you introduced the new command open in your previous post. That is also appropriate and a little more elegant.

Look at how normal commands are executed:

QString commandName = parser.positionalArguments().at(0);
Command* command = Command::getCommand(commandName);
if (command == nullptr) {
qCritical("Invalid command %s.", qPrintable(commandName));
// showHelp exits the application immediately, so we need to set the
// exit code here.
parser.showHelp(EXIT_FAILURE);
}
// Removing the first argument (keepassxc).
arguments.removeFirst();
int exitCode = command->execute(arguments);

The argument list is simply a string list which can be obtained by:

line = readline();
arguments = line.split(' ')

auto command = Command::getCommand(arguments.takeFirst())
command->execute(arguments)

You can also split using a regular expression like: QRegularExpression('\s+')

@sjamesr

This comment has been minimized.

Copy link
Contributor

@sjamesr sjamesr commented Jul 31, 2019

@droidmonkey

This comment has been minimized.

Copy link
Member

@droidmonkey droidmonkey commented Jul 31, 2019

That is a good point. You can just emulate the functionality of the entire "main" function in keepassxc-cli.cpp. Define a QCommandLineParser with the single command positional argument and pass the remainder onto the execute function.

@sjamesr

This comment has been minimized.

Copy link
Contributor

@sjamesr sjamesr commented Aug 5, 2019

You can try out interactive mode now with pull request #3426, it's just a demo but it supports the ls and show commands, thus it's already quite useful.

Tab completion is just standard readline (i.e. filenames) right now, but I'm planning to extend that with context-aware completion.

sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 7, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 7, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 7, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 7, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 7, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 8, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 19, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 20, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 20, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Aug 20, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
droidmonkey added a commit to sjamesr/keepassxc that referenced this issue Aug 31, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

* Fixes keepassxreboot#3224.
* Add help command.
- This change eliminates the use of the QCommandLineParser::addHelpOption
builtin, because that causes the program to exit if the option is specified, which is not what we want for an interactive program.

* Allow users to open a new database even if one is already open
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Sep 3, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

* Fixes keepassxreboot#3224.
* Add help command.
- This change eliminates the use of the QCommandLineParser::addHelpOption
builtin, because that causes the program to exit if the option is specified, which is not what we want for an interactive program.

* Allow users to open a new database even if one is already open
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Sep 3, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

* Fixes keepassxreboot#3224.
* Add help command.
- This change eliminates the use of the QCommandLineParser::addHelpOption
builtin, because that causes the program to exit if the option is specified, which is not what we want for an interactive program.

* Allow users to open a new database even if one is already open
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Sep 6, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli.
If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to
the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each
invocation, and existing command implementations do not have to be
changed to support interactive mode.

Fixes keepassxreboot#3224.
sjamesr added a commit to sjamesr/keepassxc that referenced this issue Sep 9, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin
with no editing support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of
DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

* Fixes keepassxreboot#3224.
* Add help command.
- This change eliminates the use of the QCommandLineParser::addHelpOption
builtin, because that causes the program to exit if the option is specified, which is not what we want for an interactive program.

* Allow users to open a new database even if one is already open
droidmonkey added a commit to sjamesr/keepassxc that referenced this issue Sep 23, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin with no editing or auto-complete support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

This change also introduces a new way of handling commands between interactive and batch modes.

* Fixes keepassxreboot#3224.
* Ran make format
droidmonkey added a commit to sjamesr/keepassxc that referenced this issue Sep 28, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin with no editing or auto-complete support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

This change also introduces a new way of handling commands between interactive and batch modes.

* Fixes keepassxreboot#3224.
* Ran make format
droidmonkey added a commit that referenced this issue Sep 28, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin with no editing or auto-complete support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

This change also introduces a new way of handling commands between interactive and batch modes.

* Fixes #3224.
* Ran make format
phoerious added a commit that referenced this issue Oct 26, 2019
Added

- Add 'Paper Backup' aka 'Export to HTML file' to the 'Database' menu [[#3277](#3277)]
- Add statistics panel with information about the database (number of entries, number of unique passwords, etc.) to the Database Settings dialog [[#2034](#2034)]
- Add offline user manual accessible via the 'Help' menu [[#3274](#3274)]
- Add support for importing 1Password OpVault files [[#2292](#2292)]
- Implement Freedesktop.org secret storage DBus protocol so that KeePassXC can be used as a vault service by libsecret [[#2726](#2726)]
- Add support for OnlyKey as an alternative to YubiKeys (requires yubikey-personalization >= 1.20.0) [[#3352](#3352)]
- Add group sorting feature [[#3282](#3282)]
- Add feature to download favicons for all entries at once [[#3169](#3169)]
- Add word case option to passphrase generator [[#3172](#3172)]
- Add support for RFC6238-compliant TOTP hashes [[#2972](#2972)]
- Add UNIX man page for main program [[#3665](#3665)]
- Add 'Monospaced font' option to the notes field [[#3321](#3321)]
- Add support for key files in auto open [[#3504](#3504)]
- Add search field for filtering entries in Auto-Type dialog [[#2955](#2955)]
- Complete usernames based on known usernames from other entries [[#3300](#3300)]
- Parse hyperlinks in the notes field of the entry preview pane [[#3596](#3596)]
- Allow abbreviation of field names in entry search [[#3440](#3440)]
- Allow setting group icons recursively [[#3273](#3273)]
- Add copy context menu for username and password in Auto-Type dialog [[#3038](#3038)]
- Drop to background after copying a password to the clipboard [[#3253](#3253)]
- Add 'Lock databases' entry to tray icon menu [[#2896](#2896)]
- Add option to minimize window after unlocking [[#3439](#3439)]
- Add option to minimize window after opening a URL [[#3302](#3302)]
- Request accessibility permissions for Auto-Type on macOS [[#3624](#3624)]
- Browser: Add initial support for multiple URLs [[#3558](#3558)]
- Browser: Add entry-specific browser integration settings [[#3444](#3444)]
- CLI: Add offline HIBP checker (requires a downloaded HIBP dump) [[#2707](#2707)]
- CLI: Add 'flatten' option to the 'ls' command [[#3276](#3276)]
- CLI: Add password generation options to `Add` and `Edit` commands [[#3275](#3275)]
- CLI: Add XML import [[#3572](#3572)]
- CLI: Add CSV export to the 'export' command [[#3278](#3278)]
- CLI: Add `-y --yubikey` option for YubiKey [[#3416](#3416)]
- CLI: Add `--dry-run` option for merging databases [[#3254](#3254)]
- CLI: Add group commands (mv, mkdir and rmdir) [[#3313](#3313)].
- CLI: Add interactive shell mode command `open` [[#3224](#3224)]

Changed

- Redesign database unlock dialog [ [#3287](#3287)]
- Rework the entry preview panel [ [#3306](#3306)]
- Move notes to General tab on Group Preview Panel [[#3336](#3336)]
- Enable entry actions when editing an entry and cleanup entry context menu  [[#3641](#3641)]
- Improve detection of external database changes  [[#2389](#2389)]
- Warn if user is trying to use a KDBX file as a key file [[#3625](#3625)]
- Add option to disable KeePassHTTP settings migrations prompt [[#3349](#3349), [#3344](#3344)]
- Re-enabled Wayland support (no Auto-Type yet) [[#3520](#3520), [#3341](#3341)]
- Add icon to 'Toggle Window' action in tray icon menu [[3244](#3244)]
- Merge custom data between databases only when necessary [[#3475](#3475)]
- Improve various file-handling related issues when picking files using the system's file dialog [[#3473](#3473)]
- Add 'New Entry' context menu when no entries are selected [[#3671](#3671)]
- Reduce default Argon2 settings from 128 MiB and one thread per CPU core to 64 MiB and two threads to account for lower-spec mobile hardware [ [#3672](#3672)]
- Browser: Remove unused 'Remember' checkbox for HTTP Basic Auth [[#3371](#3371)]
- Browser: Show database name when pairing with a new browser [[#3638](#3638)]
- Browser: Show URL in allow access dialog [[#3639](#3639)]
- CLI: The password length option `-l` for the CLI commands `Add` and `Edit` is now `-L` [[#3275](#3275)]
- CLI: The `-u` shorthand for the `--upper` password generation option has been renamed to `-U` [[#3275](#3275)]
- CLI: Rename command `extract` to `export`. [[#3277](#3277)]

Fixed

- Improve accessibility for assistive technologies [[#3409](#3409)]
- Correctly unlock all databases if `--pw-stdin` is provided [[#2916](#2916)]
- Fix password generator issues with special characters [[#3303](#3303)]
- Fix KeePassXC interrupting shutdown procedure [[#3666](#3666)]
- Fix password visibility toggle button state on unlock dialog [[#3312](#3312)]
- Fix potential data loss if database is reloaded while user is editing an entry [[#3656](#3656)]
- Fix hard-coded background color in search help popup [[#3001](#3001)]
- Fix font choice for password preview [[#3425](#3425)]
- Fix handling of read-only files when autosave is enabled [[#3408](#3408)]
- Handle symlinks correctly when atomic saves are disabled [[#3463](#3463)]
- Enable HighDPI icon scaling on Linux [[#3332](#3332)]
- Make Auto-Type on macOS more robust and remove old Carbon API calls [[#3634](#3634), [[#3347](#3347))]
- Hide Share tab if KeePassXC is compiled without KeeShare support and other minor KeeShare improvements [[#3654](#3654), [[#3291](#3291), [#3029](#3029), [#3031](#3031), [#3236](#3236)]
- Correctly bring window to the front when clicking tray icon on macOS [[#3576](#3576)]
- Correct application shortcut created by MSI Installer on Windows [[#3296](#3296)]
- Fix crash when removing custom data [[#3508](#3508)]
- Fix placeholder resolution in URLs [[#3281](#3281)]
- Fix various inconsistencies and platform-dependent compilation bugs [[#3664](#3664), [#3662](#3662), [#3660](#3660), [#3655](#3655), [#3649](#3649), [#3417](#3417), [#3357](#3357), [#3319](#3319), [#3318](#3318), [#3304](#3304)]
- Browser: Fix potential leaking of entries through the browser integration API if multiple databases are opened [[#3480](#3480)]
- Browser: Fix password entropy calculation [[#3107](#3107)]
- Browser: Fix Windows registry settings for portable installation [[#3603](#3603)]
scoroi added a commit to scoroi/keepassxc that referenced this issue Nov 10, 2019
This change adds a GNU Readline-based interactive mode to keepassxc-cli. If GNU Readline is not available, commands are just read from stdin with no editing or auto-complete support.

DatabaseCommand is modified to add the path to the current database to the arguments passed to executeWithDatabase. In this way, instances of DatabaseCommand do not have to prompt to re-open the database after each invocation, and existing command implementations do not have to be changed to support interactive mode.

This change also introduces a new way of handling commands between interactive and batch modes.

* Fixes keepassxreboot#3224.
* Ran make format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.