Initial commit

This commit is contained in:
Naomi Warner 2024-02-25 12:40:23 -06:00
commit b88940a22c
6 changed files with 174 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
config/*.php

22
LICENSE Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright © 2024
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# Akkoma Mod Log
A quick and dirty mod log viewer for if you want to make your moderation activities public.
Copy `config/config.php.example` to `config/config.php` and edit it to match up with your instance info.

43
config/config.php.example Normal file
View file

@ -0,0 +1,43 @@
<?php
// Akkoma-Mod-Log settings
$meta = [
// Suppresses debug output such as PHP errors
'production' => true,
// Which actions should be shown publicly
'actions' => [
'grant',
// 'deactivate',
// 'activate',
'report_update',
// 'relay_follow',
// 'relay_unfollow',
// 'delete',
'revoke',
'tag',
'untag',
// 'approve',
//'report_note',
'status_update',
'status_delete',
// 'updated_users',
// 'force_password_reset'
]
];
// Which instance is this?
$instance = [
'name' => 'My Akkoma',
'url' => 'https://example.com/'
];
// Database connection info
$database = [
'host' => '127.0.0.1',
'port' => 5432,
'dbname' => 'akkoma',
'table' => 'moderation_log',
// You should probably make a new read only user to read from the table
'user' => 'modlog',
'pass' => ''
];

1
css/page.css Normal file
View file

@ -0,0 +1 @@
/* put your custom css here :) */

102
index.php Normal file
View file

@ -0,0 +1,102 @@
<?php
require_once('./config/config.php');
// Error reporting
if ($meta['production'] == false) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
// Connect to database, pull mod log data, then close connection
$database['connection'] = pg_connect("host=" . $database['host'] . " port=" . $database['port'] . " dbname=" . $database['dbname'] . " user=" . $database['user'] . " password=" . $database['password']) or die("database connection failed");
$database['query'] = 'SELECT * FROM ' . $database['table'];
$database['result'] = pg_query($database['connection'], $database['query']);
pg_close($database['connection']);
// Unscrew all the arrays lol
while ($line = pg_fetch_array($database['result'], null, PGSQL_ASSOC)) {
foreach ($line as $key => $value) {
$result[$line['id']] = [
'data' => json_decode($line['data'], true),
'inserted_at' => $line['inserted_at'],
'updated_at' => $line['updated_at']
];
}
}
// Free up some memory
pg_free_result($database['result']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- -->
<title><?= $instance['name'] ?> Mod Log</title>
<!-- Stylesheets -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="/css/page.css">
</head>
<body>
<!-- Nav -->
<nav class="navbar bg-body-tertiary">
<div class="container">
<?= $instance['name'] ?> Mod Log
<div class="navbar-nav">
<a href="<?= $instance['url'] ?>" class="nav-link">Go to instance &rarr;</a>
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col">
<table class="table table-striped table-hover text-center">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">User</th>
<th scope="col">Action</th>
<th scope="col">Message</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $key => $value) :?>
<?php if (in_array($value["data"]["action"], $meta['actions'])) :?>
<tr>
<th scope="row"><?= $key ?></th>
<td><?= $value["data"]["actor"]["nickname"] ?></td>
<td><?= $value["data"]["action"] ?></td>
<td class="text-start"><?= $value["data"]["message"] ?></td>
<td><?= $value["inserted_at"] ?></td>
</tr>
<?php endif ?>
<?php endforeach ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Footer -->
<div class="container">
<div class="row">
<div class="col text-center">
<p>From <a href="https://labyrinth.zone/users/Velveteen" target="_blank">Vel</a>, With Love 💖
<a href="https://git.void.lgbt/Velveteen/akkoma-mod-log" target="_blank">Source Code</a>
</p>
</div>
</div>
</div>
</body>
</html>