mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-02 07:07:18 -04:00
Fix copy_id_check resulting in errors when called from another module
Former-commit-id: 31bb5415499ca5f06413eba61eaafd284d2d5da1 Former-commit-id: 9cd0e6852e09874a1a06c8cde22e539f1cb58345
This commit is contained in:
+4
-4
@@ -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
|
# 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
|
from stweak import write_config
|
||||||
if not _sshyp_data.has_section('CLIENT-ONLINE'):
|
if not _sshyp_data.has_section('CLIENT-ONLINE'):
|
||||||
_sshyp_data.add_section('CLIENT-ONLINE')
|
_sshyp_data.add_section('CLIENT-ONLINE')
|
||||||
try:
|
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'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)
|
f'{_client_device_id}").touch(mode=0o400, exist_ok=True)\''), stderr=DEVNULL, check=True)
|
||||||
except CalledProcessError:
|
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 '
|
'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')
|
'functionality will be disabled until this is addressed\u001b[0m\n')
|
||||||
_sshyp_data.set('CLIENT-ONLINE', 'ssh_error', 'true')
|
_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]
|
client_device_id = listdir(f"{home}/.config/sshyp/devices")[0]
|
||||||
ssh_error = sshyp_data.getboolean('CLIENT-ONLINE', 'ssh_error')
|
ssh_error = sshyp_data.getboolean('CLIENT-ONLINE', 'ssh_error')
|
||||||
if 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):
|
except (FileNotFoundError, NoSectionError, NoOptionError):
|
||||||
print(f"\n{73*'!'}")
|
print(f"\n{73*'!'}")
|
||||||
print("not all necessary configurations have been made - please run 'sshyp init'")
|
print("not all necessary configurations have been made - please run 'sshyp init'")
|
||||||
|
|||||||
+10
-10
@@ -184,11 +184,11 @@ def ssh_config():
|
|||||||
sshyp_data.set('SSHYNC', 'remote_dir', f"/home/{_username_ssh}/.local/share/sshyp/")
|
sshyp_data.set('SSHYNC', 'remote_dir', f"/home/{_username_ssh}/.local/share/sshyp/")
|
||||||
sshyp_data.set('SSHYNC', 'identity_file', _ssh_key)
|
sshyp_data.set('SSHYNC', 'identity_file', _ssh_key)
|
||||||
write_config()
|
write_config()
|
||||||
return _iport[1], _username_ssh, _iport[0]
|
return _iport[1], _username_ssh, _iport[0], _ssh_key
|
||||||
|
|
||||||
|
|
||||||
# device id configuration
|
# 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
|
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 '
|
_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 '
|
'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}")
|
remove(f"{home}/.config/sshyp/devices/{_id}")
|
||||||
open(f"{home}/.config/sshyp/devices/{_device_id}", 'w')
|
open(f"{home}/.config/sshyp/devices/{_device_id}", 'w')
|
||||||
# test server connection and attempt to register device id
|
# 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
|
# 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'):
|
if not sshyp_data.has_option('CLIENT-ONLINE', 'quick_unlock_enabled'):
|
||||||
quick_unlock_config(True)
|
quick_unlock_config(True)
|
||||||
# set to None to check if modified later
|
# 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
|
# ...and there is no sshync config present
|
||||||
if not sshyp_data.has_section('SSHYNC'):
|
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
|
# ...and there is no device ID present
|
||||||
if not listdir(f"{home}/.config/sshyp/devices"):
|
if not listdir(f"{home}/.config/sshyp/devices"):
|
||||||
if None in (_ip, _username_ssh, _port):
|
if None in (_ip, _username_ssh, _port):
|
||||||
_ip, _username_ssh, _port = ssh_config()
|
_ip, _username_ssh, _port, _identity = ssh_config()
|
||||||
dev_id_config(_ip, _username_ssh, _port)
|
dev_id_config(_ip, _username_ssh, _port, _identity)
|
||||||
# ...or ssh_error is missing
|
# ...or ssh_error is missing
|
||||||
elif not sshyp_data.has_option('CLIENT-ONLINE', 'ssh_error'):
|
elif not sshyp_data.has_option('CLIENT-ONLINE', 'ssh_error'):
|
||||||
sshyp_data.set('CLIENT-ONLINE', 'ssh_error', '1')
|
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'):
|
if not sshyp_data.has_section('SSHYNC'):
|
||||||
ssh_config()
|
ssh_config()
|
||||||
dev_id_config(sshyp_data.get('SSHYNC', 'ip'), sshyp_data.get('SSHYNC', 'user'),
|
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:
|
elif _choice == 4:
|
||||||
editor_config(False)
|
editor_config(False)
|
||||||
elif _choice == 5:
|
elif _choice == 5:
|
||||||
@@ -555,10 +555,10 @@ def initial_setup(_scr):
|
|||||||
if _dev_sync_types[1] != 'true':
|
if _dev_sync_types[1] != 'true':
|
||||||
|
|
||||||
# ssh+sshync configuration
|
# ssh+sshync configuration
|
||||||
_ip, _username_ssh, _port = ssh_config()
|
_ip, _username_ssh, _port, _identity = ssh_config()
|
||||||
|
|
||||||
# device id configuration
|
# device id configuration
|
||||||
dev_id_config(_ip, _username_ssh, _port)
|
dev_id_config(_ip, _username_ssh, _port, _identity)
|
||||||
|
|
||||||
# PORT START CLIPTOOL
|
# PORT START CLIPTOOL
|
||||||
# check for clipboard tool and display warning if missing
|
# check for clipboard tool and display warning if missing
|
||||||
|
|||||||
Reference in New Issue
Block a user