Skip to content

Commit b7fdcf1

Browse files
committed
blank password for remove password field
1 parent b48081b commit b7fdcf1

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def main():
1010
url='https://github.com/zlaxy/sshch/',
1111
description='Ssh connection manager',
1212
license='DWTWL 2.55',
13-
version='0.998',
13+
version='0.999',
1414
py_modules=['sshch'],
1515
scripts=['sshch/sshch'],
1616

sshch/sshch

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import curses
2020
from curses import textpad, panel
2121

2222
# https://github.com/zlaxy/sshch
23-
version = "0.998"
23+
version = "0.999"
2424
# path to conf file, default: ~/.config/sshch.conf
2525
conf_file = path.expanduser("~") + '/.config/sshch.conf'
2626
# expand groups by default
@@ -47,9 +47,14 @@ def SetGroupString(alias, string):
4747

4848

4949
def SetPassword(alias, string):
50-
string = base64.b64encode(base64.b16encode(
51-
base64.b32encode(string)))
52-
conf.set(alias, "password", string)
50+
if string == "" or string == b'':
51+
conf.remove_option(alias, "password")
52+
else:
53+
string = string.encode()
54+
string = base64.b64encode(base64.b16encode(
55+
base64.b32encode(string)))
56+
string = string.decode('utf-8')
57+
conf.set(alias, "password", string)
5358
conf.write(open(conf_file, "w"))
5459

5560

@@ -64,7 +69,7 @@ def ConnectAlias(alias, command=False):
6469
if conf.has_option(alias, "password"):
6570
password = base64.b32decode(base64.b16decode(
6671
base64.b64decode(conf.get(alias, "password"))))
67-
exec_string = 'sshpass -p "' + password + '" '
72+
exec_string = 'sshpass -p "' + password.decode('utf-8') + '" '
6873
if conf.has_option(alias, "exec_string"):
6974
exec_string = exec_string + conf.get(alias, "exec_string")
7075
if command:
@@ -118,7 +123,7 @@ def CMDGroup(group):
118123

119124
def CMDEdit(alias):
120125
if conf.has_section(alias):
121-
if conf.has_option(alias, "string"):
126+
if conf.has_option(alias, "exec_string"):
122127
prompt_edit = ("".join(["Enter connection string for existing alias ",
123128
"(example: ssh [email protected]):\n"]))
124129
string = ""
@@ -148,11 +153,10 @@ def CMDPassword(alias):
148153
print("Can't set password for group.")
149154
else:
150155
if conf.has_section(alias):
151-
prompt_pass = ("[UNSAFE] Enter password for sshpass: ")
156+
prompt_pass = ("[UNSAFE] Enter password for sshpass (Ctrl+C - cancel, blank - clear password):\n")
152157
string = ""
153158
string = getpass(prompt_pass)
154-
if not string == "":
155-
SetPassword(alias, string)
159+
SetPassword(alias, string)
156160
else:
157161
print("error: '" + alias + "' alias does not exists")
158162

@@ -600,8 +604,7 @@ def CursesMain():
600604
(height // 2) - 1, 3,
601605
" Enter user password for sshpass and press 'enter':\n>",
602606
normal_text, highlight_text, "password")
603-
if not set_password == "":
604-
SetPassword(strings[position - 1].split()[0].strip(), set_password)
607+
SetPassword(strings[position - 1].split()[0].strip(), set_password)
605608
strings = GetTreeList(False, expanded)
606609
stringsfull = GetTreeList(True, expanded)
607610
if (key_pressed == ord('r') or key_pressed == ord(

0 commit comments

Comments
 (0)