summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-02-12 16:31:35 +0100
committerxengineering <mail2xengineering@protonmail.com>2021-02-12 16:31:35 +0100
commitf36e1a635e0611a0783cf232ba7a70ca0fa87f2f (patch)
treed5eb5486a827426217e346965302c5166da31411
parent4cb1ef1ff3985f7fbd8768f1c5dae5bbbe347b26 (diff)
downloadweb-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.tar
web-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.tar.zst
web-template-f36e1a635e0611a0783cf232ba7a70ca0fa87f2f.zip
Check if settings.json Values are valid
-rw-r--r--README.md2
-rw-r--r--manage.py50
2 files changed, 51 insertions, 1 deletions
diff --git a/README.md b/README.md
index 8bd9f65..9b544e3 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/manage.py b/manage.py
index 612f78c..60d2f53 100644
--- a/manage.py
+++ b/manage.py
@@ -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