From 7163c128dc8248d5fa5c52e2c83af2500f8b662a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 5 Dec 2015 15:50:52 -0800 Subject: [PATCH] System.get API - Return MySQL settings --- api/v3/System.php | 53 ++++- api/v3/System/mysql-whitelist.txt | 328 ++++++++++++++++++++++++++++++ 2 files changed, 374 insertions(+), 7 deletions(-) create mode 100644 api/v3/System/mysql-whitelist.txt diff --git a/api/v3/System.php b/api/v3/System.php index f6ef94a64a..7bdfe299e3 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -240,6 +240,7 @@ function civicrm_api3_system_get($params) { ), 'mysql' => array( 'version' => CRM_Core_DAO::singleValueQuery('SELECT @@version'), + 'vars' => _civicrm_api3_system_get_redacted_mysql(), ), 'cms' => array( 'version' => $config->userSystem->getVersion(), @@ -287,13 +288,7 @@ function civicrm_api3_system_get($params) { function _civicrm_api3_system_get_redacted_ini() { static $whitelist = NULL; if ($whitelist === NULL) { - $whitelistFile = __DIR__ . '/System/ini-whitelist.txt'; - $whitelist = array_filter( - explode("\n", file_get_contents($whitelistFile)), - function ($k) { - return !empty($k) && !preg_match('/^\s*#/', $k); - } - ); + $whitelist = _civicrm_api3_system_get_whitelist(__DIR__ . '/System/ini-whitelist.txt'); } $inis = ini_get_all(NULL, FALSE); @@ -309,3 +304,47 @@ function _civicrm_api3_system_get_redacted_ini() { return $result; } + +/** + * Generate ae sanitized/anonymized/redacted dump of MySQL configuration. + * + * @return array + * @see _civicrm_api3_system_get_redacted_ini + */ +function _civicrm_api3_system_get_redacted_mysql() { + static $whitelist = NULL; + if ($whitelist === NULL) { + $whitelist = _civicrm_api3_system_get_whitelist(__DIR__ . '/System/mysql-whitelist.txt'); + } + + $inis = ini_get_all(NULL, FALSE); + $result = array(); + $dao = CRM_Core_DAO::executeQuery('SHOW VARIABLES'); + while ($dao->fetch()) { + if (empty($dao->Variable_name) || in_array($dao->Variable_name, $whitelist)) { + $result[$dao->Variable_name] = $dao->Value; + } + else { + $result[$dao->Variable_name] = 'REDACTED'; + } + } + + return $result; +} + +/** + * Read a whitelist. + * + * @param string $whitelistFile + * Name of a file. Each line is a field name. Comments begin with "#". + * @return array + */ +function _civicrm_api3_system_get_whitelist($whitelistFile) { + $whitelist = array_filter( + explode("\n", file_get_contents($whitelistFile)), + function ($k) { + return !empty($k) && !preg_match('/^\s*#/', $k); + } + ); + return $whitelist; +} diff --git a/api/v3/System/mysql-whitelist.txt b/api/v3/System/mysql-whitelist.txt new file mode 100644 index 0000000000..bd5419e8a8 --- /dev/null +++ b/api/v3/System/mysql-whitelist.txt @@ -0,0 +1,328 @@ +auto_increment_increment +auto_increment_offset +autocommit +automatic_sp_privileges +back_log +#|| basedir | /Applications/MAMP/Library/ | +big_tables +binlog_cache_size +binlog_direct_non_transactional_updates +binlog_format +binlog_stmt_cache_size +bulk_insert_buffer_size +character_set_client +character_set_connection +character_set_database +character_set_filesystem +character_set_results +character_set_server +character_set_system +#|| character_sets_dir | /Applications/MAMP/Library/share/charsets/ | +collation_connection +collation_database +collation_server +#|| completion_type | NO_CHAIN | +concurrent_insert +connect_timeout +#|| datadir | /Users/foobar/.amp/ram_disk/mysql/ | +date_format +datetime_format +default_storage_engine +default_week_format +delay_key_write +delayed_insert_limit +delayed_insert_timeout +delayed_queue_size +#|| div_precision_increment | 4 | +#|| engine_condition_pushdown | ON | +error_count +#|| event_scheduler | OFF | +#|| expire_logs_days | 0 | +#|| external_user | | +flush +flush_time +foreign_key_checks +ft_boolean_syntax +ft_max_word_len +ft_min_word_len +ft_query_expansion_limit +#|| ft_stopword_file | (built-in) | +#|| general_log | OFF | +#|| general_log_file | /Users/foobar/.amp/ram_disk/mysql/whizbangz.log | +group_concat_max_len +have_compress +have_crypt +have_csv +have_dynamic_loading +have_geometry +have_innodb +have_ndbcluster +have_openssl +have_partitioning +have_profiling +have_query_cache +have_rtree_keys +have_ssl +have_symlink +#|| hostname | whizbangz.local | +#|| identity | 0 | +ignore_builtin_innodb +#|| init_connect | | +#|| init_file | | +#|| init_slave | | +innodb_adaptive_flushing +innodb_adaptive_hash_index +innodb_additional_mem_pool_size +innodb_autoextend_increment +innodb_autoinc_lock_mode +innodb_buffer_pool_instances +innodb_buffer_pool_size +#|| innodb_change_buffering | all | +#|| innodb_checksums | ON | +innodb_commit_concurrency +innodb_concurrency_tickets +#|| innodb_data_file_path | ibdata1:10M:autoextend | +#|| innodb_data_home_dir | | +innodb_doublewrite +innodb_fast_shutdown +innodb_file_format +innodb_file_format_check +innodb_file_format_max +innodb_file_per_table +innodb_flush_log_at_trx_commit +#|| innodb_flush_method | | +#|| innodb_force_load_corrupted | OFF | +#|| innodb_force_recovery | 0 | +innodb_io_capacity +#|| innodb_large_prefix | OFF | +innodb_lock_wait_timeout +#|| innodb_locks_unsafe_for_binlog | OFF | +innodb_log_buffer_size +innodb_log_file_size +innodb_log_files_in_group +#|| innodb_log_group_home_dir | ./ | +#|| innodb_max_dirty_pages_pct | 75 | +#|| innodb_max_purge_lag | 0 | +#|| innodb_mirrored_log_groups | 1 | +#|| innodb_old_blocks_pct | 37 | +#|| innodb_old_blocks_time | 0 | +innodb_open_files +innodb_print_all_deadlocks +#|| innodb_purge_batch_size | 20 | +#|| innodb_purge_threads | 0 | +#|| innodb_random_read_ahead | OFF | +#|| innodb_read_ahead_threshold | 56 | +#|| innodb_read_io_threads | 4 | +innodb_replication_delay +innodb_rollback_on_timeout +innodb_rollback_segments +innodb_spin_wait_delay +innodb_stats_method +#|| innodb_stats_on_metadata | ON | +#|| innodb_stats_sample_pages | 8 | +innodb_strict_mode +innodb_support_xa +innodb_sync_spin_loops +innodb_table_locks +innodb_thread_concurrency +#|| innodb_thread_sleep_delay | 10000 | +#|| innodb_use_native_aio | OFF | +#|| innodb_use_sys_malloc | ON | +innodb_version +innodb_write_io_threads +#|| insert_id | 0 | +#|| interactive_timeout | 28800 | +join_buffer_size +#|| keep_files_on_create | OFF | +key_buffer_size +key_cache_age_threshold +key_cache_block_size +key_cache_division_limit +large_files_support +large_page_size +large_pages +#|| last_insert_id | 0 | +lc_messages +#|| lc_messages_dir | /Applications/MAMP/Library/share/ | +lc_time_names +#|| license | GPL | +#|| local_infile | ON | +lock_wait_timeout +#|| locked_in_memory | OFF | +#|| log | OFF | +#|| log_bin | OFF | +#|| log_bin_trust_function_creators | OFF | +#|| log_error | | +#|| log_output | FILE | +#|| log_queries_not_using_indexes | OFF | +#|| log_slave_updates | OFF | +#|| log_slow_queries | OFF | +#|| log_warnings | 1 | +long_query_time +#|| low_priority_updates | OFF | +lower_case_file_system +lower_case_table_names +max_allowed_packet +max_binlog_cache_size +max_binlog_size +max_binlog_stmt_cache_size +max_connect_errors +max_connections +max_delayed_threads +max_error_count +max_heap_table_size +max_insert_delayed_threads +max_join_size +max_length_for_sort_data +max_long_data_size +max_prepared_stmt_count +max_relay_log_size +max_seeks_for_key +max_sort_length +max_sp_recursion_depth +max_tmp_tables +max_user_connections +max_write_lock_count +metadata_locks_cache_size +#|| min_examined_row_limit | 0 | +#|| multi_range_count | 256 | +#|| myisam_data_pointer_size | 6 | +#|| myisam_max_sort_file_size | 9223372036853727232 | +#|| myisam_mmap_size | 18446744073709551615 | +#|| myisam_recover_options | OFF | +#|| myisam_repair_threads | 1 | +#|| myisam_sort_buffer_size | 8388608 | +#|| myisam_stats_method | nulls_unequal | +#|| myisam_use_mmap | OFF | +net_buffer_length +net_read_timeout +net_retry_count +net_write_timeout +#|| new | OFF | +#|| old | OFF | +#|| old_alter_table | OFF | +#|| old_passwords | OFF | +#|| open_files_limit | 961 | +optimizer_prune_level +optimizer_search_depth +#|| optimizer_switch | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on | +#|| performance_schema | OFF | +#|| performance_schema_events_waits_history_long_size | 10000 | +#|| performance_schema_events_waits_history_size | 10 | +#|| performance_schema_max_cond_classes | 80 | +#|| performance_schema_max_cond_instances | 1000 | +#|| performance_schema_max_file_classes | 50 | +#|| performance_schema_max_file_handles | 32768 | +#|| performance_schema_max_file_instances | 10000 | +#|| performance_schema_max_mutex_classes | 200 | +#|| performance_schema_max_mutex_instances | 1000000 | +#|| performance_schema_max_rwlock_classes | 30 | +#|| performance_schema_max_rwlock_instances | 1000000 | +#|| performance_schema_max_table_handles | 100000 | +#|| performance_schema_max_table_instances | 50000 | +#|| performance_schema_max_thread_classes | 50 | +#|| performance_schema_max_thread_instances | 1000 | +#|| pid_file | /Users/foobar/.amp/ram_disk/tmp/mysqld.pid | +#|| plugin_dir | /Applications/MAMP/Library/lib/plugin/ | +#|| port | 3307 | +#|| preload_buffer_size | 32768 | +profiling +profiling_history_size +protocol_version +#|| proxy_user | | +#|| pseudo_slave_mode | OFF | +#|| pseudo_thread_id | 834 | +query_alloc_block_size +query_cache_limit +query_cache_min_res_unit +query_cache_size +query_cache_type +query_cache_wlock_invalidate +query_prealloc_size +#|| rand_seed1 | 0 | +#|| rand_seed2 | 0 | +#|| range_alloc_block_size | 4096 | +read_buffer_size +read_only +read_rnd_buffer_size +#|| relay_log | | +#|| relay_log_index | | +#|| relay_log_info_file | relay-log.info | +#|| relay_log_purge | ON | +#|| relay_log_recovery | OFF | +#|| relay_log_space_limit | 0 | +#|| report_host | | +#|| report_password | | +#|| report_port | 3307 | +#|| report_user | | +#|| rpl_recovery_rank | 0 | +#|| secure_auth | OFF | +#|| secure_file_priv | | +#|| server_id | 0 | +#|| skip_external_locking | ON | +#|| skip_name_resolve | OFF | +skip_networking +#|| skip_show_database | OFF | +#|| slave_compressed_protocol | OFF | +#|| slave_exec_mode | STRICT | +#|| slave_load_tmpdir | /Users/foobar/.amp/ram_disk/tmp | +#|| slave_max_allowed_packet | 1073741824 | +#|| slave_net_timeout | 3600 | +#|| slave_skip_errors | OFF | +#|| slave_transaction_retries | 10 | +#|| slave_type_conversions | | +#|| slow_launch_time | 2 | +#|| slow_query_log | OFF | +#|| slow_query_log_file | /Users/foobar/.amp/ram_disk/mysql/whizbangz-slow.log | +#|| socket | /Users/foobar/.amp/ram_disk/tmp/mysqld.sock | +#|| sort_buffer_size | 2097152 | +sql_auto_is_null +sql_big_selects +sql_big_tables +sql_log_bin +sql_log_off +sql_low_priority_updates +sql_max_join_size +sql_mode +sql_notes +sql_quote_show_create +sql_safe_updates +sql_select_limit +sql_slave_skip_counter +sql_warnings +#|| ssl_ca | | +#|| ssl_capath | | +#|| ssl_cert | | +#|| ssl_cipher | | +#|| ssl_key | | +storage_engine +stored_program_cache +#|| sync_binlog | 0 | +#|| sync_frm | ON | +#|| sync_master_info | 0 | +#|| sync_relay_log | 0 | +#|| sync_relay_log_info | 0 | +system_time_zone +table_definition_cache +table_open_cache +thread_cache_size +thread_concurrency +thread_handling +thread_stack +time_format +time_zone +timed_mutexes +#|| timestamp | 1449353441 | +tmp_table_size +#|| tmpdir | /Users/foobar/.amp/ram_disk/tmp | +transaction_alloc_block_size +transaction_prealloc_size +tx_isolation +unique_checks +updatable_views_with_limit +version +version_comment +version_compile_machine +version_compile_os +wait_timeout +warning_count -- 2.25.1