mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-29 21:36:31 -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
|
||||
|
||||
# external modules
|
||||
|
||||
from os import environ, mkdir, remove, system
|
||||
from os import environ, mkdir, remove, system, path
|
||||
from shutil import copy, move, rmtree
|
||||
from sys import argv, exit as s_exit
|
||||
from pathlib import Path
|
||||
@@ -49,21 +48,21 @@ def edit_note(_shm_folder, _shm_entry):
|
||||
def tweak(): # runs configuration wizard
|
||||
# storage directory creation
|
||||
try:
|
||||
mkdir(f"/home/{environ.get('USER')}/.password-pasture", 0o700)
|
||||
mkdir(f"{path.expanduser('~')}/.password-pasture", 0o700)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
# device type configuration
|
||||
_device_type = input('\nIs this installation for a client or for a server? (C/s) ')
|
||||
if _device_type.lower() == 's':
|
||||
open("/var/lib/sshyp/sshyp-device", 'w').write(_device_type)
|
||||
copy('/usr/bin/sshync.py', f"/home/{environ.get('USER')}/")
|
||||
open(f"{path.expanduser('~/.config/sshyp')}/sshyp-device", 'w').write(_device_type)
|
||||
copy('/usr/bin/sshync.py', path.expanduser('~/'))
|
||||
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
||||
s_exit()
|
||||
else:
|
||||
# device type configuration
|
||||
_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_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.')
|
||||
system('gpg --full-generate-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
|
||||
try:
|
||||
open('/var/lib/sshyp/lock', 'x').write('')
|
||||
open(f"{path.expanduser('~/.config/sshyp')}/lock", 'x').write('')
|
||||
except FileExistsError:
|
||||
pass
|
||||
system(f"gpg -r {str(_gpg_id)} -e /var/lib/sshyp/lock")
|
||||
remove('/var/lib/sshyp/lock')
|
||||
system(f"gpg -r {str(_gpg_id)} -e {path.expanduser('~/.config/sshyp')}/lock")
|
||||
remove(f"{path.expanduser('~/.config/sshyp')}/lock")
|
||||
|
||||
# ssh key configuration
|
||||
_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':
|
||||
system('ssh-keygen -t ed25519 -f ~/.ssh/sshyp')
|
||||
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
|
||||
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/")
|
||||
|
||||
# sshync profile generation
|
||||
sshync.make_profile('/var/lib/sshyp/sshyp.sshync', f"/home/{environ.get('USER')}/.password-pasture/",
|
||||
f"/home/{_username_ssh}/.password-pasture/", f"/home/{environ.get('USER')}/.ssh/sshyp",
|
||||
_ip, _port, _username_ssh)
|
||||
sshync.make_profile(f"{path.expanduser('~/.config/sshyp')}/sshyp.sshync",
|
||||
f"{path.expanduser('~')}/.password-pasture/", f"/home/{_username_ssh}/.password-pasture/",
|
||||
f"{path.expanduser('~')}/.ssh/sshyp", _ip, _port, _username_ssh)
|
||||
print('\nConfiguration complete!\n')
|
||||
|
||||
|
||||
@@ -202,7 +201,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
||||
# set permissions before uploading
|
||||
system('find ' + directory + ' -type d -exec chmod -R 700 {} +')
|
||||
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
|
||||
@@ -340,7 +339,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard
|
||||
_shm_folder, _shm_entry = shm_gen()
|
||||
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()
|
||||
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':
|
||||
system('termux-clipboard-set ' + "'" + _copy_line[0].replace('\n', '').replace("'", "'\\''") + "'")
|
||||
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('/'):
|
||||
_entry_name = _entry_name.replace('/', '', 1)
|
||||
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()
|
||||
remove('/dev/shm/sshyp.lock')
|
||||
except FileNotFoundError:
|
||||
@@ -403,10 +402,10 @@ argument = argument[:-1]
|
||||
if argument != 'tweak':
|
||||
device_type = ''
|
||||
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':
|
||||
gpg_id = open('/var/lib/sshyp/sshyp-gpg').read().strip()
|
||||
ssh_info = sshync.get_profile('/var/lib/sshyp/sshyp.sshync')
|
||||
gpg_id = open(f"{path.expanduser('~/.config/sshyp')}/sshyp-gpg").read().strip()
|
||||
ssh_info = sshync.get_profile(f"{path.expanduser('~/.config/sshyp')}/sshyp.sshync")
|
||||
username_ssh = ssh_info[0].replace('\n', '')
|
||||
ip = ssh_info[1].replace('\n', '')
|
||||
port = ssh_info[2].replace('\n', '')
|
||||
|
||||
Reference in New Issue
Block a user