diff --git a/.gitignore b/.gitignore index cdc52ec..ecac2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ env/ venv/ venv/* +.idea/ +__pycache__/ +__pycache__/* +app/__pycache__/ +app/__pycache__/* +app/static/dewatermark/ +app/static/dewatermark/* \ No newline at end of file diff --git a/README.md b/README.md index e69de29..75ae627 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,88 @@ +# Run + +## in Development +`export FLASK_APP=run.py` +`export FLASK_ENV=development` +`flask run` + +**Using gunicorn:** + +`gunicorn --env SCRIPT_NAME=/watermarks -w 4 -b 127.0.0.1:5000 app:app --log-level debug` +* `-w` workers +* `-b` bind to address / unix socker + +**And gunicorn with using unix sock:** (this how it should run in production) +` gunicorn --env SCRIPT_NAME=/watermarks --workers 4 --bind unix:app.sock -m 007 app:app --log-level debug + +## in Production with gunicorn and unix sockets +Based on https://medium.com/faun/deploy-flask-app-with-nginx-using-gunicorn-7fda4f50066a + +### systemd service file + +Add to /etc/systemd/system/watermarks.service + +``` +[Unit] +After=network.target + +[Service] +User=psc +Group=www-data +WorkingDirectory=/var/www/TacticalApp +Environment="PATH=/var/www/TacticalApp/venv/bin" +ExecStart=/var/www/TacticalApp/venv/bin/gunicorn --env SCRIPT_NAME=/watermarks --workers 4 --bind unix:app.sock -m 007 app:app + +[Install] +WantedBy=multi-user.target +``` + +## enable & start service file +`systemctl enable watermarks.service` + +`systemctl start watermarks.service` + +It is also a good idea to check the status of the service +`systemctl status watermarks.service` + +## Nginx config + +``` +location / { + # if using gunicorn with app sock, use: + proxy_pass http://unix:/var/www/TacticalApp/app.sock; + # if using gunicord with port 5000, use: + proxy_pass http://127.0.0.1:5000; + } +``` + +## debug. + +It might be helpful to enable gunicorn logging, while in development, to check what is going on, + by replacing in watermarks.service, the `ExecStart=` value with: + +`ExecStart=/var/www/TacticalApp/venv/bin/gunicorn --log-level debug --error-logfile /var/www/TacticalApp/app.log --workers 4 --bind unix:app.sock -m 007 app:app` + +And reloading the services +`systemctl daemon-reload` + +`systemctl restart watermarks.service` + +and the start following app.log: +`tail -f /var/www/TacticalApp/app.log` + +But in the long run logging should be disabled + +---- +09.06.2020 Handling url path /watermarks + +* gunicorn has to be started with argument `--env SCRIPT_NAME=/watermarks` which defines its path: +`gunicorn --env SCRIPT_NAME=/watermarks --workers 4 --bind unix:app.sock -m 007 app:app --log-level debug` + * allows for the following URLs + * http://127.0.0.1/watermarks + * http://127.0.0.1/watermarks/uploadbook + * http://127.0.0.1/watermarks/about + +* added page /test `watermarks/test` for testing url_for() - correct +* made urls relative +* service file with `--env SCRIPT_NAME=/watermarks` see above +* diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc deleted file mode 100644 index 657ef5b..0000000 Binary files a/__pycache__/config.cpython-37.pyc and /dev/null differ diff --git a/app/__pycache__/__init__.cpython-37.pyc b/app/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 58d9b24..0000000 Binary files a/app/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/app/__pycache__/views.cpython-37.pyc b/app/__pycache__/views.cpython-37.pyc deleted file mode 100644 index 5715495..0000000 Binary files a/app/__pycache__/views.cpython-37.pyc and /dev/null differ diff --git a/app/templates/public/404.html b/app/templates/public/404.html index 455f5c6..9b19082 100644 --- a/app/templates/public/404.html +++ b/app/templates/public/404.html @@ -12,7 +12,7 @@
ov73e3lxezo2klxva2frlzqbb2usiozqbe56xiochvz5lznpkk6kw4ad.onion
- +

404

TACTICAL WATERMARKS
ON TOR BROWSER!

diff --git a/app/templates/public/bookrequest.html b/app/templates/public/bookrequest.html index 53e2bf1..246ff05 100644 --- a/app/templates/public/bookrequest.html +++ b/app/templates/public/bookrequest.html @@ -7,7 +7,7 @@

Books Requested

-

Fill a form to request a book

+

Fill a form to request a book

{% for book in books %}
diff --git a/app/templates/public/index.html b/app/templates/public/index.html index 88956c7..9fd9f03 100644 --- a/app/templates/public/index.html +++ b/app/templates/public/index.html @@ -10,15 +10,15 @@ diff --git a/app/templates/public/republish.html b/app/templates/public/republish.html index 12e6a9f..3f4a78d 100644 --- a/app/templates/public/republish.html +++ b/app/templates/public/republish.html @@ -9,14 +9,14 @@

Here you can upload a file that will be republished to Library Genesis. We take care of the whole process of republishing. Your book should not have watermarks. They will not be removed.

-

We will also create a uploaders signature, read more about it here! Please feel free to leave your remarks on the process of sharing the file. If you want to batch upload, please contact me directly!

+

We will also create a uploaders signature, read more about it here! Please feel free to leave your remarks on the process of sharing the file. If you want to batch upload, please contact me directly!

-
+

UPLOAD THE FILE

- +
@@ -27,7 +27,7 @@

WATERMARK

- +

@@ -69,7 +69,7 @@

Books Requested

-

Fill a form to request a book

+

Fill a form to request a book

{% for book in books %} diff --git a/app/templates/public/templates/main_template.html b/app/templates/public/templates/main_template.html index 1ab0172..af43ea9 100644 --- a/app/templates/public/templates/main_template.html +++ b/app/templates/public/templates/main_template.html @@ -18,7 +18,7 @@ diff --git a/app/templates/public/templates/public_template.html b/app/templates/public/templates/public_template.html index e44e42a..485aad5 100644 --- a/app/templates/public/templates/public_template.html +++ b/app/templates/public/templates/public_template.html @@ -18,7 +18,7 @@ @@ -28,11 +28,11 @@

Sitemap


diff --git a/app/templates/public/terms.html b/app/templates/public/terms.html index 67ac50d..56cfc5d 100644 --- a/app/templates/public/terms.html +++ b/app/templates/public/terms.html @@ -18,7 +18,7 @@
-

Leave a comment +

Leave a comment

{% for comment in comments %}
diff --git a/app/templates/public/upload_book.html b/app/templates/public/upload_book.html index 46f3926..7547bfe 100644 --- a/app/templates/public/upload_book.html +++ b/app/templates/public/upload_book.html @@ -9,10 +9,10 @@

Here you can upload a watermarked file that will be republished to Library Genesis. I will de-watermark your text and take care of the whole process of republishing. All watermarks will be removed.

-

We will also create a uploaders signature, read more about it here! Please feel free to leave your remarks on the process of sharing the file. If you want to batch upload, please contact me directly!

+

We will also create a uploaders signature, read more about it here! Please feel free to leave your remarks on the process of sharing the file. If you want to batch upload, please contact me directly!

- +

UPLOAD THE FILE

@@ -26,7 +26,7 @@

WATERMARK

- +

@@ -68,7 +68,7 @@

Books Requested

-

Fill a form to request a book

+

Fill a form to request a book

{% for book in books %} diff --git a/app/views.py b/app/views.py index 97f16b9..b543a3c 100644 --- a/app/views.py +++ b/app/views.py @@ -15,6 +15,15 @@ app.secret_key = 'PiracyIsCool' now = datetime.datetime.now() +@app.route('/test', methods=['GET']) +def test(): + index = url_for('index') + about = url_for('about') + links = f"index
about" + return links + + + @app.route('/', methods=['GET']) def index(): return render_template("public/index.html") @@ -25,9 +34,9 @@ def about(): # UPLOAD FILES # THIS SHOULD BE IN CONFIG -app.config["BOOK_UPLOAD_DEWATERMARK"] = "/var/www/TacticalApp/app/static/dewatermark" -app.config["BOOK_UPLOAD_REPUBLISH"] = "/var/www/TacticalApp/app/static/republish" -app.config["BOOK_REQUEST"] = "/var/www/TacticalApp/app/static/request" +app.config["BOOK_UPLOAD_DEWATERMARK"] = "app/static/dewatermark" +app.config["BOOK_UPLOAD_REPUBLISH"] = "app/static/republish" +app.config["BOOK_REQUEST"] = "app/static/request" app.config["ALLOWED_BOOK_EXTENSIONS"] = ["PDF", "EPUB"] app.config["MAX_BOOK_FILESIZE"] = 500000000