Commit 589c23cf authored by Mindiell's avatar Mindiell
Browse files

Version 0.1 - still in beta

parent 88656066
__pycache__
config.py
templates/pastes/*
VLOZIT
======
Version 0.1
Vlozit (insert, paste in slovak) is a simplistic, open source online pastebin.
......
#encoding: utf-8
DEBUG = True
HOST = '127.0.0.1'
FLASK_PORT = 8080
NETCAT_PORT = 5000
SECRET_KEY = 'choose a secret key'
#encoding: utf-8
from flask import Flask, render_template, redirect, request, url_for
from vlozit import Vlozit
app = Flask(__name__)
app.config.from_object('config')
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.jinja_env.lstrip_blocks = True
# ================================================
# Main
# ================================================
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/send', methods=['POST'])
def send():
"""
Sending a paste via the web interface
"""
return redirect(Vlozit().create_paste(request.form['paste']))
@app.route('/p')
def paste():
# Get first and only key arg
for key in request.args.keys():
return render_template(Vlozit().get_template(key))
# ================================================
# Launching
# ================================================
if __name__ == '__main__':
app.run(debug=app.config['DEBUG'], host=app.config['HOST'], port=app.config['FLASK_PORT'])
#encoding: utf-8
import signal
import socketserver
import config
from vlozit import Vlozit
class TimeoutError(Exception):
pass
class MyHandler(socketserver.BaseRequestHandler):
def handle(self):
self.data = b''
signal.signal(signal.SIGALRM, self.stop_receive)
self.get_message()
def stop_receive(self, signum, frame):
raise TimeoutError()
def get_message(self):
while True:
signal.alarm(1)
try:
self.data += self.request.recv(1024)
except TimeoutError:
url = Vlozit().create_paste(str(self.data, "utf-8"))
self.request.sendall(url+b'\n')
return
if __name__=="__main__":
server = socketserver.TCPServer((config.HOST, config.NETCAT_PORT), MyHandler)
server.serve_forever()
.hll{background-color:#ffffcc}
.c{color:#408080;font-style:italic}
.err{border:1pxsolid#FF0000}
.k{color:#008000;font-weight:bold}
.o{color:#666666}
.ch{color:#408080;font-style:italic}
.cm{color:#408080;font-style:italic}
.cp{color:#BC7A00}
.cpf{color:#408080;font-style:italic}
.c1{color:#408080;font-style:italic}
.cs{color:#408080;font-style:italic}
.gd{color:#A00000}
.ge{font-style:italic}
.gr{color:#FF0000}
.gh{color:#000080;font-weight:bold}
.gi{color:#00A000}
.go{color:#888888}
.gp{color:#000080;font-weight:bold}
.gs{font-weight:bold}
.gu{color:#800080;font-weight:bold}
.gt{color:#0044DD}
.kc{color:#008000;font-weight:bold}
.kd{color:#008000;font-weight:bold}
.kn{color:#008000;font-weight:bold}
.kp{color:#008000}
.kr{color:#008000;font-weight:bold}
.kt{color:#B00040}
.m{color:#666666}
.s{color:#BA2121}
.na{color:#7D9029}
.nb{color:#008000}
.nc{color:#0000FF;font-weight:bold}
.no{color:#880000}
.nd{color:#AA22FF}
.ni{color:#999999;font-weight:bold}
.ne{color:#D2413A;font-weight:bold}
.nf{color:#0000FF}
.nl{color:#A0A000}
.nn{color:#0000FF;font-weight:bold}
.nt{color:#008000;font-weight:bold}
.nv{color:#19177C}
.ow{color:#AA22FF;font-weight:bold}
.w{color:#bbbbbb}
.mb{color:#666666}
.mf{color:#666666}
.mh{color:#666666}
.mi{color:#666666}
.mo{color:#666666}
.sb{color:#BA2121}
.sc{color:#BA2121}
.sd{color:#BA2121;font-style:italic}
.s2{color:#BA2121}
.se{color:#BB6622;font-weight:bold}
.sh{color:#BA2121}
.si{color:#BB6688;font-weight:bold}
.sx{color:#008000}
.sr{color:#BB6688}
.s1{color:#BA2121}
.ss{color:#19177C}
.bp{color:#008000}
.vc{color:#19177C}
.vg{color:#19177C}
.vi{color:#19177C}
.il{color:#666666}
body{margin:0}
a{font-size:inherit;color:inherit}
.head{background:#669;padding:0.6em;height:2em;color:#fff;margin:0}
.title{margin:0;display:inline-block;vertical-align:top}
.about{display:block;float:right;max-width:60%;font-size:8pt}
.container{width:90%;margin:0 auto;padding:1em}
p{margin:0;font-size:11pt}
table{width: 100%;border:1px solid #336;margin-bottom:1em}
pre{margin:0}
.linenos{width: 24px}
textarea{width: 100%;border:1px solid #000}
input[type="submit"]{text-align:right;text-decoration:none;text-align:center;border-radius:4px;background:#336;padding:.4em;margin:.3em;color:#fff}
footer{padding:4px;font-size:10pt;background:#669;color:#fff;text-align:center}
@media(max-width:400px){.about{display:none}}
;Supervisor configuration file for Vlozit's flask server
;
[program:vlozit_flask_server]
command = /home/vlozit/ve/bin/python /home/vlozit/flask_server.py 1>/var/log/vlozit/flask_server.log 2>&1
process_name = flask_server
directory = /home/vlozit/
user = vlozit
autostart = true
autorestart = true
killasgroup = true
stopasgroup = true
;Supervisor configuration file for Vlozit's netcat server
;
[program:vlozit_netcat_server]
command = /home/vlozit/ve/bin/python /home/vlozit/netcat_server.py 1>/var/log/vlozit/netcat_server.log 2>&1
process_name = netcat_server
directory = /home/vlozit/
user = vlozit
autostart = true
autorestart = true
killasgroup = true
stopasgroup = true
{% extends 'base.html' %}
{% block content %}
<p>Zlovit is a simple pastebin tool which you can use either via web and via netcat inline command.</p>
<p>To use it via web, just click on New Paste in the menu.</p>
<p>To use it via netcat, just type your command on your terminal :
<pre>ls -l |nc easypaste 8080</pre>
It will return you an url like : https://zlovit/paste?59aa94c0888008ef814faebdacef9984a293b4c8t
you can use in order to share your paste.
</p>
{% endblock %}
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Vlozit</title>
<link rel="stylesheet" href="/static/css/pygments.css" /><link rel="stylesheet" href="/static/css/style.css" />
</head><body><section class="head">
<span class="title"><a href="/">Vlozit</a></span>
<span class="about">Vlozit is a simplistic, <a href="">opensource</a> online pastebin at which you can send paste through netcat or its website.</span>
</section>
<div class="container">{% block content %}{% endblock %}</div>
<footer>Licence : <a href="https://www.gnu.org/licenses/agpl-3.0.html">AGPLv3+</a> | <a href="">get sources here</a></footer>
</body></html>
{% extends 'base.html' %}
{% block content %}
<form action="/send" method="POST"><textarea name="paste" rows="10"></textarea>
<input type="submit" value="Create new paste" /></form>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<p>You can share this paste using url : <a href="##URL##">##URL##</a></p>
##FORMATTED##
<p>Edit paste:</p><form action="/send" method="POST"><textarea name="paste" rows="10">##RAW##</textarea>
<input type="submit" class="btn" value="Create new paste" /></form>
{% endblock %}
#encoding: utf-8
from Crypto.Hash import SHA
import os
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import guess_lexer, TextLexer
import time
class Vlozit():
def get_template(self, filename):
return (os.path.sep).join(("pastes",filename[0:2],filename[2:4],filename[4:6],filename))
def get_path(self, filename):
return (os.path.sep).join(("templates/pastes",filename[0:2],filename[2:4],filename[4:6],filename))
def create_paste(self, data):
# Idées possibles :
#
# * Chiffrer le contenu, la clef est dans l'url (c'est donc plutôt pour le serveur)
# Utilisation de pycrypto (https://pypi.python.org/pypi/pycrypto)
# * Permettre de discuter du contenu
# * Permettre de modifier le contenu (en-dessous) et donc d'en reposter un facilement
while True:
filename = SHA.new(bytes(str(time.perf_counter()),"utf-8")).hexdigest()
path = self.get_path(filename)
if not os.path.exists(path):
break
# Create path if not yet existing
os.makedirs(os.path.dirname(path))
# Format url to return
url = "https://vloz.it/p?%s" % filename
url = "http://localhost:8080/p?%s" % filename
# Guessing which lexer to use
try:
lexer = guess_lexer(data)
except:
lexer = TextLexer()
# Converting data via pygments
colored = highlight(data, lexer, HtmlFormatter(linenos=True))
# Replace specific characters in order to keep clean
data = data.replace("#", "&num;").replace("%", "&percnt;").replace("<", "&lt;").replace(">", "&gt;")
colored = colored.replace("#", "&num;").replace("%", "&percnt;")
# Write file based on skeleton
with open("templates/skeleton.html") as f:
html = f.read()
html = html.replace("##FORMATTED##", colored)
html = html.replace("##RAW##", data)
html = html.replace("##URL##", url)
with open(path, "w") as f:
f.write(html)
return bytes(url, "utf-8")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment