Compare commits

...
4 changed files with 104 additions and 53 deletions
+7 -10
View File
@@ -1,29 +1,26 @@
#!/usr/bin/python3 #!/usr/bin/python3
# sshync 2022.01.16.unreleased10 # sshync 2022.01.16.unreleased11
# external modules # external modules
from os import system, remove, mkdir, walk from os import system, remove, mkdir, walk
from os.path import getmtime, join, expanduser from os.path import getmtime, join, expanduser
from sys import exit as s_exit from sys import exit as s_exit
from pathlib import Path
# utility functions # utility functions
def get_titles_mods(_directory, _destination, _user_data): def get_titles_mods(_directory, _destination, _user_data):
_title_list, _mod_list = [], [] _title_list, _mod_list = [], []
try: # create config directory
mkdir(expanduser('~/.config/sshync'), 0o700)
except FileExistsError:
pass
# local fetching # local fetching
if _destination == 'l': if _destination == 'l':
if Path(expanduser('~/.config/sshync/database')).is_file(): remove(expanduser('~/.config/sshync/database')) # assumed to exist because remote runs first
remove(expanduser('~/.config/sshync/database')) open(expanduser('~/.config/sshync/database'), 'w') # create blank database file
else:
try:
mkdir(expanduser('~/.config/sshync'), 0o700)
except FileExistsError:
pass
system('touch ~/.config/sshync/database')
for _root, _directories, _files in walk(_directory): for _root, _directories, _files in walk(_directory):
for _filename in _files: for _filename in _files:
_title_list.append(join(_root.replace(_directory, '', 1), _filename)) _title_list.append(join(_root.replace(_directory, '', 1), _filename))
+42 -37
View File
@@ -19,28 +19,28 @@ def replace_line(file_name, line_num, text): # replaces text in a given line wi
open(file_name, 'w').writelines(_lines) open(file_name, 'w').writelines(_lines)
def shm_gen(): # generates random folder in /dev/shm for security and returns random names for the folder and temp file def shm_gen(): # generates a random temporary folder for security and returns random names for the folder and temp file
_shm_folder_gen = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) _shm_folder_gen = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits)
for _ in range(random.randint(10, 30))) for _ in range(random.randint(10, 30)))
_shm_entry_gen = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) _shm_entry_gen = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits)
for _ in range(random.randint(10, 30))) for _ in range(random.randint(10, 30)))
mkdir(f"/dev/shm/{_shm_folder_gen}", 0o700) mkdir(f"{tmp_dir}{_shm_folder_gen}", 0o700)
return _shm_folder_gen, _shm_entry_gen return _shm_folder_gen, _shm_entry_gen
def encrypt(_shm_folder, _shm_entry, _location): def encrypt(_shm_folder, _shm_entry, _location):
system(f"gpg -r {str(gpg_id)} -e '/dev/shm/{_shm_folder}/{_shm_entry}'") system(f"gpg -r {str(gpg_id)} -e '{tmp_dir}{_shm_folder}/{_shm_entry}'")
move(f"/dev/shm/{_shm_folder}/{_shm_entry}.gpg", f"{directory}{_location}.gpg") move(f"{tmp_dir}{_shm_folder}/{_shm_entry}.gpg", f"{directory}{_location}.gpg")
rmtree(f"/dev/shm/{_shm_folder}") rmtree(f"{tmp_dir}{_shm_folder}")
def edit_note(_shm_folder, _shm_entry): def edit_note(_shm_folder, _shm_entry):
lines = open(f"/dev/shm/{_shm_folder}/{_shm_entry}").readlines() lines = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}").readlines()
open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'w').writelines(lines[0:3]) open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'w').writelines(lines[0:3])
open(f"/dev/shm/{_shm_folder}/{_shm_entry}-n", 'w').writelines(lines[4:-2]) open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n", 'w').writelines(lines[4:-2])
system(f"nano /dev/shm/{_shm_folder}/{_shm_entry}-n") system(f"nano {tmp_dir}{_shm_folder}/{_shm_entry}-n")
edit_notes = open(f"/dev/shm/{_shm_folder}/{_shm_entry}-n").read() edit_notes = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n").read()
open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'a').write('\n' + edit_notes + '\n\n') open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'a').write('\n' + edit_notes + '\n\n')
# argument-specific functions # argument-specific functions
@@ -56,7 +56,11 @@ def tweak(): # runs configuration wizard
mkdir(path.expanduser('~/.config/sshyp'), 0o700) mkdir(path.expanduser('~/.config/sshyp'), 0o700)
except FileExistsError: except FileExistsError:
pass pass
if not Path(f"{path.expanduser('~/.config/sshyp/tmp')}").is_file():
if Path("/data/data/com.termux").is_file():
system(f"ln -s {path.expanduser('~/../usr/tmp')} {path.expanduser('~/.config/sshyp/tmp')}")
else:
system(f"ln -s /dev/shm {path.expanduser('~/.config/sshyp/tmp')}")
# 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':
@@ -152,7 +156,7 @@ def print_info(): # prints help text based on argument
print('/ /') print('/ /')
print('/ sshyp Copyright (C) 2021 Randall Winkhart /') print('/ sshyp Copyright (C) 2021 Randall Winkhart /')
print('/ /') print('/ /')
print('/ Version 2022.01.13.fr3.1 /') print('/ Version 2022.01.16.fr3.2 /')
print('/ The Boxing Update /') print('/ The Boxing Update /')
print('/ /') print('/ /')
print('////////////////////////////////////////////////////////\n') print('////////////////////////////////////////////////////////\n')
@@ -216,9 +220,9 @@ def add_entry(): # adds a new entry
_entry_name = _entry_name.replace('/', '', 1) _entry_name = _entry_name.replace('/', '', 1)
if argument == 'add note' or argument == 'add -n': if argument == 'add note' or argument == 'add -n':
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"nano /dev/shm/{_shm_folder}/{_shm_entry}-n") system(f"nano {tmp_dir}{_shm_folder}/{_shm_entry}-n")
_notes = open(f"/dev/shm/{_shm_folder}/{_shm_entry}-n", 'r').read() _notes = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n", 'r').read()
open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'w').writelines('\n\n\n\n' + _notes + '\n\n') open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'w').writelines('\n\n\n\n' + _notes + '\n\n')
elif argument == 'add password' or argument == 'add -p': elif argument == 'add password' or argument == 'add -p':
_username = str(input('Username: ')) _username = str(input('Username: '))
_password = str(input('Password: ')) _password = str(input('Password: '))
@@ -226,11 +230,11 @@ def add_entry(): # adds a new entry
_add_note = input('Add a note to this entry? (y/N) ') _add_note = input('Add a note to this entry? (y/N) ')
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
if _add_note.lower() == 'y': if _add_note.lower() == 'y':
system(f"nano /dev/shm/{_shm_folder}/{_shm_entry}-n") system(f"nano {tmp_dir}{_shm_folder}/{_shm_entry}-n")
_notes = open(f"/dev/shm/{_shm_folder}/{_shm_entry}-n", 'r').read() _notes = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n", 'r').read()
else: else:
_notes = '' _notes = ''
open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'w').writelines(_username + '\n' + _password + '\n' + _url + '\n\n' open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'w').writelines(_username + '\n' + _password + '\n' + _url + '\n\n'
+ _notes + '\n\n') + _notes + '\n\n')
encrypt(_shm_folder, _shm_entry, _entry_name) encrypt(_shm_folder, _shm_entry, _entry_name)
system(f"gpg -d '{directory}{_entry_name}.gpg'") system(f"gpg -d '{directory}{_entry_name}.gpg'")
@@ -270,21 +274,21 @@ def edit(): # edits the contents of an entry
if argument == 'edit username' or argument == 'edit -u': if argument == 'edit username' or argument == 'edit -u':
_detail = str(input('New Username: ')) _detail = str(input('New Username: '))
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'") system(f"gpg -d --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'")
replace_line(f"/dev/shm/{_shm_folder}/{_shm_entry}", 0, _detail + '\n') replace_line(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 0, _detail + '\n')
elif argument == 'edit password' or argument == 'edit -p': elif argument == 'edit password' or argument == 'edit -p':
_detail = str(input('New Password: ')) _detail = str(input('New Password: '))
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'") system(f"gpg -d --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'")
replace_line(f"/dev/shm/{_shm_folder}/{_shm_entry}", 1, _detail + '\n') replace_line(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 1, _detail + '\n')
elif argument == 'edit url' or argument == 'edit -l': elif argument == 'edit url' or argument == 'edit -l':
_detail = str(input('New URL: ')) _detail = str(input('New URL: '))
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'") system(f"gpg -d --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'")
replace_line(f"/dev/shm/{_shm_folder}/{_shm_entry}", 2, _detail + '\n') replace_line(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 2, _detail + '\n')
elif argument == 'edit note' or argument == 'edit -n': elif argument == 'edit note' or argument == 'edit -n':
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'") system(f"gpg -d --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'")
edit_note(_shm_folder, _shm_entry) edit_note(_shm_folder, _shm_entry)
remove(f"{directory}{_entry_name}.gpg") remove(f"{directory}{_entry_name}.gpg")
encrypt(_shm_folder, _shm_entry, _entry_name) encrypt(_shm_folder, _shm_entry, _entry_name)
@@ -317,18 +321,18 @@ def gen(): # generates a password for a new or an existing entry
_add_note = input('Add a note to this entry? (y/N) ') _add_note = input('Add a note to this entry? (y/N) ')
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
if _add_note.lower() == 'y': if _add_note.lower() == 'y':
system(f"nano /dev/shm/{_shm_folder}/{_shm_entry}-n") system(f"nano {tmp_dir}{_shm_folder}/{_shm_entry}-n")
_notes = open(f"/dev/shm/{_shm_folder}/{_shm_entry}-n", 'r').read() _notes = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}-n", 'r').read()
else: else:
_notes = '' _notes = ''
open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'w').writelines(_username + '\n' + _pass_gen + '\n' + _url + '\n\n' open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'w').writelines(_username + '\n' + _pass_gen + '\n' + _url + '\n\n'
+ _notes + '\n\n') + _notes + '\n\n')
encrypt(_shm_folder, _shm_entry, _entry_name) encrypt(_shm_folder, _shm_entry, _entry_name)
system(f"gpg -d '{directory}{_entry_name}.gpg'") system(f"gpg -d '{directory}{_entry_name}.gpg'")
else: else:
_shm_folder, _shm_entry = shm_gen() _shm_folder, _shm_entry = shm_gen()
system(f"gpg -d --output /dev/shm/{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'") system(f"gpg -d --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_entry_name}.gpg'")
replace_line(f"/dev/shm/{_shm_folder}/{_shm_entry}", 1, _pass_gen + '\n') replace_line(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 1, _pass_gen + '\n')
remove(f"{directory}{_entry_name}.gpg") remove(f"{directory}{_entry_name}.gpg")
encrypt(_shm_folder, _shm_entry, _entry_name) encrypt(_shm_folder, _shm_entry, _entry_name)
system(f"gpg -d '{directory}{_entry_name}.gpg'") system(f"gpg -d '{directory}{_entry_name}.gpg'")
@@ -342,8 +346,8 @@ def copy_data(): # copies a specified field of an entry to the clipboard
print("\nThe file does not exist!\n") print("\nThe file does not exist!\n")
s_exit() s_exit()
_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 {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
_copy_line = open(f"/dev/shm/{_shm_folder}/{_shm_entry}", 'r').readlines() _copy_line = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines()
if Path("/data/data/com.termux").is_file(): # checks for Termux, Wayland, or X if Path("/data/data/com.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("'", "'\\''") + "'")
@@ -371,7 +375,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard
system('echo -n ' + "'" + _copy_line[2].replace('\n', '').replace("'", "'\\''") + "'" + ' | xclip -sel c') system('echo -n ' + "'" + _copy_line[2].replace('\n', '').replace("'", "'\\''") + "'" + ' | xclip -sel c')
elif argument == 'copy note' or argument == 'copy -n': elif argument == 'copy note' or argument == 'copy -n':
system('echo -n ' + "'" + _copy_line[4].replace('\n', '').replace("'", "'\\''") + "'" + ' | xclip -sel c') system('echo -n ' + "'" + _copy_line[4].replace('\n', '').replace("'", "'\\''") + "'" + ' | xclip -sel c')
rmtree(f"/dev/shm/{_shm_folder}") rmtree(f"{tmp_dir}{_shm_folder}")
def remove_data(): # deletes an entry or folder from both the client and the server def remove_data(): # deletes an entry or folder from both the client and the server
@@ -381,9 +385,9 @@ 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(f"gpg -d --output /dev/shm/sshyp.lock {path.expanduser('~/.config/sshyp/lock.gpg')}") system(f"gpg -d --output {tmp_dir}sshyp.lock {path.expanduser('~/.config/sshyp/lock.gpg')}")
_unlock = open('/dev/shm/sshyp.lock', 'r').readlines() _unlock = open('{tmp_dir}sshyp.lock', 'r').readlines()
remove('/dev/shm/sshyp.lock') remove(f"{tmp_dir}sshyp.lock")
except FileNotFoundError: except FileNotFoundError:
print('\nAccess denied.\n') print('\nAccess denied.\n')
s_exit() s_exit()
@@ -406,6 +410,7 @@ argument = argument[:-1]
# import saved userdata # import saved userdata
if argument != 'tweak': if argument != 'tweak':
device_type = '' device_type = ''
tmp_dir = path.expanduser('~/.config/sshyp/tmp/')
try: try:
device_type = open(path.expanduser('~/.config/sshyp/sshyp-device')).read().strip() device_type = open(path.expanduser('~/.config/sshyp/sshyp-device')).read().strip()
if device_type == 'c': if device_type == 'c':
+50
View File
@@ -1,5 +1,55 @@
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
sshyp 2022.01.16.fr3.2
The Boxing Update
This release is a hotfix for 2022.01.16.fr3.1. It fixes major bugs, including one massively impacting Termux.
Changes:
- sshyp now uses a symlink to the temporary storage directory, allowing for easy implementation of different temporary directories on different platforms
^ the first usage of this is enabling the use of temporary storage on Termux
- sshync now properly auto-generates its config directory
Additions planned for minor releases:
** updated the manpage with more information regarding how sshyp works and how to set it up
** ensured that it is now impossible for ghosts of entires to remain in /dev/shm
** reduced total lines of code with small optimizations
&&
Planned for next major update (fr4, The sshyp Doing a Split Update):
sshyp:
** sshyp has recieved a major visual overhaul
^ this includes the new file list and thematic text art
sshync:
** sshync has been split into a separate package and now has standalone functionality as a backup/syncing utility
^ more details will be available in the sshync repo, once it is created
&&
Planned for next, next major update (fr5, The Farmer Shearing the sshyp Update):
** allow for multi-client deletion... somehow (in sshync)
** when syncing, a check is made to see if any folders are not on all devices - if the check comes back true, it is corrected (in sshyp)
** imporove password generator to guarantee more secure results
** enforce permissions on the server-side
** allow for copying entire notes (not just first line)
** ability to pass entries as arguments for more functions
&&
Backlog:
** create separate gui frontend targetting mobile and desktop Linux
** auto-completion on tab (currently unsure of best way to make this work)
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
sshyp 2022.01.16.fr3.1 sshyp 2022.01.16.fr3.1
The Boxing Update The Boxing Update
+5 -6
View File
@@ -1,15 +1,14 @@
sshyp 2022.01.16.fr3.1 sshyp 2022.01.16.fr3.2
The Boxing Update The Boxing Update
This release is a hotfix for 2022.01.13.fr3. It fixes sshync/syncing support after the changes in the last release. This release is a hotfix for 2022.01.16.fr3.1. It fixes major bugs, including one massively impacting Termux.
Changes: Changes:
- sshync has been updated to work with the new config directory - sshyp now uses a symlink to the temporary storage directory, allowing for easy implementation of different temporary directories on different platforms
- sshync now uses its own directory to store the database file ^ the first usage of this is enabling the use of temporary storage on Termux
^ this is preperation for separating sshync into its own package - sshync now properly auto-generates its config directory
- expanduser lines in sshyp have been simplified (no user-facing impact)
Additions planned for minor releases: Additions planned for minor releases: