From c004bea706c4c3ff55f9d3825fb63ab777e2e16c Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 08:04:22 +0200 Subject: [PATCH 1/8] ignore pycharm dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cdc52ec..78b2a5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ env/ venv/ venv/* +.idea/ \ No newline at end of file -- 2.30.2 From 855deeec8ca3d97f6be140855f2a332b02a10ba9 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 08:06:53 +0200 Subject: [PATCH 2/8] README --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README.md b/README.md index e69de29..ddc9b30 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,75 @@ +# Run + +## in Development +`export FLASK_APP=run.py` +`export FLASK_ENV=development` +`flask run` + +**Using gunicorn:** + +`gunicorn -w 4 -b 127.0.0.1:5000 app:app` +* `-w` workers +* `-b` bind to address / unix socker + +**And gunicorn with using unix sock:** (this how it should run in production) +`gunicorn --workers 4 --bind unix:app.sock -m 007 app:app ` + +## 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 --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 / { + include proxy_params; + # it will pass the requests to the socket + proxy_pass http://unix:/var/www/TacticalApp/app.sock; + # @andre: unsure whether we need a proxy_redirect as well + # if so, it might be somthing like + # http://unix:/var/www/TacticalApp/app.sock $scheme://$host:80/; + } +``` + +## 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 \ No newline at end of file -- 2.30.2 From e101ad4ad6c0c1c407401eb74f95a9eac267d463 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 17:20:03 +0200 Subject: [PATCH 3/8] Read me with gunicorn -env SCRIPT_NAME=/watermarks --- .gitignore | 6 +++++- __pycache__/config.cpython-37.pyc | Bin 790 -> 0 bytes app/__pycache__/__init__.cpython-37.pyc | Bin 346 -> 0 bytes app/__pycache__/views.cpython-37.pyc | Bin 6110 -> 0 bytes 4 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 __pycache__/config.cpython-37.pyc delete mode 100644 app/__pycache__/__init__.cpython-37.pyc delete mode 100644 app/__pycache__/views.cpython-37.pyc diff --git a/.gitignore b/.gitignore index 78b2a5d..c8f060d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ env/ venv/ venv/* -.idea/ \ No newline at end of file +.idea/ +__pycache__/ +__pycache__/* +app/__pycache__/ +app/__pycache__/* \ No newline at end of file diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc deleted file mode 100644 index 657ef5b9a1100acbcb944477959fbe3b40ab0a43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 790 zcmb7C%}&BV5Z>*!r63qgH1Xt}i@bm_DpW#Dim~O=gPYP_2?knh`H4rPFXJoi)wl5E z%ob^4(8NtNg!S#qBg1&)C^2$OA*bodb zlN7K4*c29E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!^$7L6e?iatV9O2<{{J1i=FYD+th`)3Ac?247HIkq;4# zAw~WaK=Po&cp@Jm?lA%?QNBffiPfHT5MVKp04hV^otD6>nANa=g>n9JC zbs%&~Yef9-fKLyD*I6TkRB*C*Mgt+?EO_8Al%`o0mHn;8zVWa?BOegmIh_bIU z(MQ5!7jkH)5yOYSNa8nZHP8rsAHER6D>9M;fN`?4405{>?M9RsRUW<-N)gw$#I7=0 z;kL?1_^u}CZ7K1?SK?HZ@h>7(C=yywdBjTRYsr%huYexX^k$U!3QOvBeELv5PbD{{ zJc+id3ZT7EHr*Bn|Dy{h{T$OGc@jC1eJcog#~1H2*csvdU=A)*UM(=};}8CI3v%nE mIb!9Z$j?I_hD Date: Tue, 9 Jun 2020 17:20:25 +0200 Subject: [PATCH 4/8] Read me with gunicorn -env SCRIPT_NAME=/watermarks - now for REAL --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ddc9b30..cbeab41 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,12 @@ **Using gunicorn:** -`gunicorn -w 4 -b 127.0.0.1:5000 app:app` +`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 --workers 4 --bind unix:app.sock -m 007 app:app ` +` 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 @@ -72,4 +72,18 @@ And reloading the services and the start following app.log: `tail -f /var/www/TacticalApp/app.log` -But in the long run logging should be disabled \ No newline at end of file +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 pages /test and + +* make urls relative -- 2.30.2 From 5c1002b5a0ec975b352eab909d4cbd97d27222eb Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 17:22:19 +0200 Subject: [PATCH 5/8] test/ with url_for( ) --- README.md | 5 ++--- app/templates/public/404.html | 2 +- app/views.py | 9 +++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cbeab41..8a0fa06 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,5 @@ But in the long run logging should be disabled * http://127.0.0.1/watermarks/uploadbook * http://127.0.0.1/watermarks/about -* added pages /test and - -* make urls relative +* added page /test `watermarks/test` for testing url_for() - correct +* made urls relative 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/views.py b/app/views.py index 97f16b9..54167e0 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") -- 2.30.2 From bb5238593844945dae0f1bb4edbd201ee37bb46d Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 17:36:59 +0200 Subject: [PATCH 6/8] urls in templates /about -> about --- .gitignore | 4 +++- app/templates/public/bookrequest.html | 2 +- app/templates/public/index.html | 8 ++++---- app/templates/public/republish.html | 10 +++++----- app/templates/public/templates/main_template.html | 2 +- app/templates/public/templates/public_template.html | 12 ++++++------ app/templates/public/terms.html | 2 +- app/templates/public/upload_book.html | 8 ++++---- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index c8f060d..ecac2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ venv/* __pycache__/ __pycache__/* app/__pycache__/ -app/__pycache__/* \ No newline at end of file +app/__pycache__/* +app/static/dewatermark/ +app/static/dewatermark/* \ No newline at end of file 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 %} -- 2.30.2 From 5b4ef9e1ddc6620abd10d764caa1edab5a2a99bd Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 17:40:09 +0200 Subject: [PATCH 7/8] relative paths for storing files - so the app can work in any dir --- app/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views.py b/app/views.py index 54167e0..b543a3c 100644 --- a/app/views.py +++ b/app/views.py @@ -34,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 -- 2.30.2 From 6fd437363acb1a9ae61cb4330633ff2294cf3f58 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Tue, 9 Jun 2020 17:47:40 +0200 Subject: [PATCH 8/8] update on nginx config and service file --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8a0fa06..75ae627 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ User=psc Group=www-data WorkingDirectory=/var/www/TacticalApp Environment="PATH=/var/www/TacticalApp/venv/bin" -ExecStart=/var/www/TacticalApp/venv/bin/gunicorn --workers 4 --bind unix:app.sock -m 007 app:app +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 @@ -48,12 +48,10 @@ It is also a good idea to check the status of the service ``` location / { - include proxy_params; - # it will pass the requests to the socket - proxy_pass http://unix:/var/www/TacticalApp/app.sock; - # @andre: unsure whether we need a proxy_redirect as well - # if so, it might be somthing like - # http://unix:/var/www/TacticalApp/app.sock $scheme://$host:80/; + # 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; } ``` @@ -86,3 +84,5 @@ But in the long run logging should be disabled * added page /test `watermarks/test` for testing url_for() - correct * made urls relative +* service file with `--env SCRIPT_NAME=/watermarks` see above +* -- 2.30.2