2021-10-13 21:46:34 -07:00
< ? php
2021-11-22 05:25:21 +01:00
// Can user generate the debug link?
2022-04-29 15:18:39 +02:00
if ( ! defined ( 'DEBUGGING' ) && ! $user -> hasPermission ( 'admincp.core.debugging' )) {
2021-11-22 05:25:21 +01:00
require_once ( ROOT_PATH . '/403.php' );
die ();
}
2021-10-13 21:46:34 -07:00
$namelessmc_modules = [];
$namelessmc_fe_templates = [];
$namelessmc_panel_templates = [];
2021-11-02 16:24:38 -07:00
// Get all modules
2022-05-28 14:10:01 +02:00
$modules = DB :: getInstance () -> get ( 'modules' , [ 'id' , '<>' , 0 ]) -> results ();
2021-11-02 16:24:38 -07:00
$enabled_modules = Module :: getModules ();
2021-10-16 15:48:48 -07:00
2021-11-02 16:24:38 -07:00
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' );
2021-10-16 15:48:48 -07:00
}
2021-10-13 21:46:34 -07:00
$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 (),
];
}
2022-05-28 14:10:01 +02:00
$templates_query = DB :: getInstance () -> get ( 'templates' , [ 'id' , '<>' , 0 ]) -> results ();
2021-10-13 21:46:34 -07:00
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' ]);
2021-10-13 21:46:34 -07:00
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 ,
2025-06-04 21:45:50 -07:00
'is_default' => ( bool ) Settings :: get ( 'default_template' ) === $fe_template -> name ,
2021-10-13 21:46:34 -07:00
'author' => $template -> getAuthor (),
'template_version' => $template -> getVersion (),
'namelessmc_version' => $template -> getNamelessVersion (),
];
}
2022-05-28 14:10:01 +02:00
$panel_templates_query = DB :: getInstance () -> get ( 'panel_templates' , [ 'id' , '<>' , 0 ]) -> results ();
2021-10-13 21:46:34 -07:00
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' ]);
2021-10-13 21:46:34 -07:00
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 ,
2025-06-04 21:45:50 -07:00
'is_default' => ( bool ) Settings :: get ( 'default_panel_template' ) === $panel_template -> name ,
2021-10-13 21:46:34 -07:00
'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 (),
];
}
2021-11-10 17:48:54 -08:00
$group_sync [ 'rules' ] = [];
2021-10-13 21:46:34 -07:00
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 ;
2021-10-13 21:46:34 -07:00
} else {
$rules [ $column ] = $value ;
}
}
2021-12-07 22:14:12 -08:00
$group_sync [ 'rules' ][( int ) $rule -> id ] = $rules ;
2021-10-13 21:46:34 -07:00
}
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 = [];
2022-04-17 16:53:58 -07:00
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
];
}
2022-06-10 23:15:05 -06:00
$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 ],
];
}
2023-06-12 10:30:49 -06:00
$namelessmc_version = Settings :: get ( 'nameless_version' );
2021-10-13 21:46:34 -07:00
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 ]);
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 ) {
2022-04-28 05:43:54 +00:00
$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 = [
2025-05-11 14:57:43 +02:00
'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
];
}
2025-05-11 14:57:43 +02:00
$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 ,
];
}
2021-10-13 21:46:34 -07:00
$data = [
2021-10-14 16:27:20 -07:00
'generated_at' => time (),
2021-10-16 12:11:33 -07:00
'generated_by_name' => $user -> data () -> username ,
2022-04-16 18:42:24 +02:00
'generated_by_uuid' => $uuid ,
2023-01-15 18:40:35 +01:00
'user' => $user_data ,
2021-10-13 21:46:34 -07:00
'namelessmc' => [
2022-02-22 13:15:47 -08:00
'version' => $namelessmc_version ,
2023-06-12 10:30:49 -06:00
'update_available' => Settings :: get ( 'version_update' ) === 'urgent' || Settings :: get ( 'version_update' ) === 'true' ,
'update_checked' => ( int ) Settings :: get ( 'version_checked' ),
2021-10-13 21:46:34 -07:00
'settings' => [
2023-06-12 10:30:49 -06:00
'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
2021-10-13 21:46:34 -07:00
'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-10-13 21:46:34 -07:00
],
2021-11-02 20:20:57 -07:00
'groups' => $groups ,
2021-10-13 21:46:34 -07:00
'config' => [
2021-11-21 21:09:37 -08:00
'core' => array_filter (
2022-06-13 02:21:21 +00:00
Config :: get ( 'core' ),
static fn ( string $key ) => $key !== 'hostname' && $key !== 'trustedProxies' ,
2021-11-21 21:09:37 -08:00
ARRAY_FILTER_USE_KEY
),
2021-10-13 21:46:34 -07:00
],
2021-10-16 12:11:33 -07:00
'modules' => $namelessmc_modules ,
'templates' => [
'front_end' => $namelessmc_fe_templates ,
'panel' => $namelessmc_panel_templates ,
],
2022-04-24 17:51:31 +02:00
'integrations' => $integrations ,
2022-06-10 23:15:05 -06:00
'oauth_providers' => $oauth_providers ,
2021-10-13 21:46:34 -07:00
],
2022-04-26 22:30:58 -07:00
'logs' => [
'fatal' => $logs [ 'fatal' ],
'warning' => $logs [ 'warning' ],
'notice' => $logs [ 'notice' ],
'other' => $logs [ 'other' ],
'custom' => $logs [ 'custom' ],
2025-05-11 14:57:43 +02:00
'group_sync' => $group_sync_logs ,
2022-04-26 22:30:58 -07:00
],
2021-11-09 16:51:06 -08:00
'environment' => [
2022-01-15 15:18:05 -08:00
'php_version' => PHP_VERSION ,
2021-10-13 21:46:34 -07:00
'php_modules' => get_loaded_extensions (),
2021-11-21 21:09:37 -08:00
'host_os' => PHP_OS ,
2021-10-13 21:46:34 -07:00
'host_kernel_version' => php_uname ( 'r' ),
2021-10-14 16:27:20 -07:00
'official_docker_image' => getenv ( 'NAMELESSMC_METRICS_DOCKER' ) == true ,
2021-10-16 12:11:33 -07:00
'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' ),
2021-10-13 21:46:34 -07:00
],
];
2022-02-22 13:15:47 -08:00
$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 );
2021-10-13 21:46:34 -07:00
2022-01-30 19:37:28 -08:00
die ( 'https://debug.namelessmc.com/' . $result [ 'key' ]);