Option to turn off SSL, moved secret keys to config.py, switched to sqlite WAL mode to avoid locked database problems

This commit is contained in:
Simon 2018-06-07 10:33:35 -04:00
parent 460357f183
commit 4f6d7f32ad
3 changed files with 20 additions and 8 deletions

View File

@ -9,6 +9,13 @@ git clone https://github.com/simon987/od-database
cd od-database
pip3 install -r requirements.txt
```
Create `/config.py` and fill out the parameters. Empty config:
```python
CAPTCHA_SITE_KEY = ""
CAPTCHA_SECRET_KEY = ""
FLASK_SECRET = ""
USE_SSL = True
```
## Running
```bash
@ -16,5 +23,4 @@ python3 app.py
```
You should be able to connect with your browser at `https://localhost:12345`
*_Note: For now, you need to have the appropriate SSL certificates (cert.pem & privkey.pem) in /certificates. There will
be an option to disable SSL very soon_
*_Note: To use SSL you have to put the appropriate certificates in /certificates/_

16
app.py
View File

@ -7,15 +7,16 @@ from database import Database, Website, InvalidQueryException
from flask_recaptcha import ReCaptcha
import od_util
import sqlite3
import config
from flask_caching import Cache
from task import TaskManager
app = Flask(__name__)
recaptcha = ReCaptcha(app=app,
site_key="6LfpFFsUAAAAADgxNJ9PIE9UVO3SM69MCxjzYyOM",
secret_key="6LfpFFsUAAAAADuzRvXZfq_nguS3RGj3FCA_2cc3")
app.secret_key = "A very secret key"
site_key=config.CAPTCHA_SITE_KEY,
secret_key=config.CAPTCHA_SECRET_KEY)
app.secret_key = config.FLASK_SECRET
db = Database("db.sqlite3")
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
app.jinja_env.globals.update(truncate_path=od_util.truncate_path)
@ -182,6 +183,9 @@ def enqueue():
if __name__ == '__main__':
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.load_cert_chain('certificates/cert.pem', 'certificates/privkey.pem')
app.run("0.0.0.0", port=12345, ssl_context=context)
if config.USE_SSL:
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.load_cert_chain('certificates/cert.pem', 'certificates/privkey.pem')
app.run("0.0.0.0", port=12345, ssl_context=context)
else:
app.run("0.0.0.0", port=12345)

View File

@ -1,3 +1,5 @@
PRAGMA journal_mode=WAL;
CREATE TABLE Website (
id INTEGER PRIMARY KEY NOT NULL,