System.get API - Return MySQL settings
[civicrm-core.git] / api / v3 / System.php
index f6ef94a64a6040ef9a138d9c875d5548cd775191..7bdfe299e3876759e96f2704700e1ceba0fc1c77 100644 (file)
@@ -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;
+}