Exemplo n.º 1
0
    def __get_actions(self, server_status):
        actions = []

        if Permission(CanAccessServerHubAdditional()):
            actions.append(
                NavigationLink(
                    endpoint="hub.control",
                    name=_("Control"),
                    icon="fa fa-tablet",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        if Permission(CanAccessServerHubAdditional()):
            actions.append(
                NavigationLink(
                    endpoint="hub.configs",
                    name=_("Configs"),
                    icon="fa fa-wrench",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        if Permission(CanAccessServerHub()):
            actions.append(
                NavigationLink(
                    endpoint="hub.gamelogs",
                    name=_("Game Logs"),
                    icon="fa fa-file",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        actions.append(
            NavigationLink(
                endpoint="hub.bans",
                name=_("Bans"),
                icon="fa fa-wheelchair-alt",
                urlforkwargs={"server": hub_current_server.id},
            )
        )

        if Permission(CanAccessServerHubManagement()):
            actions.append(
                NavigationLink(
                    endpoint="hub.team",
                    name=_("Team"),
                    icon="fa fa-group",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        return actions
Exemplo n.º 2
0
class ConfigsView(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHubAdditional(),
            on_fail=FlashAndRedirect(
                message=_("You are not allowed to access the hub"),
                level="danger",
                endpoint="forum.index"
            )
        )
    ]

    def get(self):
        server_id = request.args["server"]
        servers = current_app.config["BYOND_SERVERS"]

        for server in servers:
            if server.id == server_id:
                config_folder_entries = [os.path.join(server.configs_path, f) for f in os.listdir(server.configs_path)]
                config_files = [f for f in config_folder_entries if os.path.isfile(f)]

                config_files_names = [os.path.split(f)[1] for f in config_files]
                config_files_names = [f for f in config_files_names if f not in server.configs_exclude]
                config_files_names.sort()

                return render_template("hub/configs.html", **self.get_args(), configs=config_files_names)

        return render_template("hub/configs.html", **self.get_args())
Exemplo n.º 3
0
class ControlView(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHubAdditional(),
            on_fail=FlashAndRedirectToHub(
                message=_("You are not allowed to access this page"),
                level="danger"
            )
        )
    ]

    def get(self):
        view = "HubLogs"
        if "view" in request.args:
            view = request.args["view"]

        logs = []
        if view == "HubLogs":
            logs = db.session.query(HubLog) \
                .filter(HubLog.server_id == hub_current_server.id) \
                .order_by(HubLog.id.desc()) \
                .limit(100) \
                .all()
        elif view == "UpdateLogs":
            update_log_path = get_update_log_path(hub_current_server.id)
            logs = open(update_log_path, 'r').read().split("\n")[-500:]
        elif view == "ServerLogs":
            server_log_path = get_server_log_file_path(hub_current_server)
            logs = open(server_log_path, 'r').read().split("\n")[-500:]

        return render_template("hub/control.html", **self.get_args(), view=view, logs=logs)
Exemplo n.º 4
0
class ConfigEditView(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHubAdditional(),
            on_fail=FlashAndRedirectToHub(
                message=_("You are not allowed to access the hub"),
                level="danger"
            )
        )
    ]

    def get(self):
        server_id = request.args["server"]
        config_name = request.args["config_name"]

        servers = current_app.config["BYOND_SERVERS"]
        server = None

        for srv in servers:
            if srv.id == server_id:
                server = srv
                break

        if server is None:
            abort(404)

        form = self.form()
        with open(os.path.join(server.configs_path, config_name)) as f:
            form.content.data = f.read()

        return render_template("hub/config_edit.html", **self.get_args(), config_name=config_name, form=form)

    def post(self):
        server_id = request.args["server"]
        config_name = request.args["config_name"]

        servers = current_app.config["BYOND_SERVERS"]
        server = None

        for srv in servers:
            if srv.id == server_id:
                server = srv
                break

        if server is None:
            abort(404)

        form = self.form()
        if form.validate_on_submit():
            with open(os.path.join(server.configs_path, config_name), "w") as f:
                f.write(form.content.data)
                LogAction(current_user, 'updated server\'s config file "{}"'.format(config_name))
                flash("Configuration file was saved!")

        return render_template("hub/config_edit.html", **self.get_args(), config_name=config_name, form=form)

    def form(self):
        return ConfigEditForm()
Exemplo n.º 5
0
class ServerControl(MethodView):
    decorators = [
        allows.requires(
            CanAccessServerHubAdditional(),
            on_fail=FlashAndRedirectToHub(
                message=_("You are not allowed to use server controls"),
                level="danger"))
    ]
    _action = "made unknown action with"

    def _report(self, user):
        LogAction(user, self._action + " server")
Exemplo n.º 6
0
    def __get_actions(self, server_status):
        actions = []

        if Permission(CanAccessServerHub()):
            actions.append(
                NavigationLink(
                    endpoint="hub.hublogs",
                    name=_("Logs"),
                    icon="fa fa-clock-o",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        if Permission(CanAccessServerHubAdditional()):
            if server_status == "online":
                actions.append(
                    NavigationLink(
                        endpoint="hub.stop",
                        name=_("Stop"),
                        icon="fa fa-power-off",
                        urlforkwargs={"server": hub_current_server.id},
                    ))

                actions.append(
                    NavigationLink(
                        endpoint="hub.restart",
                        name=_("Restart"),
                        icon="fa fa-undo",
                        urlforkwargs={"server": hub_current_server.id},
                    ))

            else:
                actions.append(
                    NavigationLink(
                        endpoint="hub.start",
                        name=_("Start"),
                        icon="fa fa-power-off",
                        urlforkwargs={"server": hub_current_server.id},
                    ))

        if Permission(CanAccessServerHubAdditional()):
            actions.append(
                NavigationLink(
                    endpoint="hub.configs",
                    name=_("Configs"),
                    icon="fa fa-wrench",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        if Permission(CanAccessServerHub()):
            actions.append(
                NavigationLink(
                    endpoint="hub.gamelogs",
                    name=_("Game Logs"),
                    icon="fa fa-file",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        actions.append(
            NavigationLink(
                endpoint="hub.bans",
                name=_("Bans"),
                icon="fa fa-wheelchair-alt",
                urlforkwargs={"server": hub_current_server.id},
            )
        )

        if Permission(CanAccessServerHubManagement()):
            actions.append(
                NavigationLink(
                    endpoint="hub.team",
                    name=_("Team"),
                    icon="fa fa-group",
                    urlforkwargs={"server": hub_current_server.id},
                ))

        return actions