mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-31 22:36:31 -04:00
Initial addition of offline mode
Former-commit-id: 8bd18e3b3ba4d5d737c25416632ba13a6a38c0ef [formerly 2c1241a1bc]
Former-commit-id: fdb675335dd16ed90cf1deb439a665ba2b3621bb
This commit is contained in:
+61
-46
@@ -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,55 +260,64 @@ 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')
|
||||||
|
|
||||||
# ssh ip+port configuration
|
if not _offline_mode:
|
||||||
_ip_port = str(input(f"{_divider}example input: 10.10.10.10:9999\n\nip and ssh port of the remote server: "))
|
# ssh ip+port configuration
|
||||||
_ip, _sep, _port = _ip_port.partition(':')
|
_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(':')
|
||||||
|
|
||||||
# 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
|
# sshync profile generation
|
||||||
_sshyp_data += input(f"{_divider}example input: vim\n\npreferred text editor: ")
|
sshync.make_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'),
|
||||||
|
path.expanduser('~/.local/share/sshyp/'), f"/home/{_username_ssh}/.local/share/sshyp/",
|
||||||
|
path.expanduser('~/.ssh/sshyp'), _ip, _port, _username_ssh)
|
||||||
|
|
||||||
# sshync profile generation
|
# device id configuration
|
||||||
sshync.make_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'),
|
for _id in listdir(path.expanduser('~/.config/sshyp/devices')): # remove existing device id
|
||||||
path.expanduser('~/.local/share/sshyp/'), f"/home/{_username_ssh}/.local/share/sshyp/",
|
remove(f"{path.expanduser('~/.config/sshyp/devices/')}{_id}")
|
||||||
path.expanduser('~/.ssh/sshyp'), _ip, _port, _username_ssh)
|
print(f"{_divider}\u001b[4;1mimportant:\u001b[0m this id \u001b[4;1mmust\u001b[0m be unique amongst your "
|
||||||
|
f"client devices\n\nthis is used to keep track of database syncing and quick-unlock permissions\n")
|
||||||
|
_device_id_prefix = str(input('device id: '))
|
||||||
|
_device_id_suffix = string_gen('c', randint(12, 48))
|
||||||
|
_device_id = _device_id_prefix + _device_id_suffix
|
||||||
|
open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w')
|
||||||
|
|
||||||
# device id configuration
|
# quick-unlock configuration
|
||||||
for _id in listdir(path.expanduser('~/.config/sshyp/devices')): # remove existing device id
|
print(f"{_divider}\nthis allows you to use a shorter version of your gpg key password and\n"
|
||||||
remove(f"{path.expanduser('~/.config/sshyp/devices/')}{_id}")
|
f"requires a constant connection to your sshyp server to authenticate\n")
|
||||||
print(f"{_divider}\u001b[4;1mimportant:\u001b[0m this id \u001b[4;1mmust\u001b[0m be unique amongst your "
|
_quick_unlock_enabled = input('enable quick-unlock? (y/N)')
|
||||||
f"client devices\n\nthis is used to keep track of database syncing and quick-unlock permissions\n")
|
if _quick_unlock_enabled.lower() == 'y':
|
||||||
_device_id_prefix = str(input('device id: '))
|
_sshyp_data += 'quick'
|
||||||
_device_id_suffix = string_gen('c', randint(12, 48))
|
_sshyp_data += int(
|
||||||
_device_id = _device_id_prefix + _device_id_suffix
|
input('this must be half the number of characters in your gpg key password or shorter'
|
||||||
open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w')
|
'\n\nquick-unlock key length: '))
|
||||||
copy_id_check(_port, _username_ssh, _ip, _device_id)
|
print(f"\nquick-unlock has been enabled client-side - in order for this device to be able to read "
|
||||||
|
f"entries,\nyou must first login to the sshyp server and run:\n\nsshyp whitelist add "
|
||||||
|
f"{_device_id}")
|
||||||
|
else:
|
||||||
|
_sshyp_data += 'slow', 0
|
||||||
|
|
||||||
# quick-unlock configuration
|
# test server connection and attempt to register device id
|
||||||
print(f"{_divider}\nthis allows you to use a shorter version of your gpg key password and\n"
|
copy_id_check(_port, _username_ssh, _ip, _device_id)
|
||||||
f"requires a constant connection to your sshyp server to authenticate\n")
|
|
||||||
_quick_unlock_enabled = input('enable quick-unlock? (y/N)')
|
elif Path(path.expanduser('~/.config/sshyp/sshyp.sshync')).is_file():
|
||||||
if _quick_unlock_enabled.lower() == 'y':
|
remove(path.expanduser('~/.config/sshyp/sshyp.sshync'))
|
||||||
_sshyp_data += 'quick'
|
|
||||||
_sshyp_data += int(input('this must be half the number of characters in your gpg key password or shorter'
|
|
||||||
'\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,"
|
|
||||||
f"\nyou must first login to the sshyp server and run:\n\nsshyp whitelist add {_device_id}")
|
|
||||||
else:
|
|
||||||
_sshyp_data += 'slow', 0
|
|
||||||
|
|
||||||
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()
|
||||||
ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'))
|
if Path(path.expanduser('~/.config/sshyp/sshyp.sshync')).is_file():
|
||||||
username_ssh = ssh_info[0].rstrip()
|
ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'))
|
||||||
ip = ssh_info[1].rstrip()
|
username_ssh = ssh_info[0].rstrip()
|
||||||
port = ssh_info[2].rstrip()
|
ip = ssh_info[1].rstrip()
|
||||||
directory = str(ssh_info[3].rstrip())
|
port = ssh_info[2].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":
|
||||||
|
|||||||
Reference in New Issue
Block a user