Commit 0c9d431a authored by Joshua Tauberer's avatar Joshua Tauberer

major cleanup to adding new version check to the status checks

parent 1a525df8
...@@ -402,23 +402,19 @@ def backup_status(): ...@@ -402,23 +402,19 @@ def backup_status():
from backup import backup_status from backup import backup_status
return json_response(backup_status(env)) return json_response(backup_status(env))
@app.route('/system/privacy/enable', methods=["POST"]) @app.route('/system/privacy', methods=["GET"])
@authorized_personnel_only @authorized_personnel_only
def privacy_status_enable(): def privacy_status_get():
config = utils.load_settings() config = utils.load_settings(env)
config["PRIVACY"] = 'True' return json_response(config.get("privacy", True))
utils.write_settings(config)
return "Ok" @app.route('/system/privacy', methods=["POST"])
@app.route('/system/privacy/disable', methods=["POST"])
@authorized_personnel_only @authorized_personnel_only
def privacy_status_disable(): def privacy_status_set():
config = utils.load_settings() config = utils.load_settings(env)
config["PRIVACY"] = 'False' config["privacy"] = (request.form.get('value') == "private")
utils.write_settings(config) utils.write_settings(config, env)
return "OK"
return "Ok"
# MUNIN # MUNIN
......
...@@ -820,15 +820,18 @@ def get_latest_miab_version(): ...@@ -820,15 +820,18 @@ 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):
config = load_settings(env)
config = load_settings() if config.get("privacy", True):
output.print_warning("Mail-in-a-Box version check disabled by privacy setting.")
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/. ")
else: else:
output.print_ok("Mail-in-a-Box is up to date. You are running version %s." % what_version_is_this(env)) this_ver = what_version_is_this(env)
latest_ver = get_latest_miab_version()
if this_ver == latest_ver:
output.print_ok("Mail-in-a-Box is up to date. You are running version %s." % this_ver)
else:
output.print_error("A new version of Mail-in-a-Box is available. You are running version %s. The latest version is %s. For upgrade instructions, see https://mailinabox.email. "
% (this_ver, latest_ver))
def run_and_output_changes(env, pool, send_via_email): def run_and_output_changes(env, pool, send_via_email):
import json import json
......
...@@ -34,8 +34,20 @@ ...@@ -34,8 +34,20 @@
font-family: monospace; font-family: monospace;
white-space: pre-wrap; white-space: pre-wrap;
} }
#system-privacy-setting {
float: right;
max-width: 20em;
margin-bottom: 1em;
}
</style> </style>
<div id="system-privacy-setting" style="display: none">
<div><a onclick="return enable_privacy(!current_privacy_setting)" href="#"><span>Enable/Disable</span> New-Version Check</a></div>
<p style="line-height: 125%"><small>(When enabled, status checks phone-home to check for a new release of Mail-in-a-Box.)</small></p>
</div>
<table id="system-checks" class="table" style="max-width: 60em"> <table id="system-checks" class="table" style="max-width: 60em">
<thead> <thead>
</thead> </thead>
...@@ -43,13 +55,21 @@ ...@@ -43,13 +55,21 @@
</tbody> </tbody>
</table> </table>
<h4>Privacy Setting</h4>
<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> <script>
function show_system_status() { function show_system_status() {
$('#system-checks tbody').html("<tr><td colspan='2' class='text-muted'>Loading...</td></tr>") $('#system-checks tbody').html("<tr><td colspan='2' class='text-muted'>Loading...</td></tr>")
api(
"/system/privacy",
"GET",
{ },
function(r) {
current_privacy_setting = r;
$('#system-privacy-setting').show();
$('#system-privacy-setting a span').text(r ? "Enable" : "Disable");
$('#system-privacy-setting p').toggle(r);
});
api( api(
"/system/status", "/system/status",
"POST", "POST",
...@@ -86,17 +106,20 @@ function show_system_status() { ...@@ -86,17 +106,20 @@ function show_system_status() {
} }
} }
}) })
} }
function enable_privacy() {
api( var current_privacy_setting = null;
"/system/privacy/enable", function enable_privacy(status) {
"Post",
{ });
}
function disable_privacy() {
api( api(
"/system/privacy/disable", "/system/privacy",
"Post", "POST",
{ }); {
value: (status ? "private" : "off")
},
function(res) {
show_system_status();
});
return false; // disable link
} }
</script> </script>
import os.path 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(): def load_environment():
# Load settings from /etc/mailinabox.conf. # Load settings from /etc/mailinabox.conf.
...@@ -13,32 +14,28 @@ def load_env_vars_from_file(fn): ...@@ -13,32 +14,28 @@ 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 def save_environment(env):
settings_root = os.path.join(load_environment()["STORAGE_ROOT"], '/') with open("/etc/mailinabox.conf", "w") as f:
default_settings = { for k, v in env.items():
"PRIVACY": 'TRUE' f.write("%s=%s\n" % (k, v))
}
def write_settings(newconfig): # THE SETTINGS FILE AT STORAGE_ROOT/settings.yaml.
with open(os.path.join(settings_root, 'settings.yaml'), "w") as f:
f.write(rtyaml.dump(newconfig))
def load_settings(): 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: try:
config = rtyaml.load(open(os.path.join(settings_root, 'settings.yaml'), "w")) config = rtyaml.load(open(fn, "r"))
if not isinstance(config, dict): raise ValueError() # caught below if not isinstance(config, dict): raise ValueError() # caught below
except:
return default_settings
merged_config = default_settings.copy()
merged_config.update(config)
return config return config
except:
return { }
def save_environment(env): # UTILITIES
with open("/etc/mailinabox.conf", "w") as f:
for k, v in env.items():
f.write("%s=%s\n" % (k, v))
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment