diff --git a/drama/__main__.py b/drama/__main__.py index a6ac62ef55..0f9e8d4340 100644 --- a/drama/__main__.py +++ b/drama/__main__.py @@ -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 diff --git a/drama/classes/domains.py b/drama/classes/domains.py index 0332b35c92..a43b912a9a 100644 --- a/drama/classes/domains.py +++ b/drama/classes/domains.py @@ -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}" diff --git a/drama/helpers/embed.py b/drama/helpers/embed.py deleted file mode 100644 index c785d29f5e..0000000000 --- a/drama/helpers/embed.py +++ /dev/null @@ -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"] \ No newline at end of file diff --git a/drama/helpers/filters.py b/drama/helpers/filters.py index e67b213488..f9857f927f 100644 --- a/drama/helpers/filters.py +++ b/drama/helpers/filters.py @@ -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 diff --git a/drama/routes/admin.py b/drama/routes/admin.py index 7fca611e33..4c7ceb61b7 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -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) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 82b29ed0ad..3250bfed92 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -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()) diff --git a/drama/templates/admin/manage_domain.html b/drama/templates/admin/manage_domain.html index c74af121d0..65ade827d9 100644 --- a/drama/templates/admin/manage_domain.html +++ b/drama/templates/admin/manage_domain.html @@ -14,9 +14,6 @@

Current

-

can_submit

-

{{domain.can_submit}}

-

reason

{{domain.reason_text}}

diff --git a/drama/templates/submission_listing.html b/drama/templates/submission_listing.html index c104a18902..d4b0865597 100644 --- a/drama/templates/submission_listing.html +++ b/drama/templates/submission_listing.html @@ -390,19 +390,6 @@ -{% elif b %} -
-
-
-
+{{b.name}} is barren and needs posts!
- {% if v and b and b.can_submit(v) %} - - {% endif %} -
-
-
- - {% elif u %} {% if v and v.id == u.id %}