API Reference¶
While dropafile is not designed as a library, you might want to use single components for building bigger and better webservices. For instance you can use the dropafile.DropAFileApplication as WSGI app in other environments.
dropafile - Drop a file on a webpage.
- dropafile.ALLOWED_PWD_CHARS = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz'¶
Chars allowed in passwords. We allow plain ASCII chars and numbers, with some entitites removed, that can be easily mixed up: letter l and number one, for instance.
- class dropafile.DropAFileApplication(password=None, upload_dir=None)[source]¶
Drop-A-File application.
A werkzeug based WSGI application providing a basic-auth protected web interface for file uploads.
password is required to access the application’s service. If none is provided, we generate one for you.
upload_dir is the directory, where we store files uploaded by users. If none is given we create a temporary directory on start-up. Please note: the directory is not removed on shutdown.
- authenticate()[source]¶
Send 401 requesting basic auth from client.
Send back 401 response to client. Contains some HTML to display an ‘Unauhorized’ page. Should make browsers ask users for username and password.
- check_auth(request)[source]¶
Check basic auth against local password.
We accept any username, but only the one password. Returns True in case of success, False otherwise.
request must contain basic-auth authorization headers (as set by browsers) to succeed.
- handle_uploaded_files(request)[source]¶
Look for an upload file in request.
If one is found, it is saved to self.upload_dir.
- password = None¶
the password we require (no username neccessary)
- upload_dir = None¶
a path where we store files uploaded by users.
- dropafile.create_ssl_cert(path=None, bits=4096, days=2, cn='localhost', country='US', state='', location='')[source]¶
Create an SSL RSA cert and key in directory path.
Returns a tuple (certificate_path, key_path).
- path
- A directory, where certificate and key can be stored. If none is given, we create a temporary one.
Default attribute values of the certificate are read from a package-local SSL configuration file openssl.conf.
Some attribute values can be overridden:
- bits
- number of bits of the key.
- days
- number of days of validity of the generated certificate.
- cn
- Common Name. Put the domain under which the app will be served in here.
- state and location
- will be empty by default.
- dropafile.execute_cmd(cmd_list)[source]¶
Excute the command cmd_list.
Returns stdout and stderr output.
- dropafile.get_random_password()[source]¶
Get a password generated from ALLOWED_PWD_CHARS.
The password entropy should be >= 128 bits. We use SystemRandom(), which should provide enough randomness to work properly.
- dropafile.get_ssl_context(cert_path=None, key_path=None)[source]¶
Get an SSL context to serve HTTP.
If cert_path or key_path are None, we create some. Then we add some modifiers (avail. with Python >= 2.7.9) to disable unsafe ciphers etc.
The returned SSL context can be used with Werkzeug run_simple.
- dropafile.get_store_path(directory, filename)[source]¶
Get a path where we can safely store a file.
The file should be stored in directory under name filename. If filename already exists in directory, we construct new names by appending ‘-<NUM>’ to the original filename, where <NUM> is a number counting up.
- dropafile.handle_options(args)[source]¶
Handle commandline options.
Expects the arguments passed to dropafile as a list of arguments. args is expected to represent sys.argv[1:], i.e. the arguments when called, without the programme name.
Returns parsed options as provided by argparse.
- dropafile.run_server(args=None)[source]¶
Run a werkzeug server, serving a DropAFileApplication.
Called when running dropafile from commandline. Serves a DropAFileApplication instance until aborted.
Options argv are taken from commandline if not specified.
Generates a password and temporary SSL certificate/key on startup unless otherwise requested in options/args.