2018-04-14 01:13:47 -05:00
|
|
|
<?php
|
2025-03-29 10:50:03 +00:00
|
|
|
|
2022-02-14 20:48:15 -08:00
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* Log handling class.
|
2020-12-13 19:38:04 +01:00
|
|
|
*
|
2022-02-14 20:48:15 -08:00
|
|
|
* @package NamelessMC\Core
|
|
|
|
|
* @author Timothy Gibbons
|
|
|
|
|
* @version 2.0.0-pr13
|
|
|
|
|
* @license MIT
|
2018-04-14 01:13:47 -05:00
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
class Log extends Instanceable
|
|
|
|
|
{
|
2022-02-14 20:48:15 -08:00
|
|
|
/**
|
|
|
|
|
* @var array Mapping of log Actions to their language key
|
|
|
|
|
*/
|
2021-10-07 14:02:46 -07:00
|
|
|
private static array $_actions = [
|
2020-12-13 19:38:04 +01:00
|
|
|
'admin' => [
|
|
|
|
|
'login' => 'acp_login',
|
|
|
|
|
'core' => [
|
|
|
|
|
'general' => 'acp_core_update',
|
|
|
|
|
'avatar' => 'acp_avatar_update',
|
|
|
|
|
'profile' => [
|
|
|
|
|
'add' => 'acp_core_profile_add',
|
|
|
|
|
'delete' => 'acp_core_profile_delete',
|
|
|
|
|
'update' => 'acp_core_profile_update',
|
|
|
|
|
],
|
|
|
|
|
'maintenance' => [
|
|
|
|
|
'enable' => 'acp_maintenance_enable',
|
|
|
|
|
'disable' => 'acp_maintenance_disable',
|
|
|
|
|
'update' => 'acp_maintenance_update',
|
|
|
|
|
],
|
|
|
|
|
'email' => [
|
|
|
|
|
'update' => 'acp_email_update',
|
|
|
|
|
'test' => 'acp_email_test',
|
2024-03-09 03:19:55 -08:00
|
|
|
'mass_message' => 'acp_email_mass_message',
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'nav' => 'admin_nav_update',
|
|
|
|
|
'reaction' => [
|
|
|
|
|
'update' => 'acp_reaction_update',
|
|
|
|
|
'add' => 'acp_reaction_add',
|
2024-03-09 03:19:55 -08:00
|
|
|
'delete' => 'acp_reaction_remove',
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'social' => 'acp_social_update',
|
|
|
|
|
'term' => 'acp_term_update',
|
2023-03-30 18:42:40 +01:00
|
|
|
'queue' => [
|
|
|
|
|
'cancel_task' => 'acp_cancel_task',
|
|
|
|
|
'requeue_task' => 'acp_requeue_task',
|
|
|
|
|
],
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'api' => [
|
|
|
|
|
'change' => 'acp_api_change',
|
|
|
|
|
],
|
|
|
|
|
'group' => [
|
|
|
|
|
'create' => 'acp_group_create',
|
|
|
|
|
'update' => 'acp_group_update',
|
|
|
|
|
'delete' => 'acp_group_delte',
|
|
|
|
|
],
|
|
|
|
|
'bgimage' => [
|
|
|
|
|
'submit' => 'acp_bgimage_submit',
|
|
|
|
|
'reset' => 'acp_bgimage_reset',
|
|
|
|
|
],
|
2021-12-07 22:14:12 -08:00
|
|
|
'mc' => [
|
2021-10-30 16:25:44 -07:00
|
|
|
'update' => 'acp_mc_update',
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'authme' => [
|
|
|
|
|
'update' => 'acp_authme_update',
|
|
|
|
|
],
|
|
|
|
|
'server' => [
|
|
|
|
|
'update' => 'acp_server_update',
|
|
|
|
|
'delete' => 'acp_server_delete',
|
|
|
|
|
'add' => 'acp_server_add',
|
|
|
|
|
'default' => 'acp_server_default_update',
|
2021-10-30 16:25:44 -07:00
|
|
|
'banner' => 'acp_server_banner_update',
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'module' => [
|
|
|
|
|
'install' => 'acp_module_install',
|
|
|
|
|
'enable' => 'acp_module_enable',
|
|
|
|
|
'disable' => 'acp_module_disable',
|
|
|
|
|
],
|
|
|
|
|
'pages' => [
|
|
|
|
|
'new' => 'acp_pages_new',
|
|
|
|
|
'edit' => 'acp_pages_edit',
|
|
|
|
|
'delete' => 'acp_pages_delete',
|
|
|
|
|
],
|
|
|
|
|
'template' => [
|
2021-12-07 22:14:12 -08:00
|
|
|
'update' => 'acp_template_update',
|
2020-12-13 19:38:04 +01:00
|
|
|
'install' => 'acp_template_install',
|
|
|
|
|
'default' => 'acp_template_default_change',
|
|
|
|
|
'activate' => 'acp_template_activate',
|
|
|
|
|
'deactivate' => 'acp_template_deactivate',
|
|
|
|
|
'delete' => 'acp_template_delete',
|
|
|
|
|
],
|
|
|
|
|
'user' => [
|
|
|
|
|
'create' => 'acp_user_add',
|
|
|
|
|
'delete' => 'acp_user_remove',
|
|
|
|
|
'update' => 'acp_user_update',
|
|
|
|
|
'register' => 'acp_register_change',
|
|
|
|
|
],
|
|
|
|
|
'widget' => [
|
|
|
|
|
'update' => 'acp_widget_update',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'mod' => [
|
|
|
|
|
'iplookup' => 'mcp_ip_lookup',
|
|
|
|
|
'punishment' => [
|
|
|
|
|
'create' => 'mcp_punishment_create',
|
|
|
|
|
'revoke' => 'mcp_punishment_revoke',
|
|
|
|
|
],
|
|
|
|
|
'report' => [
|
|
|
|
|
'comment' => 'mcp_report_comment',
|
|
|
|
|
'open' => 'mcp_report_open',
|
|
|
|
|
'close' => 'mcp_report_close',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'user' => [
|
|
|
|
|
'login' => 'user_login',
|
|
|
|
|
'logout' => 'user_logout',
|
|
|
|
|
'register' => 'user_register',
|
|
|
|
|
'acknowledge' => 'user_acknowledge',
|
|
|
|
|
'ucp' => [
|
|
|
|
|
'update' => 'ucp_update',
|
|
|
|
|
],
|
|
|
|
|
'tfa' => [
|
|
|
|
|
'key' => [
|
|
|
|
|
'sent' => 'tfa_key_sent',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'forums' => [
|
|
|
|
|
'topic' => [
|
|
|
|
|
'delete' => 'forums_topic_delete',
|
|
|
|
|
'edit' => 'forums_topic_edit',
|
|
|
|
|
'lock' => 'forums_topic_lock',
|
|
|
|
|
'create' => 'forums_topic_create',
|
|
|
|
|
'search' => 'forums_topic_search',
|
|
|
|
|
'stick' => 'forums_topic_stick',
|
|
|
|
|
'view' => 'forums_topic_view',
|
|
|
|
|
'move' => 'forums_topic_move',
|
|
|
|
|
'merge' => 'forums_topic_merge',
|
|
|
|
|
'react' => 'forums_topic_react',
|
|
|
|
|
'unstick' => 'forum_topic_unstick',
|
|
|
|
|
],
|
|
|
|
|
'post' => [
|
|
|
|
|
'delete' => 'forums_post_delete',
|
|
|
|
|
'edit' => 'forums_post_edit',
|
|
|
|
|
'lock' => 'forums_post_lock',
|
|
|
|
|
'create' => 'forums_post_create',
|
|
|
|
|
'search' => 'forums_post_search',
|
|
|
|
|
'stick' => 'forums_post_stick',
|
|
|
|
|
'unstick' => 'forum_topic_unstick',
|
|
|
|
|
'view' => 'forums_post_view',
|
|
|
|
|
'move' => 'forums_post_move',
|
|
|
|
|
'merge' => 'forums_post_merge',
|
|
|
|
|
'react' => 'forums_post_react',
|
|
|
|
|
],
|
|
|
|
|
'delete' => 'forum_delete',
|
|
|
|
|
'edit' => 'forum_edit',
|
|
|
|
|
'lock' => 'forum_lock',
|
|
|
|
|
'create' => 'forum_create',
|
|
|
|
|
'search' => 'forum_search',
|
|
|
|
|
'stick' => 'forum_stick',
|
|
|
|
|
'view' => 'forum_view',
|
|
|
|
|
'move' => 'forum_move',
|
|
|
|
|
'merge' => 'forum_merge',
|
|
|
|
|
'react' => 'forum_react',
|
|
|
|
|
],
|
|
|
|
|
'misc' => [
|
|
|
|
|
'report' => 'report',
|
2024-03-09 03:19:55 -08:00
|
|
|
'curl_error' => 'curl_error',
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'api' => [
|
2022-01-15 11:48:52 -08:00
|
|
|
// TODO
|
2020-12-13 19:38:04 +01:00
|
|
|
],
|
|
|
|
|
'discord' => [
|
2023-01-28 10:02:27 -08:00
|
|
|
'bot_request_failed' => 'discord_bot_request_failed',
|
2020-12-13 14:32:03 -08:00
|
|
|
'role_set' => 'discord_role_set',
|
2021-02-24 10:37:51 -08:00
|
|
|
],
|
|
|
|
|
'mc_group_sync' => [
|
2024-03-09 03:19:55 -08:00
|
|
|
'role_set' => 'mc_group_sync_set',
|
|
|
|
|
],
|
2020-12-13 19:38:04 +01:00
|
|
|
];
|
2018-04-14 01:13:47 -05:00
|
|
|
|
2021-10-09 10:10:56 -07:00
|
|
|
private DB $_db;
|
2018-04-14 01:13:47 -05:00
|
|
|
|
2024-03-09 03:19:55 -08:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2020-12-13 19:38:04 +01:00
|
|
|
$this->_db = DB::getInstance();
|
|
|
|
|
}
|
2018-04-14 01:13:47 -05:00
|
|
|
|
2020-12-13 19:38:04 +01:00
|
|
|
/**
|
2021-04-12 18:36:34 -07:00
|
|
|
* Get an action from the Action array.
|
2021-12-07 22:14:12 -08:00
|
|
|
*
|
2024-03-09 03:19:55 -08:00
|
|
|
* @param string $path The path to the action.
|
2021-04-12 18:36:34 -07:00
|
|
|
* @return string|array The keys
|
2020-12-13 19:38:04 +01:00
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public static function Action(string $path)
|
|
|
|
|
{
|
2020-12-13 19:38:04 +01:00
|
|
|
$path = explode('/', $path);
|
2020-12-27 14:48:36 -08:00
|
|
|
$config = self::$_actions;
|
2021-04-12 18:36:34 -07:00
|
|
|
|
2020-12-13 19:38:04 +01:00
|
|
|
foreach ($path as $bit) {
|
|
|
|
|
if (isset($config[$bit])) {
|
|
|
|
|
$config = $config[$bit];
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-13 20:42:04 -08:00
|
|
|
|
2020-12-13 19:38:04 +01:00
|
|
|
return $config;
|
|
|
|
|
}
|
2018-04-14 01:13:47 -05:00
|
|
|
|
2020-12-13 19:38:04 +01:00
|
|
|
/**
|
2021-04-12 18:36:34 -07:00
|
|
|
* Logs an action.
|
2021-12-07 22:14:12 -08:00
|
|
|
*
|
2024-03-09 03:19:55 -08:00
|
|
|
* @param string $action The action being logged
|
|
|
|
|
* @param string $info Some more information about what the action is about
|
|
|
|
|
* @param ?int $user The User ID who is doing the action
|
|
|
|
|
* @return bool Return true or false if inserted into the database.
|
2020-12-13 19:38:04 +01:00
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public function log(string $action, string $info = '', ?int $user = null): bool
|
|
|
|
|
{
|
2022-07-03 20:56:15 +02:00
|
|
|
if ($user === null) {
|
2021-10-11 21:31:23 +02:00
|
|
|
$userTemp = new User();
|
2021-01-23 18:54:34 -08:00
|
|
|
$user = ($userTemp->isLoggedIn() ? $userTemp->data()->id : 0);
|
2020-12-13 19:38:04 +01:00
|
|
|
}
|
2021-01-23 18:54:34 -08:00
|
|
|
|
2022-06-13 22:24:43 -06:00
|
|
|
$ip = HttpUtils::getRemoteAddress();
|
2022-06-05 23:47:37 +02:00
|
|
|
|
2021-10-29 22:00:05 -07:00
|
|
|
return $this->_db->insert('logs', [
|
2020-12-13 19:38:04 +01:00
|
|
|
'time' => date('U'),
|
|
|
|
|
'action' => $action,
|
2020-12-30 20:31:25 +00:00
|
|
|
'user_id' => $user,
|
2023-03-30 18:42:40 +01:00
|
|
|
'ip' => $ip ?? 'unknown',
|
2020-12-13 19:38:04 +01:00
|
|
|
'info' => $info,
|
2021-10-29 22:00:05 -07:00
|
|
|
]);
|
2020-12-13 19:38:04 +01:00
|
|
|
}
|
2018-04-14 01:13:47 -05:00
|
|
|
}
|