curl backend now accepts files, names and stores them, and returns a link

This commit is contained in:
kageru 2017-10-18 13:25:34 +02:00
parent 37d5de9d67
commit 97d185d604
4 changed files with 44 additions and 6 deletions

View File

@ -1,8 +1,8 @@
# pyshare # pyshare
A very simple python script that aims to replace the most basic functionalities (TL Note: the ones I used) of ShareX. A simple python script that aims to replace the most basic functionalities (TL Note: the ones I used) of ShareX.
This wouldn't be necessary if ShareX had just been developed as a cross-platform project, but I digress. This wouldn't be necessary if ShareX had just been developed as a cross-platform project, but I digress.
Needless to say, this is being developed for and tested on Linux. If you're on Windows, just use ShareX.\ Needless to say, this is being developed for and tested on Linux. If you're on Windows, just use ShareX.\
Only (s)ftp uploads for now, but I might add simple curl commands (like used by 0x0) later on. ~~Only (s)ftp uploads for now~~ I added simple curl commands (like used by 0x0), as well as a small server that can receive them.
I should add that the focus will be on a self-hosted server. If you don't care about that, just `curl` 0x0.st or something. I should add that the focus will be on a self-hosted server. If you don't care about that, just `curl` 0x0.st or something.
#### What works: #### What works:
- Taking area screenshots - Taking area screenshots

View File

@ -17,6 +17,6 @@ if __name__ == '__main__':
sys.exit(0) sys.exit(0)
else: else:
username, password = sys.argv[1:] username, password = sys.argv[1:]
salt = choices(character_pool, k=10) salt = ''.join(choices(character_pool, k=10))
hash = salthash(password, salt) hash = salthash(password, salt)
print(f" '{username}': ['{hash}', '{salt}'],") print(f" '{username}': ['{hash}', '{salt}'],")

View File

@ -1,8 +1,21 @@
# (S)FTP credentials # Can be 'curl' or 'sftp'
uploader = 'curl'
# (S)FTP credentials, only if you want to use SFTP for uploads
sftp_address = 'your_domain.com' sftp_address = 'your_domain.com'
username = 'your_ftp_user' username = 'your_ftp_user'
password = 'your_ftp_password' password = 'your_ftp_password'
# curl parameters, if you're using pyshare_receivere
curl_target = 'your_domain.com:5000'
curl_user = 'user1'
curl_password = 'password'
# This should contain a complete curl command with a {} to insert the filename.
# Setting this to anything but None will result in the other curl parameters to be ignored
# Example: 'curl -F"file=@{}" https://0x0.st'
custom_curl_command = None
# This is where the screenshots are saved locally # This is where the screenshots are saved locally
local_directory = '/home/kageru/pyshare/' local_directory = '/home/kageru/pyshare/'
# Directory on the ftp server where you want the screenshots to be sent to # Directory on the ftp server where you want the screenshots to be sent to

View File

@ -5,7 +5,12 @@ from flask import Flask, request
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from hashlib import sha3_256 from hashlib import sha3_256
from users import users from users import users
import os
import config import config
from string import ascii_letters, digits
from random import choices
character_pool = ascii_letters + digits
app = Flask(__name__) app = Flask(__name__)
@ -27,14 +32,34 @@ def authenticate(request):
return False return False
def find_filename(length, ext):
def generate_filename(length, ext):
return ''.join(choices(character_pool, k=length)) + ext
filename = generate_filename(length, ext)
i = 0
while os.path.exists(os.path.join(config.remote_directory, filename)):
i += 1
if i > 1000:
length += 1
i = 0
filename = generate_filename(length, ext)
return filename
@app.route('/', methods=['POST']) @app.route('/', methods=['POST'])
def receive_file() -> tuple: def receive_file() -> tuple:
if 'file' in request.files: if 'file' in request.files:
if authenticate(request) is True: if authenticate(request) is True:
file = request.files.get('file') file = request.files.get('file')
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
file.save(filename) if '.' in filename:
return config.url_template.format(filename), 201 extension = '.' + filename.rsplit('.', 1)[1]
else:
extension = ''
storename = find_filename(config.length, extension)
file.save(os.path.join(config.remote_directory, storename))
return config.url_template.format(storename), 201
else: else:
return 'Wrong or no credentials', 403 return 'Wrong or no credentials', 403
return 'you\'re doing this wrong', 418 return 'you\'re doing this wrong', 418