mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-05 16:47:14 -04:00
Changed config directory from /var/lib/sshyp to ~/.config/sshyp (for Termux compatibility)
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
# external modules
|
# external modules
|
||||||
|
from os import environ, mkdir, remove, system, path
|
||||||
from os import environ, mkdir, remove, system
|
|
||||||
from shutil import copy, move, rmtree
|
from shutil import copy, move, rmtree
|
||||||
from sys import argv, exit as s_exit
|
from sys import argv, exit as s_exit
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -49,21 +48,21 @@ def edit_note(_shm_folder, _shm_entry):
|
|||||||
def tweak(): # runs configuration wizard
|
def tweak(): # runs configuration wizard
|
||||||
# storage directory creation
|
# storage directory creation
|
||||||
try:
|
try:
|
||||||
mkdir(f"/home/{environ.get('USER')}/.password-pasture", 0o700)
|
mkdir(f"{path.expanduser('~')}/.password-pasture", 0o700)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# device type configuration
|
# device type configuration
|
||||||
_device_type = input('\nIs this installation for a client or for a server? (C/s) ')
|
_device_type = input('\nIs this installation for a client or for a server? (C/s) ')
|
||||||
if _device_type.lower() == 's':
|
if _device_type.lower() == 's':
|
||||||
open("/var/lib/sshyp/sshyp-device", 'w').write(_device_type)
|
open(f"{path.expanduser('~/.config/sshyp')}/sshyp-device", 'w').write(_device_type)
|
||||||
copy('/usr/bin/sshync.py', f"/home/{environ.get('USER')}/")
|
copy('/usr/bin/sshync.py', path.expanduser('~/'))
|
||||||
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
||||||
s_exit()
|
s_exit()
|
||||||
else:
|
else:
|
||||||
# device type configuration
|
# device type configuration
|
||||||
_device_type = 'c' # ensure device type flag is properly set
|
_device_type = 'c' # ensure device type flag is properly set
|
||||||
open("/var/lib/sshyp/sshyp-device", 'w').write(_device_type)
|
open(f"{path.expanduser('~/.config/sshyp')}/sshyp-device", 'w').write(_device_type)
|
||||||
|
|
||||||
# gpg configuration
|
# gpg configuration
|
||||||
_gpg_id = input('\nsshyp requires the use of a unique gpg key. Do you already have one that you are '
|
_gpg_id = input('\nsshyp requires the use of a unique gpg key. Do you already have one that you are '
|
||||||
@@ -72,15 +71,15 @@ def tweak(): # runs configuration wizard
|
|||||||
print('\nA unique gpg key has been generated for you.')
|
print('\nA unique gpg key has been generated for you.')
|
||||||
system('gpg --full-generate-key')
|
system('gpg --full-generate-key')
|
||||||
_gpg_id = str(input('\nPlease input the ID of your gpg key: '))
|
_gpg_id = str(input('\nPlease input the ID of your gpg key: '))
|
||||||
open("/var/lib/sshyp/sshyp-gpg", 'w').write(_gpg_id + '\n')
|
open(f"{path.expanduser('~/.config/sshyp')}/sshyp-gpg", 'w').write(_gpg_id + '\n')
|
||||||
|
|
||||||
# lock file generation
|
# lock file generation
|
||||||
try:
|
try:
|
||||||
open('/var/lib/sshyp/lock', 'x').write('')
|
open(f"{path.expanduser('~/.config/sshyp')}/lock", 'x').write('')
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
system(f"gpg -r {str(_gpg_id)} -e /var/lib/sshyp/lock")
|
system(f"gpg -r {str(_gpg_id)} -e {path.expanduser('~/.config/sshyp')}/lock")
|
||||||
remove('/var/lib/sshyp/lock')
|
remove(f"{path.expanduser('~/.config/sshyp')}/lock")
|
||||||
|
|
||||||
# ssh key configuration
|
# ssh key configuration
|
||||||
_ssh_gen = (input('\nMake sure the ssh service on the remote server is running and properly configured.'
|
_ssh_gen = (input('\nMake sure the ssh service on the remote server is running and properly configured.'
|
||||||
@@ -89,7 +88,7 @@ def tweak(): # runs configuration wizard
|
|||||||
if _ssh_gen.lower() != 'n':
|
if _ssh_gen.lower() != 'n':
|
||||||
system('ssh-keygen -t ed25519 -f ~/.ssh/sshyp')
|
system('ssh-keygen -t ed25519 -f ~/.ssh/sshyp')
|
||||||
else:
|
else:
|
||||||
print(f"\nEnsure that the key file you are using is located at /home/{environ.get('USER')}/.ssh/sshyp")
|
print(f"\nEnsure that the key file you are using is located at {path.expanduser('~')}/.ssh/sshyp")
|
||||||
|
|
||||||
# ssh ip+port configuration
|
# ssh ip+port configuration
|
||||||
print('\nExample input: 10.10.10.10:9999\n')
|
print('\nExample input: 10.10.10.10:9999\n')
|
||||||
@@ -101,9 +100,9 @@ def tweak(): # runs configuration wizard
|
|||||||
print(f"\nEntry directory: /home/{_username_ssh}/.password-pasture/")
|
print(f"\nEntry directory: /home/{_username_ssh}/.password-pasture/")
|
||||||
|
|
||||||
# sshync profile generation
|
# sshync profile generation
|
||||||
sshync.make_profile('/var/lib/sshyp/sshyp.sshync', f"/home/{environ.get('USER')}/.password-pasture/",
|
sshync.make_profile(f"{path.expanduser('~/.config/sshyp')}/sshyp.sshync",
|
||||||
f"/home/{_username_ssh}/.password-pasture/", f"/home/{environ.get('USER')}/.ssh/sshyp",
|
f"{path.expanduser('~')}/.password-pasture/", f"/home/{_username_ssh}/.password-pasture/",
|
||||||
_ip, _port, _username_ssh)
|
f"{path.expanduser('~')}/.ssh/sshyp", _ip, _port, _username_ssh)
|
||||||
print('\nConfiguration complete!\n')
|
print('\nConfiguration complete!\n')
|
||||||
|
|
||||||
|
|
||||||
@@ -202,7 +201,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
|||||||
# set permissions before uploading
|
# set permissions before uploading
|
||||||
system('find ' + directory + ' -type d -exec chmod -R 700 {} +')
|
system('find ' + directory + ' -type d -exec chmod -R 700 {} +')
|
||||||
system('find ' + directory + ' -type f -exec chmod -R 600 {} +')
|
system('find ' + directory + ' -type f -exec chmod -R 600 {} +')
|
||||||
sshync.run_profile('/var/lib/sshyp/sshyp.sshync')
|
sshync.run_profile(f"{path.expanduser('~/.config/sshyp')}/sshyp.sshync")
|
||||||
|
|
||||||
|
|
||||||
def add_entry(): # adds a new entry
|
def add_entry(): # adds a new entry
|
||||||
@@ -340,7 +339,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard
|
|||||||
_shm_folder, _shm_entry = shm_gen()
|
_shm_folder, _shm_entry = shm_gen()
|
||||||
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
|
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
|
||||||
_copy_line = open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'r').readlines()
|
_copy_line = open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'r').readlines()
|
||||||
if Path(f"/home/{environ.get('USER')}/.config/sshyp/flag_termux").is_file(): # checks for Termux, Wayland, or X
|
if Path(f"{path.expanduser('~')}/.config/sshyp/flag_termux").is_file(): # checks for Termux, Wayland, or X
|
||||||
if argument == 'copy username' or argument == 'copy -u':
|
if argument == 'copy username' or argument == 'copy -u':
|
||||||
system('termux-clipboard-set ' + "'" + _copy_line[0].replace('\n', '').replace("'", "'\\''") + "'")
|
system('termux-clipboard-set ' + "'" + _copy_line[0].replace('\n', '').replace("'", "'\\''") + "'")
|
||||||
elif argument == 'copy password' or argument == 'copy -p':
|
elif argument == 'copy password' or argument == 'copy -p':
|
||||||
@@ -377,7 +376,7 @@ def remove_data(): # deletes an entry or folder from both the client and the se
|
|||||||
if _entry_name.startswith('/'):
|
if _entry_name.startswith('/'):
|
||||||
_entry_name = _entry_name.replace('/', '', 1)
|
_entry_name = _entry_name.replace('/', '', 1)
|
||||||
try:
|
try:
|
||||||
system('gpg -d --output /dev/shm/sshyp.lock /var/lib/sshyp/lock.gpg')
|
system(f"gpg -d --output /dev/shm/sshyp.lock {path.expanduser('~/.config/sshyp')}/lock.gpg")
|
||||||
_unlock = open('/dev/shm/sshyp.lock', 'r').readlines()
|
_unlock = open('/dev/shm/sshyp.lock', 'r').readlines()
|
||||||
remove('/dev/shm/sshyp.lock')
|
remove('/dev/shm/sshyp.lock')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -403,10 +402,10 @@ argument = argument[:-1]
|
|||||||
if argument != 'tweak':
|
if argument != 'tweak':
|
||||||
device_type = ''
|
device_type = ''
|
||||||
try:
|
try:
|
||||||
device_type = open('/var/lib/sshyp/sshyp-device').read().strip()
|
device_type = open(f"{path.expanduser('~/.config/sshyp')}/sshyp-device").read().strip()
|
||||||
if device_type == 'c':
|
if device_type == 'c':
|
||||||
gpg_id = open('/var/lib/sshyp/sshyp-gpg').read().strip()
|
gpg_id = open(f"{path.expanduser('~/.config/sshyp')}/sshyp-gpg").read().strip()
|
||||||
ssh_info = sshync.get_profile('/var/lib/sshyp/sshyp.sshync')
|
ssh_info = sshync.get_profile(f"{path.expanduser('~/.config/sshyp')}/sshyp.sshync")
|
||||||
username_ssh = ssh_info[0].replace('\n', '')
|
username_ssh = ssh_info[0].replace('\n', '')
|
||||||
ip = ssh_info[1].replace('\n', '')
|
ip = ssh_info[1].replace('\n', '')
|
||||||
port = ssh_info[2].replace('\n', '')
|
port = ssh_info[2].replace('\n', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user