From 5ac5070d11b8cffdb363b22c54508c481e249e8c Mon Sep 17 00:00:00 2001 From: boltgolt Date: Fri, 4 May 2018 21:39:52 +0200 Subject: [PATCH] Updated the autocomplete file and disable command --- autocomplete/howdy | 33 +++++++++++++++++++++++++++++++-- src/cli/disable.py | 11 ++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/autocomplete/howdy b/autocomplete/howdy index 40ce2a2..339bcca 100755 --- a/autocomplete/howdy +++ b/autocomplete/howdy @@ -5,11 +5,40 @@ _howdy() { local cur prev opts COMPREPLY=() + # The argument typed so far cur="${COMP_WORDS[COMP_CWORD]}" + # The previous argument prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="help list add remove clear" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + # Go though all cases we support + case "${prev}" in + # After the main command, show the commands + "howdy") + opts="add clear config disable list remove clear test" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; + # For disable, grab the current "disabled" config option and give the reverse + "disable") + local status=$(cut -d'=' -f2 <<< $(cat /lib/security/howdy/config.ini | grep 'disabled =') | xargs echo -n) + + [ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false" + return 0 + ;; + # List the users availible + "-U") + COMPREPLY=( $(compgen -u -- ${cur}) ) + return 0 + ;; + "--user") + COMPREPLY=( $(compgen -u -- ${cur}) ) + return 0 + ;; + *) + ;; + esac + + # Nothing matched, so return nothing return 0 } diff --git a/src/cli/disable.py b/src/cli/disable.py index 2c2b03b..8bc0341 100644 --- a/src/cli/disable.py +++ b/src/cli/disable.py @@ -21,13 +21,18 @@ if builtins.howdy_args.argument == None: sys.exit(1) # Translate the argument to the right string -if builtins.howdy_args.argument == "1": +if builtins.howdy_args.argument == "1" or builtins.howdy_args.argument.lower() == "true": out_value = "true" -elif builtins.howdy_args.argument == "0": +elif builtins.howdy_args.argument == "0" or builtins.howdy_args.argument.lower() == "false": out_value = "false" else: # Of it's not a 0 or a 1, it's invalid - print("Please only use a 0 (enable) or a 1 (disable) as an argument") + print("Please only use false (enable) or true (disable) as an argument") + sys.exit(1) + +# Don't do anything when the state is already the requested one +if out_value == config.get("core", "disabled"): + print("The disable option has already been set to " + out_value) sys.exit(1) # Loop though the config file and only replace the line containing the disable config