diff options
Diffstat (limited to 'manage.py')
-rw-r--r-- | manage.py | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -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 |