mc-cms-namelessmc/modules/Core/queries/debug_link.php

286 lines
10 KiB
PHP
Raw Permalink Normal View History

<?php
// Can user generate the debug link?
2022-04-29 15:18:39 +02:00
if (!defined('DEBUGGING') && !$user->hasPermission('admincp.core.debugging')) {
require_once(ROOT_PATH . '/403.php');
die();
}
$namelessmc_modules = [];
$namelessmc_fe_templates = [];
$namelessmc_panel_templates = [];
// Get all modules
$modules = DB::getInstance()->get('modules', ['id', '<>', 0])->results();
$enabled_modules = Module::getModules();
foreach ($modules as $item) {
$exists = false;
foreach ($enabled_modules as $enabled_item) {
if ($enabled_item->getName() == $item->name) {
$exists = true;
$module = $enabled_item;
break;
}
}
if (!$exists) {
if (!file_exists(ROOT_PATH . '/modules/' . $item->name . '/init.php')) {
continue;
}
require_once(ROOT_PATH . '/modules/' . $item->name . '/init.php');
}
$namelessmc_modules[$module->getName()] = [
'name' => $module->getName(),
'enabled' => Util::isModuleEnabled($module->getName()),
'author' => $module->getAuthor(),
'module_version' => $module->getVersion(),
'namelessmc_version' => $module->getNamelessVersion(),
'debug_info' => $module->getDebugInfo(),
];
}
$templates_query = DB::getInstance()->get('templates', ['id', '<>', 0])->results();
foreach ($templates_query as $fe_template) {
2022-03-31 21:56:57 +02:00
$template_path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'custom', 'templates', Output::getClean($fe_template->name), 'template.php']);
if (file_exists($template_path)) {
require_once($template_path);
}
$namelessmc_fe_templates[$fe_template->name] = [
'name' => $fe_template->name,
2021-12-07 22:14:12 -08:00
'enabled' => (bool)$fe_template->enabled,
'is_default' => (bool)Settings::get('default_template') === $fe_template->name,
'author' => $template->getAuthor(),
'template_version' => $template->getVersion(),
'namelessmc_version' => $template->getNamelessVersion(),
];
}
$panel_templates_query = DB::getInstance()->get('panel_templates', ['id', '<>', 0])->results();
foreach ($panel_templates_query as $panel_template) {
2022-03-31 21:56:57 +02:00
$template_path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'custom', 'panel_templates', Output::getClean($panel_template->name), 'template.php']);
if (file_exists($template_path)) {
require_once($template_path);
}
$namelessmc_panel_templates[$panel_template->name] = [
'name' => $panel_template->name,
2021-12-07 22:14:12 -08:00
'enabled' => (bool)$panel_template->enabled,
'is_default' => (bool)Settings::get('default_panel_template') === $panel_template->name,
'author' => $template->getAuthor(),
'template_version' => $template->getVersion(),
'namelessmc_version' => $template->getNamelessVersion(),
];
}
$group_sync = [];
foreach (GroupSyncManager::getInstance()->getInjectors() as $injector) {
$group_sync['injectors'][] = [
'name' => $injector->getName(),
'enabled' => $injector->shouldEnable(),
'module' => $injector->getModule(),
'column_name' => $injector->getColumnName(),
];
}
$group_sync['rules'] = [];
foreach (DB::getInstance()->get('group_sync', ['id', '<>', 0])->results() as $rule) {
$rules = [];
foreach (get_object_vars($rule) as $column => $value) {
if ($column == 'id') {
2021-12-07 22:14:12 -08:00
$rules[$column] = (int)$value;
} else {
$rules[$column] = $value;
}
}
2021-12-07 22:14:12 -08:00
$group_sync['rules'][(int)$rule->id] = $rules;
}
2021-11-21 21:09:37 -08:00
$webhooks = [];
2022-05-01 23:16:22 -07:00
foreach (DB::getInstance()->query('SELECT `id`, `name`, `action`, `events` FROM nl2_hooks')->results() as $webhook) {
2021-11-21 21:09:37 -08:00
$webhooks[$webhook->id] = [
2021-12-07 22:14:12 -08:00
'id' => (int)$webhook->id,
2021-11-21 21:09:37 -08:00
'name' => $webhook->name,
2021-12-07 22:14:12 -08:00
'action' => (int)$webhook->action,
2021-11-21 21:09:37 -08:00
'events' => json_decode($webhook->events),
];
}
$forum_hooks = [];
2022-05-01 23:16:22 -07:00
foreach (DB::getInstance()->query('SELECT `id`, `forum_title`, `hooks` FROM nl2_forums WHERE `hooks` IS NOT NULL')->results() as $forum) {
2021-11-21 21:09:37 -08:00
$forum_hooks[] = [
2021-12-07 22:14:12 -08:00
'forum_id' => (int)$forum->id,
2021-11-21 21:09:37 -08:00
'title' => $forum->forum_title,
2021-12-07 22:14:12 -08:00
'hooks' => array_map(static fn($hook) => (int)$hook, json_decode($forum->hooks)),
2021-11-21 21:09:37 -08:00
];
}
2021-11-02 20:20:57 -07:00
$groups = [];
foreach (Group::all() as $group) {
2021-12-07 22:14:12 -08:00
$groups[(int)$group->id] = [
'id' => (int)$group->id,
2021-11-02 20:20:57 -07:00
'name' => $group->name,
'group_html' => $group->group_html,
2021-12-07 22:14:12 -08:00
'admin_cp' => (bool)$group->admin_cp,
'staff' => (bool)$group->staff,
2021-11-02 20:20:57 -07:00
'permissions' => json_decode($group->permissions, true) ?? [],
2021-12-07 22:14:12 -08:00
'default_group' => (bool)$group->default_group,
'order' => (int)$group->order,
'force_tfa' => (bool)$group->force_tfa,
'deleted' => (bool)$group->deleted,
2021-11-02 20:20:57 -07:00
];
}
2022-04-24 17:51:31 +02:00
$integrations = [];
foreach (Integrations::getInstance()->getAll() as $integration) {
$integrations[$integration->getName()] = [
'id' => (int) $integration->data()->id,
'name' => $integration->data()->name,
'enabled' => (bool) $integration->data()->enabled,
'can_unlink' => (bool) $integration->data()->can_unlink,
'required' => (bool) $integration->data()->required,
'order' => (int) $integration->data()->order
];
}
$oauth_providers = [];
$providers_available = array_keys(NamelessOAuth::getInstance()->getProvidersAvailable());
foreach (NamelessOAuth::getInstance()->getProviders() as $provider_name => $data) {
$oauth_providers[$provider_name] = [
'provider_name' => $provider_name,
'module' => $data['module'],
'class' => $data['class'],
'user_id_name' => $data['user_id_name'],
'scope_id_name' => $data['scope_id_name'],
'enabled' => in_array($provider_name, $providers_available),
'client_id' => NamelessOAuth::getInstance()->getCredentials($provider_name)[0],
];
}
$namelessmc_version = Settings::get('nameless_version');
2022-05-01 23:16:22 -07:00
$uuid = DB::getInstance()->query('SELECT identifier FROM nl2_users_integrations INNER JOIN nl2_integrations on integration_id=nl2_integrations.id WHERE name = \'Minecraft\' AND user_id = ?;', [$user->data()->id]);
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
if ($uuid->count()) {
$uuid = $uuid->first()->identifier;
} else {
$uuid = '';
}
2022-04-26 22:30:58 -07:00
$logs = [];
foreach (['fatal', 'warning', 'notice', 'other', 'custom'] as $type) {
$file_path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'cache', 'logs', $type . '-log.log']);
2022-06-02 20:50:53 +02:00
$logs[$type] = file_exists($file_path) ? Util::readFileEnd($file_path, $max_bytes = 10_000) : '';
2022-04-26 22:30:58 -07:00
}
2023-01-15 14:49:18 +01:00
$user_data = [];
if ($user->isLoggedIn()) {
$user_integrations = [];
foreach ($user->getIntegrations() as $integrationUser) {
$user_integrations[$integrationUser->getIntegration()->getName()] = [
'username' => $integrationUser->data()->username,
'identifier' => $integrationUser->data()->identifier,
2023-01-15 18:40:35 +01:00
'verified' => $integrationUser->data()->verified
2023-01-15 14:49:18 +01:00
];
}
$user_data = [
'id' => (int)$user->data()->id,
2023-01-15 14:49:18 +01:00
'username' => $user->data()->username,
'nickname' => $user->getDisplayname(),
2023-01-15 18:41:55 +01:00
'groups' => array_values($user->getAllGroupIds()),
2023-01-15 14:49:18 +01:00
'integrations' => $user_integrations
];
}
$group_sync_logs = [];
$logs_set = DB::getInstance()->orderWhere('logs', 'action LIKE \'%_role_set\' OR action LIKE \'%_group_set\'OR action = \'mc_group_sync_set\' ', 'time', 'DESC LIMIT 50')->results();
foreach ($logs_set as $log) {
$group_sync_logs[] = [
'time' => $log->time,
'user_id' => $log->user_id,
'action' => $log->action,
'info' => json_decode($log->info, true) ?? $log->info,
];
}
$data = [
2021-10-14 16:27:20 -07:00
'generated_at' => time(),
'generated_by_name' => $user->data()->username,
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
'generated_by_uuid' => $uuid,
2023-01-15 18:40:35 +01:00
'user' => $user_data,
'namelessmc' => [
'version' => $namelessmc_version,
'update_available' => Settings::get('version_update') === 'urgent' || Settings::get('version_update') === 'true',
'update_checked' => (int) Settings::get('version_checked'),
'settings' => [
'phpmailer' => Settings::get('phpmailer') === '1',
'api_enabled' => Settings::get('use_api') === '1',
'email_verification' => Settings::get('email_verification') === '1',
'login_method' => Settings::get('login_method'),
'captcha_type' => Settings::get('recaptcha_type'),
'captcha_login' => Settings::get('recaptcha_login') === 'false' ? false : true, // dont ask
'group_sync' => $group_sync,
2021-11-21 21:09:37 -08:00
'webhooks' => [
'actions' => [
2 => 'Discord',
],
'hooks' => $webhooks,
'forum_hooks' => $forum_hooks,
],
2022-06-13 22:24:43 -06:00
'trusted_proxies' => HttpUtils::getTrustedProxies(),
],
2021-11-02 20:20:57 -07:00
'groups' => $groups,
'config' => [
2021-11-21 21:09:37 -08:00
'core' => array_filter(
Config::get('core'),
static fn(string $key) => $key !== 'hostname' && $key !== 'trustedProxies',
2021-11-21 21:09:37 -08:00
ARRAY_FILTER_USE_KEY
),
],
'modules' => $namelessmc_modules,
'templates' => [
'front_end' => $namelessmc_fe_templates,
'panel' => $namelessmc_panel_templates,
],
2022-04-24 17:51:31 +02:00
'integrations' => $integrations,
'oauth_providers' => $oauth_providers,
],
2022-04-26 22:30:58 -07:00
'logs' => [
'fatal' => $logs['fatal'],
'warning' => $logs['warning'],
'notice' => $logs['notice'],
'other' => $logs['other'],
'custom' => $logs['custom'],
'group_sync' => $group_sync_logs,
2022-04-26 22:30:58 -07:00
],
'environment' => [
2022-01-15 15:18:05 -08:00
'php_version' => PHP_VERSION,
'php_modules' => get_loaded_extensions(),
2021-11-21 21:09:37 -08:00
'host_os' => PHP_OS,
'host_kernel_version' => php_uname('r'),
2021-10-14 16:27:20 -07:00
'official_docker_image' => getenv('NAMELESSMC_METRICS_DOCKER') == true,
'disk_total_space' => disk_total_space('./'),
'disk_free_space' => disk_free_space('./'),
'memory_total_space' => ini_get('memory_limit'),
2021-10-18 21:15:42 -07:00
'memory_used_space' => memory_get_usage(),
2021-10-18 21:31:05 -07:00
'config_writable' => is_writable(ROOT_PATH . '/core/config.php'),
2021-10-18 21:28:57 -07:00
'cache_writable' => is_writable(ROOT_PATH . '/cache'),
],
];
$result = HttpClient::post('https://bytebin.rkslot.nl/post', json_encode($data, JSON_PRETTY_PRINT), [
'headers' => [
'Content-Type' => 'application/json',
'User-Agent' => 'NamelessMC/' . $namelessmc_version,
],
])->json(true);
die('https://debug.namelessmc.com/' . $result['key']);