public function onControllerInit($event) { $controller = $event->subject(); if (isset($controller->request->params['prefix'])) { $menuFile = $controller->request->params['prefix'] . '_menus'; if ($theme = Configure::read('App.admin.theme')) { if ($theme != '' && $theme != 'RearEngine' && Plugin::loaded($theme)) { $controller->viewBuilder()->theme($theme); } } foreach (Plugin::loaded() as $plugin) { try { Configure::load($plugin . '.' . $menuFile, 'default', true); } catch (\Exception $e) { if (Configure::read('debug')) { Log::warning('Unable to load app ' . $plugin . '/Config/' . $menuFile . ' config file', ['scope' => 'RearEngine plugin']); } } } try { Configure::load($menuFile, 'default', true); } catch (\Exception $e) { if (Configure::read('debug')) { Log::warning('Unable to load App/Config/' . $menuFile . ' config file.', ['scope' => 'RearEngine plugin']); } } } }
/** * {@inheritDoc} */ public function emit(ResponseInterface $response, $maxBufferLength = 8192) { $file = $line = null; if (headers_sent($file, $line)) { $message = "Unable to emit headers. Headers sent in file={$file} line={$line}"; if (Configure::read('debug')) { trigger_error($message, E_USER_WARNING); } else { Log::warning($message); } } $this->emitStatusLine($response); $this->emitHeaders($response); $this->flush(); $range = $this->parseContentRange($response->getHeaderLine('Content-Range')); if (is_array($range)) { $this->emitBodyRange($range, $response, $maxBufferLength); } else { $this->emitBody($response, $maxBufferLength); } if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } }
/** * test convenience methods */ public function testConvenienceMethods() { $this->_deleteLogs(); Log::config('debug', ['engine' => 'File', 'path' => LOGS, 'types' => ['notice', 'info', 'debug'], 'file' => 'debug']); Log::config('error', ['engine' => 'File', 'path' => LOGS, 'types' => ['emergency', 'alert', 'critical', 'error', 'warning'], 'file' => 'error']); $testMessage = 'emergency message'; Log::emergency($testMessage); $contents = file_get_contents(LOGS . 'error.log'); $this->assertRegExp('/(Emergency|Critical): ' . $testMessage . '/', $contents); $this->assertFileNotExists(LOGS . 'debug.log'); $this->_deleteLogs(); $testMessage = 'alert message'; Log::alert($testMessage); $contents = file_get_contents(LOGS . 'error.log'); $this->assertRegExp('/(Alert|Critical): ' . $testMessage . '/', $contents); $this->assertFileNotExists(LOGS . 'debug.log'); $this->_deleteLogs(); $testMessage = 'critical message'; Log::critical($testMessage); $contents = file_get_contents(LOGS . 'error.log'); $this->assertContains('Critical: ' . $testMessage, $contents); $this->assertFileNotExists(LOGS . 'debug.log'); $this->_deleteLogs(); $testMessage = 'error message'; Log::error($testMessage); $contents = file_get_contents(LOGS . 'error.log'); $this->assertContains('Error: ' . $testMessage, $contents); $this->assertFileNotExists(LOGS . 'debug.log'); $this->_deleteLogs(); $testMessage = 'warning message'; Log::warning($testMessage); $contents = file_get_contents(LOGS . 'error.log'); $this->assertContains('Warning: ' . $testMessage, $contents); $this->assertFileNotExists(LOGS . 'debug.log'); $this->_deleteLogs(); $testMessage = 'notice message'; Log::notice($testMessage); $contents = file_get_contents(LOGS . 'debug.log'); $this->assertRegExp('/(Notice|Debug): ' . $testMessage . '/', $contents); $this->assertFileNotExists(LOGS . 'error.log'); $this->_deleteLogs(); $testMessage = 'info message'; Log::info($testMessage); $contents = file_get_contents(LOGS . 'debug.log'); $this->assertRegExp('/(Info|Debug): ' . $testMessage . '/', $contents); $this->assertFileNotExists(LOGS . 'error.log'); $this->_deleteLogs(); $testMessage = 'debug message'; Log::debug($testMessage); $contents = file_get_contents(LOGS . 'debug.log'); $this->assertContains('Debug: ' . $testMessage, $contents); $this->assertFileNotExists(LOGS . 'error.log'); $this->_deleteLogs(); }
use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; use Cake\Event\EventManager; use Cake\Log\Log; use Cake\Routing\DispatcherFactory; use Cake\Routing\Router; use DebugKit\Routing\Filter\DebugBarFilter; use PDO; $debugBar = new DebugBarFilter(EventManager::instance(), (array) Configure::read('DebugKit')); if (!$debugBar->isEnabled() || php_sapi_name() === 'cli') { return; } $hasDebugKitConfig = ConnectionManager::config('debug_kit'); if (!$hasDebugKitConfig && !in_array('sqlite', PDO::getAvailableDrivers())) { $msg = 'DebugKit not enabled. You need to either install pdo_sqlite, ' . 'or define the "debug_kit" connection name.'; Log::warning($msg); return; } if (!$hasDebugKitConfig) { ConnectionManager::config('debug_kit', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => TMP . 'debug_kit.sqlite', 'encoding' => 'utf8', 'cacheMetadata' => true, 'quoteIdentifiers' => false]); } Router::plugin('DebugKit', function ($routes) { $routes->extensions('json'); $routes->connect('/toolbar/clear_cache', ['controller' => 'Toolbar', 'action' => 'clearCache']); $routes->connect('/toolbar/*', ['controller' => 'Requests', 'action' => 'view']); $routes->connect('/panels/view/*', ['controller' => 'Panels', 'action' => 'view']); $routes->connect('/panels/*', ['controller' => 'Panels', 'action' => 'index']); }); // Setup toolbar $debugBar->setup(); DispatcherFactory::add($debugBar);
/** * Load a config file containing editor options. * * @param string $file The file to load * @return void */ public function loadConfig($file) { $options = []; try { $loader = new PhpConfig(); $options = $loader->read($file); } catch (\Exception $e) { Log::warning($e->getMessage()); } $this->config('options', $options); }
/** * Sends the HTTP headers and cookies. * * @return void */ public function sendHeaders() { $file = $line = null; if (headers_sent($file, $line)) { Log::warning("Headers already sent in {$file}:{$line}"); return; } $codeMessage = $this->_statusCodes[$this->_status]; $this->_setCookies(); $this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}"); $this->_setContentType(); foreach ($this->_headers as $header => $values) { foreach ((array) $values as $value) { $this->_sendHeader($header, $value); } } }
/** * Helper function to find a user on the LDAP server and validate his credentials * Looks at the plugin's settings to get the LDAP connection details * @param string $username The username/identifier * @param string $password The password * @return boolean TRUE on success or FALSE on failure. */ public function validateUser($username, $password) { // Get the user_filter setting and insert the username $this->user_filter = preg_replace('/%USERNAME%/', $username, $this->user_filter); // Connect to LDAP server and search for the user object $ldapConnection = $this->__ldapConnect(); // Suppress warning when no object found $results = @ldap_search($ldapConnection, $this->base_dn, $this->user_filter, $this->ldap_attribs, 0, 1); // Failed to find user details, not authenticated. if (!$results || ldap_count_entries($ldapConnection, $results) == 0) { Log::error("[YalpUtility->validateUser] Could not find user '{$username}' on LDAP", 'yalp'); return false; } // Got multiple results, sysadmin did something wrong! if (ldap_count_entries($ldapConnection, $results) > 1) { Log::warning("[Yalp.authenticate] Multiple LDAP results for {$username}", 'yalp'); return false; } // Found the user! Get their details $ldapUser = ldap_get_entries($ldapConnection, $results); $ldapUser = $ldapUser[0]; // Now try to re-bind as that user $bind = @ldap_bind($ldapConnection, $ldapUser['dn'], $password); // If the password didn't work, bomb out return $bind; }
/** * Run readiness test to see if a directory can be used for composer/git * installations. * * @param string $directory Full path to directory to check. * @return bool */ public function dirAvailable($directory) { Log::debug("Checking installation directory readiness"); # Directory does not exist Log::debug("* Checking if installation directory exists"); if (!file_exists($directory)) { Log::debug("* Pass: directory does not exist"); return true; } # Directory exists but is not empty Log::debug("* Checking if existing directory is empty"); $files = scandir($directory); if (count($files) > 2) { Log::warning("* Fail: directory exists but is NOT empty"); return false; } # Check if the directory is writable by vagrant user $Execute = new CakeboxExecute(); if (!$Execute->isVagrantWritable($directory)) { return false; } Log::debug("* Pass: directory is writable"); return true; }
/** * Create a warning entry in the application's log AND store the entry in the * $_log collection. * * @param string $message Debug message. * @return void */ protected function _warn($message) { Log::warning($message); $this->_debug[] = $message; }
<?php use Cake\Core\Configure; use Cake\Log\Log; /* * Autoload TCPDF configuration */ try { Configure::load('tcpdf'); } catch (\Exception $ex) { Log::warning("Tcpdf: Failed to load configuration: " . $ex->getMessage()); if (Configure::read('debug')) { throw $ex; } }
/** * Always output warning message to screen (even when using --quiet) * * @param string $message Message to be logged. * @return void */ public function logError($message = null) { if (empty($message)) { $message = 'Error'; } Log::warning($message); $this->out("<error>{$message}</error>", 1, Shell::QUIET); $this->out("<info>See /var/log/cakephp/cakebox.cli.log for details.</info>"); }
/** * Authentication hook to authenticate a user against an LDAP server. * * @param \Cake\Network\Request $request The request that contains login information. * @param \Cake\Network\Response $response Unused response object. * @return mixed False on login failure. An array of User data on success. */ public function authenticate(Request $request, Response $response) { // This will probably be cn or an email field to search for Log::debug("[Yalp.authenticate] Authentication started", 'yalp'); $userField = $this->form_fields['username']; $passField = $this->form_fields['password']; $userModel = $this->config('userModel'); list($plugin, $model) = pluginSplit($userModel); // Definitely not authenticated if we haven't got the request data... if (!isset($request->data[$userModel])) { Log::error("[Yalp.authenticate] No request data, cannot authenticate", 'yalp'); return false; } // We need to know the username, or email, or some other unique ID $submittedDetails = $request->data[$userModel]; if (!isset($submittedDetails[$userField])) { //Log::write('yalp', "[Yalp.authenticate] No username supplied, cannot authenticate"); return false; } // Make sure it's a valid string... $username = $submittedDetails[$userField]; if (!is_string($username)) { Log::error("[Yalp.authenticate] Invalid username, cannot authenticate", 'yalp'); return false; } // Make sure they gave us a password too... $password = $submittedDetails[$passField]; if (!is_string($password) || empty($password)) { Log::error("[Yalp.authenticate] Invalid password, cannot authenticate", 'yalp'); return false; } // Check whether or not user exists on LDAP if (!$this->Yalp->validateUser($username, $password)) { Log::error("[Yalp.authenticate] User '{$username}' could not be found on LDAP", 'yalp'); return false; } else { Log::debug("[Yalp.authenticate] User '{$username}' was found on LDAP", 'yalp'); } // Check on DB $comparison = 'LOWER(' . $model . '.' . $userField . ')'; $conditions = array($comparison => strtolower($username)); $dbUser = TableRegistry::get($userModel)->find('all', array('conditions' => $conditions, 'recursive' => false))->first(); // If we couldn't find them in the database, warn and fail if (empty($dbUser)) { Log::warning("[Yalp.authenticate] Could not find a database entry for {$username}", 'yalp'); return false; } // ...and return the user object. return $dbUser->toArray(); }