Esempio n. 1
0
class LogDownload(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHub(),
            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"]
        path = request.args["path"]
        servers = current_app.config["BYOND_SERVERS"]

        assert path
        assert server_id

        server = None

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

        if server is None:
            abort(404)

        file_path = os.path.join(server.logs_path, path)
        return send_file(file_path, as_attachment=True)
Esempio n. 2
0
    def get(self):
        if "user_to_add" in request.args:
            self.__add_group_to_user(request.args["user_to_add"])
            return redirect(url_for("hub.team", server=hub_current_server.id))

        if "user_to_remove_group" in request.args:
            self.__remove_group_from_user(request.args["user_to_remove_group"])
            return redirect(url_for("hub.team", server=hub_current_server.id))

        @attr.s
        class TeamMember:
            id = attr.ib()
            username = attr.ib()
            group = attr.ib(default="")
            discord_role = attr.ib(default="")
            url = attr.ib(default="")
            remove_group_url = attr.ib(default="")

        members = []
        for user in User.query.all():
            if Permission(CanAccessServerHub(), identity=user):
                new_member = TeamMember(id=user.discord,
                                        username=user.display_name,
                                        group=user.primary_group.name,
                                        url=user.url)

                if user.primary_group.id in hub_current_server.discord_role_to_group.values(
                ):
                    new_member.remove_group_url = \
                        url_for("hub.team", server=hub_current_server.id, user_to_remove_group=user.discord)

                members.append(new_member)

        discord_users_with_pedalique_role = db.session.query(DiscordUser)\
            .join(DiscordUserRole)\
            .join(DiscordRole)\
            .filter(DiscordUserRole.role.in_(hub_current_server.discord_full_access_titles))\
            .distinct(DiscordUser.id)\
            .add_entity(DiscordRole)\
            .all()

        members_from_discord = []
        for discord_user, discord_role in discord_users_with_pedalique_role:
            found = False
            for member in members:
                if member.id == discord_user.id:
                    member.discord_role = discord_role.title
                    found = True
                    break
            if not found:
                members_from_discord.append(
                    TeamMember(id=discord_user.id,
                               username=discord_user.pure_name,
                               discord_role=discord_role.title))

        return render_template("hub/team.html",
                               **self.get_args(),
                               members=members + members_from_discord)
Esempio n. 3
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
Esempio n. 4
0
class HubLogView(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHub(),
            on_fail=FlashAndRedirect(
                message=_("You are not allowed to access the hub"),
                level="danger",
                endpoint="forum.index"
            )
        )
    ]

    def get(self):
        logs = db.session.query(HubLog)\
            .filter(HubLog.server_id == hub_current_server.id)\
            .order_by(HubLog.id.desc())\
            .limit(100)\
            .all()
        return render_template("hub/hublogs.html", **self.get_args(), logs=logs)
Esempio n. 5
0
class LogsView(Hub):
    decorators = [
        allows.requires(
            CanAccessServerHub(),
            on_fail=FlashAndRedirect(
                message=_("You are not allowed to access the hub"),
                level="danger",
                endpoint="forum.index"
            )
        )
    ]

    # returns list [{"name": name, "url": url)]
    @staticmethod
    def get_title_parent_folders(server_id, root_path, current_path):
        folders = []

        path = current_path
        while root_path != path:
            name = os.path.split(path)[1]
            url = url_for("hub.gamelogs", server=server_id, path=os.path.relpath(path, root_path))
            folders.insert(0, {"name": name, "url": url})
            path = os.path.dirname(path)

        name = "logs"
        url = url_for("hub.gamelogs", server=server_id)
        folders.insert(0, {"name": name, "url": url})

        if len(folders):
            folders[-1]["url"] = None

        return folders

    def get(self, **kwargs):
        server_id = request.args["server"]
        path = None
        if "path" in request.args:
            path = request.args["path"]
        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)

        current_path = server.logs_path
        if path:
            current_path = os.path.realpath(os.path.join(current_path, path))
            if not current_path.startswith(server.logs_path + os.sep):
                abort(404)

        title_parent_folders = self.get_title_parent_folders(server_id, server.logs_path, current_path)

        logs_folder_entries = [os.path.join(current_path, f) for f in os.listdir(current_path)]
        entries = {}

        for entry in logs_folder_entries:
            entry_pure = os.path.split(entry)[1]
            if os.path.isfile(entry):
                entries[entry_pure] = url_for("hub.download_gamelog", server=server_id, path=os.path.relpath(entry, server.logs_path))
            else:
                lll = os.path.relpath(entry, server.logs_path)
                entries[entry_pure] = url_for("hub.gamelogs", server=server_id, path=os.path.relpath(entry, server.logs_path))

        return render_template(
            "hub/gamelogs.html",
            **self.get_args(),
            entries=sorted(entries.items()),
            title_parent_folders=title_parent_folders
        )
Esempio n. 6
0
 def get(self):
     if Permission(CanAccessServerHub()):
         return redirect(url_for("hub.hublogs", server=hub_current_server.id))
     return redirect(url_for("hub.bans", server=hub_current_server.id))
Esempio n. 7
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