Code Monkey home page Code Monkey logo

pastefile's Introduction

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

guits avatar gaell avatar amaumene avatar

Watchers

James Cloos avatar

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.