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():
from backup import backup_status
return json_response(backup_status(env))
@app.route('/system/privacy/enable', methods=["POST"])
@app.route('/system/privacy', methods=["GET"])
@authorized_personnel_only
def privacy_status_enable():
config = utils.load_settings()
config["PRIVACY"] = 'True'
utils.write_settings(config)
def privacy_status_get():
config = utils.load_settings(env)
return json_response(config.get("privacy", True))
return "Ok"
@app.route('/system/privacy/disable', methods=["POST"])
@app.route('/system/privacy', methods=["POST"])
@authorized_personnel_only
def privacy_status_disable():
config = utils.load_settings()
config["PRIVACY"] = 'False'
utils.write_settings(config)
return "Ok"
def privacy_status_set():
config = utils.load_settings(env)
config["privacy"] = (request.form.get('value') == "private")
utils.write_settings(config, env)
return "OK"
# MUNIN
......
......@@ -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")
def check_miab_version(env, output):
config = load_settings(env)
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/. ")
if config.get("privacy", True):
output.print_warning("Mail-in-a-Box version check disabled by privacy setting.")
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):
import json
......
......@@ -34,8 +34,20 @@
font-family: monospace;
white-space: pre-wrap;
}
#system-privacy-setting {
float: right;
max-width: 20em;
margin-bottom: 1em;
}
</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">
<thead>
</thead>
......@@ -43,13 +55,21 @@
</tbody>
</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>
function show_system_status() {
$('#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(
"/system/status",
"POST",
......@@ -86,17 +106,20 @@ function show_system_status() {
}
}
})
}
function enable_privacy() {
api(
"/system/privacy/enable",
"Post",
{ });
}
function disable_privacy() {
var current_privacy_setting = null;
function enable_privacy(status) {
api(
"/system/privacy/disable",
"Post",
{ });
"/system/privacy",
"POST",
{
value: (status ? "private" : "off")
},
function(res) {
show_system_status();
});
return false; // disable link
}
</script>
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,32 +14,28 @@ 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 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(newconfig):
with open(os.path.join(settings_root, 'settings.yaml'), "w") as f:
f.write(rtyaml.dump(newconfig))
# THE SETTINGS FILE AT STORAGE_ROOT/settings.yaml.
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:
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
except:
return default_settings
merged_config = default_settings.copy()
merged_config.update(config)
return config
except:
return { }
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))
# UTILITIES
def safe_domain_name(name):
# 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