<commit_before><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:			Admin_Controller
 *
 * Description:	This controller executes various bits of common admin functionality
 *
 **/


class NAILS_Admin_Controller extends NAILS_Controller
{
	protected $_loaded_modules;


	// --------------------------------------------------------------------------


	/**
	 * Common constructor for all admin pages
	 *
	 * @access	public
	 * @return	void
	 *
	 **/
	public function __construct()
	{
		parent::__construct();

		// --------------------------------------------------------------------------

		//	IP whitelist?
		$_ip_whitelist = (array) app_setting( 'whitelist', 'admin' );

		if ( $_ip_whitelist ) :

			if ( ! ip_in_range( $this->input->ip_address(), $_ip_whitelist ) ) :

				show_404();

			endif;

		endif;

		// --------------------------------------------------------------------------

		//	Admins only please
		if ( ! $this->user_model->is_admin() ) :

			unauthorised();

		endif;

		// --------------------------------------------------------------------------

		//	Load up the generic admin langfile
		$this->lang->load( 'admin_generic' );

		// --------------------------------------------------------------------------

		//	Check that admin is running on the SECURE_BASE_URL url
		if ( APP_SSL_ROUTING ) :

			$_host1 = $this->input->server( 'HTTP_HOST' );
			$_host2 = parse_url( SECURE_BASE_URL );

			if ( ! empty( $_host2['host'] ) && $_host2['host'] != $_host1 ) :

				//	Not on the secure URL, redirect with message
				$_redirect = $this->input->server( 'REQUEST_URI' );

				if ( $_redirect ) :

					$this->session->set_flashdata( 'message', lang( 'admin_not_secure' ) );
					redirect( $_redirect );

				endif;

			endif;

		endif;

		// --------------------------------------------------------------------------

		//	Load admin helper and config
		$this->load->model( 'admin_model' );
		$this->config->load( 'admin/admin' );
		if ( file_exists( FCPATH . APPPATH . 'config/admin.php' ) ) :

			$this->config->load( 'admin' );

		endif;

		// --------------------------------------------------------------------------

		//	Load up the modules which have been enabled for this installation and the
		//	user has permission to see.

		$this->_loaded_modules			= array();
		$this->data['loaded_modules']	=& $this->_loaded_modules;
		$this->_load_active_modules();

		// --------------------------------------------------------------------------

		//	Check the user has permission to view this module (skip the dashboard
		//	we need to show them _something_)

		$_active_module	= $this->uri->segment( 2 );
		$_active_method	= $this->uri->segment( 3, 'index' );
		$_acl			= active_user( 'acl' );

		if ( ! $this->user_model->is_superuser() && ! isset( $this->_loaded_modules[$_active_module] ) ) :

			//	If this is the dashboard, we should see if the user has permission to
			//	access any other modules before we 404 their ass.
<commit_msg>Correctly loading nails & app admin configs<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:			Admin_Controller
 *
 * Description:	This controller executes various bits of common admin functionality
 *
 **/


class NAILS_Admin_Controller extends NAILS_Controller
{
	protected $_loaded_modules;


	// --------------------------------------------------------------------------


	/**
	 * Common constructor for all admin pages
	 *
	 * @access	public
	 * @return	void
	 *
	 **/
	public function __construct()
	{
		parent::__construct();

		// --------------------------------------------------------------------------

		//	IP whitelist?
		$_ip_whitelist = (array) app_setting( 'whitelist', 'admin' );

		if ( $_ip_whitelist ) :

			if ( ! ip_in_range( $this->input->ip_address(), $_ip_whitelist ) ) :

				show_404();

			endif;

		endif;

		// --------------------------------------------------------------------------

		//	Admins only please
		if ( ! $this->user_model->is_admin() ) :

			unauthorised();

		endif;

		// --------------------------------------------------------------------------

		//	Load up the generic admin langfile
		$this->lang->load( 'admin_generic' );

		// --------------------------------------------------------------------------

		//	Check that admin is running on the SECURE_BASE_URL url
		if ( APP_SSL_ROUTING ) :

			$_host1 = $this->input->server( 'HTTP_HOST' );
			$_host2 = parse_url( SECURE_BASE_URL );

			if ( ! empty( $_host2['host'] ) && $_host2['host'] != $_host1 ) :

				//	Not on the secure URL, redirect with message
				$_redirect = $this->input->server( 'REQUEST_URI' );

				if ( $_redirect ) :

					$this->session->set_flashdata( 'message', lang( 'admin_not_secure' ) );
					redirect( $_redirect );

				endif;

			endif;

		endif;

		// --------------------------------------------------------------------------

		//	Load admin helper and config
		$this->load->model( 'admin_model' );
		$this->config->load( 'admin/admin' );
		if ( file_exists( FCPATH . APPPATH . 'config/admin.php' ) ) :

			$this->config->load( FCPATH . APPPATH . 'config/admin.php' );

		endif;

		// --------------------------------------------------------------------------

		//	Load up the modules which have been enabled for this installation and the
		//	user has permission to see.

		$this->_loaded_modules			= array();
		$this->data['loaded_modules']	=& $this->_loaded_modules;
		$this->_load_active_modules();

		// --------------------------------------------------------------------------

		//	Check the user has permission to view this module (skip the dashboard
		//	we need to show them _something_)

		$_active_module	= $this->uri->segment( 2 );
		$_active_method	= $this->uri->segment( 3, 'index' );
		$_acl			= active_user( 'acl' );

		if ( ! $this->user_model->is_superuser() && ! isset( $this->_loaded_modules[$_active_module] ) ) :

			//	If this is the dashboard, we should see if the user has permission to
			//	access any other modules before we 404 their ass.

{'fraction_non_alphanumeric': 0.3147233201581028, 'fraction_numerical': 0.004281949934123847, 'mean_word_length': 1.5335836462244472, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6786937', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1620, 'n_words': 427}