Verified Commit f1221ddf authored by Štěpán Henek's avatar Štěpán Henek 🌩

unite devices with and without contract

parent 3e183129
......@@ -25,8 +25,7 @@ from functools import wraps
from foris import BASE_DIR
from foris.utils import (
redirect_unauthenticated, is_safe_redirect, login_required, contract_valid,
check_password
redirect_unauthenticated, is_safe_redirect, login_required, check_password,
)
from foris.middleware.bottle_csrf import update_csrf_token, CSRFValidationError, CSRFPlugin
from foris.utils.routing import reverse
......@@ -135,26 +134,6 @@ def static(filename):
return prepare_response(filename, os.path.join(BASE_DIR, "static"))
def require_contract_valid(valid=True):
"""
Decorator for methods that require valid contract.
Raises bottle HTTPError if validity differs.
:param valid: should be contrat valid
:type valid: bool
:return: decorated function
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
if not (contract_valid() == valid):
raise bottle.HTTPError(403, "Contract validity mismatched.")
return func(*args, **kwargs)
return wrapper
return decorator
@login_required
def reboot():
data = current_state.backend.perform("maintain", "reboot")
......
......@@ -27,14 +27,14 @@ from bottle import Bottle, request, template, response, jinja2_template
from urllib.parse import urlencode
import bottle
from foris.common import require_contract_valid, login
from foris.common import login
from foris.guide import Workflow
from foris.utils.translators import gettext_dummy as gettext, _
from foris.config_handlers import (
backups, dns, misc, notifications, wan, lan, updater, wifi, networks,
guest, profile
)
from foris.utils import login_required, messages, is_safe_redirect, contract_valid
from foris.utils import login_required, messages, is_safe_redirect
from foris.middleware.bottle_csrf import CSRFPlugin
from foris.utils.routing import reverse
from foris.state import current_state
......@@ -606,17 +606,6 @@ class AboutConfigPage(ConfigPageMixin):
template_type = "jinja2"
userfriendly_title = gettext("About")
@require_contract_valid(True)
def _action_registration_code(self):
data = current_state.backend.perform("about", "get_registration_number")
return data["registration_number"]
def call_ajax_action(self, action):
if action == "registration_code":
regnum = self._action_registration_code()
return dict(success=regnum is not False, data=regnum)
raise ValueError("Unknown AJAX action.")
def render(self, **kwargs):
data = current_state.backend.perform("about", "get")
# process dates etc
......
......@@ -25,16 +25,11 @@ import bottle
from foris import __version__
from foris.config import init_app as init_app_config, top_index
from foris.common_app import prepare_common_app
from foris.utils import contract_valid
logger = logging.getLogger("foris.config")
bottle.SimpleTemplate.defaults['contract_valid'] = contract_valid
bottle.Jinja2Template.defaults['contract_valid'] = contract_valid
def prepare_config_app(args):
"""
Prepare Foris main application - i.e. apply CLI arguments, mount applications,
......
......@@ -23,7 +23,6 @@ from foris import validators
from foris.form import Checkbox, Textbox, Dropdown
from foris.state import current_state
from foris.utils import contract_valid
from foris.utils.translators import gettext_dummy as gettext, _
......@@ -57,11 +56,10 @@ class DNSHandler(BaseConfigHandler):
args=available_forwarders,
).requires("forwarding_enabled", True)
if not contract_valid():
dns_main.add_field(
Checkbox, name="dnssec_disabled", label=_("Disable DNSSEC"),
preproc=lambda val: bool(int(val)), default=False
)
dns_main.add_field(
Checkbox, name="dnssec_disabled", label=_("Disable DNSSEC"),
preproc=lambda val: bool(int(val)), default=False
)
dns_main.add_field(
Checkbox, name="dns_from_dhcp_enabled", label=_("Enable DHCP clients in DNS"),
......
......@@ -21,7 +21,6 @@ import copy
from foris import fapi, validators
from foris.form import Checkbox, Radio, RadioSingle, Number, Hidden
from foris.state import current_state
from foris.utils import contract_valid
from foris.utils.translators import gettext_dummy as gettext, _
from .base import BaseConfigHandler
......@@ -38,13 +37,10 @@ class UpdaterHandler(BaseConfigHandler):
def __init__(self, *args, **kwargs):
super(UpdaterHandler, self).__init__(*args, **kwargs)
if not contract_valid():
agreed = current_state.backend.perform(
"data_collect", "get", raise_exception_on_failure=False
)
self.agreed_collect = False if agreed is None else agreed["agreed"]
else:
self.agreed_collect = True
agreed = current_state.backend.perform(
"data_collect", "get", raise_exception_on_failure=False
)
self.agreed_collect = False if agreed is None else agreed["agreed"]
self.backend_data = current_state.backend.perform(
"updater", "get_settings", {"lang": current_state.language})
......@@ -174,11 +170,6 @@ class UpdaterHandler(BaseConfigHandler):
elif data[self.APPROVAL_NO] == self.APPROVAL_NO:
data["approval_settings"] = {"status": self.APPROVAL_NO}
if contract_valid():
data["enabled"] = True
data["approval_settings"]["status"] = self.APPROVAL_NO
data["approval_settings"].pop("delay", None)
if self.agreed_collect:
data["enabled"] = True
......
......@@ -24,55 +24,5 @@
</tbody>
</table>
{% if not contract_valid() %}
</div>
{% else %}
<h2>{% trans %}Device registration{% endtrans %}</h2>
<div class="about-description">
<p>
{% trans url="https://project.turris.cz/user/register-router" %}If you have not registered your device yet, click on the following button to obtain a registration code. This code must be submitted on the Turris site in your user profile available at: <a href="{{ url }}">{{ url }}</a>.{% endtrans %}
</p>
<p>
{% trans %}Registration code{% endtrans %}: <span id="registration-code">????????</span>
</p>
<div id="registration-code-fail">
{% trans %}Unfortunately, it wasn't possible to generate the registration code. This usually means the router is not connected to the internet. Please, try registering later. If the problem persists, contact the support.{% endtrans %}
</div>
<button id="registration-code-update" class="button">{% trans %}Get registration code{% endtrans %}</button>
</div>
</div>
<script>
$(document).ready(function() {
$("#registration-code-update").click(function(e) {
var self = $(this);
e.preventDefault();
self.attr("disabled", "disabled");
self.after('<img src="{{ static("img/icon-loading.gif") }}" id="registration-code-loader" alt="' + Foris.messages.loading +'">');
$.get('{{ url("config_ajax", page_name="about") }}', {action: "registration_code"})
.done(function(response, status, xhr) {
if (response.success) {
$("#registration-code").text(response.data).show();
$("#registration-code-fail").hide();
}
else {
$("#registration-code").text("????????");
$("#registration-code-fail").show();
}
})
.fail(function(xhr) {
if (xhr.responseJSON && xhr.responseJSON.loggedOut && xhr.responseJSON.loginUrl) {
window.location.replace(xhr.responseJSON.loginUrl);
return;
}
$("#registration-code").text("????????");
$("#registration-code-fail").show();
})
.always(function() {
$("#registration-code-loader").remove();
self.removeAttr("disabled");
});
});
});
</script>
{% endif %}
{% endblock %}
......@@ -6,9 +6,7 @@
{% include '_messages.html.j2' %}
<p>{% trans %}Router Turris uses its own DNS resolver with DNSSEC support. It is capable of working independently or it can forward your DNS queries your internet service provider's DNS resolver.{% endtrans %}</p>
<p>{% trans %}The following setting determines the behavior of the DNS resolver. Usually, it is better to use the ISP's resolver in networks where it works properly. If it does not work for some reason, it is necessary to use direct resolving without forwarding.{% endtrans %}</p>
{% if not contract_valid() %}
<p>{% trans %}In rare cases ISP's have improperly configured network which interferes with DNSSEC validation. If you experience problems with DNS, you can <strong>temporarily</strong> disable DNSSEC validation to determine the source of the problem. However, keep in mind that without DNSSEC validation, you are vulnerable to DNS spoofing attacks! Therefore we <strong>recommend keeping DNSSEC turned on</strong> and resolving the situation with your ISP as this is a serious flaw on their side.{% endtrans %}</p>
{% endif %}
<form id="main-form" class="config-form" action="{{ request.fullpath }}" method="post" enctype="multipart/form-data" autocomplete="off" novalidate>
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{% for field in form.active_fields %}
......
......@@ -7,9 +7,9 @@
{% include '_messages.html.j2' %}
<p>{{ form.sections[0].description|safe }}</p>
{% if agreed_collect and not contract_valid() %}
{% if agreed_collect %}
<div class="message info">{% trans %}Data collection is currently enabled. You can not disable updater without disabling the data collection first.{% endtrans %}</div>
{% elif not contract_valid() %}
{% else %}
{% include 'includes/updater_eula.html.j2' %}
{% endif %}
......@@ -17,14 +17,14 @@
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{# main updater switch #}
{% if not agreed_collect and not contract_valid() %}
{% if not agreed_collect %}
<div class="row" id="updater-toggle">
{{ form.sections[0].active_fields[0].render()|safe }}
</div>
{% endif %}
{# approval settings #}
{% if is_updater_enabled() and not contract_valid() %}
{% if is_updater_enabled() %}
<h4>{% trans %}Update approvals{% endtrans %}</h4>
<div id="updater-approvals">
{% if foris_info.device_customization == "turris" %}
......@@ -105,7 +105,7 @@
{% endif %}
{% endif %}
{% if is_updater_enabled() or contract_valid() %}
{% if is_updater_enabled() %}
<h2>{% trans %}Package lists{% endtrans %}</h2>
{% for field in form.sections[0].sections[1].active_fields %}
<div class="row">
......
......@@ -196,35 +196,6 @@ def localized_sorted(iterable, lang, key=None, reverse=False):
return sorted(iterable, key=key_fn, reverse=reverse)
def contract_valid():
"""Read whether the contract related with the current router is valid
:return: whether the contract is still valid
"""
CONRACT_VALID = "valid"
CONRACT_UNKNOWN = "unknown"
if current_state.device_customization != "turris":
return False
# perform backend query or obtain from cache
args = ("about", "get_contract_status", None)
hashable_args = ("about", "get_contract_status", None)
data = per_request.backend_data[hashable_args] if hashable_args in per_request.backend_data \
else current_state.backend.perform(*args)
# store into cache
per_request.backend_data[hashable_args] = data
if data["contract_status"] == CONRACT_VALID:
return True
if data["contract_status"] == CONRACT_UNKNOWN:
# Consider old contract valid for old turrises
return True
return False
def check_password(password):
res = current_state.backend.perform(
"password", "check",
......
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