Skip to content

Commit 986b4c2

Browse files
committed
readonly: add new readonly mode
1 parent 91ea815 commit 986b4c2

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

src/config.py.sample

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,17 @@ config = {
8585
##
8686
# 'userdata-root-path': '/opt/0-hub/public',
8787
# 'workdir-root-path': '/opt/0-hub/workdir',
88-
88+
89+
## In order to host a hub which is a mirror of another
90+
## hub, since hub right now don't support multiple master,
91+
## you should enable this read-only mode to avoid modifying
92+
## your local database and be able to stay synced with your
93+
## main hub instance. For a normal or main hub instance,
94+
## keep this setting to False
95+
'readonly': False,
96+
8997
## By default, the hub is made to be used publicly
90-
## and needs to be protected (with itsyou.online)
98+
## and needs to be protected (with threefold connect)
9199
##
92100
## If you are running a local test hub on your local
93101
## network and you don't have any security issue, you

src/flist-uploader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ def logout():
272272
def login_method():
273273
return internalRedirect("logins.html")
274274

275+
@app.route('/readonly')
276+
def read_only_mode():
277+
if not config['readonly']:
278+
return redirect("/")
279+
280+
return globalTemplate("readonly.html", {})
281+
275282
@app.route('/login-iyo')
276283
@hub.itsyouonline.force_login()
277284
def login_iyo():

src/hub/security.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ def apicall():
88
def decorator(handler):
99
@wraps(handler)
1010
def _wrapper(*args, **kwargs):
11+
if config['readonly']:
12+
return jsonify({"message": "readonly mode", "status": "error"}), 400
13+
1114
if not config['authentication']:
1215
session['accounts'] = ['Administrator']
1316
session['username'] = 'Administrator'
@@ -48,6 +51,9 @@ def protected():
4851
def decorator(handler):
4952
@wraps(handler)
5053
def _wrapper(*args, **kwargs):
54+
if config['readonly']:
55+
return redirect("/readonly")
56+
5157
if not config['authentication']:
5258
session['accounts'] = ['Administrator']
5359
session['username'] = 'Administrator'

src/templates/readonly.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "layout.html" %}
2+
{% block title %}Zero-OS Hub{% endblock %}
3+
4+
{% block content %}
5+
<div class="jumbotron">
6+
<div class="container">
7+
<h1>Instance modification disabled</h1>
8+
<p>This Hub instance doesn't allow modification, this is a <code>read-only hub instance</code>.</p>
9+
<p>This is probably a mirror of a main instance, you should point to that one, or
10+
this instance is a special serve-only instance.<p>
11+
</div>
12+
</div>
13+
{% endblock %}

0 commit comments

Comments
 (0)