forked from rDrama/rDrama
1
0
Fork 0

add ip templates

master
Aevann 2024-02-06 03:19:38 +02:00
parent db7dbe8cf9
commit 7747b7844a
6 changed files with 78 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import time
from sqlalchemy import Column, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql.sqltypes import *
from files.classes import Base
@ -12,6 +13,8 @@ class IPLog(Base):
created_utc = Column(Integer)
last_used = Column(Integer)
user = relationship("User")
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs:
kwargs["created_utc"] = int(time.time())

View File

@ -205,6 +205,7 @@ PERMS = { # Minimum admin_level to perform action.
'MODERATE_PENDING_SUBMITTED_ASSETS': 3,
'UPDATE_ASSETS': 3,
'CHANGE_UNDER_SIEGE': 3,
'VIEW_IPS': 3,
'PROGSTACK': 4,
'UNDO_AWARD_PINS': 4,

View File

@ -2156,3 +2156,21 @@ def change_under_siege_post(v):
g.db.add(ma)
return {"message": "Thresholds changed successfully!"}
if FEATURES['IP_LOGGING']:
@app.get("/@<username>/ips/")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@admin_level_required(PERMS['VIEW_IPS'])
def view_user_ips(v, username):
u = get_user(username, v=v)
ip_logs = g.db.query(IPLog).filter_by(user_id=u.id).order_by(IPLog.last_used.desc())
return render_template('admin/user_ips.html', v=v, u=u, ip_logs=ip_logs)
@app.get("/ip_users/<ip>")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@admin_level_required(PERMS['VIEW_IPS'])
def view_ip_users(v, ip):
ip_logs = g.db.query(IPLog).filter_by(ip=ip).order_by(IPLog.last_used.desc())
return render_template('admin/ip_users.html', v=v, ip=ip, ip_logs=ip_logs)

View File

@ -0,0 +1,28 @@
{% extends "default.html" %}
{% block pagetitle %}{{ip}} Users{% endblock %}
{% block content %}
<h5 class="pt-4 pl-2 pb-3">Users who visited from {{ip}}</h5>
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Name</th>
<th>First Used</th>
<th>Last Used</th>
</tr>
</thead>
{% for ip_log in ip_logs %}
<tr>
<td>
{% with user=ip_log.user %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td data-time="{{ip_log.created_utc}}"></td>
<td data-time="{{ip_log.last_used}}"></td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}

View File

@ -0,0 +1,24 @@
{% extends "default.html" %}
{% block pagetitle %}@{{u.username}}'s IPs{% endblock %}
{% block content %}
<h5 class="pt-4 pl-2 pb-3">@{{u.username}}'s IPs</h5>
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>IP</th>
<th>First Used</th>
<th>Last Used</th>
</tr>
</thead>
{% for ip_log in ip_logs %}
<tr>
<td><a href="/ip_users/{{ip_log.ip}}">{{ip_log.ip}}</a></td>
<td data-time="{{ip_log.created_utc}}"></td>
<td data-time="{{ip_log.last_used}}"></td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}

View File

@ -127,6 +127,10 @@
{% if v.admin_level >= PERMS['USER_RESET_PASSWORD'] %}
<button type="button" id="reset-password-{{deviceType}}" class="mt-1 btn btn-danger" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="postToast(this,'/admin/reset_password/{{u.id}}')">Reset Password</button>
{% endif %}
{% if FEATURES['IP_LOGGING'] and v.admin_level >= PERMS['VIEW_IPS'] %}
<a id="view-user-ips-{{deviceType}}" class="btn btn-primary" style="display:inline-block!important" href="/@{{u.username}}/ips">View User IPs</a>
{% endif %}
</div>
</div>
{% endif %}