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"])
|
@app.route('/system/privacy/enable', methods=["POST"])
|
||||||
@authorized_personnel_only
|
@authorized_personnel_only
|
||||||
def privacy_status_enable():
|
def privacy_status_enable():
|
||||||
env.update({'PRIVACY' : 'True'})
|
config = utils.load_settings()
|
||||||
utils.save_environment(env)
|
config["PRIVACY"] = 'True'
|
||||||
|
utils.write_settings(config)
|
||||||
|
|
||||||
return "Ok"
|
return "Ok"
|
||||||
|
|
||||||
@app.route('/system/privacy/disable', methods=["POST"])
|
@app.route('/system/privacy/disable', methods=["POST"])
|
||||||
@authorized_personnel_only
|
@authorized_personnel_only
|
||||||
def privacy_status_disable():
|
def privacy_status_disable():
|
||||||
env.update({'PRIVACY' : 'False'})
|
config = utils.load_settings()
|
||||||
utils.save_environment(env)
|
config["PRIVACY"] = 'False'
|
||||||
|
utils.write_settings(config)
|
||||||
|
|
||||||
return "Ok"
|
return "Ok"
|
||||||
|
|
||||||
# MUNIN
|
# 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 web_update import get_web_domains, get_default_www_redirects, get_domain_ssl_files
|
||||||
from mailconfig import get_mail_domains, get_mail_aliases
|
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):
|
def run_checks(rounded_values, env, output, pool):
|
||||||
# run systems checks
|
# 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")
|
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):
|
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.")
|
output.print_warning("Mail-in-a-Box version check disabled.")
|
||||||
elif what_version_is_this(env) != get_latest_miab_version():
|
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/. ")
|
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>
|
</table>
|
||||||
|
|
||||||
<h4>Privacy Setting</h4>
|
<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>
|
<p>Advanced Privacy <a onclick="enable_privacy()" href="">On</a> | <a onclick="disable_privacy()" href="">Off</a></p>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -13,11 +13,37 @@ def load_env_vars_from_file(fn):
|
|||||||
for line in open(fn): env.setdefault(*line.strip().split("=", 1))
|
for line in open(fn): env.setdefault(*line.strip().split("=", 1))
|
||||||
return env
|
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):
|
def save_environment(env):
|
||||||
with open("/etc/mailinabox.conf", "w") as f:
|
with open("/etc/mailinabox.conf", "w") as f:
|
||||||
for k, v in env.items():
|
for k, v in env.items():
|
||||||
f.write("%s=%s\n" % (k, v))
|
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):
|
def safe_domain_name(name):
|
||||||
# Sanitize a domain name so it is safe to use as a file name on disk.
|
# Sanitize a domain name so it is safe to use as a file name on disk.
|
||||||
import urllib.parse
|
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.
|
# Then in right-to-left lexicographic order of the .-separated parts of the name.
|
||||||
list(reversed(d.split("."))),
|
list(reversed(d.split("."))),
|
||||||
))
|
))
|
||||||
|
|
||||||
return domain_names
|
return domain_names
|
||||||
|
|
||||||
def sort_email_addresses(email_addresses, env):
|
def sort_email_addresses(email_addresses, env):
|
||||||
@ -128,7 +154,7 @@ def exclusive_process(name):
|
|||||||
f.write(str(mypid))
|
f.write(str(mypid))
|
||||||
f.truncate()
|
f.truncate()
|
||||||
atexit.register(clear_my_pid, pidfile)
|
atexit.register(clear_my_pid, pidfile)
|
||||||
|
|
||||||
|
|
||||||
def clear_my_pid(pidfile):
|
def clear_my_pid(pidfile):
|
||||||
import os
|
import os
|
||||||
|
Loading…
Reference in New Issue
Block a user