-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9e228bf
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from flask import Flask, request, jsonify, render_template, \ | ||
make_response | ||
from paster import paste, get_content | ||
import requests as req | ||
|
||
app = Flask(__name__) | ||
errors = {'405': 'Get method is not allowed !'} | ||
|
||
@app.route('/api/documents') | ||
def newdocument(): | ||
method = request.method | ||
if method == 'POST': | ||
content = request.form['content'] | ||
result = paste(content) | ||
url = '127.0.0.1:5000/'+result | ||
key = result | ||
return jsonify({'ok': True, 'result': [{'key': key, 'url': url}]}) | ||
else: | ||
return jsonify({'ok': False, 'result': [{'err_code': 405, 'error': errors['405']}]}) | ||
|
||
|
||
@app.route('/raw/<key>') | ||
def viewraw(key): | ||
if '.' in key: | ||
ext = key.split('.')[1] | ||
key = key.split('.')[0] | ||
else: | ||
ext = 'txt' | ||
response = make_response(get_content(key), 200) | ||
response.mimetype = "text/plain" | ||
return response | ||
|
||
@app.route('/<key>') | ||
def view(key): | ||
if '.' in key: | ||
ext = key.split('.')[1] | ||
key = key.split('.')[0] | ||
else: | ||
ext = 'txt' | ||
return render_template('viewer.html', row=False, code=get_content(key), extension=ext) | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sqlite3 | ||
import base64 | ||
import uuid | ||
from random import choice | ||
|
||
chars = 'abcdefghijklmnopqrstuvwxyz' | ||
db_path = 'db\Pastes.db' | ||
db_conn = sqlite3.connect(db_path, check_same_thread=False) | ||
|
||
def key_is_not_exists(key): | ||
cur = db_conn.cursor() | ||
cur.execute('SELECT * FROM pastes WHERE key=?', (key,)) | ||
if not cur.fetchall(): | ||
return True | ||
else: | ||
return False | ||
|
||
def gen_key(): | ||
while True: | ||
key = '' | ||
for i in range(10): | ||
key += choice(chars) | ||
if key_is_not_exists(key): | ||
break | ||
return key | ||
|
||
def sqlitify(content): | ||
key = gen_key() | ||
cur = db_conn.cursor() | ||
cur.execute('INSERT INTO pastes(key, contents) VALUES(?, ?)', (key, base64.b64encode(content.encode()).decode())) | ||
db_conn.commit() | ||
del cur | ||
print(key) | ||
return key | ||
|
||
def paste(content): | ||
key = sqlitify( | ||
content=content | ||
) | ||
return key | ||
|
||
def get_content(key): | ||
cur = db_conn.cursor() | ||
cur.execute('SELECT * FROM pastes WHERE key=?', (key,)) | ||
f = cur.fetchall() | ||
if not f: | ||
return 'DOCUMENT(PASTE)_NOT_FOUND' | ||
else: | ||
content = f[0][1] | ||
content_dec = base64.b64decode(content.encode()).decode() | ||
return content_dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import socket | ||
import secrets | ||
from paster import paste | ||
def server(): | ||
# create the socket | ||
# AF_INET => IPv4 | ||
# SOCK_STREAM => TCP Connections | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
||
s.bind(('0.0.0.0', 9999)) | ||
|
||
s.listen(10) | ||
|
||
while True: | ||
try: | ||
clientSocket, address = s.accept() | ||
print(f"Connection from {address} has been established") | ||
|
||
|
||
full_message = "" | ||
while True: | ||
data = clientSocket.recv(32768) | ||
if len(data) <= 0: | ||
|
||
break | ||
full_message += data.decode('utf-8') | ||
|
||
res = paste(full_message) | ||
|
||
clientSocket.sendall( | ||
bytes('127.0.0.1:5000/'+res+"\n", "utf-8")) | ||
clientSocket.shutdown(socket.SHUT_WR) | ||
except: | ||
pass | ||
server() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
{% if not raw %} | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism.css" integrity="sha512-jtWR3pdYjGwfw9df601YF6uGrKdhXV37c+/6VNzNctmrXoO0nkgHcS03BFxfkWycOa2P2Nw9Y9PCT9vjG9jkVg==" crossorigin="anonymous" /> | ||
{% endif %} | ||
</head> | ||
<body> | ||
{% if not raw %} | ||
<pre>[+] PyFarsi's Pastebin</pre> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/components/prism-core.min.js" integrity="sha512-xR+IAyN+t9EBIOOJw5m83FTVMDsPd63IhJ3ElP4gmfUFnQlX9+eWGLp3P4t3gIjpo2Z1JzqtW/5cjgn+oru3yQ==" crossorigin="anonymous"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-zc7WDnCM3aom2EziyDIRAtQg1mVXLdILE09Bo+aE1xk0AM2c2cVLfSW9NrxE5tKTX44WBY0Z2HClZ05ur9vB6A==" crossorigin="anonymous"></script> | ||
<pre><code class="language-{{extension}}">{{code}}</code></pre> | ||
{% else %} | ||
<pre>{{code}}</pre> | ||
{% endif %} | ||
</body> | ||
</html> |