<commit_before><?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

// TODO GPG encryption has issues when keys are expired

App::uses('Controller', 'Controller');
App::uses('File', 'Utility');
App::uses('RequestRearrangeTool', 'Tools');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 *
 * @throws ForbiddenException // TODO Exception
 */
class AppController extends Controller {

	public $defaultModel = '';

	public $debugMode = false;
	
	// Used for _isAutomation(), a check that returns true if the controller & action combo matches an action that is a non-xml and non-json automation method
	// This is used to allow authentication via headers for methods not covered by _isRest() - as that only checks for JSON and XML formats 
	public $automationArray = array(
		'events' => array('csv', 'nids', 'hids', 'xml', 'restSearch', 'stix', 'updateGraph'),
		'attributes' => array('text', 'downloadAttachment', 'returnAttributes', 'restSearch', 'rpz'),
	);

	public function __construct($id = false, $table = null, $ds = null) {
		parent::__construct($id, $table, $ds);

		$name = get_class($this);
		$name = str_replace('sController', '', $name);
		$name = str_replace('Controller', '', $name);
		$this->defaultModel = $name;
	}

	public $components = array(
			'Session',
			'Auth' => array(
				'authError' => 'Unauthorised access.',
				'loginRedirect' => array('controller' => 'users', 'action' => 'routeafterlogin'),
				'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'admin' => false),
				//'authorize' => array('Controller', // Added this line
				//'Actions' => array('actionPath' => 'controllers')) // TODO ACL, 4: tell actionPath
				),
			'Security',
			'ACL'
	);
	
	public $auth_user_vars = array(
			'id',
			'password',
			'org_id',
			'server_id',
			'email',
			'autoalert',
			'authkey',
			'invited_by',
			'nids_sid',
			'termsaccepted',
			'newsread',
			'role_id',
			'change_pw',
			'contactalert',
			'disabled',
			'expiration',
			'last_login',
			'current_login',
			'external_auth_required',
			'external_auth_key',
			'force_logout',
			'Role.*',
			'Organisation.*',
			'Server.*'
	);
	
	public function beforeFilter() {
		//Let s check if Apache have kerberos auth.
		$envvar = Configure::read('ApacheSecureAuth.apacheEnv');
		if (isset($_SERVER[$envvar])) {
			$this->Auth->className = 'ApacheSecureAuth';
			$this->Auth->authenticate = array(
				'Apache' => array(
					// envvar = field return by Apache when used Authentificatied
					'fields' => array('username' => 'email', 'envvar' => $envvar),
					'userFields' => $this->auth_user_vars	
				)
			);
		} else {
			$this->Auth->className = 'SecureAuth';
			$this->Auth->authenticate = array(
				'Form' => array(
					'fields' => array('username' => 'email'),
					'userFields' => $this->auth_user_vars
				)
			);
		}
		$versionArray = $this->{$this->modelClass}->checkMISPVersion();
		$this->mispVersion = implode('.', array_values($versionArray));

		$this->Security->blackHoleCallback = 'blackHole';

		// Let us access $baseurl from all views
		$baseurl = Configure::read('MISP.baseurl');
		if (substr($baseurl, -1) == '/') {
			// if the baseurl has a trailing slash, remove it. It can lead to issues with the CSRF protection
			$baseurl = rtrim($baseurl, '/');
			Configure::write('MISP.baseurl', $baseurl); 
		}<commit_msg>Fix to the previous commit<commit_after><?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

// TODO GPG encryption has issues when keys are expired

App::uses('Controller', 'Controller');
App::uses('File', 'Utility');
App::uses('RequestRearrangeTool', 'Tools');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 *
 * @throws ForbiddenException // TODO Exception
 */
class AppController extends Controller {

	public $defaultModel = '';

	public $debugMode = false;
	
	// Used for _isAutomation(), a check that returns true if the controller & action combo matches an action that is a non-xml and non-json automation method
	// This is used to allow authentication via headers for methods not covered by _isRest() - as that only checks for JSON and XML formats 
	public $automationArray = array(
		'events' => array('csv', 'nids', 'hids', 'xml', 'restSearch', 'stix', 'updateGraph'),
		'attributes' => array('text', 'downloadAttachment', 'returnAttributes', 'restSearch', 'rpz'),
	);

	public function __construct($id = false, $table = null, $ds = null) {
		parent::__construct($id, $table, $ds);

		$name = get_class($this);
		$name = str_replace('sController', '', $name);
		$name = str_replace('Controller', '', $name);
		$this->defaultModel = $name;
	}

	public $components = array(
			'Session',
			'Auth' => array(
				'authError' => 'Unauthorised access.',
				'loginRedirect' => array('controller' => 'users', 'action' => 'routeafterlogin'),
				'logoutRedirect' => array('controller' => 'users', 'action' => 'login', 'admin' => false),
				//'authorize' => array('Controller', // Added this line
				//'Actions' => array('actionPath' => 'controllers')) // TODO ACL, 4: tell actionPath
				),
			'Security',
			'ACL'
	);
	
	public function beforeFilter() {
		$this->loadModel('User');
		$auth_user_fields = $this->User->describeAuthFields();
		//Let s check if Apache have kerberos auth.
		$envvar = Configure::read('ApacheSecureAuth.apacheEnv');
		if (isset($_SERVER[$envvar])) {
			$this->Auth->className = 'ApacheSecureAuth';
			$this->Auth->authenticate = array(
				'Apache' => array(
					// envvar = field return by Apache when used Authentificatied
					'fields' => array('username' => 'email', 'envvar' => $envvar),
					'userFields' => $auth_user_fields
				)
			);
		} else {
			$this->Auth->className = 'SecureAuth';
			$this->Auth->authenticate = array(
				'Form' => array(
					'fields' => array('username' => 'email'),
					'userFields' => $auth_user_fields
				)
			);
		}
		$versionArray = $this->{$this->modelClass}->checkMISPVersion();
		$this->mispVersion = implode('.', array_values($versionArray));

		$this->Security->blackHoleCallback = 'blackHole';

		// Let us access $baseurl from all views
		$baseurl = Configure::read('MISP.baseurl');
		if (substr($baseurl, -1) == '/') {
			// if the baseurl has a trailing slash, remove it. It can lead to issues with the CSRF protection
			$baseurl = rtrim($baseurl, '/');
			Configure::write('MISP.baseurl', $baseurl); 
		}
{'fraction_non_alphanumeric': 0.1617031749938469, 'fraction_numerical': 0.005906965296578882, 'mean_word_length': 3.8461538461538463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '341243', 'n_tokens_mistral': 2825, 'n_tokens_neox': 2479, 'n_words': 684}