mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
password management
This commit is contained in:
parent
00e5bf4cde
commit
dbcbcc1ad2
1 changed files with 45 additions and 5 deletions
|
|
@ -22,9 +22,6 @@ from prompt_toolkit.history import FileHistory
|
||||||
from prompt_toolkit.formatted_text import ANSI
|
from prompt_toolkit.formatted_text import ANSI
|
||||||
from prompt_toolkit.key_binding import KeyBindings
|
from prompt_toolkit.key_binding import KeyBindings
|
||||||
from prompt_toolkit.shortcuts import radiolist_dialog
|
from prompt_toolkit.shortcuts import radiolist_dialog
|
||||||
|
|
||||||
#from typing import Iterable, Mapping, Set, Union
|
|
||||||
|
|
||||||
from prompt_toolkit.completion.word_completer import WordCompleter
|
from prompt_toolkit.completion.word_completer import WordCompleter
|
||||||
from prompt_toolkit.document import Document
|
from prompt_toolkit.document import Document
|
||||||
|
|
||||||
|
|
@ -316,7 +313,7 @@ class MyNestedCompleter(NestedCompleter):
|
||||||
opts = []
|
opts = []
|
||||||
for k in self.options.keys():
|
for k in self.options.keys():
|
||||||
if k[0] == "/" :
|
if k[0] == "/" :
|
||||||
v = "/" + k.split("/")[1] + ("/" if k.count("/") == 2 else "")
|
v = "/" + k.split("/")[1] #+ ("/" if k.count("/") == 2 else "")
|
||||||
if v not in opts:
|
if v not in opts:
|
||||||
opts.append(v)
|
opts.append(v)
|
||||||
else:
|
else:
|
||||||
|
|
@ -478,6 +475,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
|
||||||
"change_flags" : None,
|
"change_flags" : None,
|
||||||
"req_telemetry" : None,
|
"req_telemetry" : None,
|
||||||
"req_binary" : None,
|
"req_binary" : None,
|
||||||
|
"forget_password" : None,
|
||||||
}
|
}
|
||||||
|
|
||||||
client_completion_list = dict(contact_completion_list)
|
client_completion_list = dict(contact_completion_list)
|
||||||
|
|
@ -623,7 +621,6 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
|
||||||
contact = to
|
contact = to
|
||||||
prev_contact = None
|
prev_contact = None
|
||||||
|
|
||||||
# await get_contacts(mc, anim=True)
|
|
||||||
await get_contacts(mc, anim=True)
|
await get_contacts(mc, anim=True)
|
||||||
await get_channels(mc, anim=True)
|
await get_channels(mc, anim=True)
|
||||||
await subscribe_to_msgs(mc, above=True)
|
await subscribe_to_msgs(mc, above=True)
|
||||||
|
|
@ -889,6 +886,14 @@ async def process_contact_chat_line(mc, contact, line):
|
||||||
await process_cmds(mc, args)
|
await process_cmds(mc, args)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# special case for rp that can be chained from cmdline
|
||||||
|
if line.startswith("rp ") or line.startswith("reset_path ") :
|
||||||
|
args = ["rp", contact['adv_name']]
|
||||||
|
await process_cmds(mc, args)
|
||||||
|
secline = line.split(" ", 1)[1]
|
||||||
|
await process_contact_chat_line(mc, contact, secline)
|
||||||
|
return True
|
||||||
|
|
||||||
if line.startswith("set timeout "):
|
if line.startswith("set timeout "):
|
||||||
cmds=line.split(" ")
|
cmds=line.split(" ")
|
||||||
contact["timeout"] = float(cmds[2])
|
contact["timeout"] = float(cmds[2])
|
||||||
|
|
@ -961,6 +966,38 @@ async def process_contact_chat_line(mc, contact, line):
|
||||||
await process_cmds(mc, args)
|
await process_cmds(mc, args)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if line == "login": # use stored password or prompt for it
|
||||||
|
password_file = ""
|
||||||
|
password = ""
|
||||||
|
if os.path.isdir(MCCLI_CONFIG_DIR) :
|
||||||
|
password_file = MCCLI_CONFIG_DIR + contact['adv_name'] + ".pass"
|
||||||
|
if os.path.exists(password_file) :
|
||||||
|
with open(password_file, "r", encoding="utf-8") as f :
|
||||||
|
password=f.readline().strip()
|
||||||
|
|
||||||
|
if password == "":
|
||||||
|
sess = PromptSession("Password: ", is_password=True)
|
||||||
|
password = await sess.prompt_async()
|
||||||
|
|
||||||
|
if password_file != "":
|
||||||
|
with open(password_file, "w", encoding="utf-8") as f :
|
||||||
|
f.write(password)
|
||||||
|
|
||||||
|
args = ["login", contact['adv_name'], password]
|
||||||
|
await process_cmds(mc, args)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if line.startswith("forget_password") or line.startswith("fp"):
|
||||||
|
password_file = MCCLI_CONFIG_DIR + contact['adv_name'] + ".pass"
|
||||||
|
if os.path.exists(password_file):
|
||||||
|
os.remove(password_file)
|
||||||
|
try:
|
||||||
|
secline = line.split(" ", 1)[1]
|
||||||
|
await process_contact_chat_line(mc, contact, secline)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
return True
|
||||||
|
|
||||||
if contact["type"] == 4 and \
|
if contact["type"] == 4 and \
|
||||||
(line.startswith("req_mma ") or line.startswith('rm ')) :
|
(line.startswith("req_mma ") or line.startswith('rm ')) :
|
||||||
cmds = line.split(" ")
|
cmds = line.split(" ")
|
||||||
|
|
@ -1089,6 +1126,9 @@ async def get_channel_by_name (mc, name):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def get_contacts (mc, anim=False, lastomod=0, timeout=5) :
|
async def get_contacts (mc, anim=False, lastomod=0, timeout=5) :
|
||||||
|
if mc._contacts:
|
||||||
|
return
|
||||||
|
|
||||||
if anim:
|
if anim:
|
||||||
print("Fetching contacts ", end="", flush=True)
|
print("Fetching contacts ", end="", flush=True)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue