Updated the URL return, https is now a config

Updated the read function so you can get a raw outout
Fixed a couple bugs
Made some more ;)
This commit is contained in:
Benjamyn Love 2018-12-15 08:29:53 +11:00
parent 24f3d00602
commit 2663cbea17
2 changed files with 24 additions and 7 deletions

27
paste.py Normal file → Executable file
View File

@ -1,9 +1,8 @@
#!/usr/bin/python3.6 #!/usr/bin/python3.6
from flask import Flask, request, render_template from flask import Flask, request, render_template, make_response
import random, string import random, string
from pathlib import Path from pathlib import Path
from pprint import pprint
# Basic settings for paste # Basic settings for paste
@ -11,7 +10,8 @@ pasteDir = Path("pastes")
nameLength = 10 nameLength = 10
useSpecialChars = False useSpecialChars = False
allowListing = False allowListing = False
hostedURL = "http://paste.benjamyn.love/" hostedURL = "paste.benjamyn.love/"
method = "https://" # https:// or http://
letters = string.ascii_letters letters = string.ascii_letters
if useSpecialChars: if useSpecialChars:
@ -43,6 +43,11 @@ def writePaste(pasteName, pasteData):
for line in tmpData: for line in tmpData:
with pasten.open('a') as f: f.write(line + '\n') with pasten.open('a') as f: f.write(line + '\n')
def printRealIP():
if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
print(request.environ['REMOTE_ADDR'])
else:
print(request.environ['HTTP_X_FORWARDED_FOR'])
doesDirExist() doesDirExist()
@ -56,6 +61,7 @@ app.config['DEBUG'] = False
@app.route('/', methods=['POST', 'GET']) @app.route('/', methods=['POST', 'GET'])
def index(): def index():
printRealIP()
if request.method == "GET": if request.method == "GET":
if allowListing == True: if allowListing == True:
return "FileList" return "FileList"
@ -71,20 +77,31 @@ def index():
else: else:
print("Writing: " + data) print("Writing: " + data)
writePaste(name, data) writePaste(name, data)
return hostedURL + name return method + hostedURL + name
@app.route('/<path:path>') @app.route('/<path:path>')
def getPaste(path): def getPaste(path):
printRealIP()
raw = False
tmpPath = Path(path) tmpPath = Path(path)
pasten = pasteDir / tmpPath.name pasten = pasteDir / tmpPath.name
try:
if request.values['raw'] == 'true':
raw = True
except:
pass
print("Checking " + str(pasten)) print("Checking " + str(pasten))
if pasten.is_file(): if pasten.is_file():
with pasten.open() as f: data = f.read() with pasten.open() as f: data = f.read()
print(data) print(data)
if raw:
r = make_response(data)
r.headers.set('Content-Type', "text/plain")
return r
return render_template("read.html", data=data) return render_template("read.html", data=data)
else: else:
return "No paste found" return render_template("read.html", data="No paste found")
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='127.0.0.1') app.run(host='127.0.0.1')

View File

@ -13,10 +13,10 @@
<center> <center>
<h1>PasteBen</h1> <h1>PasteBen</h1>
<div class="container container-fluid"> <div class="container container-fluid">
<form action="http://paste.benjamyn.love" method="post" class="card"> <form action="https://paste.benjamyn.love" method="post" class="card">
<textarea name="textarea" style="height:600px;"></textarea> <textarea name="textarea" style="height:600px;"></textarea>
<input type="submit" name="buttonwaspushed" class="btn btn-outline-secondary"> <input type=submit name="buttonwaspushed" class="btn btn-outline-secondary">
</form> </form>
</div> </div>
</center> </center>