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:
parent
24f3d00602
commit
2663cbea17
27
paste.py
Normal file → Executable file
27
paste.py
Normal file → Executable file
@ -1,9 +1,8 @@
|
||||
#!/usr/bin/python3.6
|
||||
|
||||
from flask import Flask, request, render_template
|
||||
from flask import Flask, request, render_template, make_response
|
||||
import random, string
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
# Basic settings for paste
|
||||
|
||||
@ -11,7 +10,8 @@ pasteDir = Path("pastes")
|
||||
nameLength = 10
|
||||
useSpecialChars = False
|
||||
allowListing = False
|
||||
hostedURL = "http://paste.benjamyn.love/"
|
||||
hostedURL = "paste.benjamyn.love/"
|
||||
method = "https://" # https:// or http://
|
||||
|
||||
letters = string.ascii_letters
|
||||
if useSpecialChars:
|
||||
@ -43,6 +43,11 @@ def writePaste(pasteName, pasteData):
|
||||
for line in tmpData:
|
||||
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()
|
||||
@ -56,6 +61,7 @@ app.config['DEBUG'] = False
|
||||
|
||||
@app.route('/', methods=['POST', 'GET'])
|
||||
def index():
|
||||
printRealIP()
|
||||
if request.method == "GET":
|
||||
if allowListing == True:
|
||||
return "FileList"
|
||||
@ -71,20 +77,31 @@ def index():
|
||||
else:
|
||||
print("Writing: " + data)
|
||||
writePaste(name, data)
|
||||
return hostedURL + name
|
||||
return method + hostedURL + name
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def getPaste(path):
|
||||
printRealIP()
|
||||
raw = False
|
||||
tmpPath = Path(path)
|
||||
pasten = pasteDir / tmpPath.name
|
||||
try:
|
||||
if request.values['raw'] == 'true':
|
||||
raw = True
|
||||
except:
|
||||
pass
|
||||
print("Checking " + str(pasten))
|
||||
if pasten.is_file():
|
||||
with pasten.open() as f: data = f.read()
|
||||
print(data)
|
||||
if raw:
|
||||
r = make_response(data)
|
||||
r.headers.set('Content-Type', "text/plain")
|
||||
return r
|
||||
return render_template("read.html", data=data)
|
||||
else:
|
||||
return "No paste found"
|
||||
return render_template("read.html", data="No paste found")
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='127.0.0.1')
|
||||
|
||||
@ -13,10 +13,10 @@
|
||||
<center>
|
||||
<h1>PasteBen</h1>
|
||||
<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>
|
||||
|
||||
<input type="submit" name="buttonwaspushed" class="btn btn-outline-secondary">
|
||||
<input type=submit name="buttonwaspushed" class="btn btn-outline-secondary">
|
||||
</form>
|
||||
</div>
|
||||
</center>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user