1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

css btc tip

This commit is contained in:
papee
2020-08-14 18:20:31 +02:00
12 changed files with 723 additions and 66 deletions

View File

@ -34,7 +34,6 @@ def runserver(
data_dir="",
debug=None,
version=False,
paste_id_length=None,
server="paste",
):
if version:
@ -42,22 +41,34 @@ 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:
print(f"Admin URL: {settings.ADMIN_URL}")
if updated_settings.DEBUG:
print(
f"Admin URL for dev: http://{updated_settings.HOST}:{updated_settings.PORT}{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

View File

@ -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"

View File

@ -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

View File

@ -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()

View File

@ -185,15 +185,31 @@ input.hide-upload {
/* Paste Page */
.paste-options {
background-color: #424141;
.paste-options-res {
text-align: center;
margin-bottom: 10px;
opacity: 0.9 !important;
}
.paste-options-res .btn-group{
float: none;
}
.paste-options,
.paste-options-res {
background-color: #333333;
padding: 10px;
opacity: 0.5;
}
.paste-options-res svg {
margin-left: 8px;
}
.paste-options span {
background-color: #375A7F;
color: #f9fafc;
width: 70px;
}
.paste-options:hover{
@ -255,6 +271,8 @@ pre.prettyprint {
width: 100%;
min-height: 100px;
padding: 5px;
word-break: break-word;
margin-bottom: 0px;
}
/* Specify class=linenums on a pre to get line numbering */
@ -283,6 +301,7 @@ pre {
.upload-file {
min-width: 100px;
margin-right: 4px;
}
.form-group {
@ -525,13 +544,11 @@ nav ul li a:hover {
}
/* Fonts */
.btn {
.btn,
.btn-group span {
font-size: 0.77em;
}
pre {
font-size: 70%;
}
.reader-tools {
bottom: 30px;

View File

@ -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
@ -117,11 +119,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: () => {
@ -240,7 +246,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
@ -866,6 +873,11 @@ window.onload = function () {
app.currentPaste.title = title.innerText;
}
let btcTipAddress = document.querySelector('.btc-tip-address');
if (btcTipAddress) {
app.currentPaste.btcTipAddress = btcTipAddress.innerText;
}
}
/* Display previous pastes */

View File

@ -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.

View File

@ -82,7 +82,7 @@
<div class="container-md" id="wrap-content">
%if defined('paste') and paste.title:
<h1>{{ paste.title }}</h1>
<h3>{{ paste.title }}</h3>
%end

View File

@ -3,7 +3,7 @@
<div>
<div class="file-upload" v-if="support.fileUpload">
<label type="button" class="btn btn-primary"
<label type="button" class="btn btn-primary upload-file"
:disabled="isUploading">{% isUploading ? 'Uploading...': 'Upload file' %}
<input type="file" class="hide-upload" id="file-upload" @change="handleUpload($event.target.files)">
</label>
@ -36,15 +36,24 @@
@keydown.ctrl.enter="encryptAndSendPaste()"></textarea>
<div class="paste-options">
<h5>Paste Options (these options are optionals)</h5>
<h6>Paste Options (these options are optionals)</h6>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Title</span>
</div>
<input type="text" class="form-control 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">
placeholder="Optional paste title. This part is NOT encrypted: anything you type here will be visible by anyone"
v-model="newPaste.title" maxlength="60">
</div>
<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>

View File

@ -57,6 +57,16 @@
{{ paste.content }}
</code>
</pre>
<div class="paste-options-res">
<div class="btn-group">
<span class="input-group-text">Tip it with<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"><path d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm0 18v-1.511h-.5v1.511h-1v-1.511h-2.484l.25-1.489h.539c.442 0 .695-.425.695-.854v-4.444c0-.416-.242-.702-.683-.702h-.817v-1.5h2.5v-1.5h1v1.5h.5v-1.5h1v1.526c2.158.073 3.012.891 3.257 1.812.29 1.09-.429 2.005-1.046 2.228.75.192 1.789.746 1.789 2.026 0 1.742-1.344 2.908-4 2.908v1.5h-1zm-.5-5.503v2.503c1.984 0 3.344-.188 3.344-1.258 0-1.148-1.469-1.245-3.344-1.245zm0-.997c1.105 0 2.789-.078 2.789-1.25 0-1-1.039-1.25-2.789-1.25v2.5z" fill="#eee"/></svg></span>
<a class="btn btn-primary btc-tip-address"
href="bitcoin:{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS }}">
{{ paste.btc_tip_address or settings.DEFAULT_BTC_TIP_ADDRESS}}
</a>
<button class="btn btn-secondary">copy</button>
</div>
</div>
<div>
<div id="readable-paste-content" v-if="readerMode">
@ -120,9 +130,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">>

View File

@ -1,3 +1,3 @@
from zerobin.wsgi import setup_app
from zerobin.routes import get_app
settings, app = get_app()