Compare commits
19 Commits
Release-V2
...
main
Author | SHA1 | Date | |
---|---|---|---|
70305a5e3c | |||
7ddd4b7fb7 | |||
b5a4b4192c | |||
a29104f172 | |||
fa63472d8c | |||
464f45cbb9 | |||
5705ab6919 | |||
e9b82016f3 | |||
7125cc0719 | |||
72f971162d | |||
58f21ca06e | |||
9a46b52904 | |||
0473c590a4 | |||
52b4ab5647 | |||
290830571d | |||
0da679957b | |||
3f81c6fb1a | |||
80ee9e0496 | |||
96ea3675f9 |
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 Domeniko Gentner <code@tuxstash.de>
|
Copyright (c) 2020-2077 Domeniko Gentner <code@tuxstash.de>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -57,7 +57,6 @@ def check_and_insert_new_comment(name):
|
|||||||
if not is_valid_json(new_comment) or \
|
if not is_valid_json(new_comment) or \
|
||||||
len(new_comment['content']) < 40 or \
|
len(new_comment['content']) < 40 or \
|
||||||
len(new_comment['email']) < 5:
|
len(new_comment['email']) < 5:
|
||||||
print("too short", file=stderr)
|
|
||||||
return make_response(jsonify(status='post-invalid-json'), 400)
|
return make_response(jsonify(status='post-invalid-json'), 400)
|
||||||
|
|
||||||
# Strip any HTML from message body
|
# Strip any HTML from message body
|
||||||
@ -208,7 +207,6 @@ def check_deletion_link(name, email_hash):
|
|||||||
if comment:
|
if comment:
|
||||||
location = db.session.query(TLocation).filter(TLocation.id_location == comment.location_id).first()
|
location = db.session.query(TLocation).filter(TLocation.id_location == comment.location_id).first()
|
||||||
if compare_digest(comment.deletion, email_hash):
|
if compare_digest(comment.deletion, email_hash):
|
||||||
print("True")
|
|
||||||
db.session.delete(comment)
|
db.session.delete(comment)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
url = f"{project.blogurl}?deleted=true"
|
url = f"{project.blogurl}?deleted=true"
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
from . import bp_dbupgrades
|
from . import bp_dbupgrades
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from flask import render_template, jsonify, make_response, redirect, url_for
|
from flask import render_template, jsonify, make_response, redirect, url_for, current_app
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from labertasche.database import labertasche_db as db
|
from labertasche.database import labertasche_db as db
|
||||||
from labertasche.models import TProjects, TComments, TLocation, TEmail, TVersion
|
from labertasche.models import TProjects, TComments, TLocation, TEmail, TVersion
|
||||||
@ -22,7 +22,8 @@ from datetime import datetime
|
|||||||
|
|
||||||
|
|
||||||
def get_backup_folder() -> Path:
|
def get_backup_folder() -> Path:
|
||||||
path = Path('.').absolute() / "backup" / "v1"
|
path = Path(current_app.root_path)
|
||||||
|
path = path / "backup" / "v1"
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ def upgrade_db_to_v2_backup():
|
|||||||
# Create path for backup
|
# Create path for backup
|
||||||
try:
|
try:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
path.mkdir(mode=755, exist_ok=True, parents=True)
|
path.mkdir(mode=777, exist_ok=True, parents=True)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
return make_response(jsonify(status='exception', msg=str(e)), 400)
|
return make_response(jsonify(status='exception', msg=str(e)), 400)
|
||||||
|
|
||||||
@ -135,8 +136,9 @@ def upgrade_db_to_v2_export():
|
|||||||
if compare_digest(db_uri[0:6], "sqlite"):
|
if compare_digest(db_uri[0:6], "sqlite"):
|
||||||
m = search("([/]{3})(.*)", db_uri)
|
m = search("([/]{3})(.*)", db_uri)
|
||||||
new_db = get_backup_folder() / "labertasche.db"
|
new_db = get_backup_folder() / "labertasche.db"
|
||||||
old_db = Path(m.group(2)).absolute()
|
old_db = Path(current_app.root_path)
|
||||||
copy(old_db, new_db)
|
old_db = old_db / m.group(2)
|
||||||
|
copy(old_db.absolute(), new_db.absolute())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return make_response(jsonify(status='exception-copy-db', msg=str(e)), 400)
|
return make_response(jsonify(status='exception-copy-db', msg=str(e)), 400)
|
||||||
|
|
||||||
@ -212,7 +214,6 @@ def upgrade_db_to_v2_import():
|
|||||||
|
|
||||||
# walk json and readd to database with project set to project 1
|
# walk json and readd to database with project set to project 1
|
||||||
for each in mails:
|
for each in mails:
|
||||||
each.update({'project_id': 1})
|
|
||||||
db.session.add(TEmail(**each))
|
db.session.add(TEmail(**each))
|
||||||
|
|
||||||
for each in locations:
|
for each in locations:
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# * _repo : https://git.tuxstash.de/gothseidank/labertasche
|
# * _repo : https://git.tuxstash.de/gothseidank/labertasche
|
||||||
# * _license : This project is under MIT License
|
# * _license : This project is under MIT License
|
||||||
# *********************************************************************************/
|
# *********************************************************************************/
|
||||||
from flask import Request
|
from flask import Request, current_app
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from json import load
|
from json import load
|
||||||
|
|
||||||
@ -19,7 +19,8 @@ class Language:
|
|||||||
self.languages = list()
|
self.languages = list()
|
||||||
|
|
||||||
# Directory where translations live
|
# Directory where translations live
|
||||||
i18n_dir = Path('./i18n').absolute()
|
i18n_dir = Path(current_app.root_path).absolute()
|
||||||
|
i18n_dir = i18n_dir / "i18n"
|
||||||
|
|
||||||
# Looks for translations
|
# Looks for translations
|
||||||
for filename in i18n_dir.glob("*.json"):
|
for filename in i18n_dir.glob("*.json"):
|
||||||
|
@ -25,7 +25,7 @@ def hash_password(password, secret=None):
|
|||||||
secret = Secret()
|
secret = Secret()
|
||||||
h = pbkdf2_hmac('sha512',
|
h = pbkdf2_hmac('sha512',
|
||||||
password=password.encode('utf8'),
|
password=password.encode('utf8'),
|
||||||
salt=secret.key.encode('utf8'),
|
salt=secret.encode('utf8'),
|
||||||
iterations=250000)
|
iterations=250000)
|
||||||
return h.hex()
|
return h.hex()
|
||||||
|
|
||||||
@ -113,6 +113,7 @@ class LegacySettings:
|
|||||||
file = file.with_suffix('.bak')
|
file = file.with_suffix('.bak')
|
||||||
|
|
||||||
with file.open('r') as fp:
|
with file.open('r') as fp:
|
||||||
|
print(f"Loading old conf from {file}")
|
||||||
conf = yaml.safe_load(fp)
|
conf = yaml.safe_load(fp)
|
||||||
|
|
||||||
self.system = conf['system']
|
self.system = conf['system']
|
||||||
@ -129,10 +130,10 @@ class LegacySettings:
|
|||||||
systemvars = {
|
systemvars = {
|
||||||
'system': {
|
'system': {
|
||||||
'weburl': self.system['web_url'],
|
'weburl': self.system['web_url'],
|
||||||
'cookie_domain': self.system['cookie_domain'],
|
'cookie_domain': self.system['cookie-domain'],
|
||||||
'database_uri': self.system['database_uri'],
|
'database_uri': self.system['database_uri'],
|
||||||
'debug': self.system['debug'],
|
'debug': self.system['debug'],
|
||||||
'cookie_secure': self.system['cookie_secure']
|
'cookie_secure': False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +149,7 @@ class LegacySettings:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# backup old config
|
# backup old config
|
||||||
|
print("Copying old config to backup")
|
||||||
copy(old, old.with_suffix('.bak'))
|
copy(old, old.with_suffix('.bak'))
|
||||||
|
|
||||||
# Write new config files
|
# Write new config files
|
||||||
@ -163,10 +165,14 @@ class LegacySettings:
|
|||||||
p_secret = '/etc/labertasche/' / p_secret
|
p_secret = '/etc/labertasche/' / p_secret
|
||||||
|
|
||||||
with p_sys.open('w') as fp:
|
with p_sys.open('w') as fp:
|
||||||
|
print("Dumping system vars as yaml")
|
||||||
yaml.dump(systemvars, fp)
|
yaml.dump(systemvars, fp)
|
||||||
with p_credentials.open('w') as fp:
|
with p_credentials.open('w') as fp:
|
||||||
|
print("Dumping credentials as yaml")
|
||||||
yaml.dump(credentials, fp)
|
yaml.dump(credentials, fp)
|
||||||
with p_smileys.open('w') as fp:
|
with p_smileys.open('w') as fp:
|
||||||
|
print("Dumping smileys as yaml")
|
||||||
yaml.dump(smileys, fp)
|
yaml.dump(smileys, fp)
|
||||||
with p_secret.open('w') as fp:
|
with p_secret.open('w') as fp:
|
||||||
|
print("Dumping secret")
|
||||||
fp.write(self.system['secret'])
|
fp.write(self.system['secret'])
|
||||||
|
@ -70,7 +70,7 @@ with laberflask.app_context():
|
|||||||
|
|
||||||
|
|
||||||
# CORS
|
# CORS
|
||||||
cors = CORS(laberflask)
|
cors = CORS(laberflask, resources={r"/comments/*": {"origins": "*"}})
|
||||||
|
|
||||||
|
|
||||||
# There is only one user
|
# There is only one user
|
||||||
@ -102,3 +102,5 @@ def set_sqlite_pragma(dbapi_connection, connection_record):
|
|||||||
def inject_language():
|
def inject_language():
|
||||||
lang = Language(request)
|
lang = Language(request)
|
||||||
return {"i18n": lang.i18n}
|
return {"i18n": lang.i18n}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user