3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM system functionality.
31 * Includes caching, logging, and checking system functionality.
33 * @package CiviCRM_APIv3
37 * Flush all system caches.
39 * @param array $params
41 * - triggers: bool, whether to drop/create SQL triggers; default: FALSE
42 * - session: bool, whether to reset the CiviCRM session data; default: FALSE
46 function civicrm_api3_system_flush($params) {
47 CRM_Core_Invoke
::rebuildMenuAndCaches(
48 CRM_Utils_Array
::value('triggers', $params, FALSE),
49 CRM_Utils_Array
::value('session', $params, FALSE)
51 return civicrm_api3_create_success();
55 * Adjust Metadata for Flush action.
57 * The metadata is used for setting defaults, documentation & validation.
59 * @param array $params
60 * Array of parameters determined by getfields.
62 function _civicrm_api3_system_flush_spec(&$params) {
63 $params['triggers'] = array(
64 'title' => 'Triggers',
65 'description' => 'rebuild triggers (boolean)',
66 'type' => CRM_Utils_Type
::T_BOOLEAN
,
68 $params['session'] = array(
69 'title' => 'Sessions',
70 'description' => 'refresh sessions (boolean)',
71 'type' => CRM_Utils_Type
::T_BOOLEAN
,
76 * System.Check API specification (optional).
78 * This is used for documentation and validation.
81 * Description of fields supported by this API call.
83 * @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
85 function _civicrm_api3_system_check_spec(&$spec) {
88 'description' => 'Not a real identifier - do not use',
89 'type' => CRM_Utils_Type
::T_INT
,
91 $spec['name'] = array(
93 'description' => 'Unique identifier',
94 'type' => CRM_Utils_Type
::T_STRING
,
96 $spec['title'] = array(
98 'description' => 'Short title text',
99 'type' => CRM_Utils_Type
::T_STRING
,
101 $spec['message'] = array(
102 'title' => 'Message',
103 'description' => 'Long description html',
104 'type' => CRM_Utils_Type
::T_STRING
,
106 $spec['help'] = array(
108 'description' => 'Optional extra help (html string)',
109 'type' => CRM_Utils_Type
::T_STRING
,
111 $spec['severity'] = array(
112 'title' => 'Severity',
113 'description' => 'Psr\Log\LogLevel string',
114 'type' => CRM_Utils_Type
::T_STRING
,
115 'options' => array_combine(CRM_Utils_Check
::getSeverityList(), CRM_Utils_Check
::getSeverityList()),
117 $spec['severity_id'] = array(
118 'title' => 'Severity ID',
119 'description' => 'Integer representation of Psr\Log\LogLevel',
120 'type' => CRM_Utils_Type
::T_INT
,
121 'options' => CRM_Utils_Check
::getSeverityList(),
123 $spec['is_visible'] = array(
124 'title' => 'is visible',
125 'description' => '0 if message has been hidden by the user',
126 'type' => CRM_Utils_Type
::T_BOOLEAN
,
128 $spec['hidden_until'] = array(
129 'title' => 'Hidden_until',
130 'description' => 'When will hidden message be visible again?',
131 'type' => CRM_Utils_Type
::T_DATE
,
138 * @param array $params
141 * API result descriptor; return items are alert codes/messages
142 * @see civicrm_api3_create_success
143 * @see civicrm_api3_create_error
144 * @throws API_Exception
146 function civicrm_api3_system_check($params) {
147 // array(array('name'=> $, 'severity'=>$, ...))
149 $returnValues = $fields = array();
150 _civicrm_api3_system_check_spec($fields);
152 // array(CRM_Utils_Check_Message)
153 $messages = CRM_Utils_Check
::checkAll();
155 foreach ($messages as $msg) {
156 $returnValues[] = $msg->toArray() +
array('id' => $id++
);
159 return _civicrm_api3_basic_array_get('systemCheck', $params, $returnValues, "id", array_keys($fields));
163 * Log entry to system log table.
165 * @param array $params
169 function civicrm_api3_system_log($params) {
170 $log = new CRM_Utils_SystemLogger();
171 // This part means fields with separate db storage are accepted as params which kind of seems more intuitive to me
172 // because I felt like not doing this required a bunch of explanation in the spec function - but perhaps other won't see it as helpful?
173 if (!isset($params['context'])) {
174 $params['context'] = array();
176 $specialFields = array('contact_id', 'hostname');
177 foreach ($specialFields as $specialField) {
178 if (isset($params[$specialField]) && !isset($params['context'])) {
179 $params['context'][$specialField] = $params[$specialField];
182 $returnValues = $log->log($params['level'], $params['message'], $params['context']);
183 return civicrm_api3_create_success($returnValues, $params, 'System', 'Log');
187 * Metadata for log function.
189 * @param array $params
191 function _civicrm_api3_system_log_spec(&$params) {
192 $params['level'] = array(
193 'title' => 'Log Level',
194 'description' => 'Log level as described in PSR3 (info, debug, warning etc)',
195 'type' => CRM_Utils_Type
::T_STRING
,
196 'api.required' => TRUE,
198 $params['message'] = array(
199 'title' => 'Log Message',
200 'description' => 'Standardised message string, you can also ',
201 'type' => CRM_Utils_Type
::T_STRING
,
202 'api.required' => TRUE,
204 $params['context'] = array(
205 'title' => 'Log Context',
206 'description' => 'An array of additional data to store.',
207 'type' => CRM_Utils_Type
::T_LONGTEXT
,
208 'api.default' => array(),
210 $params['contact_id'] = array(
211 'title' => 'Log Contact ID',
212 'description' => 'Optional ID of relevant contact',
213 'type' => CRM_Utils_Type
::T_INT
,
215 $params['hostname'] = array(
216 'title' => 'Log Hostname',
217 'description' => 'Optional name of host',
218 'type' => CRM_Utils_Type
::T_STRING
,
225 * @param array $params
229 function civicrm_api3_system_get($params) {
230 $config = CRM_Core_Config
::singleton();
231 $returnValues = array(
233 'version' => CRM_Utils_System
::version(), // deprecated in favor of civi.version
234 'uf' => CIVICRM_UF
, // deprecated in favor of cms.type
236 'version' => phpversion(),
238 'tz' => date_default_timezone_get(),
239 'sapi' => php_sapi_name(),
240 'extensions' => get_loaded_extensions(),
241 'ini' => _civicrm_api3_system_get_redacted_ini(),
244 'version' => CRM_Core_DAO
::singleValueQuery('SELECT @@version'),
245 'time' => CRM_Core_DAO
::singleValueQuery('SELECT unix_timestamp()'),
246 'vars' => _civicrm_api3_system_get_redacted_mysql(),
249 'version' => $config->userSystem
->getVersion(),
250 'type' => CIVICRM_UF
,
251 'modules' => CRM_Core_Module
::collectStatuses($config->userSystem
->getModules()),
254 'version' => CRM_Utils_System
::version(),
255 'dev' => (bool) CRM_Utils_System
::isDevelopment(),
256 'components' => array_keys(CRM_Core_Component
::getEnabledComponents()),
257 'extensions' => preg_grep(
259 CRM_Extension_System
::singleton()->getManager()->getStatuses(),
262 'domains' => CRM_Core_DAO
::singleValueQuery('SELECT count(*) FROM civicrm_domain'),
263 'languageLimit' => CRM_Core_Config
::singleton()->languageLimit
,
264 'lcMessages' => CRM_Core_Config
::singleton()->lcMessages
,
265 'exampleUrl' => CRM_Utils_System
::url('civicrm/example', NULL, TRUE, NULL, FALSE),
268 'software' => CRM_Utils_Array
::value('SERVER_SOFTWARE', $_SERVER),
269 'forwarded' => !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ||
!empty($_SERVER['X_FORWARDED_PROTO']),
270 'port' => (empty($_SERVER['SERVER_PORT']) ||
$_SERVER['SERVER_PORT'] == 80 ||
$_SERVER['SERVER_PORT'] == 443) ?
'Standard' : 'Nonstandard',
273 'type' => php_uname('s'),
274 'release' => php_uname('r'),
275 'version' => php_uname('v'),
276 'machine' => php_uname('m'),
281 return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
285 * Generate a sanitized/anonymized/redacted dump of the PHP configuration.
287 * Some INI fields contain site-identifying information (SII) -- e.g. URLs,
288 * hostnames, file paths, IP addresses, passwords, or free-form comments
289 * could be used to identify a site or gain access to its resources.
291 * A number of INI fields have been examined to determine whether they
292 * contain SII. Approved fields are put in a whitelist; all other fields
295 * Redaction hides the substance of a field but does not completely omit
296 * all information. Consider the field 'mail.log' - setting this field
297 * has a functional effect (it enables or disables the logging behavior)
298 * and also points to particular file. Empty values (FALSE/NULL/0/"")
299 * will pass through redaction, but all other values will be replaced
300 * by a string (eg "REDACTED"). This roughly indicates whether the
301 * option is enabled/disabled without giving away its content.
305 function _civicrm_api3_system_get_redacted_ini() {
306 static $whitelist = NULL;
307 if ($whitelist === NULL) {
308 $whitelist = _civicrm_api3_system_get_whitelist(__DIR__
. '/System/ini-whitelist.txt');
311 $inis = ini_get_all(NULL, FALSE);
313 foreach ($inis as $k => $v) {
314 if (empty($v) ||
in_array($k, $whitelist)) {
318 $result[$k] = 'REDACTED';
326 * Generate ae sanitized/anonymized/redacted dump of MySQL configuration.
329 * @see _civicrm_api3_system_get_redacted_ini
331 function _civicrm_api3_system_get_redacted_mysql() {
332 static $whitelist = NULL;
333 if ($whitelist === NULL) {
334 $whitelist = _civicrm_api3_system_get_whitelist(__DIR__
. '/System/mysql-whitelist.txt');
337 $inis = ini_get_all(NULL, FALSE);
339 $dao = CRM_Core_DAO
::executeQuery('SHOW VARIABLES');
340 while ($dao->fetch()) {
341 if (empty($dao->Variable_name
) ||
in_array($dao->Variable_name
, $whitelist)) {
342 $result[$dao->Variable_name
] = $dao->Value
;
345 $result[$dao->Variable_name
] = 'REDACTED';
355 * @param string $whitelistFile
356 * Name of a file. Each line is a field name. Comments begin with "#".
359 function _civicrm_api3_system_get_whitelist($whitelistFile) {
360 $whitelist = array_filter(
361 explode("\n", file_get_contents($whitelistFile)),
363 return !empty($k) && !preg_match('/^\s*#/', $k);