Initial addition of offline mode

Former-commit-id: 8bd18e3b3ba4d5d737c25416632ba13a6a38c0ef [formerly 2c1241a1bc]
Former-commit-id: fdb675335dd16ed90cf1deb439a665ba2b3621bb
This commit is contained in:
2022-10-06 16:42:58 -04:00
parent 6d3ba2714b
commit dede7cf8ac
+27 -12
View File
@@ -249,6 +249,9 @@ def tweak(): # runs configuration wizard
remove(path.expanduser('~/.config/sshyp/gpg-gen')) remove(path.expanduser('~/.config/sshyp/gpg-gen'))
_sshyp_data += run(f"{gpg} -k", shell=True, stdout=PIPE, text=True).stdout.split('\n')[-4].strip() _sshyp_data += run(f"{gpg} -k", shell=True, stdout=PIPE, text=True).stdout.split('\n')[-4].strip()
# text editor configuration
_sshyp_data += input(f"{_divider}example input: vim\n\npreferred text editor: ")
# lock file generation # lock file generation
if Path(path.expanduser('~/.config/sshyp/lock.gpg')).is_file(): if Path(path.expanduser('~/.config/sshyp/lock.gpg')).is_file():
remove(path.expanduser('~/.config/sshyp/lock.gpg')) remove(path.expanduser('~/.config/sshyp/lock.gpg'))
@@ -257,27 +260,29 @@ def tweak(): # runs configuration wizard
remove(path.expanduser('~/.config/sshyp/lock')) remove(path.expanduser('~/.config/sshyp/lock'))
# ssh key configuration # ssh key configuration
_offline_mode = False
_ssh_gen = (input(f"{_divider}make sure the ssh service on the remote server is running and properly " _ssh_gen = (input(f"{_divider}make sure the ssh service on the remote server is running and properly "
f"configured\n\nsync support requires a unique ssh key - would you like to have this " f"configured\n\nsync support requires a unique ssh key - would you like to have this "
f"automatically generated? (Y/n) ")) f"automatically generated? (Y/n/o(ffline)) "))
if _ssh_gen.lower() != 'n': if _ssh_gen.lower() != 'n' and _ssh_gen.lower() != 'o' and _ssh_gen.lower() != 'offline':
if uname()[0] == 'Haiku': if uname()[0] == 'Haiku':
Path(f"{path.expanduser('~')}/.ssh").mkdir(0o700, exist_ok=True) Path(f"{path.expanduser('~')}/.ssh").mkdir(0o700, exist_ok=True)
system('ssh-keygen -t ed25519 -f ~/.ssh/sshyp') system('ssh-keygen -t ed25519 -f ~/.ssh/sshyp')
else: elif _ssh_gen.lower() == 'n':
print(f"\n\u001b[4;1mensure that the key file you are using is located at " print(f"\n\u001b[4;1mensure that the key file you are using is located at "
f"{path.expanduser('~/.ssh/sshyp')}\u001b[0m") f"{path.expanduser('~/.ssh/sshyp')}\u001b[0m")
elif _ssh_gen.lower() == 'o' or _ssh_gen.lower() == 'offline':
_offline_mode = True
print('\nsshyp has been set to offline mode - to enable syncing, run "sshyp tweak" again')
if not _offline_mode:
# ssh ip+port configuration # ssh ip+port configuration
_ip_port = str(input(f"{_divider}example input: 10.10.10.10:9999\n\nip and ssh port of the remote server: ")) _ip_port = str(input(f"{_divider}example input: 10.10.10.10:9999\n\nip and ssh port of sshyp server: "))
_ip, _sep, _port = _ip_port.partition(':') _ip, _sep, _port = _ip_port.partition(':')
# ssh user configuration # ssh user configuration
_username_ssh = str(input('\nusername of the remote server: ')) _username_ssh = str(input('\nusername of the remote server: '))
# text editor configuration
_sshyp_data += input(f"{_divider}example input: vim\n\npreferred text editor: ")
# sshync profile generation # sshync profile generation
sshync.make_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'), sshync.make_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'),
path.expanduser('~/.local/share/sshyp/'), f"/home/{_username_ssh}/.local/share/sshyp/", path.expanduser('~/.local/share/sshyp/'), f"/home/{_username_ssh}/.local/share/sshyp/",
@@ -292,7 +297,6 @@ def tweak(): # runs configuration wizard
_device_id_suffix = string_gen('c', randint(12, 48)) _device_id_suffix = string_gen('c', randint(12, 48))
_device_id = _device_id_prefix + _device_id_suffix _device_id = _device_id_prefix + _device_id_suffix
open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w') open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w')
copy_id_check(_port, _username_ssh, _ip, _device_id)
# quick-unlock configuration # quick-unlock configuration
print(f"{_divider}\nthis allows you to use a shorter version of your gpg key password and\n" print(f"{_divider}\nthis allows you to use a shorter version of your gpg key password and\n"
@@ -300,13 +304,21 @@ def tweak(): # runs configuration wizard
_quick_unlock_enabled = input('enable quick-unlock? (y/N)') _quick_unlock_enabled = input('enable quick-unlock? (y/N)')
if _quick_unlock_enabled.lower() == 'y': if _quick_unlock_enabled.lower() == 'y':
_sshyp_data += 'quick' _sshyp_data += 'quick'
_sshyp_data += int(input('this must be half the number of characters in your gpg key password or shorter' _sshyp_data += int(
input('this must be half the number of characters in your gpg key password or shorter'
'\n\nquick-unlock key length: ')) '\n\nquick-unlock key length: '))
print(f"\nquick-unlock has been enabled client-side - in order for this device to be able to read entries," print(f"\nquick-unlock has been enabled client-side - in order for this device to be able to read "
f"\nyou must first login to the sshyp server and run:\n\nsshyp whitelist add {_device_id}") f"entries,\nyou must first login to the sshyp server and run:\n\nsshyp whitelist add "
f"{_device_id}")
else: else:
_sshyp_data += 'slow', 0 _sshyp_data += 'slow', 0
# test server connection and attempt to register device id
copy_id_check(_port, _username_ssh, _ip, _device_id)
elif Path(path.expanduser('~/.config/sshyp/sshyp.sshync')).is_file():
remove(path.expanduser('~/.config/sshyp/sshyp.sshync'))
open(path.expanduser('~/.config/sshyp/sshyp-data'), 'w').writelines(sshyp_data) open(path.expanduser('~/.config/sshyp/sshyp-data'), 'w').writelines(sshyp_data)
print(f"{_divider}configuration complete\n") print(f"{_divider}configuration complete\n")
@@ -743,21 +755,24 @@ if __name__ == "__main__":
sshyp_data = open(path.expanduser('~/.config/sshyp/sshyp-data')).readlines() sshyp_data = open(path.expanduser('~/.config/sshyp/sshyp-data')).readlines()
device_type = sshyp_data[0].rstrip() device_type = sshyp_data[0].rstrip()
if device_type == 'client': if device_type == 'client':
directory = path.expanduser('~/.local/share/sshyp')
gpg_id = sshyp_data[1].rstrip() gpg_id = sshyp_data[1].rstrip()
editor = sshyp_data[2].rstrip() editor = sshyp_data[2].rstrip()
quick_unlock_status = sshyp_data[3].rstrip() quick_unlock_status = sshyp_data[3].rstrip()
if quick_unlock_status == 'quick': if quick_unlock_status == 'quick':
quick_unlock_length = sshyp_data[4].rstrip() quick_unlock_length = sshyp_data[4].rstrip()
if Path(path.expanduser('~/.config/sshyp/sshyp.sshync')).is_file():
ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync')) ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'))
username_ssh = ssh_info[0].rstrip() username_ssh = ssh_info[0].rstrip()
ip = ssh_info[1].rstrip() ip = ssh_info[1].rstrip()
port = ssh_info[2].rstrip() port = ssh_info[2].rstrip()
directory = str(ssh_info[3].rstrip())
directory_ssh = str(ssh_info[4].rstrip()) directory_ssh = str(ssh_info[4].rstrip())
client_device_id = listdir(path.expanduser('~/.config/sshyp/devices'))[0] client_device_id = listdir(path.expanduser('~/.config/sshyp/devices'))[0]
ssh_error = int(open(path.expanduser('~/.config/sshyp/ssh-error')).read().rstrip()) ssh_error = int(open(path.expanduser('~/.config/sshyp/ssh-error')).read().rstrip())
if ssh_error != 0: if ssh_error != 0:
ssh_error = copy_id_check(port, username_ssh, ip, client_device_id) ssh_error = copy_id_check(port, username_ssh, ip, client_device_id)
else:
ssh_error = 1
elif argument_list[1] != "help" and argument_list[1] != "--help" and argument_list[1] != "-h" and \ elif argument_list[1] != "help" and argument_list[1] != "--help" and argument_list[1] != "-h" and \
argument_list[1] != "license" and argument_list[1] != "version" and argument_list[1] != "-v" \ argument_list[1] != "license" and argument_list[1] != "version" and argument_list[1] != "-v" \
and argument_list[1] != "whitelist": and argument_list[1] != "whitelist":