diff --git a/lib/sshyp.py b/lib/sshyp.py index 14974c0..620452a 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -260,16 +260,16 @@ def line_edit(_lines, _edit_data, _edit_line): # attempts to connect to the user's server via ssh to register the device for syncing -def copy_id_check(_port, _username_ssh, _ip, _client_device_id, _sshyp_data): +def copy_id_check(_port, _username_ssh, _ip, _client_device_id, _identity, _sshyp_data): from stweak import write_config if not _sshyp_data.has_section('CLIENT-ONLINE'): _sshyp_data.add_section('CLIENT-ONLINE') try: - run(('ssh', '-o', 'ConnectTimeout=3', '-i', identity, '-p', _port, f"{_username_ssh}@{_ip}", + run(('ssh', '-o', 'ConnectTimeout=3', '-i', _identity, '-p', _port, f"{_username_ssh}@{_ip}", f'python3 -c \'from pathlib import Path; Path("/home/{_username_ssh}/.config/sshyp/devices/' f'{_client_device_id}").touch(mode=0o400, exist_ok=True)\''), stderr=DEVNULL, check=True) except CalledProcessError: - print(f'\n\u001b[38;5;9mwarning: ssh connection could not be made - ensure the public key ({identity}) is ' + print(f'\n\u001b[38;5;9mwarning: ssh connection could not be made - ensure the public key ({_identity}) is ' 'registered on the remote server and that the entered ip, port, and username are correct\n\nsyncing ' 'functionality will be disabled until this is addressed\u001b[0m\n') _sshyp_data.set('CLIENT-ONLINE', 'ssh_error', 'true') @@ -664,7 +664,7 @@ if __name__ == "__main__": client_device_id = listdir(f"{home}/.config/sshyp/devices")[0] ssh_error = sshyp_data.getboolean('CLIENT-ONLINE', 'ssh_error') if ssh_error: - ssh_error = copy_id_check(port, username_ssh, ip, client_device_id, sshyp_data) + ssh_error = copy_id_check(port, username_ssh, ip, client_device_id, identity, sshyp_data) except (FileNotFoundError, NoSectionError, NoOptionError): print(f"\n{73*'!'}") print("not all necessary configurations have been made - please run 'sshyp init'") diff --git a/lib/stweak.py b/lib/stweak.py index e26f035..0c2517d 100644 --- a/lib/stweak.py +++ b/lib/stweak.py @@ -184,11 +184,11 @@ def ssh_config(): sshyp_data.set('SSHYNC', 'remote_dir', f"/home/{_username_ssh}/.local/share/sshyp/") sshyp_data.set('SSHYNC', 'identity_file', _ssh_key) write_config() - return _iport[1], _username_ssh, _iport[0] + return _iport[1], _username_ssh, _iport[0], _ssh_key # device id configuration -def dev_id_config(_ip, _username_ssh, _port): +def dev_id_config(_ip, _username_ssh, _port, _identity): from sshyp import copy_id_check, string_gen _device_id_prefix = curses_text('name this device:\n\n\n\n\n(ctrl+g/enter to confirm)\n\nimportant: this ' 'id must be unique amongst your client devices\n\nthis is used to keep track of ' @@ -200,7 +200,7 @@ def dev_id_config(_ip, _username_ssh, _port): remove(f"{home}/.config/sshyp/devices/{_id}") open(f"{home}/.config/sshyp/devices/{_device_id}", 'w') # test server connection and attempt to register device id - copy_id_check(_ip, _username_ssh, _port, _device_id, sshyp_data) + copy_id_check(_ip, _username_ssh, _port, _device_id, _identity, sshyp_data) # quick-unlock configuration @@ -464,15 +464,15 @@ def global_menu(_scr, _device_type, _top_message): if not sshyp_data.has_option('CLIENT-ONLINE', 'quick_unlock_enabled'): quick_unlock_config(True) # set to None to check if modified later - _ip, _username_ssh, _port = None, None, None + _ip, _username_ssh, _port, _identity = None, None, None, None # ...and there is no sshync config present if not sshyp_data.has_section('SSHYNC'): - _ip, _username_ssh, _port = ssh_config() + _ip, _username_ssh, _port, _identity = ssh_config() # ...and there is no device ID present if not listdir(f"{home}/.config/sshyp/devices"): if None in (_ip, _username_ssh, _port): - _ip, _username_ssh, _port = ssh_config() - dev_id_config(_ip, _username_ssh, _port) + _ip, _username_ssh, _port, _identity = ssh_config() + dev_id_config(_ip, _username_ssh, _port, _identity) # ...or ssh_error is missing elif not sshyp_data.has_option('CLIENT-ONLINE', 'ssh_error'): sshyp_data.set('CLIENT-ONLINE', 'ssh_error', '1') @@ -492,7 +492,7 @@ def global_menu(_scr, _device_type, _top_message): if not sshyp_data.has_section('SSHYNC'): ssh_config() dev_id_config(sshyp_data.get('SSHYNC', 'ip'), sshyp_data.get('SSHYNC', 'user'), - sshyp_data.get('SSHYNC', 'port')) + sshyp_data.get('SSHYNC', 'port'), sshyp_data.get('SSHYNC', 'identity_file')) elif _choice == 4: editor_config(False) elif _choice == 5: @@ -555,10 +555,10 @@ def initial_setup(_scr): if _dev_sync_types[1] != 'true': # ssh+sshync configuration - _ip, _username_ssh, _port = ssh_config() + _ip, _username_ssh, _port, _identity = ssh_config() # device id configuration - dev_id_config(_ip, _username_ssh, _port) + dev_id_config(_ip, _username_ssh, _port, _identity) # PORT START CLIPTOOL # check for clipboard tool and display warning if missing