Skip to content

Commit

Permalink
Merge pull request #3 from k1LoW/mod-notifier
Browse files Browse the repository at this point in the history
Update ExceptionNotifier `Client IP` `Referer`
  • Loading branch information
k1LoW committed Apr 2, 2015
2 parents bc42a9d + 4cf523c commit 81946e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Lib/ExceptionText.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;

class ExceptionText {
Expand Down Expand Up @@ -35,7 +34,8 @@ public static function getText($message, $file, $line, $context = null){
'-------------------------------',
'',
'* URL : ' . self::getUrl(),
'* IP address: ' . env('REMOTE_ADDR'),
'* Client IP : ' . self::getClientIp(),
'* Referer : ' . env('HTTP_REFERER'),
'* Parameters: ' . trim(print_r($params, true)),
'* Cake root : ' . APP,
'',
Expand Down Expand Up @@ -95,8 +95,10 @@ public static function getHtml($message, $file, $line, $context = null){
'',
'<h3>URL</h3>',
self::getUrl(),
'<h3>IP address</h3>',
env('REMOTE_ADDR'),
'<h3>Client IP</h3>',
self::getClientIp(),
'<h3>Referer</h3>',
env('HTTP_REFERER'),
'<h3>Parameters</h3>',
self::dumper($params),
'<h3>Cake root</h3>',
Expand Down Expand Up @@ -152,4 +154,36 @@ public static function getUrl() {
$protocol = array_key_exists('HTTPS', $_SERVER) ? 'https' : 'http';
return $protocol . '://' . env('HTTP_HOST') . env('REQUEST_URI');
}

/**
* getClientIp
*
*/
public static function getClientIp(){
$safe = Configure::read('ExceptionNotifier.clientIpSafe');
if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
$env = 'HTTP_X_FORWARDED_FOR';
$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
} else {
if (env('HTTP_CLIENT_IP')) {
$env = 'HTTP_CLIENT_IP';
$ipaddr = env('HTTP_CLIENT_IP');
} else {
$env = 'REMOTE_ADDR';
$ipaddr = env('REMOTE_ADDR');
}
}

if (env('HTTP_CLIENTADDRESS')) {
$tmpipaddr = env('HTTP_CLIENTADDRESS');

if (!empty($tmpipaddr)) {
$env = 'HTTP_CLIENTADDRESS';
$ipaddr = preg_replace('/(?:,.*)/', '', $tmpipaddr);
}
}
return trim($ipaddr) . ' [' . $env . ']';
}


}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Add the following code in AppController.php
- ExceptionNotifier.force
- ExceptionNotifier.prefix
- ExceptionNotifier.html
- ExceptionNotifier.clientIpSafe
- ExceptionNotifier.allowedException
- ExceptionNotifier.deniedException

Expand Down

0 comments on commit 81946e5

Please sign in to comment.