mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Add btc tip
This commit is contained in:
@@ -34,7 +34,6 @@ def runserver(
|
||||
data_dir="",
|
||||
debug=None,
|
||||
version=False,
|
||||
paste_id_length=None,
|
||||
server="paste",
|
||||
):
|
||||
if version:
|
||||
@@ -42,22 +41,32 @@ def runserver(
|
||||
sys.exit(0)
|
||||
|
||||
try:
|
||||
settings, app = get_app(debug=debug, config_dir=config_dir, data_dir=data_dir,)
|
||||
updated_settings, app = get_app(
|
||||
debug=debug, config_dir=config_dir, data_dir=data_dir,
|
||||
)
|
||||
except SettingsValidationError as err:
|
||||
print("Configuration error: %s" % err.message, file=sys.stderr)
|
||||
print("Configuration error: %s" % err, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
settings.HOST = host or os.environ.get("ZEROBIN_HOST", settings.HOST)
|
||||
settings.PORT = port or os.environ.get("ZEROBIN_PORT", settings.PORT)
|
||||
updated_settings.HOST = host or os.environ.get(
|
||||
"ZEROBIN_HOST", updated_settings.HOST
|
||||
)
|
||||
updated_settings.PORT = port or os.environ.get(
|
||||
"ZEROBIN_PORT", updated_settings.PORT
|
||||
)
|
||||
|
||||
if settings.DEBUG:
|
||||
if updated_settings.DEBUG:
|
||||
print(f"Admin URL: {settings.ADMIN_URL}")
|
||||
print()
|
||||
run(
|
||||
app, host=settings.HOST, port=settings.PORT, reloader=True, server=server,
|
||||
app,
|
||||
host=updated_settings.HOST,
|
||||
port=updated_settings.PORT,
|
||||
reloader=True,
|
||||
server=server,
|
||||
)
|
||||
else:
|
||||
run(app, host=settings.HOST, port=settings.PORT, server=server)
|
||||
run(app, host=settings.HOST, port=updated_settings.PORT, server=server)
|
||||
|
||||
|
||||
# The regex parse the url and separate the paste's id from the decription key
|
||||
|
@@ -32,3 +32,5 @@ REFRESH_COUNTER = 60 # in seconds
|
||||
# for PASTE_ID_LENGTH=8, for example, it's 2^(6*8) = 281 474 976 710 656
|
||||
PASTE_ID_LENGTH = 8
|
||||
|
||||
# The Bitcoin address displayed in the paste if the author didn't chose one
|
||||
DEFAULT_BTC_TIP_ADDRESS = "bc1q4x6nwp56s9enmwtsa8um0gywpxdzeyrdluga04"
|
||||
|
@@ -1,7 +1,3 @@
|
||||
# coding: utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import os
|
||||
import hashlib
|
||||
import base64
|
||||
@@ -12,7 +8,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
import bleach
|
||||
|
||||
from zerobin.utils import settings, to_ascii, as_unicode, safe_open as open
|
||||
from zerobin.utils import settings
|
||||
|
||||
|
||||
class Paste(object):
|
||||
@@ -21,7 +17,7 @@ class Paste(object):
|
||||
calculation of the expiration date.
|
||||
"""
|
||||
|
||||
DIR_CACHE = set()
|
||||
DIR_CACHE: set = set()
|
||||
|
||||
DURATIONS = {
|
||||
"1_day": 24 * 3600,
|
||||
@@ -30,12 +26,19 @@ class Paste(object):
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self, uuid=None, uuid_length=None, content=None, expiration=None, title=""
|
||||
self,
|
||||
uuid=None,
|
||||
uuid_length=None,
|
||||
content=None,
|
||||
expiration=None,
|
||||
title="",
|
||||
btc_tip_address="",
|
||||
):
|
||||
|
||||
self.content = content
|
||||
self.expiration = self.get_expiration(expiration)
|
||||
self.title = bleach.clean(title, strip=True)[:60]
|
||||
self.btc_tip_address = bleach.clean(btc_tip_address, strip=True)[:50]
|
||||
|
||||
if not uuid:
|
||||
# generate the uuid from the decoded content by hashing it
|
||||
@@ -120,6 +123,7 @@ class Paste(object):
|
||||
expiration=expiration,
|
||||
content=content,
|
||||
title=" ".join(metadata.get("title", "").split()),
|
||||
btc_tip_address=" ".join(metadata.get("btc_tip_address", "").split()),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -184,14 +188,18 @@ class Paste(object):
|
||||
if "burn_after_reading" == self.expiration:
|
||||
expiration = self.expiration + "#%s" % datetime.now() # TODO: use UTC dates
|
||||
else:
|
||||
expiration = as_unicode(self.expiration)
|
||||
expiration = str(self.expiration)
|
||||
|
||||
# write the paste
|
||||
with open(self.path, "w") as f:
|
||||
f.write(expiration + "\n")
|
||||
f.write(self.content + "\n")
|
||||
metadata = {}
|
||||
if self.title:
|
||||
f.write(json.dumps({"title": self.title}) + "\n")
|
||||
metadata["title"] = self.title
|
||||
if self.btc_tip_address:
|
||||
metadata["btc_tip_address"] = self.btc_tip_address
|
||||
f.write(json.dumps(metadata) + "\n")
|
||||
|
||||
return self
|
||||
|
||||
|
@@ -130,12 +130,14 @@ def create_paste():
|
||||
|
||||
expiration = request.forms.get("expiration", "burn_after_reading")
|
||||
title = request.forms.get("title", "")
|
||||
btc_tip_address = request.forms.get("btcTipAddress", "")
|
||||
|
||||
paste = Paste(
|
||||
expiration=expiration,
|
||||
content=content,
|
||||
uuid_length=settings.PASTE_ID_LENGTH,
|
||||
title=title,
|
||||
btc_tip_address=btc_tip_address,
|
||||
)
|
||||
paste.save()
|
||||
|
||||
|
@@ -34,11 +34,13 @@ const app = new Vue({
|
||||
content: '',
|
||||
downloadLink: {},
|
||||
title: '',
|
||||
btcTipAddress: ''
|
||||
},
|
||||
newPaste: {
|
||||
expiration: '1_day',
|
||||
content: '',
|
||||
title: '',
|
||||
btcTipAddress: ''
|
||||
},
|
||||
messages: [],
|
||||
/** Check for browser support of the named featured. Store the result
|
||||
@@ -118,11 +120,15 @@ const app = new Vue({
|
||||
|
||||
document.querySelector('.submit-form').style.display = "inherit";
|
||||
document.querySelector('.paste-form').style.display = "none";
|
||||
document.querySelector('h1').style.display = "none";
|
||||
let title = document.querySelector('h1');
|
||||
if (title) {
|
||||
title.style.display = "none";
|
||||
}
|
||||
let content = document.getElementById('content');
|
||||
content.value = zerobin.getPasteContent();
|
||||
content.dispatchEvent(new Event('change'));
|
||||
this.newPaste.title = this.currentPaste.title;
|
||||
this.newPaste.btcTipAddress = this.currentPaste.btcTipAddress;
|
||||
},
|
||||
|
||||
handleCancelClone: () => {
|
||||
@@ -241,7 +247,8 @@ const app = new Vue({
|
||||
var data = {
|
||||
content: content,
|
||||
expiration: app.newPaste.expiration,
|
||||
title: app.newPaste.title
|
||||
title: app.newPaste.title,
|
||||
btcTipAddress: app.newPaste.btcTipAddress
|
||||
};
|
||||
var sizebytes = zerobin.count(JSON.stringify(data));
|
||||
var oversized = sizebytes > zerobin.max_size; // 100kb - the others header information
|
||||
@@ -867,6 +874,11 @@ window.onload = function () {
|
||||
app.currentPaste.title = title.innerText;
|
||||
}
|
||||
|
||||
let btcTipAddress = document.querySelector('.btc-tip-address a');
|
||||
if (btcTipAddress) {
|
||||
app.currentPaste.btcTipAddress = btcTipAddress.innerText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Display previous pastes */
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import codecs
|
||||
import unicodedata
|
||||
import hashlib
|
||||
import secrets
|
||||
from functools import partial
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
@@ -35,12 +32,12 @@ class SettingsContainer(object):
|
||||
cls._instance.update_with_module(default_settings)
|
||||
return cls._instance
|
||||
|
||||
def update_with_dict(self, dict):
|
||||
def update_with_dict(self, mapping):
|
||||
"""
|
||||
Update settings with values from the given mapping object.
|
||||
(Taking only variable with uppercased name)
|
||||
"""
|
||||
for name, value in dict.items():
|
||||
for name, value in mapping.items():
|
||||
if name.isupper():
|
||||
setattr(self, name, value)
|
||||
return self
|
||||
@@ -58,43 +55,22 @@ class SettingsContainer(object):
|
||||
Create an instance of SettingsContainer with values based
|
||||
on the one in the passed module.
|
||||
"""
|
||||
settings = cls()
|
||||
settings.update_with_module(module)
|
||||
return settings
|
||||
params = cls()
|
||||
params.update_with_module(module)
|
||||
return params
|
||||
|
||||
def update_with_file(self, filepath):
|
||||
"""
|
||||
Update settings with values from the given module file.
|
||||
Uses update_with_dict() behind the scenes.
|
||||
"""
|
||||
settings = run_path(filepath)
|
||||
return self.update_with_dict(settings)
|
||||
params = run_path(filepath)
|
||||
return self.update_with_dict(params)
|
||||
|
||||
|
||||
settings = SettingsContainer()
|
||||
|
||||
|
||||
def to_ascii(utext):
|
||||
""" Take a unicode string and return ascii bytes.
|
||||
|
||||
Try to replace non ASCII char by similar ASCII char. If it can't,
|
||||
replace it with "?".
|
||||
"""
|
||||
return unicodedata.normalize("NFKD", utext).encode("ascii", "replace")
|
||||
|
||||
|
||||
# Make sure to always specify encoding when using open in Python 2 or 3
|
||||
safe_open = partial(codecs.open, encoding="utf8")
|
||||
|
||||
|
||||
def as_unicode(obj):
|
||||
""" Return the unicode representation of an object """
|
||||
try:
|
||||
return unicode(obj)
|
||||
except NameError:
|
||||
return str(obj)
|
||||
|
||||
|
||||
def ensure_app_context(data_dir=None, config_dir=None):
|
||||
""" Ensure all the variable things we generate are available.
|
||||
|
||||
|
@@ -32,9 +32,19 @@
|
||||
</div>
|
||||
<textarea rows="10" style="width:100%;" class="form-control" id="content" name="content" autofocus
|
||||
@keydown.ctrl.enter="encryptAndSendPaste()"></textarea>
|
||||
<input type="text" class="paste-excerpt" name="paste-excerpt"
|
||||
placeholder="Optional paste title. This part is NOT encrypted: anything you type here will be visible by anyone"
|
||||
v-model="newPaste.title" maxlength="60">
|
||||
<p>
|
||||
<input type="text" class="paste-excerpt" name="paste-excerpt"
|
||||
placeholder="Optional paste title. This part is NOT encrypted: anything you type here will be visible by anyone"
|
||||
v-model="newPaste.title" maxlength="60">
|
||||
</p>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="basic-addon1">BTC tip</span>
|
||||
</div>
|
||||
<input type="text" class="form-control paste-btc-tip-address" name="paste-btc-tip-address"
|
||||
placeholder="Put a BTC address to ask for a tip. Leave it empty to let us use our."
|
||||
v-model="newPaste.btcTipAddress" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group select-date paste-option down" v-if="displayBottomToolBar">
|
||||
|
@@ -64,6 +64,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="btc-tip-address">
|
||||
Tip in bitcoin: <a
|
||||
href="bitcoin:{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS }}">{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS}}</a>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between down">
|
||||
<div v-if="currentPaste.ownerKey">
|
||||
<button class="btn btn-clone btn-secondary" @click="handleDeletePaste()">Delete Paste</button>
|
||||
@@ -120,9 +125,22 @@
|
||||
<div>
|
||||
<textarea rows="10" style="width:100%;" class=" form-control" @keydown.ctrl.enter="encryptAndSendPaste()"
|
||||
id="content" name="content"></textarea>
|
||||
<input type="text" class="paste-excerpt" name="paste-excerpt"
|
||||
placeholder="Optional paste title. This part is NOT encrypted: anything you type here will be visible by anyone"
|
||||
v-model="newPaste.title" maxlength="60">
|
||||
<p>
|
||||
<input type="text" class="paste-excerpt" name="paste-excerpt"
|
||||
placeholder="Optional paste title. This part is NOT encrypted: anything you type here will be visible by anyone"
|
||||
v-model="newPaste.title" maxlength="60">
|
||||
</p>
|
||||
<p>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="basic-addon1">BTC tip</span>
|
||||
</div>
|
||||
<input type="text" class="form-control paste-btc-tip-address" name="paste-btc-tip-address"
|
||||
placeholder="Put a BTC address to ask for a tip" v-model="newPaste.btcTipAddress" maxlength="50">
|
||||
</div>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between" v-if="displayBottomToolBar">>
|
||||
|
Reference in New Issue
Block a user