Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

run:
@ echo "This command should not be used in a production environment. OAuth requires an https connection outside of development."
AUTHLIB_INSECURE_TRANSPORT=true TEMPLATES_AUTO_RELOAD=true ../venv/bin/flask --debug run --reload --debug
GATEWAY_HOST="localhost:4000/gateway" AUTHLIB_INSECURE_TRANSPORT=true TEMPLATES_AUTO_RELOAD=true ../venv/bin/flask --debug run --reload --debug

sass:
cd static/styles/ && sass .
Expand Down
5 changes: 5 additions & 0 deletions application/controllers/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from controllers.api.v1 import (
bot,
faction,
gateway,
items,
key,
notification,
Expand Down Expand Up @@ -407,3 +408,7 @@
view_func=notification.notification.toggle_guild_notification,
methods=["POST"],
)

# /api/v1/gateway
mod.add_url_rule("/api/v1/gateway/token", view_func=gateway.create_token, methods=["POST"])
mod.add_url_rule("/api/v1/gateway/token/revoke", view_func=gateway.revoke_token, methods=["POST"])
78 changes: 78 additions & 0 deletions application/controllers/api/v1/gateway/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2021-2025 tiksan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import datetime
import json
import os
import secrets
import uuid

from flask import request
from peewee import DoesNotExist
from tornium_commons.models import GatewayToken

from controllers.api.v1.decorators import ratelimit, require_oauth, session_required
from controllers.api.v1.utils import api_ratelimit_response, make_exception_response
from controllers.authroutes import _log_auth

GATEWAY_HOST = os.environ.get("GATEWAY_HOST") or "https://gateway.tornium.com/"

# NOTE: secrets.token_hex generates double the number of characters as the number of bytes inputted
TOKEN_LENGTH = 64


@require_oauth("gateway")
@ratelimit
def create_token(*args, **kwargs):
key = f"tornium:ratelimit:{kwargs['user'].tid}"
token = GatewayToken.create(
guid=uuid.uuid4(),
user_id=kwargs["user"].tid,
token=secrets.token_hex(TOKEN_LENGTH / 2),
created_at=datetime.datetime.utcnow(),
created_ip=request.headers.get("CF-Connecting-IP") or request.remote_addr,
expires_at=datetime.datetime.utcnow() + datetime.timedelta(minutes=15),
)

return (
{"token": token.token, "expires_at": token.expires_at.timestamp(), "gateway_url": f"{GATEWAY_HOST}/"},
200,
api_ratelimit_response(key),
)


@require_oauth("gateway")
@ratelimit
def revoke_token(*args, **kwargs):
data = json.loads(request.get_data().decode("utf-8"))
key = f"tornium:ratelimit:{kwargs['user'].tid}"

token = data.get("token")

if token is None or not isinstance(token, str) or len(token) != TOKEN_LENGTH:
return make_exception_response("1300", key)

try:
gateway_token: GatewayToken = (
GatewayToken.select()
.where((GatewayToken.token == token) & (GatewayToken.user_id == kwargs["user"].tid))
.get()
)
except DoesNotExist:
return make_exception_response("1300", key)

gateway_token.delete_instance()

return "", 204, api_ratelimit_response(key)
6 changes: 3 additions & 3 deletions application/controllers/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@
},
"1300": {
"code": 1300,
"name": "UnknownGatewayClient",
"http": 404,
"message": "[DEPRECATED] Server failed to locate the requested gateway client.",
"name": "InvalidGatewayToken",
"http": 401,
"message": "The provided gateway token was invalid.",
},
"1400": {
"code": 1400,
Expand Down
5 changes: 4 additions & 1 deletion application/controllers/faction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from flask import Blueprint, render_template

from controllers.faction import armory, banking, bot, crimes, members
from controllers.faction import armory, banking, bot, crimes, members, ranked_war

mod = Blueprint("factionroutes", __name__)

Expand All @@ -39,6 +39,9 @@
# Armory Routes
mod.add_url_rule("/faction/armory", view_func=armory.armory, methods=["GET"])

# Ranked War Routes
mod.add_url_rule("/faction/ranked-war/tracker", view_func=ranked_war.tracker, methods=["GET"])


@mod.route("/faction")
def index():
Expand Down
30 changes: 30 additions & 0 deletions application/controllers/faction/ranked_war.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2021-2025 tiksan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import typing

from flask import render_template
from flask_login import current_user, login_required
from tornium_commons.models import Faction, User

from controllers.faction.decorators import fac_required


@login_required
@fac_required
def tracker(*args, **kwargs):
return render_template(
"faction/ranked_war_tracker.html",
)
3 changes: 2 additions & 1 deletion application/controllers/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

valid_scopes = (
"identity",
"gateway",
# Faction scopes
"faction",
"faction:attacks",
Expand All @@ -48,7 +49,7 @@ def openid_configuration():
{
"issuer": "https://tornium.com",
"authorization_endpoint": "https://tornium.com/oauth/authorize",
"token_endpoint": "https://tornium.com/oauth/token",
"token_endpoint": "https://tornium.com/oauth/token", # nosec
"scopes_supported": list(valid_scopes),
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code"],
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/armory.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/banking.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/banking_aa.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/bot.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/crime_cpr.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/crimes.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
6 changes: 6 additions & 0 deletions application/templates/faction/members.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
Expand Down
107 changes: 107 additions & 0 deletions application/templates/faction/ranked_war_tracker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{% extends 'base.html' %}

{% block title %}
Tornium - Ranked War Tracker
{% endblock %}

{% block breadcrumbs %}
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/">Tornium</a>
</li>
<li class="breadcrumb-item">
<a href="/faction">Faction</a>
</li>
<li class="breadcrumb-item disabled">
<a href="faction/ranked-war" disabled>Ranked War</a>
</li>
<li class="breadcrumb-item active">
<a href="/faction/ranked-war/tracker">Ranked War Tracker</a>
</li>
</ol>
{% endblock %}

{% block subnav %}
<div class="row pt-3 border-top">
<div class="container-fluid px-md-3">
<div class="row mb-3">
<a class="nav-link" href="/faction/members">
<i class="col-1 col-sm-2 fa-solid fa-shield-halved"></i> <span class="col">Members</span>
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/banking">
<i class="col-1 col-sm-2 fa-solid fa-money-check"></i> <span class="col">Banking</span>
</a>
</div>

{% if current_user.is_authenticated and current_user.factiontid != 0 %}
<div class="row mb-3">
<a class="nav-link" href="/faction/armory">
<i class="col-1 col-sm-2 fa-solid fa-warehouse"></i> <span class="col">Armory</span>
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/crimes/cpr">
<i class="col-1 col-sm-2 fa-solid fa-star-half-stroke"></i> <span class="col">Organized Crimes CPR</span>
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/ranked-war/tracker">
<i class="col-1 col-sm-2 fa-solid fa-location-crosshairs"></i> <span class="col">Ranked War Tracker</span>
</a>
</div>

{% if current_user.can_manage_crimes() %}
<div class="row mb-3">
<a class="nav-link" href="/faction/crimes">
<i class="col-1 col-sm-2 fa-solid fa-handcuffs"></i> <span class="col">Organized Crimes</span>
</a>
</div>
{% endif %}

{% if current_user.faction_aa %}
<div class="row mb-3">
<a class="nav-link" href="/faction/bankingaa">
<i class="col-1 col-sm-2 fa-solid fa-cash-register"></i> <span class="col">Banking AA</span>
</a>
</div>

<div class="row mb-3">
<a class="nav-link" href="/faction/bot">
<i class="col-1 col-sm-2 fa-brands fa-discord"></i> <span class="col">Bot Configuration</span>
</a>
</div>
{% endif %}
{% endif %}
</div>
</div>
{% endblock %}

{% block content %}
<div class="py-3 px-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Ranked War Tracker</h5>

<p class="card-text">
TBA
</p>

<p class="card-text">
For information on using this tool, see the <a href="https://docs.tornium.com/en/latest/reference/faction-ranked-war-tracker.html">tool's documentation page</a>.
</p>
</div>
</div>

<div class="card mt-3">
<div class="card-header">Monitoring: NYI</div>
<div class="card-body">
<p class="card-text">This feature has not been implemented yet.</p>
</div>
</div>
</div>
{% endblock %}
Loading