Example #1
0
 public function onLoginEvents($event)
 {
     $safe = Configure::read('Audit.trustHttpForwardedFor');
     if ($safe === null) {
         $safe = false;
     }
     $controller = $event->subject;
     $user_id = $source_id = AuthComponent::user('id');
     if (empty($user_id)) {
         $user_id = $this->_guessUserId($controller);
     }
     $host = env('HTTP_HOST');
     $ua = env('HTTP_USER_AGENT');
     $referer = $controller->request->referer();
     $server_name = env('SERVER_NAME');
     $server_port = env('SERVER_PORT');
     $remote_addr = $controller->request->clientIp($safe);
     $request_scheme = env('REQUEST_SCHEME');
     $request_time = env('REQUEST_TIME');
     $session_id = session_id();
     $audit = compact('user_id', 'source_id', 'host', 'ua', 'referer', 'server_name', 'server_port', 'remote_addr', 'request_time', 'request_time_float', 'session_id');
     $audit['event'] = $event->name;
     $SessionAudit = ClassRegistry::init('Audit.SessionAudit');
     $SessionAudit->create();
     $result = $SessionAudit->save(array('SessionAudit' => $audit));
     if (!$result) {
         CakeLog::critical('Unable to log session audit records');
         $event->result = false;
         $event->stopPropagation();
     }
     return $event;
 }
Example #2
0
 /**
  * Get Plugin Name from zip file
  *
  * @param string $path Path to zip file of plugin
  * @return string Plugin name
  * @throws CakeException
  */
 public function getPluginName($path = null)
 {
     if (empty($path)) {
         throw new CakeException(__d('croogo', 'Invalid plugin path'));
     }
     if (isset($this->_pluginName[$path])) {
         return $this->_pluginName[$path];
     }
     $Zip = new ZipArchive();
     if ($Zip->open($path) === true) {
         $search = 'Config/plugin.json';
         $indexJson = $Zip->locateName('plugin.json', ZIPARCHIVE::FL_NODIR);
         if ($indexJson === false) {
             throw new CakeException(__d('croogo', 'Invalid zip archive'));
         } else {
             $fileName = $Zip->getNameIndex($indexJson);
             $fileJson = json_decode($Zip->getFromIndex($indexJson));
             if (empty($fileJson->name)) {
                 throw new CakeException(__d('croogo', 'Invalid plugin.json or missing plugin name'));
             }
             $this->_rootPath[$path] = str_replace($search, '', $fileName);
             $plugin = $fileJson->name;
             $searches = array($plugin . 'Activation.php', $plugin . 'AppController.php', $plugin . 'AppModel.php', $plugin . 'Helper.php');
             $hasFile = false;
             foreach ($searches as $search) {
                 if ($Zip->locateName($search, ZIPARCHIVE::FL_NODIR) !== false) {
                     $hasFile = true;
                     break;
                 }
             }
             if (!$hasFile) {
                 CakeLog::critical(__d('croogo', 'Missing expected files: %s in: %s', implode(',', $searches), $path));
                 throw new CakeException(__d('croogo', 'Invalid plugin or missing expected files'));
             }
         }
         $Zip->close();
         if (!$plugin) {
             throw new CakeException(__d('croogo', 'Invalid plugin'));
         }
         $this->_pluginName[$path] = $plugin;
         return $plugin;
     } else {
         throw new CakeException(__d('croogo', 'Invalid zip archive'));
     }
     return false;
 }
Example #3
0
 public function createCroogoFile()
 {
     $croogoConfigFile = APP . 'Config' . DS . 'croogo.php';
     copy($croogoConfigFile . '.install', $croogoConfigFile);
     $File =& new File($croogoConfigFile);
     $salt = Security::generateAuthKey();
     $seed = mt_rand() . mt_rand();
     $contents = $File->read();
     $contents = preg_replace('/(?<=Configure::write\\(\'Security.salt\', \')([^\' ]+)(?=\'\\))/', $salt, $contents);
     $contents = preg_replace('/(?<=Configure::write\\(\'Security.cipherSeed\', \')(\\d+)(?=\'\\))/', $seed, $contents);
     if (!$File->write($contents)) {
         CakeLog::critical('Unable to write your Config' . DS . 'croogo.php file. Please check the permissions.');
         return false;
     }
     Configure::write('Security.salt', $salt);
     Configure::write('Security.cipherSeed', $seed);
     return true;
 }
Example #4
0
 /**
  * test convenience methods
  *
  * @return void
  */
 public function testConvenienceMethods()
 {
     $this->_deleteLogs();
     CakeLog::config('debug', array('engine' => 'File', 'types' => array('notice', 'info', 'debug'), 'file' => 'debug'));
     CakeLog::config('error', array('engine' => 'File', 'types' => array('emergency', 'alert', 'critical', 'error', 'warning'), 'file' => 'error'));
     $testMessage = 'emergency message';
     CakeLog::emergency($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertRegExp('/(Emergency|Critical): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'alert message';
     CakeLog::alert($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertRegExp('/(Alert|Critical): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'critical message';
     CakeLog::critical($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Critical: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'error message';
     CakeLog::error($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Error: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'warning message';
     CakeLog::warning($testMessage);
     $contents = file_get_contents(LOGS . 'error.log');
     $this->assertContains('Warning: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'debug.log'));
     $this->_deleteLogs();
     $testMessage = 'notice message';
     CakeLog::notice($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertRegExp('/(Notice|Debug): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
     $testMessage = 'info message';
     CakeLog::info($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertRegExp('/(Info|Debug): ' . $testMessage . '/', $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
     $testMessage = 'debug message';
     CakeLog::debug($testMessage);
     $contents = file_get_contents(LOGS . 'debug.log');
     $this->assertContains('Debug: ' . $testMessage, $contents);
     $this->assertFalse(file_exists(LOGS . 'error.log'));
     $this->_deleteLogs();
 }
 public function critical($message, array $context = array())
 {
     CakeLog::critical($message, $context);
 }
Example #6
0
 public function critical($message)
 {
     CakeLog::critical($message, $this->scope);
 }
Example #7
0
<?php

$handlerConfig = Hash::merge(array('engine' => 'RedisSession.RedisSession', 'userMap' => true), Configure::consume('RedisSession.handler'));
Configure::write('Session', Hash::merge(Configure::read('Session'), array('defaults' => 'php', 'handler' => $handlerConfig)));
if (isset($handlerConfig['userMap'])) {
    if (extension_loaded('wddx')) {
        ini_set('session.serialize_handler', 'wddx');
    } else {
        CakeLog::critical('wddx not available. user map not enabled');
    }
}
if (class_exists('CroogoNav')) {
    CroogoNav::add('extensions.children.RedisSession', array('title' => __d('redis_session', 'Login Sessions'), 'url' => array('plugin' => 'redis_session', 'controller' => 'session_stores', 'action' => 'index'), 'children' => array()));
}
Example #8
0
<?php

$scheme = 'https';
if (!defined('CROOGO_OAUTH_SERVER_URL') && isset($_SERVER['HTTP_HOST'])) {
    define('CROOGO_OAUTH_SERVER_URL', $scheme . '://' . $_SERVER['HTTP_HOST']);
}
$path = CakePlugin::path('Socialites');
if (file_exists($path . 'Vendor' . DS . 'autoload.php')) {
    require $path . 'Vendor' . DS . 'autoload.php';
}
Croogo::hookModelProperty('User', 'hasOne', array('Socialite' => array('className' => 'Socialites.Socialite', 'dependent' => true)));
if (file_exists($path . 'Config' . DS . 'providers.php')) {
    Configure::load('Socialites.providers');
} else {
    CakeLog::critical('Socialites provider config not found');
}
 protected function _run($id, $config, $force = false)
 {
     // open stats
     $stats = $this->_getStats($id);
     // check interval
     if (isset($stats[0])) {
         $last = $stats[0];
         if (!$force && $last['time'] + $config['interval'] > time()) {
             $wait = $last['time'] + $config['interval'] - time();
             $last['wait'] = $wait;
             $last['message'] = sprintf("Cronjob timeout. Wait %+d seconds", $wait);
             return array($last, $stats);
         }
     }
     try {
         // request cron
         $url = Router::url($config['url'], true);
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($ch);
         $info = curl_getinfo($ch);
         curl_close($ch);
     } catch (Exception $e) {
         CakeLog::critical("Cronjob {$id} failed", 'cron');
         $response = $config['expectError'];
     }
     // map results
     switch (true) {
         case $response == $config['expectError']:
         case $info['http_code'] >= 400:
             $message = 'Cronjob returned errors';
             break;
         case $response == $config['expectFail']:
             $message = 'Cronjob failed';
             break;
         case $info['http_code'] == 200:
         case $response == $config['expectOk']:
             $message = 'Cronjob successful';
             break;
         default:
             $message = 'Cronjob response unknown: ' . $response;
             $response = 'UNKNOWN';
             break;
     }
     $result = array('time' => time(), 'response' => $response, 'message' => $message, 'time_elapsed' => $info['total_time']);
     // write stats
     array_unshift($stats, $result);
     $stats = array_slice($stats, 0, $this->cronlogLimit);
     $this->_setStats($id, $stats);
     return array($result, $stats);
 }