Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captcha implementation #131

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MANIWANI_CFG=./deploy-configs/devmode.cfg
TEMPLATES_AUTO_RELOAD = True
TEMPLATES_AUTO_RELOAD=True
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
.idea/
__pycache__/
*.db
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

30 changes: 14 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
FROM python:3.7-alpine AS dev
FROM ubuntu:20.04 AS dev
WORKDIR /maniwani
# uwsgi and associated plugins
RUN apk add uwsgi-python3 uwsgi-gevent3 uwsgi-gevent py3-gevent uwsgi-http
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
# backend dependencies
RUN pip install pipenv
RUN apt-get -y install python3 python3-pip pipenv
# uwsgi, python and associated plugins
RUN apt-get -y install uwsgi-core uwsgi-plugin-python3 python3-gevent
# dependencies for Pillow
RUN apk add build-base jpeg-dev zlib-dev libwebp-dev
RUN apt-get -y install build-essential libjpeg-dev zlib1g-dev libwebp-dev
# dependencies for psycopg2
RUN apk add libpq postgresql-dev gcc python3-dev musl-dev
RUN apk add ffmpeg
RUN apt-get -y install libpq5 libpq-dev postgresql-server-dev-12 gcc-9 libpython3-dev libc6-dev
RUN apt-get -y install ffmpeg
# frontend dependencies
RUN apk add nodejs nodejs-npm
# workaround for some pip issues on alpine
ENV LIBRARY_PATH=/lib:/usr/lib
RUN apt-get -y install nodejs npm
COPY Pipfile /maniwani
COPY Pipfile.lock /maniwani
RUN pipenv install --system --deploy
# remove backend build-time dependencies
RUN apk del build-base gcc python3-dev musl-dev jpeg-dev zlib-dev
RUN apt-get -y autoremove build-essential gcc-9 libpython3-dev libc6-dev libjpeg-dev zlib1g-dev
# point MANIWANI_CFG to the devmode config file
ENV MANIWANI_CFG=./deploy-configs/devmode.cfg
# workaround for uwsgi inexplicably not picking up /usr/local/lib even though
# system python has it
ENV PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
# build static frontend files
COPY package.json /maniwani
COPY package-lock.json /maniwani
Expand All @@ -31,7 +29,7 @@ COPY Gulpfile.js /maniwani
COPY scss /maniwani/scss
RUN npm run gulp
# remove frontend build-time dependencies
RUN apk del nodejs-npm nodejs
RUN apt-get -y autoremove npm nodejs
RUN rm -rf node_modules
# copy source files over
COPY migrations /maniwani/migrations
Expand All @@ -44,7 +42,7 @@ COPY resources /maniwani/resources
COPY templates /maniwani/templates
COPY ./build-helpers/docker-entrypoint.sh ./docker-entrypoint.sh
# bootstrap dev image
RUN python bootstrap.py
RUN python3 bootstrap.py
EXPOSE 5000

ENTRYPOINT ["sh", "./docker-entrypoint.sh", "devmode"]
Expand All @@ -56,7 +54,7 @@ RUN rm ./deploy-configs/test.db
RUN rm -r uploads
ENV MANIWANI_CFG=./deploy-configs/maniwani.cfg
# chown and switch users for security purposes
RUN adduser -D maniwani
RUN adduser --disabled-login maniwani
RUN chown -R maniwani:maniwani ./
USER maniwani

Expand Down
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
Flask = "*"
Flask-SQLAlchemy = "*"
Flask-Captcha-New = "*"
Markdown = "*"
Pillow = "*"
SQLAlchemy = "*"
Expand All @@ -15,8 +16,9 @@ boto3 = "*"
flask-migrate = "*"
requests = "*"
bleach = "*"
gevent = "*"
gevent = "==1.5.0"
redis = "*"
captcha = "*"

[dev-packages]

Expand Down
399 changes: 0 additions & 399 deletions Pipfile.lock

This file was deleted.

8 changes: 3 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import gevent.monkey
gevent.monkey.patch_all()
import sys
import traceback

gevent.monkey.patch_all()
from flask import render_template, send_from_directory

from blueprints.boards import boards_blueprint
from blueprints.main import main_blueprint
from blueprints.slip import slip_blueprint
Expand All @@ -18,6 +15,7 @@
ThreadPostsResource,
)
from shared import app, rest_api
import traceback

app.register_blueprint(main_blueprint, url_prefix="/")
app.register_blueprint(boards_blueprint, url_prefix="/boards")
Expand All @@ -37,7 +35,6 @@
rest_api.add_resource(NewPostResource, "/api/v1/thread/<int:thread_id>/new")
rest_api.add_resource(FirehoseResource, "/api/v1/firehose")
app.register_blueprint(live_blueprint, url_prefix="/api/v1")



@app.errorhandler(404)
Expand All @@ -55,6 +52,7 @@ def internal_server_error(e):
def get_instance_name():
def instance_name():
return app.config["INSTANCE_NAME"]

return dict(instance_name=instance_name)


Expand Down
6 changes: 2 additions & 4 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from gevent import monkey
monkey.patch_all()

import json
import os

from alembic import command
from alembic.config import Config
from flask.cli import with_appcontext

from model.Board import Board
from model.Slip import gen_slip
from model.Tag import Tag
from model.Media import storage
from shared import app, db
import json
import os


MIGRATION_DIR = "./migrations"
Expand Down
7 changes: 6 additions & 1 deletion doc/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ other pieces of software installed:
Github repository, while Futatsu uses an actual Amazon S3 instance. Strictly speaking,
an S3 store isn't necessary, but most serious deployments should use it over the
filesystem storage backend for performance reasons.
* A keyvalue/pubsub store. Redis is recommended for production deployments, but Maniwani
comes with a stub implementation that can work if Redis is unviable.
* Docker is recommended for deploying Maniwani itself, since it removes the need
to install and manage prerequisites for Maniwani in addition to making updating
to newly-released versions a breeze. The rest of this guide assumes usage of Docker.
Expand Down Expand Up @@ -81,6 +83,10 @@ but a brief description of each follows:
supplied by Maniwani are: `ENDPOINT`, `BUCKET_UUID`, `BUCKET`, and `PATH`. `PATH` is the path to the
resource (and does not begin with a `/`), while `BUCKET_UUID` is equal to `S3_UUID_PREFIX`, if it is
present.
* `STORE_PROVIDER` - this is a string indicating which keystore/pubsub provider Maniwani should target.
Valid values are `"REDIS"` for Redis, or `"INTERNAL"` for Maniwani's built-in substitute.
* `REDIS_HOST` - this is an optional string that contains the URL of the Redis database if `STORE_PROVIDER`
is set to `"REDIS"`.
* `SERVE_STATIC` - this is a boolean that indicates whether Maniwani should serve up CSS/JS/other
static non-attachment assets itself (if set to `True`) or let the S3 store handle it (if set
to `False`). This should be set to `False` for a production deploymenet.
Expand Down Expand Up @@ -109,7 +115,6 @@ but a brief description of each follows:
a pre-rendered copy of a thread until the real view count divided by the view count in the cached render is greater
than this number. If not set, Maniwani will not attempt to fetch any fully-rendered threads from the cache. Set this
if site performance proves to be an issue; a good initial value is `1.15`.


`bootstrap-config.json` is the file used upon bootstrapping Maniwani for the first time to set up any boards,
configure any initial slips (usually admin/moderator roles, but they don't have to be) and set up any special
Expand Down
Loading