Compare commits

..

2 Commits
master ... dev

Author SHA1 Message Date
kageru 125d8f56d1
add ffmpeg recording 2018-04-13 21:19:50 +02:00
kageru 50e49edcb4
added method to get user selection rectangle 2018-04-13 20:36:24 +02:00
3 changed files with 60 additions and 9 deletions

22
add_user.py Normal file
View File

@ -0,0 +1,22 @@
# 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

@ -9,8 +9,7 @@ from random import choices
from datetime import date from datetime import date
from PIL import Image from PIL import Image
import pyperclip import pyperclip
import config import config2 as config
import time
import sys import sys
import os import os
import re import re
@ -51,11 +50,7 @@ def upload_local_file(path: str) -> None:
url = config.url_template.format(filename) url = config.url_template.format(filename)
else: else:
url = curl_upload(path) url = curl_upload(path)
# Only pass the path when uploading an image notify_user(url)
if re.search(r'\.(png|jpe?g|bmp)$', path):
notify_user(url, path)
else:
notify_user(url)
def prepare_file(ext: str) -> str: def prepare_file(ext: str) -> str:
@ -78,6 +73,26 @@ def take_screenshot(edit=False) -> None:
os.remove(file) os.remove(file)
def get_selection_rectangle() -> namedtuple:
# TODO: let user cancel selection
raw_coords = check_output(['slop', '-f', '%x,%y,%w,%h']).decode()
x, y, w, h = [int(x) for x in raw_coords.split(',')]
Rectangle = namedtuple('Rectangle', ['x', 'y', 'w', 'h'])
return Rectangle(x, y, w, h)
def record_screen() -> None:
# ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y ~/myfile.webm
# TODO: show rectangle during recording
# also TODO: find a way to end the capture
file = prepare_file('webm')
sel = get_selection_rectangle()
call(['ffmpeg', '-f', 'x11grab', '-i', f':0.0+{sel.x},{sel.y}', '-s', f'{sel.w}x{sel.h}', 'file'])
upload_local_file(file)
if not config.keep_local_copies:
os.remove(file)
def get_extension(filename: str) -> str: def get_extension(filename: str) -> str:
""" """
Returns the extension of a file/full path as a string. Returns the extension of a file/full path as a string.
@ -132,13 +147,13 @@ def notify_user(url:str, image=None) -> None:
thumbnail = os.path.join(config.local_directory, 'thumb.jpg') thumbnail = os.path.join(config.local_directory, 'thumb.jpg')
img.save(thumbnail) img.save(thumbnail)
call(['notify-send', '-a', 'pyshare', url, '-i', thumbnail, '-t', '3000']) 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) os.remove(thumbnail)
else: else:
call(['notify-send', '-a', 'pyshare', url, '-t', '3000']) call(['notify-send', '-a', 'pyshare', url, '-t', '3000'])
def parse_text(text): def parse_text():
text = pyperclip.paste()
if re.match(r'(https?|s?ftp)://', text): if re.match(r'(https?|s?ftp)://', text):
mirror_file(text) mirror_file(text)
elif os.path.isfile(text): elif os.path.isfile(text):

14
users.py Normal file
View File

@ -0,0 +1,14 @@
# 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"