forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-08-01 06:24:46 +02:00
parent 049489e359
commit a95a9ba8dc
8 changed files with 40 additions and 149 deletions

View File

@ -319,21 +319,15 @@ def after_request(response):
print(e)
abort(500)
response.headers.add('Access-Control-Allow-Headers',
"Origin, X-Requested-With, Content-Type, Accept, x-auth"
)
response.headers.add('Access-Control-Allow-Headers', "Origin, X-Requested-With, Content-Type, Accept, x-auth")
response.headers.remove("Cache-Control")
response.headers.add("Cache-Control", "public, max-age=31536000")
response.headers.add("Access-Control-Allow-Origin", app.config["SERVER_NAME"])
response.headers.add("Strict-Transport-Security", "max-age=31536000")
response.headers.add("Referrer-Policy", "same-origin")
# response.headers.add("X-Content-Type-Options","nosniff")
response.headers.add("Feature-Policy",
"geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';")
if not request.path.startswith("/embed/"):
response.headers.add("X-Frame-Options",
"deny")
response.headers.add("Feature-Policy", "geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';")
if not request.path.startswith("/embed/"): response.headers.add("X-Frame-Options", "deny")
return response

View File

@ -11,21 +11,18 @@ reasons = {
}
class Domain(Base):
class BannedDomain(Base):
__tablename__ = "domains"
id = Column(Integer, primary_key=True)
domain = Column(String)
can_submit = Column(Boolean, default=True)
reason = Column(Integer, default=0)
@property
def reason_text(self):
return reasons.get(self.reason)
def reason_text(self): return reasons.get(self.reason)
@property
def permalink(self):
return f"/admin/domain/{self.domain}"
def permalink(self): return f"/admin/domain/{self.domain}"

View File

@ -1,80 +0,0 @@
import re
from urllib.parse import *
import requests
from os import environ
from drama.__main__ import app
youtube_regex = re.compile("^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/|\&v=)([^#\&\?]*).*")
drama_regex = re.compile("^.*rdrama.net/post/+\w+/(\w+)(/\w+/(\w+))?")
twitter_regex=re.compile("/status/(\d+)")
FACEBOOK_TOKEN=environ.get("FACEBOOK_TOKEN","").strip()
def youtube_embed(url):
try:
yt_id = re.match(youtube_regex, url).group(2)
except AttributeError:
return "error"
if not yt_id or len(yt_id) != 11:
return "error"
x = urlparse(url)
params = parse_qs(x.query)
t = params.get('t', params.get('start', [0]))[0]
if t:
return f"https://youtube.com/embed/{yt_id}?start={t}"
else:
return f"https://youtube.com/embed/{yt_id}"
def drama_embed(url):
matches = re.match(drama_regex, url)
post_id = matches.group(1)
comment_id = matches.group(3)
if comment_id:
return f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}"
else:
return f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}"
def bitchute_embed(url):
return url.replace("/video/", "/embed/")
def twitter_embed(url):
oembed_url=f"https://publish.twitter.com/oembed"
params={
"url":url,
"omit_script":"t"
}
x=requests.get(oembed_url, params=params)
return x.json()["html"]
def instagram_embed(url):
oembed_url=f"https://graph.facebook.com/v9.0/instagram_oembed"
params={
"url":url,
"access_token":FACEBOOK_TOKEN,
"omitscript":'true'
}
headers={
"User-Agent":"Instagram embedder for Drama"
}
x=requests.get(oembed_url, params=params, headers=headers)
return x.json()["html"]

View File

@ -30,10 +30,7 @@ def filter_comment_html(html_text):
# search db for domain rules that prohibit commenting
bans = [
x for x in g.db.query(Domain).filter_by(
can_submit=False).filter(
Domain.domain.in_(
list(domain_list))).all()]
x for x in g.db.query(Domain).filter(Domain.domain.in_(list(domain_list))).all()]
if bans:
return bans

View File

@ -967,27 +967,17 @@ def admin_ban_domain(v):
domain=request.form.get("domain",'').strip()
if not domain:
abort(400)
if not domain: abort(400)
reason=int(request.form.get("reason",0))
if not reason:
abort(400)
if not reason: abort(400)
d_query=domain.replace("_","\_")
d=g.db.query(Domain).filter_by(domain=d_query).first()
if d:
d.can_submit=False
d.reason=reason
else:
d=Domain(
domain=domain,
can_submit=False,
reason=reason,
)
if d: d.reason=reason
else: d=Domain(domain=domain, reason=reason)
g.db.add(d)
g.db.commit()
return redirect(d.permalink)

View File

@ -6,7 +6,6 @@ import gevent
from drama.helpers.wrappers import *
from drama.helpers.sanitize import *
from drama.helpers.filters import *
from drama.helpers.embed import *
from drama.helpers.markdown import *
from drama.helpers.session import *
from drama.helpers.thumbs import *
@ -594,28 +593,38 @@ def submit_post(v):
# check ban status
domain_obj = get_domain(domain)
if domain_obj:
if not domain_obj.can_submit:
if domain_obj.reason==4:
v.ban(days=30, reason="Digitally malicious content")
elif domain_obj.reason==7:
v.ban(reason="Sexualizing minors")
if domain_obj:
if domain_obj.reason==4:
v.ban(days=30, reason="Digitally malicious content")
elif domain_obj.reason==7:
v.ban(reason="Sexualizing minors")
if request.headers.get("Authorization"): return {"error":"ToS violation"}, 400
else: return render_template("submit.html", v=v, error="ToS Violation", title=title, url=url, body=request.form.get("body", "")), 400
if request.headers.get("Authorization"): return {"error":"ToS violation"}, 400
else: return render_template("submit.html", v=v, error="ToS Violation", title=title, url=url, body=request.form.get("body", "")), 400
# check for embeds
if domain_obj.embed_function:
try:
embed = eval(domain_obj.embed_function)(url)
except BaseException:
embed = None
else:
embed = None
else:
if "twitter.com" in domain:
embed = requests.get("https://publish.twitter.com/oembed", params={"url":url, "omit_script":"t"}).json()["html"]
elif "youtu" in domain:
yt_id = re.match(re.compile("^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/|\&v=)([^#\&\?]*).*"), url).group(2)
if not yt_id or len(yt_id) != 11: embed = None
else:
params = parse_qs(urlparse(url).query)
t = params.get('t', params.get('start', [0]))[0]
if t: embed = f"https://youtube.com/embed/{yt_id}?start={t}"
else: embed = f"https://youtube.com/embed/{yt_id}"
embed = None
elif "instagram.com" in domain:
embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent":"Instagram embedder for Drama"}).json()["html"]
elif app.config['SERVER_NAME'] in domain:
matches = re.match(re.compile("^.*rdrama.net/post/+\w+/(\w+)(/\w+/(\w+))?"), url)
post_id = matches.group(1)
comment_id = matches.group(3)
if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}"
else: embed = f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}"
else: embed = None
# similarity check
now = int(time.time())

View File

@ -14,9 +14,6 @@
<h2>Current</h2>
<h3 class="h5 pt-2">can_submit</h3>
<p>{{domain.can_submit}}</p>
<h3 class="h5 pt-2">reason</h3>
<p>{{domain.reason_text}}</p>

View File

@ -390,19 +390,6 @@
</div>
{% elif b %}
<div class="row no-gutters">
<div class="col">
<div class="text-center py-7">
<div class="h4 p-2">+{{b.name}} is barren and needs posts!</div>
{% if v and b and b.can_submit(v) %}
<div class="p-2"><a href="/submit" class="btn btn-primary">Be the first to post</a></div>
{% endif %}
</div>
</div>
</div>
{% elif u %}
{% if v and v.id == u.id %}
<div class="row no-gutters">