forked from rDrama/rDrama
1
0
Fork 0

Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost

master
Aevann1 2022-10-04 20:36:35 +00:00
commit 43a33b1359
25 changed files with 7077 additions and 6986 deletions

1
.gitattributes vendored
View File

@ -2,3 +2,4 @@
*.js linguist-detectable=true
*.html linguist-detectable=false
*.py linguist-detectable=true
* text=auto

View File

@ -1,11 +1,48 @@
FROM ubuntu:22.04
ADD .. /service
ARG DEBIAN_FRONTEND=noninteractive
RUN /service/ubuntu_setup.sh
RUN apt update
RUN apt -y upgrade
RUN apt install -y supervisor
RUN apt install -y python3-pip
RUN apt install -y ffmpeg
RUN apt install -y imagemagick
RUN apt install -y postgresql
RUN apt install -y libpq-dev
RUN apt install -y nano
COPY requirements.txt /etc/requirements.txt
RUN pip3 install -r /etc/requirements.txt
RUN mkdir /images
RUN mkdir /songs
RUN mkdir /videos
RUN mkdir /audio
RUN mkdir /asset_submissions
RUN mkdir /asset_submissions/marseys
RUN mkdir /asset_submissions/hats
RUN mkdir /asset_submissions/marseys/original
RUN mkdir /asset_submissions/hats/original
ENV NODE_VERSION=16.13.0
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version
RUN npm i -g yarn
RUN apt install -y nginx
RUN rm /etc/nginx/sites-available -r
RUN rm /etc/nginx/sites-enabled/default
RUN mkdir /etc/nginx/includes
EXPOSE 80/tcp
RUN apt install -y supervisor
CMD [ "/usr/bin/supervisord", "-c", "/service/supervisord.conf" ]
CMD [ "/usr/bin/supervisord", "-c", "/rDrama/supervisord.conf" ]

View File

@ -1,12 +1,12 @@
version: '2.3'
services:
files:
container_name: "rDrama"
build:
context: .
volumes:
- "./:/service"
- "./:/rDrama"
- "./nginx.conf:/etc/nginx/sites-enabled/1"
- "./nginx-serve-static.conf:/etc/nginx/includes/serve-static"
env_file: env
environment:
- DATABASE_URL=postgresql://postgres@postgres:5432
@ -15,11 +15,10 @@ services:
- "redis"
- "postgres"
ports:
- "5000:5000"
- "80:80"
depends_on:
- redis
- postgres
- nginx
redis:
image: redis
@ -36,11 +35,3 @@ services:
- POSTGRES_HOST_AUTH_METHOD=trust
ports:
- "5432:5432"
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx.txt:/etc/nginx/conf.d/default.conf
- ./nginx-serve-static.txt:/etc/nginx/includes/serve-static

2
env
View File

@ -1,4 +1,4 @@
FLASK_APP=/service/files/cli:app
FLASK_APP=/rDrama/files/cli:app
MASTER_KEY=blahblahblah
DOMAIN=localhost
SITE_NAME=rDrama

View File

@ -129,10 +129,7 @@ def teardown_request(error):
del g.db
stdout.flush()
if app.config["SERVER_NAME"] == 'localhost':
from files.routes import *
from files.routes.chat import *
elif "load_chat" in argv:
if "load_chat" in argv:
from files.routes.chat import *
else:
from files.routes import *

View File

@ -328,7 +328,7 @@ class Comment(Base):
@lazy
def realbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.parent_comment.author_id, self.top_comment.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
body = self.body_html or ""
@ -392,7 +392,7 @@ class Comment(Base):
@lazy
def plainbody(self, v):
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.parent_comment.author_id, self.top_comment.author_id, self.post.author_id])): return f"<p>{CC} ONLY</p>"
body = self.body

View File

@ -61,10 +61,6 @@ def sub_inactive_purge_task():
Submission.private == False, Submission.is_banned == False,
Submission.deleted_utc == 0).all()]
active_holes.append('changelog') # system hole immune from deletion
active_holes.append('furry') # house holes immune from deletion
active_holes.append('vampire')
active_holes.append('racist')
active_holes.append('femboy')
dead_holes = g.db.query(Sub).filter(Sub.name.notin_(active_holes)).all()
names = [x.name for x in dead_holes]

View File

@ -9,6 +9,16 @@ from files.helpers.get import *
from files.helpers.wrappers import *
from files.routes.static import marsey_list
@app.get('/asset_submissions/<path:path>')
@limiter.exempt
def asset_submissions(path):
resp = make_response(send_from_directory('/asset_submissions', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
resp.headers.remove("Content-Type")
resp.headers.add("Content-Type", "image/webp")
return resp
@app.get("/submit/marseys")
@auth_required
def submit_marseys(v):

View File

@ -284,7 +284,7 @@ def sign_up_post(v):
return signup_error("There was a problem. Please try again.")
if not hmac.compare_digest(correct_formkey, form_formkey):
return signup_error("There was a problem. Please try again.")
return signup_error("There was a problem. Please try again!")
if not request.values.get(
"password") == request.values.get("password_confirm"):

View File

@ -1110,7 +1110,7 @@ def undelete_post_pid(pid, v):
def toggle_comment_nsfw(cid, v):
comment = get_comment(cid)
if comment.author_id != v.id and not v.admin_level > 1:
if comment.author_id != v.id and not v.admin_level > 1 and not (comment.post.sub and v.mods(comment.post.sub)):
abort(403)
comment.over_18 = not comment.over_18
@ -1132,7 +1132,7 @@ def toggle_comment_nsfw(cid, v):
def toggle_post_nsfw(pid, v):
post = get_post(pid)
if post.author_id != v.id and not v.admin_level > 1:
if post.author_id != v.id and not v.admin_level > 1 and not (post.sub and v.mods(post.sub)):
abort(403)
post.over_18 = not post.over_18

View File

@ -297,6 +297,40 @@ def static_service(path):
return resp
### BEGIN FALLBACK ASSET SERVING
# In production, we have nginx serve these locations now.
# These routes stay for local testing. Requests don't reach them on prod.
@app.get('/images/<path>')
@app.get('/hostedimages/<path>')
@app.get("/static/images/<path>")
@limiter.exempt
def images(path):
resp = make_response(send_from_directory('/images', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
resp.headers.remove("Content-Type")
resp.headers.add("Content-Type" ,"image/webp")
return resp
@app.get('/videos/<path>')
@limiter.exempt
def videos(path):
resp = make_response(send_from_directory('/videos', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
return resp
@app.get('/audio/<path>')
@limiter.exempt
def audio(path):
resp = make_response(send_from_directory('/audio', path))
resp.headers.remove("Cache-Control")
resp.headers.add("Cache-Control", "public, max-age=3153600")
return resp
### END FALLBACK ASSET SERVING
@app.get("/robots.txt")
def robots_txt():
return send_file("assets/robots.txt")

View File

@ -480,7 +480,7 @@
{% endif %}
{% endif %}
{% if c.parent_submission and (c.author_id==v.id or v.admin_level > 1) %}
{% if c.parent_submission and (c.author_id==v.id or v.admin_level > 1 or (c.post.sub and v.mods(c.post.sub))) %}
<button id="unmark-{{c.id}}" class="dropdown-item list-inline-item d-none {% if c.over_18 %}d-md-block{% endif %} text-danger" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark-{{c.id}}','unmark-{{c.id}}','d-md-block')"><i class="fas fa-eye-evil text-danger fa-fw"></i>Unmark +18</button>
<button id="mark-{{c.id}}" class="dropdown-item list-inline-item d-none {% if not c.over_18 %}d-md-block{% endif %} text-danger" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark-{{c.id}}','unmark-{{c.id}}','d-md-block')"><i class="fas fa-eye-evil text-danger fa-fw"></i>Mark +18</button>
{% endif %}
@ -636,9 +636,6 @@
<a id="undelete2-{{c.id}}" class="{% if not c.deleted_utc %}d-none{% endif %} list-group-item text-success" role="button" onclick="post_toast(this,'/undelete/comment/{{c.id}}', 'delete2-{{c.id}}', 'undelete2-{{c.id}}','d-none');document.getElementById('comment-{{c.id}}').classList.remove('deleted')" data-bs-dismiss="modal"><i class="far fa-trash-alt text-success mr-2"></i>Undelete</a>
<a id="delete2-{{c.id}}" class="{% if c.deleted_utc %}d-none{% endif %} list-group-item text-danger" role="button" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#deleteCommentModal" onclick="delete_commentModal('{{c.id}}')"><i class="far fa-trash-alt text-danger mr-2"></i>Delete</a>
<a id="mark2-{{c.id}}" class="{% if c.over_18 %}d-none{% endif %} list-group-item text-danger" role="button" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark2-{{c.id}}','unmark2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-evil text-danger mr-2"></i>Mark +18</a>
<a id="unmark2-{{c.id}}" class="{% if not c.over_18 %}d-none{% endif %} list-group-item text-danger" role="button" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark2-{{c.id}}','unmark2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-evil text-danger mr-2"></i>Unmark +18</a>
{% else %}
{% if c.body %}
<a role="button" data-bs-dismiss="modal" onclick="expandMarkdown('{{c.id}}','c')" class="list-group-item"><i class="fas text-expand-icon-{{c.id}} fa-expand-alt mr-2"></i><span class="expand-text-c-{{c.id}}">View source</span></a>
@ -651,6 +648,11 @@
{% endif %}
{% endif %}
{% if c.author_id == v.id or (c.post.sub and v.mods(c.post.sub)) %}
<a id="mark2-{{c.id}}" class="{% if c.over_18 %}d-none{% endif %} list-group-item text-danger" role="button" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark2-{{c.id}}','unmark2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-evil text-danger mr-2"></i>Mark +18</a>
<a id="unmark2-{{c.id}}" class="{% if not c.over_18 %}d-none{% endif %} list-group-item text-danger" role="button" onclick="post_toast(this,'/toggle_comment_nsfw/{{c.id}}','mark2-{{c.id}}','unmark2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-evil text-danger mr-2"></i>Unmark +18</a>
{% endif %}
{% if v.admin_level < 2 %}
{% if c.post and v.id == c.post.author_id %}
<a id="pin2-{{c.id}}" class="list-group-item {% if c.stickied %}d-none{% endif %} text-info" role="button" data-bs-target="#actionsModal-{{c.id}}" onclick="post_toast(this,'/pin_comment/{{c.id}}','pin2-{{c.id}}','unpin2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-info mr-2"></i>Pin</a>

View File

@ -93,7 +93,7 @@
{% endif %}
{% if v.id==p.author_id or v.admin_level > 1 %}
{% if v.id==p.author_id or v.admin_level > 1 or (p.sub and v.mods(p.sub)) %}
<a id="mark-{{p.id}}" class="dropdown-item {% if p.over_18 %}d-none{% endif %} list-inline-item text-danger" role="button" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark-{{p.id}}','unmark-{{p.id}}','d-none')"><i class="fas fa-eye-evil"></i>Mark +18</a>
<a id="unmark-{{p.id}}" class="dropdown-item {% if not p.over_18 %}d-none{% endif %} list-inline-item text-success" role="button" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark-{{p.id}}','unmark-{{p.id}}','d-none')"><i class="fas fa-eye-evil"></i>Unmark +18</a>
{% endif %}

View File

@ -43,11 +43,7 @@
<button id="club3-{{p.id}}" class="{% if p.club %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-danger text-left" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club3-{{p.id}}','unclub3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash mr-2"></i>Mark club</button>
<button id="unclub3-{{p.id}}" class="{% if not p.club %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-success text-left" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club3-{{p.id}}','unclub3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye mr-2"></i>Unmark club</button>
{%- endif %}
<button id="mark3-{{p.id}}" class="{% if p.over_18 %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-danger" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark3-{{p.id}}','unmark3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="far fa-eye-evil text-center mr-2"></i>Mark +18</button>
<button id="unmark3-{{p.id}}" class="{% if not p.over_18 %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-success" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark3-{{p.id}}','unmark3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="far fa-eye-evil text-center mr-2"></i>Unmark +18</button>
{% else %}
{% if not p.ghost %}
<button id="unblock2-{{p.id}}" class="nobackground btn btn-link btn-block btn-lg text-success text-left{% if not p.is_blocking %} d-none{% endif %}" data-bs-dismiss="modal" onclick="post_toast(this,'/settings/unblock?username={{p.author.username}}','block2-{{p.id}}','unblock2-{{p.id}}','d-none')"><i class="fas fa-eye mr-2 text-success"></i>Unblock user</button>
<button id="prompt2-{{p.id}}" class="blockuser nobackground btn btn-link btn-block btn-lg text-danger text-left d-none" data-bs-dismiss="modal" onclick="post_toast(this,'/settings/block?username={{p.author.username}}','prompt2-{{p.id}}','unblock2-{{p.id}}','d-none')"><i class="fas fa-eye-slash mr-2 text-danger"></i>Are you sure?</button>
@ -55,6 +51,11 @@
{% endif %}
{% endif %}
{% if v.id==p.author_id or (p.sub and v.mods(p.sub)) %}
<button id="mark3-{{p.id}}" class="{% if p.over_18 %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-danger" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark3-{{p.id}}','unmark3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="far fa-eye-evil text-center mr-2"></i>Mark +18</button>
<button id="unmark3-{{p.id}}" class="{% if not p.over_18 %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-success" onclick="post_toast(this,'/toggle_post_nsfw/{{p.id}}','mark3-{{p.id}}','unmark3-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="far fa-eye-evil text-center mr-2"></i>Unmark +18</button>
{% endif %}
{% if p.sub and v.mods(p.sub) %}
<button data-bs-dismiss="modal" class="nobackground btn btn-link btn-block btn-lg text-left text-danger" onclick="post_toast(this,'/kick/{{p.id}}')"><i class="fas fa-sign-out text-danger text-center mr-2"></i>Kick</button>

View File

@ -3,10 +3,10 @@ server {
client_max_body_size 100m;
listen 80;
listen [::]:80;
proxy_set_header Host $http_host;
location / {
proxy_set_header Host $http_host;
proxy_pass http://rDrama:5000/;
proxy_pass http://localhost:5000/;
}
location /socket.io {
proxy_set_header Host $http_host;
@ -32,4 +32,9 @@ server {
location /asset_submissions/ {
include includes/serve-static;
}
error_page 502 = /error_page/502.html;
location /error_page/ {
alias /rDrama/files/templates/errors/;
}
}

View File

@ -16,11 +16,17 @@ git clone https://github.com/Aevann1/rDrama/
cd rDrama
docker-compose down --rmi all --remove-orphans --volumes
docker-compose up
```
3- That's it! Visit `localhost` in your browser and make an account (the first account to be made will have full admin rights)
4- Optional: to change the domain from "localhost" to something else and configure the site settings, as well as integrate it with the external services the website uses, edit the variables in the `env` file and then restart the docker container.
------
For returning contributors, we have noticed the following issues (if you can help fix them, we will be very grateful!):
1. Docker doesn't know when we add a new Python dependency, `docker-compose build` is needed.
2. DB schema changes are not applied automatically, the easiest way to deal with that is to delete the entire environment from the Docker GUI and do `docker-compose up`. Also wait five minutes for a "sneed" commit from Aevann meaning that the sql file was regenerated.

0
run_tests.py 100755 → 100644
View File

View File

@ -0,0 +1,7 @@
/etc/init.d/nginx start
cd ./chat
yarn install
yarn chat
cd ..
gunicorn files.__main__:app load_chat -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 -b 0.0.0.0:5001 --max-requests 30000 --max-requests-jitter 30000 -D
gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:5000 --max-requests 30000 --max-requests-jitter 10000

View File

@ -3,9 +3,9 @@ nodaemon=true
pidfile=/tmp/supervisord.pid
logfile=/tmp/supervisord.log
[program:service]
directory=/service
command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:5000 --max-requests 30000 --max-requests-jitter 10000
[program:rDrama]
directory=/rDrama
command=sh startup_docker.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr

View File

@ -1,14 +1,17 @@
# locale-gen "en_US.UTF-8"
# update-locale LANG=en_US.utf8
# update-locale LC_ALL=en_US.utf8
# reboot
apt -y update
apt -y upgrade
apt -y install git redis-server python3-pip ffmpeg imagemagick tmux nginx snapd ufw gpg-agent htop nano
git config --global credential.helper store
cd /rDrama
cp ./env /env
sed -i 's/^/export /g;s/=/="/g;s/$/"/g' /env
. /env
apt -y update
apt -y upgrade
apt -y install git redis-server python3-pip ffmpeg imagemagick tmux nginx snapd ufw gpg-agent htop
git config --global credential.helper store
mkdir /scripts
cp ./startup.sh /scripts/s
cp ./startup_chat.sh /scripts/s2
@ -18,16 +21,17 @@ sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt -y update
apt -y install postgresql-14
sudo rm /etc/postgresql/14/main/pg_hba.conf
sudo cp pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
rm /etc/postgresql/14/main/pg_hba.conf
cp pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
service postgresql restart
chown postgres:postgres /etc/postgresql/14/main/pg_hba.conf
sudo rm /etc/nginx/sites-available -r
sudo rm /etc/nginx/sites-enabled/default
sudo mkdir /etc/nginx/includes
sudo cp nginx.txt /etc/nginx/sites-enabled/1
sudo cp nginx-serve-static.txt /etc/nginx/includes/serve-static
rm /etc/nginx/sites-available -r
rm /etc/nginx/sites-enabled/default
mkdir /etc/nginx/includes
cp nginx.conf /etc/nginx/sites-enabled/1
cp nginx-serve-static.conf /etc/nginx/includes/serve-static
/etc/init.d/nginx reload
psql -U postgres -f schema.sql postgres
psql -U postgres -f seed-db.sql postgres