mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-04-01 21:27:22 +02:00
major cleanup to adding new version check to the status checks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os.path
|
||||
import rtyaml
|
||||
|
||||
CONF_DIR = os.path.join(os.path.dirname(__file__), "../conf")
|
||||
# THE ENVIRONMENT FILE AT /etc/mailinabox.conf
|
||||
|
||||
def load_environment():
|
||||
# Load settings from /etc/mailinabox.conf.
|
||||
@@ -13,33 +14,29 @@ def load_env_vars_from_file(fn):
|
||||
for line in open(fn): env.setdefault(*line.strip().split("=", 1))
|
||||
return env
|
||||
|
||||
# Settings
|
||||
settings_root = os.path.join(load_environment()["STORAGE_ROOT"], '/')
|
||||
default_settings = {
|
||||
"PRIVACY": 'TRUE'
|
||||
}
|
||||
|
||||
def write_settings(newconfig):
|
||||
with open(os.path.join(settings_root, 'settings.yaml'), "w") as f:
|
||||
f.write(rtyaml.dump(newconfig))
|
||||
|
||||
def load_settings():
|
||||
try:
|
||||
config = rtyaml.load(open(os.path.join(settings_root, 'settings.yaml'), "w"))
|
||||
if not isinstance(config, dict): raise ValueError() # caught below
|
||||
except:
|
||||
return default_settings
|
||||
|
||||
merged_config = default_settings.copy()
|
||||
merged_config.update(config)
|
||||
|
||||
return config
|
||||
|
||||
def save_environment(env):
|
||||
with open("/etc/mailinabox.conf", "w") as f:
|
||||
for k, v in env.items():
|
||||
f.write("%s=%s\n" % (k, v))
|
||||
|
||||
# THE SETTINGS FILE AT STORAGE_ROOT/settings.yaml.
|
||||
|
||||
def write_settings(config, env):
|
||||
fn = os.path.join(env['STORAGE_ROOT'], 'settings.yaml')
|
||||
with open(fn, "w") as f:
|
||||
f.write(rtyaml.dump(config))
|
||||
|
||||
def load_settings(env):
|
||||
fn = os.path.join(env['STORAGE_ROOT'], 'settings.yaml')
|
||||
try:
|
||||
config = rtyaml.load(open(fn, "r"))
|
||||
if not isinstance(config, dict): raise ValueError() # caught below
|
||||
return config
|
||||
except:
|
||||
return { }
|
||||
|
||||
# UTILITIES
|
||||
|
||||
def safe_domain_name(name):
|
||||
# Sanitize a domain name so it is safe to use as a file name on disk.
|
||||
import urllib.parse
|
||||
|
||||
Reference in New Issue
Block a user