diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-02-12 16:31:35 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-02-12 16:31:35 +0100 |
commit | f36e1a635e0611a0783cf232ba7a70ca0fa87f2f (patch) | |
tree | d5eb5486a827426217e346965302c5166da31411 | |
parent | 4cb1ef1ff3985f7fbd8768f1c5dae5bbbe347b26 (diff) | |
download | web-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.tar web-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.tar.zst web-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.zip |
Check if settings.json Values are valid
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | manage.py | 50 |
2 files changed, 51 insertions, 1 deletions
@@ -14,7 +14,7 @@ A template project for mixed static / dynamic web applications. ## Current State -This project is in **early development** state. Please be very careful. The scripts behind the make targets will install and uninstall files on your system without any checks at the moment. Have a look at the ```Makefile``` and ```manage.py``` for details. +This project is in **early development** state. Please be very careful. The scripts behind the make targets will install and uninstall files on your system without checking for existing files. This means that existing files from other sources could be overwritten or deleted. Have a look at the ```Makefile``` and ```manage.py``` for details. ## Usage @@ -4,6 +4,9 @@ import sys import os +import re +import pwd +import grp import subprocess import json import jinja2 @@ -22,6 +25,53 @@ def read_settings(): settings = settings.read() settings = json.loads(settings) + + # check for valid project name + if not re.match(r"\A[a-z]+\Z", settings["project_name"]): + print("Please provide a project_name in settings.json containing only characters from a to z in lower case") + sys.exit(1) + + # check for valid project description + if not re.match(r"\A[a-z|A-Z|0-9| ]+\Z", settings["project_description"]): + print("Please provide a project description in settings.json containing only characters from a to z and numbers") + sys.exit(1) + + # check for valid webroot path + if not re.match(r"\A(/[a-z|A-Z|0-9|_|-]*)+\Z", settings["webroot"]): + print("Please select an absolute and valid path as webroot in settings.json") + sys.exit(1) + + # check for valid framework selection + if not settings["framework"] in [None, "flask", "actix"]: + print("Unknown framework in settings.json") + sys.exit(1) + + # check for valid framework port + if not int(settings["framework_port"]) >= 1: + print("Please select a valid framework_port in settings.json") + sys.exit(1) + + # check for valid framework bind address + if not re.match(r"\A([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])){3}\Z", settings["framework_bind"]): + print("Please provide a valid IP address as framework_bind in settings.json") + sys.exit(1) + + # check for valid user + users = [] + for user in pwd.getpwall(): + users.append(user[0]) # append just the name + if not settings["user"] in users: + print("User '{}' does not exist on this system. Please select a valid user in settings.json".format(settings["user"])) + sys.exit(1) + + # check for valid group + groups = [] + for group in grp.getgrall(): + groups.append(group[0]) # append just the name + if not settings["group"] in groups: + print("Group '{}' does not exist on this system. Please select a valid group in settings.json".format(settings["group"])) + sys.exit(1) + return settings |