<?php

use App\Lib\Environment;
return ['debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN), 'App' => ['namespace' => 'App', 'encoding' => env('APP_ENCODING', 'UTF-8'), 'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'), 'base' => false, 'dir' => 'src', 'webroot' => 'webroot', 'wwwRoot' => WWW_ROOT, 'fullBaseUrl' => false, 'imageBaseUrl' => 'img/', 'cssBaseUrl' => 'css/', 'jsBaseUrl' => 'js/', 'paths' => ['plugins' => [ROOT . DS . 'plugins' . DS], 'templates' => [APP . 'Template' . DS], 'locales' => [APP . 'Locale' . DS]]], 'Security' => ['salt' => env('SECURITY_SALT', '__SALT__')], 'Asset' => [], 'Cache' => ['default' => ['className' => 'File', 'path' => CACHE, 'url' => env('CACHE_DEFAULT_URL', null)], '_cake_core_' => ['className' => 'File', 'prefix' => 'myapp_cake_core_', 'path' => CACHE . 'persistent/', 'serialize' => true, 'duration' => '+2 minutes', 'url' => env('CACHE_CAKECORE_URL', null)], '_cake_model_' => ['className' => 'File', 'prefix' => 'myapp_cake_model_', 'path' => CACHE . 'models/', 'serialize' => true, 'duration' => '+2 minutes', 'url' => env('CACHE_CAKEMODEL_URL', null)]], 'Error' => ['errorLevel' => E_ALL, 'exceptionRenderer' => 'Cake\\Error\\ExceptionRenderer', 'skipLog' => [], 'log' => true, 'trace' => true], 'EmailTransport' => ['default' => ['className' => 'Smtp', 'host' => Environment::read('EMAIL_HOST'), 'port' => Environment::read('EMAIL_PORT'), 'timeout' => 30, 'username' => Environment::read('EMAIL_USERNAME'), 'password' => Environment::read('EMAIL_PASSWORD'), 'client' => null, 'tls' => null, 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null)]], 'Email' => ['default' => ['transport' => 'default', 'from' => Environment::read('EMAIL_FROM')]], 'Datasources' => ['default' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'persistent' => false, 'host' => Environment::read('MYSQL_HOST'), 'username' => Environment::read('MYSQL_USERNAME'), 'password' => Environment::read('MYSQL_PASSWORD'), 'database' => Environment::read('MYSQL_DATABASE'), 'encoding' => 'utf8', 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, 'log' => false, 'quoteIdentifiers' => false, 'url' => env('DATABASE_URL', null)], 'test' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'my_app', 'password' => 'secret', 'database' => 'test_myapp', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true, 'quoteIdentifiers' => false, 'log' => false, 'url' => env('DATABASE_TEST_URL', null)]], 'Log' => ['debug' => ['className' => 'Cake\\Log\\Engine\\FileLog', 'path' => LOGS, 'file' => 'debug', 'levels' => ['notice', 'info', 'debug'], 'url' => env('LOG_DEBUG_URL', null)], 'error' => ['className' => 'Cake\\Log\\Engine\\FileLog', 'path' => LOGS, 'file' => 'error', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'url' => env('LOG_ERROR_URL', null)]], 'Session' => ['defaults' => 'php', 'cookie' => Environment::read('SESSION_COOKIE_NAME') ?: 'fallback', 'timeout' => 4320, 'ini' => ['session.cookie_lifetime' => 24 * 60 * 60, 'session.cookie_domain' => '.' . Environment::read('MAIN_DOMAIN')]], 'Authentication' => ['max_login_retries' => 5, 'login_lock_duration' => '1 hour'], 'CakeMonitor' => ['accessToken' => '', 'projectName' => '', 'Sentry' => ['enabled' => !empty(Environment::read('SENTRY_DSN')), 'dsn' => Environment::read('SENTRY_DSN'), 'sanitizeFields' => ['password', 'rememberuser', 'auth_token', 'api_token', 'mysql_password', 'mysql_host', 'mysql_username', 'mysql_database', 'email_username', 'email_password', 'cookie']]], 'Notifications' => ['defaultLocale' => 'en_US', 'queueOptions' => ['queue' => 'notification']], 'Queuesadilla' => ['default' => ['engine' => 'josegonzalez\\Queuesadilla\\Engine\\MysqlEngine', 'database' => Environment::read('MYSQL_DATABASE'), 'host' => Environment::read('MYSQL_HOST'), 'user' => Environment::read('MYSQL_USERNAME'), 'pass' => Environment::read('MYSQL_PASSWORD')]], 'Glide' => ['server' => ['source' => WWW_ROOT . 'files', 'cache' => WWW_ROOT . 'cache_img', 'base_url' => '/images/'], 'security' => ['secureUrls' => true, 'signKey' => null], 'cacheTime' => '+1 days'], 'Attachments' => ['tmpUploadsPath' => ROOT . '/tmp/uploads/', 'path' => ROOT . '/app_data/attachments/', 'acceptedFileTypes' => '/\\.(gif|jpe?g|png|pdf|docx|doc|xls|xlsx|tif|tiff|zip)$/i'], 'LanguageSwitcher' => ['Helper' => ['availableLanguages' => ['de_DE' => 'de_DE', 'en_US' => 'en_US'], 'displayNames' => ['de_DE' => 'Deutsch', 'en_US' => 'English'], 'imageMapping' => ['de_DE' => 'Germany', 'en_US' => 'United-States']], 'Middleware' => ['field' => 'language_code', 'Cookie' => ['domain' => Environment::read('MAIN_DOMAIN')], 'availableLanguages' => ['de_DE' => 'de_DE', 'en_US' => 'en_US']]]];
use Cake\Console\ConsoleErrorHandler;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Core\Plugin;
use Cake\Database\Type;
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorHandler;
use Cake\Log\Log;
use Cake\Mailer\Email;
use Cake\Network\Request;
use Cake\Utility\Inflector;
use Cake\Utility\Security;
/* Set up the environemt*/
Environment::loadVariables();
define('ENVIRONMENT', Environment::detect());
/*
 * Read configuration file and inject configuration into various
 * CakePHP classes.
 *
 * By default there is only one configuration file. It is often a good
 * idea to create multiple configuration files, and separate the configuration
 * that changes from configuration that does not. This makes deployment simpler.
 */
try {
    Configure::config('default', new PhpConfig());
    Configure::load('app', 'default', false);
} catch (\Exception $e) {
    exit($e->getMessage() . "\n");
}
if (isset($_GET['cache']) && $_GET['cache'] == 'disable') {
 /**
  * maintenance redirect logic
  *
  * @return mixed|void
  */
 public function beforeFilter()
 {
     if (defined('PHPUNIT_TESTSUITE')) {
         return;
     }
     $maintenancePage = Environment::read('MAINTENANCE_PAGE_REDIRECT_URL');
     $currentUrl = $this->request->here;
     $accessibleUrls = explode('|', Environment::read('MAINTENANCE_ACCESSIBLE_URLS'));
     $accessibleUrls[] = $maintenancePage;
     if (!self::isMaintenanceActive()) {
         // if maintenance is not active but maintenance page is requested -> redirect to default page
         if (in_array($currentUrl, $accessibleUrls) && substr($maintenancePage, -strlen($currentUrl)) === $currentUrl) {
             $maintenanceBasePage = Environment::read('MAINTENANCE_BASE_URL');
             return $this->_controller->redirect($maintenanceBasePage);
         }
         return;
     }
     $cookieName = Environment::read('MAINTENANCE_COOKIE_NAME');
     $cookieExists = $this->_controller->Cookie->read($cookieName) != null;
     if ($cookieExists) {
         return;
     }
     $headerActive = Environment::read('MAINTENANCE_HEADER_ACTIVE');
     $headerName = Environment::read('MAINTENANCE_HEADER_NAME');
     $headerValue = Environment::read('MAINTENANCE_HEADER_VALUE');
     $successUrl = Environment::read('MAINTENANCE_PASSWORD_SUCCESS_URL');
     if ($headerActive && !empty($this->request->header($headerName)) && $this->request->header($headerName) == $headerValue) {
         $this->_controller->Cookie->write($cookieName, true);
         return $this->_controller->redirect($successUrl);
     }
     $passwordUrl = Environment::read('MAINTENANCE_PASSWORD_URL');
     $accessibleUrls[] = $passwordUrl;
     if (!in_array($currentUrl, $accessibleUrls)) {
         return $this->_controller->redirect($maintenancePage);
     } elseif ($currentUrl != $passwordUrl) {
         return;
     }
     $user = Environment::read('MAINTENANCE_USER');
     $password = Environment::read('MAINTENANCE_PASSWORD');
     if ($currentUrl == $passwordUrl) {
         if (!isset($_SERVER['PHP_AUTH_USER'])) {
             header('WWW-Authenticate: Basic realm="Maintenance Realm"');
             header('HTTP/1.0 401 Unauthorized');
             echo 'Unauthorized';
             exit;
         } else {
             if ($_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $password) {
                 $this->_controller->Cookie->write($cookieName, true);
                 return $this->_controller->redirect($successUrl);
             }
             return $this->_controller->redirect($maintenancePage);
         }
     }
     return $this->_controller->redirect($maintenancePage);
 }