Esempio n. 1
0
 public static function write($type, $message, $params = [], $trace_level = 0, $log_options = [])
 {
     $trace_level += 1;
     $trace = self::traceMessage($trace_level);
     $output = call_user_func_array('sprintf', array_merge([$message], $params));
     CakeLog::write($type, $trace . ' - ' . $output, $log_options);
 }
Esempio n. 2
0
 /**
  * Auth method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function auth()
 {
     //ログイン処理
     // パラメータの受取
     $name = $this->request->data['userId'];
     $pass = $this->request->data['pass'];
     //Usersテーブルを検索
     $tableUsers = TableRegistry::get('Users');
     $queryStr = "select name from users where name='" . $name . "' and password = '******'";
     // パスワード入力値 or 1=1;--
     //$queryStr = "select name from users where name='" . $name . "' and password = '******' or 1=1";
     Log::write('debug', $queryStr);
     //SQL発行
     $data = $tableUsers->connection()->query($queryStr);
     //配列のサイズで判定する
     $cnt = sizeof($data);
     if ($cnt == 0) {
         //レコードなし認証NGとする
         Log::write('debug', '認証エラー');
         $this->Flash->error('Auth Error: id or password is incorrect');
         // ログイン画面に戻る
         return $this->redirect(['action' => '../Login/index']);
     }
     Log::write('debug', '認証OK');
     foreach ($data as $key => $value) {
         Log::write('debug', 'userName is :' . $value['name']);
         $this->request->session()->write('loginUser', $value['name']);
     }
     // 成功した場合は記事一覧へ
     return $this->redirect(['action' => '../Articles/index']);
 }
Esempio n. 3
0
 /**
  * @author team_syzzygy
  * @param Connection $dbConnection
  * @param unknown $studentId
  * Fetch student organizations based on the studentId provided
  */
 public function fetchStudentOrganizations(Connection $dbConnection, $studentId)
 {
     $studentTable = $this->getStudentReference();
     Log::write('debug', "Student Id passed into fetchStudentOrganizations method is " . $studentId);
     $temp = $studentTable->find()->where(['Student_ID' => $studentId])->contain(['StudentOrganizationTypeT'])->first();
     return $temp;
 }
 /**
  * Test that the log panel outputs a summary.
  *
  * @return void
  */
 public function testSummary()
 {
     Log::write('error', 'Test');
     $this->assertEquals(1, $this->panel->summary());
     Log::write('error', 'Test 2');
     Log::write('notice', 'A thing');
     $this->assertEquals(3, $this->panel->summary());
 }
Esempio n. 5
0
 /**
  * 	
  * @return array Um array com os dados da resposta.
  */
 public function toArray()
 {
     if (is_null($this->_response->json)) {
         Log::write('debug', print_r($this->_response->body));
         return ['success' => false, 'message' => 'Erro na resposta recebida do servidor.'];
     }
     return $this->_response->json;
 }
 public function main()
 {
     $XTime = time() - 60 * 24 * 3600;
     $conditions = array('Notifications.created <' => date('Y-m-d H:i:s', $XTime));
     if (!$this->Notifications->deleteAll($conditions)) {
         Log::write('error', 'FAILED: Deleting older Notifications!!', 'cron_jobs');
     }
 }
Esempio n. 7
0
 public function initialize()
 {
     $loginUser = $this->request->session()->read('loginUser');
     Log::write('debug', 'article:' . $loginUser);
     if (empty($loginUser)) {
         Log::write('debug', '未ログインエラー');
         return $this->redirect(['action' => '../Error/index']);
     }
 }
 public function search()
 {
     if ($this->request->is('ajax')) {
         Log::write('debug', 'Dies ist ein Test');
         $isbn = $this->request->query['value'];
         echo json_encode(Dnb::dnb($isbn));
         die;
     }
 }
 /**
  * testLogging
  *
  * @return void
  */
 public function testLogging()
 {
     Log::config('dblogtest', ['className' => 'Burzum\\DatabaseLog\\Log\\Engine\\DatabaseLog', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency']]);
     Log::write('warning', 'testing');
     $result = $this->Logs->find()->first();
     $this->assertEquals($result->level, 'warning');
     $this->assertEquals($result->message, 'testing');
     $this->Logs->deleteAll([]);
 }
Esempio n. 10
0
 public function afterRules(Cake\Event\Event $event, Cat $entity, \ArrayObject $options, $result, $operation)
 {
     Log::write("debug", "afterRules");
     Log::write("debug", $event->name());
     Log::write("debug", "entity " . $entity);
     Log::write("debug", $options);
     Log::write("debug", "result " . $result);
     Log::write("debug", "operation " . $operation);
 }
Esempio n. 11
0
 public function send(Email $email)
 {
     $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']);
     $to = $headers['To'];
     $subject = str_replace(["\r", "\n"], '', $email->subject());
     $to = str_replace(["\r", "\n"], '', $to);
     $message = implode('\\n', $email->message());
     Log::write('debug', 'Mail: to(' . $to . ') subject(' . $subject . ') message(' . $message . ')');
     return ['headers' => $headers, 'message' => $message];
 }
 /**
  * @return void
  */
 public function testReset()
 {
     $this->Logs = TableRegistry::get('DatabaseLog.DatabaseLogs');
     Log::write('info', 'six');
     $count = $this->Logs->find()->count();
     $this->assertTrue($count > 0);
     $this->Shell->runCommand(['reset', '-q']);
     $count = $this->Logs->find()->count();
     $this->assertSame(0, $count);
 }
 /**
  * Tests the log write method
  *
  * @return void
  */
 public function testLogWriting()
 {
     $View = new View();
     $countBefore = $this->Logs->find()->count();
     $View->log('x');
     $View->log('warning', LOG_WARNING);
     Log::write(LOG_ERR, 'y');
     Log::write(LOG_INFO, 'z');
     $countAfter = $this->Logs->find()->count();
     $this->assertSame($countBefore + 8, $countAfter);
     // should be 4 (but for some reason everything is added twice
 }
Esempio n. 14
0
 /**
  * Handles exception logging
  *
  * @param \Exception $exception Exception instance.
  * @return bool
  */
 protected function _logException(\Exception $exception)
 {
     $blacklist = ['Cake\\Routing\\Exception\\MissingControllerException', 'Cake\\Routing\\Exception\\MissingActionException', 'Cake\\Routing\\Exception\\PrivateActionException', 'Cake\\Routing\\Exception\\NotFoundException'];
     if (isset($this->_options['log404'])) {
         $blacklist = $this->_options['log404'];
     }
     if ($blacklist && in_array(get_class($exception), (array) $blacklist)) {
         $level = LOG_ERR;
         Log::write($level, $this->_getMessage($exception), ['404']);
         return;
     }
     return parent::_logException($exception);
 }
Esempio n. 15
0
 /**
  * Handles exception logging
  *
  * @param \Exception $exception Exception instance.
  * @return bool
  */
 protected function _logException(Exception $exception)
 {
     $blacklist = ['Cake\\Routing\\Exception\\MissingControllerException', 'Cake\\Routing\\Exception\\MissingActionException', 'Cake\\Routing\\Exception\\PrivateActionException', 'Cake\\Routing\\Exception\\NotFoundException', 'Cake\\Datasource\\Exception\\RecordNotFoundException', 'Cake\\Network\\Exception\\MethodNotAllowedException', 'Cake\\Network\\Exception\\BadRequestException', 'Cake\\Network\\Exception\\ForbiddenException', 'Cake\\Network\\Exception\\GoneException', 'Cake\\Network\\Exception\\ConflictException', 'Cake\\Network\\Exception\\InvalidCsrfToken', 'Cake\\Network\\Exception\\UnauthorizedException', 'Cake\\Network\\Exception\\NotAcceptableException'];
     if (isset($this->_options['log404'])) {
         $blacklist = $this->_options['log404'];
     }
     if ($blacklist && in_array(get_class($exception), (array) $blacklist)) {
         $level = LOG_ERR;
         Log::write($level, $this->_getMessage($exception), ['404']);
         return false;
     }
     return parent::_logException($exception);
 }
 /**
  * This is the menuboard code
  * @param string $iusername
  * @return Ambigous <void, \Cake\Network\Response>
  */
 public function menuboard($iusername = null)
 {
     $this->set('username', $this->Auth->user('Admin_Username'));
     $iusername = $this->Auth->user('Admin_Username');
     $dbConn = $this->getDBConnector();
     if ($iusername == null || empty($iusername)) {
         Log::write('debug', 'Unable to display information on dashboard was shown because the email address that was passed was empty or null.');
         return $this->redirect(['action' => 'logout', 'System Error. Please check back after sometime']);
     }
     $AdministratorModel = $this->AdministratorT;
     $results = $AdministratorModel->fetchRegisteredUser($dbConn, $iusername);
     Log::write('debug', 'Admin Username retrieved from database is ' . $results->Admin_Username);
     $this->set('results', $results);
 }
 /**
  * QueueEmailTask::run()
  *
  * @param mixed $data Job data
  * @param int|null $id The id of the QueuedTask
  * @return bool Success
  */
 public function run($data, $id = null)
 {
     if (!isset($data['settings'])) {
         $this->err('Queue Email task called without settings data.');
         return false;
     }
     /* @var \Cake\Mailer\Email $email */
     $email = $data['settings'];
     if (is_object($email) && $email instanceof Email) {
         try {
             $transportClassNames = $email->configuredTransport();
             $result = $email->transport($transportClassNames[0])->send();
             if (!isset($config['log']) || !empty($config['logTrace']) && $config['logTrace'] === true) {
                 $config['log'] = 'email_trace';
             } elseif (!empty($config['logTrace'])) {
                 $config['log'] = $config['logTrace'];
             }
             if (isset($config['logTrace']) && !$config['logTrace']) {
                 $config['log'] = false;
             }
             if (!empty($config['logTrace'])) {
                 $this->_log($result, $config['log']);
             }
             return (bool) $result;
         } catch (Exception $e) {
             $error = $e->getMessage();
             $error .= ' (line ' . $e->getLine() . ' in ' . $e->getFile() . ')' . PHP_EOL . $e->getTraceAsString();
             Log::write('email_error', $error);
             return false;
         }
     }
     $class = 'Tools\\Mailer\\Email';
     if (!class_exists($class)) {
         $class = 'Cake\\Mailer\\Email';
     }
     $this->Email = new $class();
     $settings = array_merge($this->defaults, $data['settings']);
     foreach ($settings as $method => $setting) {
         call_user_func_array([$this->Email, $method], (array) $setting);
     }
     $message = null;
     if (!empty($data['vars'])) {
         if (isset($data['vars']['content'])) {
             $message = $data['vars']['content'];
         }
         $this->Email->viewVars($data['vars']);
     }
     return $this->Email->send($message);
 }
Esempio n. 18
0
function sendEmailTemplate($template, $to, $data, $options = [])
{
    try {
        $vars = [];
        foreach ($data as $k => $v) {
            $vars[] = ['name' => $k, 'content' => $v];
        }
        $to = [['email' => $to]];
        $mandrill = new Mandrill(Configure::read('Mandrill.key'));
        $message = ['to' => $to, 'headers' => array('Reply-To' => Configure::read('Mandrill.fromEmail')), 'important' => false, 'track_opens' => true, 'global_merge_vars' => $vars];
        $message = array_merge($message, $options);
        $mandrill->messages->sendTemplate($template, [], $message);
    } catch (Exception $e) {
        Log::write('error', 'Mandrill exception: ' . var_dump($e, true));
    }
}
Esempio n. 19
0
/**
 * Debug Logging Helper
 *
 * @return voidauth
 */
function dlog()
{
    $args = func_get_args();
    foreach ($args as $arg) {
        if (!is_string($arg)) {
            $arg = print_r($arg, true);
        }
        \Cake\Log\Log::write('debug', print_r($arg, true));
    }
}
Esempio n. 20
0
 /**
  * Compiles any less files passed and returns the compiled css.
  * In case of error, it will load less with the javascritp parser so you'll be
  * able to see any errors on screen. If not, check out the error.log file in your
  * CakePHP's logs folder.
  *
  * @param  mixed $less         The input .less file to be compiled or an array
  *                             of .less files
  * @param  array  $options     Options in 'js' key will be pased to the less.js
  *                             parser and options in 'parser' will be passed to the less.php parser
  * @param  array  $modify_vars Array of modify vars
  * @return string
  */
 public function less($less = 'styles.less', array $options = [], array $modify_vars = [])
 {
     $options = $this->setOptions($options);
     $less = (array) $less;
     if ($options['js']['env'] == 'development') {
         return $this->jsBlock($less, $options);
     }
     try {
         $css = $this->compile($less, $options['parser'], $modify_vars, $options['cache']);
         if (isset($options['tag']) && !$options['tag']) {
             return $css;
         }
         if (!$options['cache']) {
             return $this->Html->formatTemplate('style', ['content' => $css]);
         }
         return $this->Html->css($css);
     } catch (\Exception $e) {
         // env must be development in order to see errors on-screen
         if (Configure::read('debug')) {
             $options['js']['env'] = 'development';
         }
         $this->error = $e->getMessage();
         Log::write('error', "Error compiling less file: " . $this->error);
         return $this->jsBlock($less, $options);
     }
 }
Esempio n. 21
0
 /**
  * Creates an entry in the log file. The log entry will contain a stack trace from where it was called.
  * as well as export the variable using exportVar. By default the log is written to the debug log.
  *
  * @param mixed $var Variable or content to log.
  * @param int|string $level Type of log to use. Defaults to 'debug'.
  * @param int $depth The depth to output to. Defaults to 3.
  * @return void
  */
 public static function log($var, $level = 'debug', $depth = 3)
 {
     $source = static::trace(['start' => 1]) . "\n";
     Log::write($level, "\n" . $source . static::exportVar($var, $depth));
 }
Esempio n. 22
0
 /**
  * Creates an entry in the log file. The log entry will contain a stack trace from where it was called.
  * as well as export the variable using exportVar. By default the log is written to the debug log.
  *
  * @param mixed $var Variable or content to log
  * @param int $level type of log to use. Defaults to LOG_DEBUG
  * @param int $depth The depth to output to. Defaults to 3.
  * @return void
  * @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::log
  */
 public static function log($var, $level = LOG_DEBUG, $depth = 3)
 {
     $source = static::trace(array('start' => 1)) . "\n";
     Log::write($level, "\n" . $source . static::exportVar($var, $depth));
 }
Esempio n. 23
0
 /**
  * Log message
  *
  * @param array $contents log-data
  * @param mixed $log int for loglevel, array for merge with log-data
  * @return void
  */
 protected function _log($contents, $log)
 {
     $config = ['level' => LOG_DEBUG, 'scope' => 'email'];
     if ($log !== true) {
         if (!is_array($log)) {
             $log = ['level' => $log];
         }
         $config = array_merge($config, $log);
     }
     return;
     // for now
     Log::write($config['level'], PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'], $config['scope']);
 }
Esempio n. 24
0
 /**
  * Log an error.
  *
  * @param string $level The level name of the log.
  * @param array $data Array of error data.
  * @return bool
  */
 protected function _logError($level, $data)
 {
     $message = sprintf('%s (%s): %s in [%s, line %s]', $data['error'], $data['code'], $data['description'], $data['file'], $data['line']);
     if (!empty($this->_options['trace'])) {
         $trace = Debugger::trace(['start' => 1, 'format' => 'log']);
         $message .= "\nTrace:\n" . $trace . "\n";
     }
     $message .= "\n\n";
     return Log::write($level, $message);
 }
Esempio n. 25
0
 /**
  * Results usually from most accurate to least accurate result (street_address, ..., country)
  *
  * @param float $lat
  * @param float $lng
  * @param array $params
  * @return array Result
  */
 public function reverseGeocode($lat, $lng, $params = [])
 {
     $this->reset(false);
     $this->_setDebug('reverseGeocode', compact('lat', 'lng', 'params'));
     $latlng = $lat . ',' . $lng;
     $params = ['latlng' => $latlng] + $params;
     $this->setParams($params);
     $count = 0;
     $requestUrl = $this->_url();
     while (true) {
         $result = $this->_fetch($requestUrl, $this->params);
         if ($result === false || $result === null) {
             $this->setError('Could not retrieve url');
             Log::write('debug', __('Could not retrieve url with \'%s\'', $latlng));
             return false;
         }
         $this->_setDebug('raw', $result);
         $result = $this->_transform($result);
         if (!is_array($result)) {
             $this->setError('Result parsing failed');
             Log::write('debug', __('Failed reverseGeocode parsing of \'%s\'', $latlng));
             return false;
         }
         $status = $result['status'];
         if ($status == static::STATUS_SUCCESS) {
             if (!$this->_process($result)) {
                 return false;
             }
             // save Result
             if ($this->options['log']) {
                 Log::write('debug', __('Address \'%s\' has been geocoded', $latlng));
             }
             break;
         } elseif ($status == static::STATUS_TOO_MANY_QUERIES) {
             // sent geocodes too fast, delay +0.1 seconds
             if ($this->options['log']) {
                 Log::write('debug', __('Delay necessary for \'%s\'', $latlng));
             }
             $count++;
         } else {
             // something went wrong
             $this->setError('Error ' . $status . (isset($this->statusCodes[$status]) ? ' (' . $this->statusCodes[$status] . ')' : ''));
             if ($this->options['log']) {
                 Log::write('debug', __('Could not geocode \'%s\'', $latlng));
             }
             return false;
             # for now...
         }
         if ($count > 5) {
             if ($this->options['log']) {
                 Log::write('debug', __('Aborted after too many trials with \'%s\'', $latlng));
             }
             $this->setError(__('Too many trials - abort'));
             return false;
         }
         $this->pause(true);
     }
     return $this->getResult();
 }
Esempio n. 26
0
 /**
  * Log the email message delivery.
  *
  * @param array $contents The content with 'headers' and 'message' keys.
  * @return void
  */
 protected function _logDelivery($contents)
 {
     if (empty($this->_profile['log'])) {
         return;
     }
     $config = ['level' => LOG_DEBUG, 'scope' => 'email'];
     if ($this->_profile['log'] !== true) {
         if (!is_array($this->_profile['log'])) {
             $this->_profile['log'] = ['level' => $this->_profile['log']];
         }
         $config = $this->_profile['log'] + $config;
     }
     Log::write($config['level'], PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'], $config['scope']);
 }
Esempio n. 27
0
 public function enabled()
 {
     //Legacy Extension
     if (extension_loaded('Mongo')) {
         Log::write('debug', 'Using Legacy mongo extension');
         if (class_exists('Mongo')) {
             $this->_driverVersion = \Mongo::VERSION;
             $this->_class = 'Mongo';
         } else {
             $this->_driverVersion = \MongoClient::VERSION;
         }
         //since config should be set we will check if we have the requested version
         //if there is no config then return true
         if (empty($this->_config) || $this->_driverVersion >= $this->_config['require_version']) {
             return true;
         }
         //New Driver used with the PHP Library mongodb
     } elseif (extension_loaded('MongoDB')) {
         Log::write('debug', 'Using new mongodb extension');
         $this->_mongodb = true;
         $this->_driverVersion = MONGODB_VERSION;
         $this->_class = '\\MongoDB\\Client';
         if (empty($this->_config) || $this->_driverVersion >= $this->_config['require_version']) {
             return true;
         }
     }
     return false;
 }
Esempio n. 28
0
 /**
  * Test that write() returns false on an unhandled message.
  *
  * @return void
  */
 public function testWriteUnhandled()
 {
     Log::drop('error');
     Log::drop('debug');
     $result = Log::write('error', 'Bad stuff', 'unpossible');
     $this->assertFalse($result);
 }
 /**
  * To carry out mass actions on Reports
  * Currently only to change their statuses.
  * Can be Extended for other mass operations as well.
  * Expects an array of Report Ids as a POST parameter.
  *
  */
 public function mass_action()
 {
     $flash_class = "alert alert-error";
     $state = $this->request->data['state'];
     $newState = $this->Reports->status[$state];
     if (!$newState) {
         Log::write('error', 'ERRORED: Invalid param "state" in ReportsController::mass_action()', 'alert');
         $msg = "ERROR: Invalid State!!";
     } else {
         if (count($this->request->data['reports']) == 0) {
             $msg = "No Reports Selected!! Please Select Reports and try again.";
         } else {
             $msg = "Status has been changed to '" . $this->request->data['state'] . "' for selected Reports!";
             $flash_class = "alert alert-success";
             foreach ($this->request->data['reports'] as $report_id) {
                 $report = $this->Reports->get($report_id);
                 if (!$report) {
                     Log::write('error', 'ERRORED: Invalid report_id in ReportsController::mass_action()', 'alert');
                     $msg = "ERROR:Invalid Report ID:" . $report_id;
                     $flash_class = "alert alert-error";
                     break;
                 }
                 $report->status = $state;
                 $this->Reports->save($report);
             }
         }
     }
     $this->Flash->default($msg, array("class" => $flash_class));
     $this->redirect("/reports/");
 }
Esempio n. 30
0
 /**
  * Wrapper function for the logger object, useful for unit testing
  * or for overriding in subclasses.
  *
  * @param LoggedQuery $query to be written in log
  * @return void
  */
 protected function _log($query)
 {
     Log::write('debug', $query, ['queriesLog']);
 }