diff --git a/INSTALL.md b/INSTALL.md index 46536b65..3e33430b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -98,8 +98,6 @@ To enable https, you can generate a certificate ssl. ./script/justletsencrypt.sh ``` - - Systemctl --------- You can setup the daemon with Systemctl. @@ -124,4 +122,6 @@ Options --redirect_http_to_https : when you need to support external link with http, this will redirect request to https. --use_internet_static : Not implemented. Force using static files like css and js from another internet website. Use web browser cache. (default=False) --disable_login : Disable authentication +--disable_character : Disable access to character +--disable_user_character : Disable access to user of our character ``` diff --git a/src/web/__main__.py b/src/web/__main__.py index 382aef43..e3f32152 100644 --- a/src/web/__main__.py +++ b/src/web/__main__.py @@ -69,6 +69,8 @@ def parse_args(): group = parser.add_argument_group("Module") group.add_argument('--disable_character', default=False, action='store_true', help='Active to disable character module.') + group.add_argument('--disable_user_character', default=False, action='store_true', + help='Active to disable character module for not admin user.') group.add_argument('--disable_login', default=False, action='store_true', help='Active to disable login module.') group.add_argument('--disable_admin', default=False, action='store_true', @@ -85,6 +87,9 @@ def parse_args(): # cannot redirect http to https if ssl is not enable _parser.redirect_http_to_https = False + if _parser.disable_character: + _parser.disable_user_character = True + return _parser diff --git a/src/web/base_handler.py b/src/web/base_handler.py index 72753a4b..2911405b 100644 --- a/src/web/base_handler.py +++ b/src/web/base_handler.py @@ -29,6 +29,7 @@ def initialize(self, **kwargs): "use_internet_static": kwargs.get("use_internet_static"), "db": self._db, "disable_character": kwargs.get("disable_character"), + "disable_user_character": kwargs.get("disable_user_character"), "disable_admin": kwargs.get("disable_admin"), "disable_login": kwargs.get("disable_login"), "url": kwargs.get("url"), diff --git a/src/web/handlers.py b/src/web/handlers.py index f816d1fa..3354a161 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -351,6 +351,7 @@ def get(self): self.set_status(404) self.send_error(404) raise tornado.web.Finish() + if self.current_user: self.clear_cookie("user") self.redirect("/") @@ -364,7 +365,7 @@ class AdminHandler(base_handler.BaseHandler): @tornado.web.asynchronous @tornado.web.authenticated def get(self): - if self._global_arg["disable_admin"]: + if self._global_arg["disable_admin"] or self._global_arg["disable_login"]: # Not Found self.set_status(404) self.send_error(404) @@ -402,11 +403,14 @@ class ProfileHandler(base_handler.BaseHandler): @tornado.web.asynchronous @tornado.web.authenticated def get(self, user_id=None): - if self._global_arg["disable_character"]: - # Not Found - self.set_status(404) - self.send_error(404) - raise tornado.web.Finish() + if self._global_arg["disable_login"]: + # # Not Found + # self.set_status(404) + # self.send_error(404) + # raise tornado.web.Finish() + # don't crash, just redirect to main site + self.redirect("/") + return if user_id: user = self._db.get_user(user_id=user_id) else: @@ -417,11 +421,12 @@ def get(self, user_id=None): class CharacterHandler(base_handler.BaseHandler): @tornado.web.asynchronous def get(self): - if self._global_arg["disable_character"]: - # Not Found - self.set_status(404) - self.send_error(404) - raise tornado.web.Finish() + # don't block the page when disable character, user need to be inform + # if self._global_arg["disable_character"]: + # # Not Found + # self.set_status(404) + # self.send_error(404) + # raise tornado.web.Finish() self.render('character.html', **self._global_arg) @@ -429,15 +434,16 @@ def get(self): class CharacterViewHandler(jsonhandler.JsonHandler): @tornado.web.asynchronous def get(self): - if self._global_arg["disable_character"]: + if not self.is_permission_admin() and self._global_arg["disable_user_character"] or \ + self._global_arg["disable_character"]: # Not Found self.set_status(404) self.send_error(404) raise tornado.web.Finish() # validate argument - user_id = self.request.query[len("user_id="):] is_admin = self.request.query == "is_admin" + user_id = self.request.query[len("user_id="):] if user_id == "" and not is_admin: # Forbidden self.set_status(403) diff --git a/src/web/partials/_base.html b/src/web/partials/_base.html index b7eea911..144764ea 100644 --- a/src/web/partials/_base.html +++ b/src/web/partials/_base.html @@ -64,12 +64,10 @@
@@ -91,12 +89,14 @@ + {% if not disable_login %} {% if current_user %}