diff options
author | Nicolas Hennion <nicolas@nicolargo.com> | 2013-11-16 11:55:42 +0100 |
---|---|---|
committer | Nicolas Hennion <nicolas@nicolargo.com> | 2013-11-16 11:55:42 +0100 |
commit | 2316d8ebf43847dc284720e2b41eede3699e2f5a (patch) | |
tree | 1a52eab78b08a944cd65740e1a1ce3763c79e68a /glances/glances.py | |
parent | f5f352310960bc68ea91397e220564843e92f211 (diff) |
Add client/server managment from the command line
Diffstat (limited to 'glances/glances.py')
-rw-r--r-- | glances/glances.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/glances/glances.py b/glances/glances.py index 89ec6a6c..b17daf52 100644 --- a/glances/glances.py +++ b/glances/glances.py @@ -4270,6 +4270,7 @@ def printSyntax(): print(_("\t-p PORT\t\tDefine the client/server TCP port (default: %d)" % server_port)) print(_("\t-P password\tDefine a client/server password")) + print(_("\tor --password\tEnter the password from the command line")) print(_("\t-r\t\tDisable process list")) print(_("\t-s\t\tRun Glances in server mode")) print(_("\t-t seconds\tSet refresh time in seconds (default: %d sec)" % @@ -4303,6 +4304,28 @@ def signal_handler(signal, frame): end() +def getpassword(description = "", confirm = False): + """ + Read a password from the command line (with confirmation if confirm = True) + """ + import getpass + + if (description != ""): + sys.stdout.write("%s\n" % description) + + password1 = getpass.getpass(_("Password: ")); + if (confirm): + password2 = getpass.getpass(_("Password (confirm): ")) + else: + return password1 + + if (password1 == password2): + return password1 + else: + sys.stdout.write(_("[Warning] Passwords did not match, please try again...\n")) + return getpassword(description = description, confirm = confirm) + + def main(): # Glances - Init stuff ###################### @@ -4459,6 +4482,8 @@ def main(): if html_tag or csv_tag: print(_("Error: Cannot use both -s and -o flag")) sys.exit(2) + if (password == ''): + password = getpassword(description = _("Define the password for the Glances server"), confirm = True) if client_tag: if html_tag or csv_tag: @@ -4468,6 +4493,8 @@ def main(): print(_("Error: Cannot use both -c and -C flag")) print(_(" Limits are set based on the server ones")) sys.exit(2) + if (password == ''): + password = getpassword(description = _("Enter the Glances server password"), confirm = False) if html_tag: if not html_lib_tag: |