Moved database and user generated content to /var/matemat
This commit is contained in:
parent
a6e7c244e4
commit
3a8497325f
12 changed files with 24 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
image: s3lph/matemat-ci:20180710-03
|
||||
image: s3lph/matemat-ci:20180711-01
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
FROM debian:buster
|
||||
|
||||
RUN useradd -d /home/matemat -m matemat
|
||||
RUN mkdir -p /var/matemat/db && chown matemat:matemat -R /var/matemat/db
|
||||
RUN mkdir -p /var/matemat/upload && chown matemat:matemat -R /var/matemat/upload
|
||||
RUN apt-get update -qy
|
||||
RUN apt-get install -y --no-install-recommends python3-dev python3-pip python3-coverage python3-setuptools build-essential
|
||||
RUN pip3 install wheel pycodestyle mypy
|
||||
|
|
|
@ -13,4 +13,4 @@ if __name__ == '__main__':
|
|||
port = int(sys.argv[1])
|
||||
|
||||
# Start the web server
|
||||
MatematWebserver(port=port).start()
|
||||
MatematWebserver(port=port, staticroot='/var/matemat/upload').start()
|
||||
|
|
|
@ -23,7 +23,7 @@ def admin(method: str,
|
|||
if authlevel < 2:
|
||||
raise HttpException(403)
|
||||
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
user = db.get_user(uid)
|
||||
if method == 'POST' and 'change' in args:
|
||||
handle_change(args, user, db)
|
||||
|
@ -78,8 +78,8 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
|
|||
if 'avatar' not in args:
|
||||
return
|
||||
avatar = bytes(args.avatar)
|
||||
os.makedirs('./static/img/thumbnails/users/', exist_ok=True)
|
||||
with open(f'./static/img/thumbnails/users/{user.id}.png', 'wb') as f:
|
||||
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True)
|
||||
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f:
|
||||
f.write(avatar)
|
||||
|
||||
except UnicodeDecodeError:
|
||||
|
@ -111,8 +111,8 @@ def handle_admin_change(args: RequestArguments, db: MatematDatabase):
|
|||
newproduct = db.create_product(name, price_member, price_non_member)
|
||||
if 'image' in args:
|
||||
image = bytes(args.image)
|
||||
os.makedirs('./static/img/thumbnails/products/', exist_ok=True)
|
||||
with open(f'./static/img/thumbnails/products/{newproduct.id}.png', 'wb') as f:
|
||||
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True)
|
||||
with open(f'/var/matemat/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f:
|
||||
f.write(image)
|
||||
|
||||
elif change == 'restock':
|
||||
|
|
|
@ -13,7 +13,7 @@ def buy(method: str,
|
|||
-> Union[str, bytes, PageletResponse]:
|
||||
if 'authenticated_user' not in session_vars:
|
||||
return RedirectResponse('/')
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
uid: int = session_vars['authenticated_user']
|
||||
user = db.get_user(uid)
|
||||
if 'n' in args:
|
||||
|
|
|
@ -13,7 +13,7 @@ def deposit(method: str,
|
|||
-> Union[str, bytes, PageletResponse]:
|
||||
if 'authenticated_user' not in session_vars:
|
||||
return RedirectResponse('/')
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
uid: int = session_vars['authenticated_user']
|
||||
user = db.get_user(uid)
|
||||
if 'n' in args:
|
||||
|
|
|
@ -19,7 +19,7 @@ def login_page(method: str,
|
|||
if method == 'GET':
|
||||
return TemplateResponse('login.html')
|
||||
elif method == 'POST':
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
try:
|
||||
user: User = db.login(str(args.username), str(args.password))
|
||||
except AuthenticationError:
|
||||
|
|
|
@ -12,7 +12,7 @@ def main_page(method: str,
|
|||
session_vars: Dict[str, Any],
|
||||
headers: Dict[str, str])\
|
||||
-> Union[bytes, str, PageletResponse]:
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
if 'authenticated_user' in session_vars:
|
||||
uid: int = session_vars['authenticated_user']
|
||||
authlevel: int = session_vars['authentication_level']
|
||||
|
|
|
@ -23,7 +23,7 @@ def modproduct(method: str,
|
|||
if authlevel < 2:
|
||||
raise HttpException(403)
|
||||
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
authuser = db.get_user(auth_uid)
|
||||
if not authuser.is_admin:
|
||||
raise HttpException(403)
|
||||
|
@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
|
|||
if change == 'del':
|
||||
db.delete_product(product)
|
||||
try:
|
||||
os.remove(f'./static/img/thumbnails/products/{product.id}.png')
|
||||
os.remove(f'/var/matemat/upload/thumbnails/products/{product.id}.png')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
@ -76,6 +76,6 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
|
|||
if 'image' in args:
|
||||
image = bytes(args.image)
|
||||
if len(image) > 0:
|
||||
os.makedirs('./static/img/thumbnails/products/', exist_ok=True)
|
||||
with open(f'./static/img/thumbnails/products/{product.id}.png', 'wb') as f:
|
||||
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True)
|
||||
with open(f'/var/matemat/upload/thumbnails/products/{product.id}.png', 'wb') as f:
|
||||
f.write(image)
|
||||
|
|
|
@ -23,7 +23,7 @@ def moduser(method: str,
|
|||
if authlevel < 2:
|
||||
raise HttpException(403)
|
||||
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
authuser = db.get_user(auth_uid)
|
||||
if not authuser.is_admin:
|
||||
raise HttpException(403)
|
||||
|
@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
|
|||
if change == 'del':
|
||||
db.delete_user(user)
|
||||
try:
|
||||
os.remove(f'./static/img/thumbnails/users/{user.id}.png')
|
||||
os.remove(f'/var/matemat/upload/thumbnails/users/{user.id}.png')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
@ -83,6 +83,6 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
|
|||
if 'avatar' in args:
|
||||
avatar = bytes(args.avatar)
|
||||
if len(avatar) > 0:
|
||||
os.makedirs('./static/img/thumbnails/users/', exist_ok=True)
|
||||
with open(f'./static/img/thumbnails/users/{user.id}.png', 'wb') as f:
|
||||
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True)
|
||||
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f:
|
||||
f.write(avatar)
|
||||
|
|
|
@ -19,7 +19,7 @@ def touchkey_page(method: str,
|
|||
if method == 'GET':
|
||||
return TemplateResponse('touchkey.html', username=str(args.username), uid=int(str(args.uid)))
|
||||
elif method == 'POST':
|
||||
with MatematDatabase('test.db') as db:
|
||||
with MatematDatabase('/var/matemat/db/test.db') as db:
|
||||
try:
|
||||
user: User = db.login(str(args.username), touchkey=str(args.touchkey))
|
||||
except AuthenticationError:
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
FROM debian:buster
|
||||
|
||||
RUN useradd -d /home/matemat -m matemat
|
||||
RUN mkdir -p /var/matemat/db && chown matemat:matemat -R /var/matemat/db
|
||||
RUN mkdir -p /var/matemat/upload && chown matemat:matemat -R /var/matemat/upload
|
||||
RUN apt-get update -qy
|
||||
RUN apt-get install -y --no-install-recommends sudo git docker.io python3-dev python3-pip python3-coverage python3-setuptools build-essential
|
||||
RUN pip3 install wheel pycodestyle mypy
|
||||
|
|
Loading…
Reference in a new issue