comment fixes
[civicrm-core.git] / CRM / Core / IDS.php
index c785482eb472d972d9cf9fad3b140d7748a164d1..85180ef6beaa0c6a43a54a3bdb69877095168057 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
- * $Id$
- *
+ * @copyright CiviCRM LLC (c) 2004-2015
  */
 class CRM_Core_IDS {
 
   /**
-   * Define the threshold for the ids reactions
+   * Define the threshold for the ids reactions.
    */
   private $threshold = array(
     'log' => 25,
@@ -49,22 +47,24 @@ class CRM_Core_IDS {
   private $init = NULL;
 
   /**
+   * Check function.
+   *
    * This function includes the IDS vendor parts and runs the
    * detection routines on the request array.
    *
-   * @param object cake controller object
+   * @param object $args cake controller object
    *
-   * @return boolean
+   * @return bool
    */
   public function check(&$args) {
     // lets bypass a few civicrm urls from this check
     static $skip = array('civicrm/admin/setting/updateConfigBackend', 'civicrm/admin/messageTemplates');
     $path = implode('/', $args);
     if (in_array($path, $skip)) {
-      return;
+      return NULL;
     }
 
-    #add request url and user agent
+    // Add request url and user agent.
     $_REQUEST['IDS_request_uri'] = $_SERVER['REQUEST_URI'];
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
       $_REQUEST['IDS_user_agent'] = $_SERVER['HTTP_USER_AGENT'];
@@ -76,13 +76,14 @@ class CRM_Core_IDS {
     require_once 'IDS/Init.php';
     try {
       $init = IDS_Init::init($configFile);
-      $ids  = new IDS_Monitor($_REQUEST, $init);
-    } catch (Exception $e) {
+      $ids = new IDS_Monitor($_REQUEST, $init);
+    }
+    catch (Exception $e) {
       // might be an old stale copy of Config.IDS.ini
       // lets try to rebuild it again and see if it works
       $configFile = self::createConfigFile(TRUE);
       $init = IDS_Init::init($configFile);
-      $ids  = new IDS_Monitor($_REQUEST, $init);
+      $ids = new IDS_Monitor($_REQUEST, $init);
     }
 
     $result = $ids->run();
@@ -94,12 +95,13 @@ class CRM_Core_IDS {
   }
 
   /**
-   * Create the default config file for the IDS system
+   * Create the default config file for the IDS system.
    *
-   * @param boolean $force should we recreate it irrespective if it exists or not
+   * @param bool $force
+   *   Should we recreate it irrespective if it exists or not.
    *
-   * @return string the full path to the config file
-   * @static
+   * @return string
+   *   the full path to the config file
    */
   public static function createConfigFile($force = FALSE) {
     $config = CRM_Core_Config::singleton();
@@ -152,6 +154,7 @@ class CRM_Core_IDS {
     exceptions[]        = report_header
     exceptions[]        = report_footer
     exceptions[]        = data
+    exceptions[]        = json
     exceptions[]        = instructions
     exceptions[]        = suggested_message
     exceptions[]        = page_text
@@ -160,7 +163,6 @@ class CRM_Core_IDS {
       CRM_Core_Error::movedSiteError($configFile);
     }
 
-
     // also create the .htaccess file so we prevent the reading of the log and ini files
     // via a browser, CRM-3875
     CRM_Utils_File::restrictAccess($config->configAndLogDir);
@@ -169,17 +171,16 @@ class CRM_Core_IDS {
   }
 
   /**
-   * This function rects on the values in
-   * the incoming results array.
+   * This function reacts on the values in the incoming results array.
    *
    * Depending on the impact value certain actions are
    * performed.
    *
    * @param IDS_Report $result
    *
-   * @return boolean
+   * @return bool
    */
-  private function react(IDS_Report$result) {
+  private function react(IDS_Report $result) {
 
     $impact = $result->getImpact();
     if ($impact >= $this->threshold['kick']) {
@@ -202,21 +203,18 @@ class CRM_Core_IDS {
   }
 
   /**
-   * This function writes an entry about the intrusion
-   * to the intrusion database
+   * This function writes an entry about the intrusion to the database.
    *
    * @param array $result
    * @param int $reaction
    *
-   * @return boolean
+   * @return bool
    */
   private function log($result, $reaction = 0) {
     $ip = (isset($_SERVER['SERVER_ADDR']) &&
-      $_SERVER['SERVER_ADDR'] != '127.0.0.1'
-    ) ? $_SERVER['SERVER_ADDR'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
-      $_SERVER['HTTP_X_FORWARDED_FOR'] :
-      '127.0.0.1'
-    );
+      $_SERVER['SERVER_ADDR'] != '127.0.0.1') ? $_SERVER['SERVER_ADDR'] : (
+      isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '127.0.0.1'
+      );
 
     $data = array();
     $session = CRM_Core_Session::singleton();
@@ -238,18 +236,22 @@ class CRM_Core_IDS {
   }
 
   /**
-   * //todo
+   * Warn about IDS.
    *
+   * @param array $result
    *
+   * @return array
    */
   private function warn($result) {
     return $result;
   }
 
   /**
-   *  //todo
+   * Kick (whatever that means!).
    *
+   * @param array $result
    *
+   * @throws \Exception
    */
   private function kick($result) {
     $session = CRM_Core_Session::singleton();
@@ -259,9 +261,9 @@ class CRM_Core_IDS {
 
     $path = implode('/', $args);
     if (in_array(
-        $path,
-        array("civicrm/ajax/rest", "civicrm/api/json")
-      )) {
+      $path,
+      array("civicrm/ajax/rest", "civicrm/api/json")
+    )) {
       require_once "api/v3/utils.php";
       $error = civicrm_api3_create_error(
         $msg,
@@ -277,4 +279,5 @@ class CRM_Core_IDS {
     }
     CRM_Core_Error::fatal($msg);
   }
+
 }