Giter VIP home page Giter VIP logo

pastefile's Introduction

This project has moved to : https://github.com/pastefile/pastefile.git

Pastefile Build Status

Pastefile logo

Little daemon written with python flask for sharing any files quickly via http

Installation

You can either install by yourself with nginx or apache and use a custom configuration for uwsgi or build a docker image with the Dockerfile provided.

Quick run for test purpose

If you just want to test pastefile quickly, we provide pastefile-run.py script only for test purpose.

apt-get install -y git python-dev python-pip
pip install -r https://raw.githubusercontent.com/guits/pastefile/master/requirements.txt
git clone https://github.com/guits/pastefile.git
cd pastefile && cp pastefile.cfg.sample pastefile.cfg
# Modify pastefile.cfg config to adapt pastefile directories
./pastefile-run.py -c $PWD/pastefile.cfg

Standard

apt-get install -y git nginx-full python-pip python-dev uwsgi-plugin-python uwsgi
pip install -r https://raw.githubusercontent.com/guits/pastefile/master/requirements.txt
git clone https://github.com/guits/pastefile.git /var/www/pastefile

note that /var/www/pastefile must be writable by the uwsgi process that will be launched later. You may have to chown <uid>:<gid> it with right user/group.

Write the configuration file:

curl -s -o/etc/pastefile.cfg  https://raw.githubusercontent.com/guits/pastefile/master/pastefile.cfg.sample

Change parameters as you need:

vim /etc/pastefile.cfg

Nginx configuration:

/etc/nginx/nginx.conf :

user www-data;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
  
events {
    worker_connections 1024;
}
  
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
  
    access_log  /var/log/nginx/access.log  main;
  
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   1;
    types_hash_max_size 2048;
  
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
  
    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/pastefile.conf :

server {
    listen 80 default_server;


        location / { try_files $uri @pastefile; }

        location @pastefile {
            include uwsgi_params;
            uwsgi_pass unix:///tmp/pastefile.sock;
        }
}

uwsgi configuration:

/etc/uwsgi/apps-available/pastefile.ini :

[uwsgi]
socket = /tmp/pastefile.sock
module = pastefile.app:app
chdir  = /var/www/pastefile
uid = 33
gid = 33
env = PASTEFILE_SETTINGS=/etc/pastefile.cfg
processes = 1
threads = 1

Enable it with: ln -s /etc/uwsgi/apps-available/pastefile.ini /etc/uwsgi/apps-enabled/pastefile.ini

Now, you just have to launch nginx and uwsgi via systemd:

systemctl start nginx.service uwsgi.service

Docker

First, clone the repo where you want:

git clone https://github.com/guits/pastefile.git

Go to the extra/Docker directory :

cd pastefile/extra/Docker

Build the image:

docker build --rm -t pastefile ./

You can then run a container:

docker run -t -d -i --name=pastefile pastefile

this is the easiest way to get a pastefile application running quickly.

Options

Parameters Usage
UPLOAD_FOLDER Where the files are stored.
FILE_LIST The file that act as the db (jsondb)
TMP_FOLDER The folder where the files are stored during the transfer
EXPIRE How many long the files are stored (in seconds)
DEBUG_PORT The port used for debugging mode
LOG The path to the log file
DISABLED_FEATURE List of features you want to disable. Allowed value : delete, ls
DISPLAY_FOR Display file like png or txt directly in your browser instead of asking for download. Allowed list from flask request.user_agent.browser

Note:

The directory and the db file must be writable by uwsgi.

the format must be KEY = VALUE.

the KEY must be in uppercase

if the parameter is a string, you must quote it with ""

Usage

Upload a file:

curl -F file=@</path/to/the/file> http://pastefile.fr

View all uploaded files:

curl http://pastefile.fr/ls

Get infos about one file:

curl http://pastefile.fr/<id>/infos

Get a file:

curl -JO http://pastefile.fr/<id>

Delete a file:

curl -XDELETE http://pastefile.fr/<id>

You can use this tips by adding this line in your .bashrc :

pastefile() { curl -F file=@"$1" http://pastefile.fr; }

so you can just type:

pastefile /my/file

to easily upload a file.

Extra

Simple script to take a screenshot on a selected region of the screen and then upload the screenshot on pastefile. The pastefile link will be automatically copy in your copy/paste buffer.

#!/bin/bash

# require :
# apt-get install imagemagick xsel libnotify-bin

filename=$(mktemp --suffix=_screenshot.png)
# Take the screenshot
import $filename

# Upload the file on pastefile
url=$(curl -F "file=@${filename}" http://pastefile.fr)
if [ "$?" = "0" ]; then
    notify-send "image uploaded! $url"

    # Add file to all clipboard
    echo -n "$url"|xsel -i -p
    echo -n "$url"|xsel -i -s
    echo -n "$url"|xsel -i -b
    echo "$url" >> /tmp/import.log
else
    notify-send --urgency=critical "Upload failed."
fi

pastefile's People

Contributors

amaumene avatar gaell avatar gchenuet avatar guits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pastefile's Issues

Change the behavior when the file already exist

Actually :

~$ curl -F "file=@foo" pastefile.learnit.fr
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>403 Forbidden</title>
<h1>Forbidden</h1>
<p>You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.</p>

Should be better to only return the url of the existing file.

Clean 404.html template

We have

curl localhost:5000/dfgdfg

  <h1>File not found</h1>
  <p>Usage:<br><br>
GET /ls<br>
GET /id_file/infos<br>
POST /<br>
GET /<id_file><br>
<br><br>
TO improve

We should fix to display help like the / url

Display file in browser

Currently each url result in a file downloaded by you browser.

We should give a try to use mime type to fill the content type header.

The goal is to display text or image in your browser natively.

Check directory in config.

Check and create if possible directory in config file.
Example if the upload_folder not exist, you have a python error

Feature : allow to enable or disable /ls url

For security reason or custom usage, it could be cool to provide a way to disable /ls option.

For a usage like a pastebin where only user with the link can access to the file.

Can't opened DMG files

Hi,

When I tried to open a DMG file sent by Pastefile, it's opened a text editor with binary code inside instead of the DiskImageMounter app.

bad filename when retrieving a file

the filename is not the good one when retrieving a file.
this is because files are stored with md5 as filename

line 108: os.rename(tmp_full_filename, storage_full_filename)

need to find a way to send file with original filename

Feature : Burn after read url

Provide the possibility to upload a burn after read file.

To allow only one user to download the file. After the download the file will be removed.

Add send by email button

It could be great to add a button 'upload and send by email'
Thus we could directly upload the file and the mail client would open automatically to send the link.

Dockerize

Add a Dockerfile to build a docker image

Add default view.

When we try a random url we have an error :

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
    raise ValueError('View function did not return a response')
ValueError: View function did not return a response

Try to add a custom 404 page that print of a help page.

Favicon stack trace

When you are using explorer like chrome, chrome automatically try to get favicon.ico.

127.0.0.1 - - [02/Nov/2015 22:43:28] "GET /favicon.ico HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
    raise ValueError('View function did not return a response')
ValueError: View function did not return a response

Add a logger

add log in file to know who and when a file is uploaded.

Add tests on the code

If possible add unit test or at least a simple functional test.

For functional tests it could be in python or not.

The idea is to test the app with a customer point of view :

  • Launch the app
  • Curl help / status and verify the status code and output.
  • Upload / delete / download an object.
  • Curl wrong url and verify the status code and output.

Discussion about an admin_token

Idea is to provide a "admin_token" in the config file.
Request with the admin_token in the header could have more option than an other user.

For example, we could add in the config file, list of method only for admin :
admin_only_urls : ls,delete, ...

Default value for config

If a variable isn't present on config file, application crash.

Typical case :
Upgrade, doesn't compare your config file to template.
If a new config variable has been added, server will crash.

Split app.py into smaller files

I proposed :

Also rename some method to a more explicite name : https://github.com/guits/pastefile/blob/master/pastefile/app.py#L224-L229

For exemple :

get_or_delete_file_view
    delete_file()
    get_file()

If you are ok with that, I propose to implement that, just give me a GO when it should not impact code that you havn't merged yet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.