From 52c6bed836e667fb3dbb82a437e13e203621b431 Mon Sep 17 00:00:00 2001
From: Kento HASEGAWA
Date: Fri, 17 Aug 2018 13:27:32 +0900
Subject: [PATCH] Add support for local mode (clients other than localhost
cannot control the system)
---
comm/server/main.py | 8 ++++++--
comm/server/templates/part_client_table.html | 5 +++--
comm/server/templates/part_question_status.html | 4 ++++
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/comm/server/main.py b/comm/server/main.py
index 37623cf..4caed05 100644
--- a/comm/server/main.py
+++ b/comm/server/main.py
@@ -135,7 +135,10 @@ def update_answer_list(qname):
def before_request():
global app_args
- g.local_mode = (request.remote_addr == "127.0.0.1")
+ if app_args["force_local_mode"]:
+ g.local_mode = True
+ else:
+ g.local_mode = (request.remote_addr in ["127.0.0.1", "::1"])
@app.route("/post", methods=["POST"])
def post():
@@ -588,7 +591,7 @@ def question_status():
update_answer_list(qname)
qdata = questions[qname]
- return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"])
+ return render_template("part_question_status.html", qname=qname, qdata=qdata, solvers=clients["solver"], localmode=g.local_mode)
@app.route('/ws')
def ws():
@@ -660,6 +663,7 @@ if __name__ == "__main__":
parser.add_argument("-a", "--adccli", action="store", type=str, default="./adccli.json", help="Path to the ADCCLI configuration json file.")
parser.add_argument("-q", "--question", action="store", type=str, default="./problems", help="Path to the question folder.")
parser.add_argument("-o", "--out", action="store", type=str, default="./answers", help="Path to the output folder.")
+ parser.add_argument("--force-local-mode", action="store_true", default=False, help="Apply local mode view to all clients.")
parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.")
args = vars(parser.parse_args())
app_args = args
diff --git a/comm/server/templates/part_client_table.html b/comm/server/templates/part_client_table.html
index 7386b49..d71fe09 100644
--- a/comm/server/templates/part_client_table.html
+++ b/comm/server/templates/part_client_table.html
@@ -9,12 +9,13 @@ Viewer Mode
{% endif %}
+{% if local_mode %}
自動運営システム
-
-
+
+{% endif %}
クライアント
diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html
index 41c9ebc..738df97 100644
--- a/comm/server/templates/part_question_status.html
+++ b/comm/server/templates/part_question_status.html
@@ -1,6 +1,7 @@
【{{qname}}】
+ {% if localmode %}
@@ -9,6 +10,9 @@
+ {% else %}
+ [View Only]
+ {% endif %}