Compare commits

...

4 Commits
dev ... master

Author SHA1 Message Date
kageru de884b1df9
fixed a bug when uploading non-images and using preview 2018-08-21 17:57:04 +02:00
kageru f8ce7acd7e
reenable and fix thumbnails 2018-07-18 09:37:10 +02:00
kageru 645dd6ac1d
remove old code 2018-06-22 15:40:32 +02:00
kageru ee6229ff72
fixed bug in clipboard mode 2018-05-07 10:51:29 +02:00
3 changed files with 17 additions and 42 deletions

View File

@ -1,22 +0,0 @@
# This is probably false advertising because it doesn't actually add a user for you.
# It only generates a string that you can copy-paste into users.py
from pyshare_receiver import salthash
from pyshare import character_pool
from random import choices
import sys
if __name__ == '__main__':
if len(sys.argv) != 3:
print('''
Usage:
$ python add_user.py <username> <password>
''')
sys.exit(0)
else:
username, password = sys.argv[1:]
salt = ''.join(choices(character_pool, k=10))
hash = salthash(password, salt)
print(f" '{username}': ['{hash}', '{salt}'],")

View File

@ -4,11 +4,13 @@ from string import ascii_letters, digits
from argparse import ArgumentParser
from pysftp import Connection
from subprocess import call, check_output
from collections import namedtuple
from random import choices
from datetime import date
from PIL import Image
import pyperclip
import config
import time
import sys
import os
import re
@ -49,15 +51,24 @@ def upload_local_file(path: str) -> None:
url = config.url_template.format(filename)
else:
url = curl_upload(path)
notify_user(url)
# Only pass the path when uploading an image
if re.search(r'\.(png|jpe?g|bmp)$', path):
notify_user(url, path)
else:
notify_user(url)
def take_screenshot(edit=False) -> None:
def prepare_file(ext: str) -> str:
"Generate a file name according to the config and create folder structure if necessary"
full_path = get_local_full_path()
if not os.path.exists(full_path):
os.makedirs(full_path)
tempname = generate_filename(config.length, 'png')
file = os.path.join(get_local_full_path(), tempname)
tempname = generate_filename(config.length, ext)
return os.path.join(get_local_full_path(), tempname)
def take_screenshot(edit=False) -> None:
file = prepare_file('png')
call(['maim', '-suk', file])
Image.open(file).convert('RGB').save(file)
if edit:
@ -121,13 +132,13 @@ def notify_user(url:str, image=None) -> None:
thumbnail = os.path.join(config.local_directory, 'thumb.jpg')
img.save(thumbnail)
call(['notify-send', '-a', 'pyshare', url, '-i', thumbnail, '-t', '3000'])
time.sleep(0.2) # delay slightly before deleting the file so notify-send can actually read it
os.remove(thumbnail)
else:
call(['notify-send', '-a', 'pyshare', url, '-t', '3000'])
def parse_text():
text = pyperclip.paste()
def parse_text(text):
if re.match(r'(https?|s?ftp)://', text):
mirror_file(text)
elif os.path.isfile(text):

View File

@ -1,14 +0,0 @@
# Add credentials for your own users here.
# Since I'll only have very few users (probably just me), using a proper DB is overkill
# The password hash is generated by
# hashlib.sha3_256(bytes((password + salt).encode('utf8'))).hexdigest()
# If you actually want to use this for something serious, you should probably use argon2 or something
users = {
'user1': ['c7d9c9621e417ea09141edbac126cd1f3ab1b2b94b2ad3b155a1e26a88b216c0', 'user1salt'],
}
# And btw, the password is just 'password'.
# I'm just saying this because there will be that one guy who actually thinks
# "Oh, I could totally brute-force this password now"