mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-22 03:06:55 +00:00
Save settings in /settings.yaml
This commit is contained in:
parent
c1c1d67bc9
commit
18d2d2d1d6
@ -405,15 +405,19 @@ def backup_status():
|
||||
@app.route('/system/privacy/enable', methods=["POST"])
|
||||
@authorized_personnel_only
|
||||
def privacy_status_enable():
|
||||
env.update({'PRIVACY' : 'True'})
|
||||
utils.save_environment(env)
|
||||
config = utils.load_settings()
|
||||
config["PRIVACY"] = 'True'
|
||||
utils.write_settings(config)
|
||||
|
||||
return "Ok"
|
||||
|
||||
@app.route('/system/privacy/disable', methods=["POST"])
|
||||
@authorized_personnel_only
|
||||
def privacy_status_disable():
|
||||
env.update({'PRIVACY' : 'False'})
|
||||
utils.save_environment(env)
|
||||
config = utils.load_settings()
|
||||
config["PRIVACY"] = 'False'
|
||||
utils.write_settings(config)
|
||||
|
||||
return "Ok"
|
||||
|
||||
# MUNIN
|
||||
|
@ -16,7 +16,7 @@ from dns_update import get_dns_zones, build_tlsa_record, get_custom_dns_config,
|
||||
from web_update import get_web_domains, get_default_www_redirects, get_domain_ssl_files
|
||||
from mailconfig import get_mail_domains, get_mail_aliases
|
||||
|
||||
from utils import shell, sort_domains, load_env_vars_from_file
|
||||
from utils import shell, sort_domains, load_env_vars_from_file, load_settings
|
||||
|
||||
def run_checks(rounded_values, env, output, pool):
|
||||
# run systems checks
|
||||
@ -820,7 +820,10 @@ def get_latest_miab_version():
|
||||
return re.search(b'TAG=(.*)', urllib.request.urlopen("https://mailinabox.email/bootstrap.sh?ping=1").read()).group(1).decode("utf8")
|
||||
|
||||
def check_miab_version(env, output):
|
||||
if env['PRIVACY'] == 'True':
|
||||
|
||||
config = load_settings()
|
||||
|
||||
if config['PRIVACY'] == 'True':
|
||||
output.print_warning("Mail-in-a-Box version check disabled.")
|
||||
elif what_version_is_this(env) != get_latest_miab_version():
|
||||
output.print_error("Mail-in-a-Box is outdated. To find the latest version and for upgrade instructions, see https://mailinabox.email/. ")
|
||||
|
@ -43,7 +43,7 @@
|
||||
</table>
|
||||
|
||||
<h4>Privacy Setting</h4>
|
||||
<p>By deactivating the adavanced privacy feature your Mail-in-a-Box will contact a remote server to check if a new version got released.</p>
|
||||
<p>By deactivating the advanced privacy feature your Mail-in-a-Box will contact a remote server to check if a new version got released.</p>
|
||||
<p>Advanced Privacy <a onclick="enable_privacy()" href="">On</a> | <a onclick="disable_privacy()" href="">Off</a></p>
|
||||
|
||||
<script>
|
||||
|
@ -13,11 +13,37 @@ 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))
|
||||
|
||||
def write_settings(env):
|
||||
with open(os.path.join(settings_root, 'settings.yaml'), "w") as f:
|
||||
f.write(rtyaml.dump(newconfig))
|
||||
|
||||
def safe_domain_name(name):
|
||||
# Sanitize a domain name so it is safe to use as a file name on disk.
|
||||
import urllib.parse
|
||||
@ -68,7 +94,7 @@ def sort_domains(domain_names, env):
|
||||
# Then in right-to-left lexicographic order of the .-separated parts of the name.
|
||||
list(reversed(d.split("."))),
|
||||
))
|
||||
|
||||
|
||||
return domain_names
|
||||
|
||||
def sort_email_addresses(email_addresses, env):
|
||||
@ -128,7 +154,7 @@ def exclusive_process(name):
|
||||
f.write(str(mypid))
|
||||
f.truncate()
|
||||
atexit.register(clear_my_pid, pidfile)
|
||||
|
||||
|
||||
|
||||
def clear_my_pid(pidfile):
|
||||
import os
|
||||
|
Loading…
Reference in New Issue
Block a user