Re: feature-request : html + css logging in apache logs (example for the rest of the unix community too)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



eh oops, this would've maybe been easier, and allows me to update these
sources in the future if and when needed..

https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/functions__basicErrorHandling.php
https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/1.0.0/functions.php
https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/functions__internalErrorHandling.php
light background css :
https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/webappObfuscator-1.0.0__ajax.css
dark background css :
https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/webappObfuscator-1.0.0.css


On Sun, Aug 28, 2016 at 5:21 AM, Rene Veerman <
rene.veerman.netherlands@xxxxxxxxx> wrote:

> all are donated to public domain :
>
> __FILE__==='functions__internalErrorHandling.php';
> <?php
> require_once (dirname(__FILE__).'/1.0.0/functions.php');
> require_once (dirname(__FILE__).'/functions__basicErrorHandling.php');
>
> function woError ($errCode, $errMsgOrArray) {
> if (is_array($errMsgOrArray)) {
>
> if (ob_get_length()>0) ob_end_flush();
> ob_start();
> var_dump ($errMsgOrArray);
> $errMsg = ob_get_clean();
> } else if (
> is_string($errMsgOrArray)
> || is_int($errMsgOrArray)
> || is_float($errMsgOrArray)
> ) {
> $errMsg = '' . $errMsgOrArray;
> } else if (
> is_bool($errMsgOrArray)
> ) {
> $errMsg = (
> $errMsgOrArray
> ? 'TRUE'
> : 'FALSE'
> );
> }
> //echo 't1200';
> //echo '<pre>'; var_dump (debug_backtrace()); echo '</pre>'; in
> badResult() instead
> trigger_error ($errMsg, $errCode);
> }
>
> function woBasicErrorHandler ($errno, $errstr, $errfile, $errline,
> $errcontext) {
>   //echo 'woBasicErrorHandler.main:start';
> $stacktrace = debug_backtrace();
> $errType = wo_php_errorType_humanReadable($errno);
> $errSeverity = 'woErrorSeverity__error';
> if (stripos($errType, 'warning')!==false) $errSeverity =
> 'woErrorSeverity__warning';
> if (stripos($errType, 'notice')!==false) $errSeverity =
> 'woErrorSeverity__notice';
>
> if (stripos($errType, 'user')!==false) $errSeverity .= '
> woErrorSeverity__user';
> if (stripos($errType, 'parse')!==false) $errSeverity .= '
> woErrorSeverity__parse';
> if (stripos($errType, 'core')!==false) $errSeverity .= '
> woErrorSeverity__core';
> if (stripos($errType, 'compile')!==false) $errSeverity .= '
> woErrorSeverity__compile';
> $html =
> '<div class="woError '.$errSeverity.'"><h1>webappObfuscator error</h1>'
> .'<p>'.$errType.' : '.$errstr.'</p>'
> .woBasicErrorHandler__prettyStacktrace ($stacktrace)
> .'</div>';
> echo $html;
> //reportStatus (1, $html); // RV : where the F is that function??
> die();
> /*
> echo '<h1>dfo error</h1><p>'.errorType_humanReadable($errno).' :
> '.$errstr.'<br/>stacktrace:</p><pre>';
> var_dump ($stacktrace);
> echo '</pre>';*/
> }
>
> function woBasicErrorHandler__prettyStacktrace ($st) {
> global $errorsBasepath;
> $r =
> '<div class="woStacktrace">'
> .'<span class="woStacktrace__basePath">All filenames are under :
> '.$errorsBasepath.'</span><br/>';
> foreach ($st as $stackNumber => $stackData) {
> if (array_key_exists('file', $stackData)) {
> $relPath = '...'.str_replace($errorsBasepath, '', $stackData['file']);
> } else {
> $relPath = '.../';
> };
> if (array_key_exists('line', $stackData)) {
> $line = '<span class="woStacktrace__line">(line
> '.$stackData['line'].')</span>';
> } else {
> $line = '';
> }
> $file = '<span class="woStacktrace__file">__FILE__ : '.$relPath.'</span>
> ';
> $function =
> '<span class="woStacktrace__function">'.$stackData['function'].'( '
> .(
> array_key_exists('args',$stackData)
> ? woBasicErrorHandler__prettyStacktrace__arguments ($stackData['args'])
> : ''
> )
> .' )</span>';
> //if ($stackNumber > 0) { // ignore the call to saBasicErrorHandler()
> itself
> $r .=
> '<div class="woStacktrace__item">'
> .$file.' '
> .$line.' calls '
> .$function
> .'</div>';
> //}
> };
> $r .= '</div>';
> return $r;
> }
>
> function woBasicErrorHandler__prettyStacktrace__arguments ($args) {
> $r = '<span class="woStacktrace__args">';
> foreach ($args as $argIdx => $arg) {
> if (is_array($arg)) {
> $r .= '<span class="woStacktrace__arg">'.htmlentities(json_encode($arg)
> ).'</span>';
> } elseif (is_object($arg)) {
> $r .= '<span class="woStacktrace__arg">'.htmlentities(json_encode($arg)
> ).'</span>';
> } else {
> $r .= '<span class="woStacktrace__arg">'.htmlentities($arg).'</span>';
> }
> $r .= '<span class="woStacktrace__argSeperator">, </span>';
> }
> $r .= '</span>';
> return $r;
> }
>
> function wo_php_json_last_error_humanReadable ($errNo) {
> // taken from http://php.net/manual/en/function.json-last-error.php
> // on 2015 July 9th, valid for php version up to 5.5.0
> $errorTypes = array (
> JSON_ERROR_NONE => array (
> 'errorCode' => 'JSON_ERROR_NONE',
> 'msg' => 'No error has occurred'
> ),
> JSON_ERROR_DEPTH => array (
> 'errorCode' => 'JSON_ERROR_DEPTH',
> 'msg' => 'The maximum stack depth has been exceeded'
> ),
> JSON_ERROR_STATE_MISMATCH => array (
> 'errorCode' => 'JSON_ERROR_STATE_MISMATCH',
> 'msg' => 'Invalid or malformed JSON'
> ),
> JSON_ERROR_CTRL_CHAR => array (
> 'errorCode' => 'JSON_ERROR_CTRL_CHAR',
> 'msg' => 'Control character error, possibly incorrectly encoded'
> ),
> JSON_ERROR_SYNTAX => array (
> 'errorCode' => 'JSON_ERROR_SYNTAX',
> 'msg' => 'Syntax error'
> ),
> JSON_ERROR_UTF8 => array (
> 'errorCode' => 'JSON_ERROR_UTF8',
> 'msg' => 'Malformed UTF-8 characters, possibly incorrectly encoded'
> )/*,
> JSON_ERROR_RECURSION => array (
> 'errorCode' => 'JSON_ERROR_RECURSION',
> 'msg' => 'One or more recursive references in the value to be encoded'
> ),
> JSON_ERROR_INF_OR_NAN => array (
> 'errorCode' => 'JSON_ERROR_INF_OR_NAN',
> 'msg' => 'One or more NAN or INF values in the value to be encoded'
> ),
> JSON_ERROR_UNSUPPORTED_TYPE => array (
> 'errorCode' => 'JSON_ERROR_UNSUPPORTED_TYPE',
> 'msg' => 'A value of a type that cannot be encoded was given'
> )*/
> );
> if ($errNo===0) {
> $r = $errorTypes[0];
> } else {
> $r =
> array_key_exists ($errNo, $errorTypes)
> ? $errorTypes[$errNo]
> : array (
> 'errorCode' => 'ERROR_UNKNOWN_ERROR',
> 'msg' => 'json_last_error() returned a code that is unknown to
> fucntions__basicErrorHandling.php::wo_php_json_last_error_humanReadable()'
> );
> };
> return $r;
> }
>
> function wo_php_errorType_humanReadable ($errNo) {
>
>     if (phpversion() < '4.0.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
>     2047   => 'E_ALL'
> );
>     } elseif (phpversion() < '5.0.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
> 16  =>  'Core Error',
> 32  =>  'Core Warning',
> 64  =>  'Compile Error',
> 128 =>  'Compile Warning',
> 256 =>  'User Error',
> 512 =>  'User Warning',
> 1024=>  'User Notice',
> 2047=> 'E_ALL'
> );
>
>     } elseif (phpversion() < '5.2.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
> 16  =>  'Core Error',
> 32  =>  'Core Warning',
> 64  =>  'Compile Error',
> 128 =>  'Compile Warning',
> 256 =>  'User Error',
> 512 =>  'User Warning',
> 1024=>  'User Notice',
> 2048=> 'Strict',
> 2047=> 'E_ALL'
> );
>
>     } elseif (phpversion() < '5.3.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
> 16  =>  'Core Error',
> 32  =>  'Core Warning',
> 64  =>  'Compile Error',
> 128 =>  'Compile Warning',
> 256 =>  'User Error',
> 512 =>  'User Warning',
> 1024=>  'User Notice',
> 2048=> 'Strict',
> 4096=> 'Recoverable',
> 6143=> 'E_ALL'
> );
>
>     } elseif (phpversion() >= '5.3.0' && phpversion() < '6.0.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
> 16  =>  'Core Error',
> 32  =>  'Core Warning',
> 64  =>  'Compile Error',
> 128 =>  'Compile Warning',
> 256 =>  'User Error',
> 512 =>  'User Warning',
> 1024=>  'User Notice',
> 2048=> 'Strict',
> 4096=> 'Recoverable',
> 8192=> 'Depracated',
>       16384=> 'User-level Depracated',
>       30719=> 'E_ALL'
> );
>
>     } elseif (phpversion() >= '6.0.0') {
> $errorTypes = array (
> 1   =>  'Error',
> 2   =>  'Warning',
> 4   =>  'Parsing Error',
> 8   =>  'Notice',
> 16  =>  'Core Error',
> 32  =>  'Core Warning',
> 64  =>  'Compile Error',
> 128 =>  'Compile Warning',
> 256 =>  'User Error',
> 512 =>  'User Warning',
> 1024=>  'User Notice',
> 2048=> 'Strict',
> 4096=> 'Recoverable',
> 8192=> 'Depracated',
>       16384=> 'User-level Depracated',
>       32767=> 'E_ALL'
> );
>     }
>
>     return $errorTypes[$errNo];
> }
>
> ?>
>
> __FILE__==='functions__internalErrorHandling.php';
>
> <?php
> /*---
>   this is my way of providing quality runtime debugging info
> (to the computerprogram itself, to developers, to end-users)
> and -even more important- creating robust computerprograms that
> can be debugged quickly when they break when they're faced with the
> unexpected.
> a future version of this will email all the *releveant* debug details
> to the developer(s) whenever the unexpected hits the computer program
> using this.
> draft of this extension is detailed in webappObfuscator-1.0.0.php:::
> webappObfuscator::readTokens()
> */
>
> function badResult ($errNo, $errMeta=null) {
> if (
>  is_string($errNo)
>  || is_array($errNo)
> ) {
>  $errMeta = $errNo;
>  $errNo = E_USER_ERROR;
>  $errMeta['additionalError'] = 'badResult called with no $errNo as first
> parameter';
> };
> if (is_string($errMeta)) {
> $errMeta = array ('msg'=>$errMeta);
> };
> //$errMeta = filterArgs($errMeta, $filterSettings);
>
> $e = array (
> 'isMetaForFunc' => true,
> 'phpErrorClass' => $errNo,
> 'phpErrorType' => wo_php_errorType_humanReadable ($errNo),
> 'error' => $errMeta,
> );
> $traceData = debug_backtrace();
> $e['backtrace'] = $traceData;//phpFilterBacktraceData($
> traceData,$filterSettings);
> $e['globals'] = getGlobals();
> //var_dump ($e);
> /*if (function_exists('saError')) {
>  echo 'error handler === saError()';
>  saError ($errNo, $errMeta); // http://seductiveapps.com
> } else*/if (function_exists('woError')) {
>  echo 'error handler === woError()';
>  woError ($errNo, $errMeta);
> } else {
>  echo 'functions__internalErrorHandling.php::no error handler specified,
> var_dump-ing.<pre>';
>  var_dump ($e);
>  echo '</pre>';
> }
> return $e;
> }
>
> function getGlobals() {
> $r = array (
> '$_GET' => $_GET,
> '$_POST' => $_POST,
> '$_COOKIE' => $_COOKIE
> );
> return $r;
> }
>
> function good($r) {
> return (
> is_array($r)
> && array_key_exists('result',$r)
> );
> }
>
> //function &result(&$r) {
> function &result(&$r) {
> return $r['result'];
> }
>
> function &resultArray (&$r) {
>   $r2 = array();
>   foreach ($r as $k => $v) {
>     $r2[$k] = result($v);
>   }
>   return $r2;
> }
>
>
> function &goodResult(&$r) {
> $r2 = array (
> 'isMetaForFunc' => true,
> 'result' => &$r
> );
> return $r2;
> }
> ?>
>
> __FILE__==='errorHandling_css_forLightBackgrounds.css'
> .woError { border : 2px solid red; border-radius : 5px; padding : 5px;
> background : yellow; color : red; }
> .woStacktrace { font-size : 90%; font-weight : bold; }
> .woStacktrace__basePath { color : purple; }
> .woStacktrace__item { }
> .woStacktrace__file { color : navy; }
> .woStacktrace__function { color : #002300; }
> .woStacktrace__line { color : blue;  }
> .woStacktrace__args { color : navy; font-weight : normal; }
> .woStacktrace__arg { color : blue; }
> .woStacktrace__argSeperator { color : purple; background : white;
> font-weight : bold; font-size : 100%; }
>
>
> __FILE__==='errorHandling_css_forDarkOrSemitransparentBackgrounds.css'
> .woError { border : 2px solid red; border-radius : 5px; padding : 5px;
> background : yellow; color : red; opacity : 0.767 }
> .woStacktrace { font-size : 90%; font-weight : bold; }
> .woStacktrace__basePath { color : purple; }
> .woStacktrace__item { }
> .woStacktrace__file { color : navy; }
> .woStacktrace__function { color : #002300; }
> .woStacktrace__line { color : blue;  }
> .woStacktrace__args { color : navy; font-weight : normal; }
> .woStacktrace__arg { color : blue; }
> .woStacktrace__argSeperator { color : purple; background : white;
> font-weight : bold; font-size : 100%; }
>
> On Sun, Aug 28, 2016 at 5:16 AM, Rene Veerman <rene.veerman.netherlands@
> gmail.com> wrote:
>
>> nothing's better than cut-n-pasting, i knooow :)
>>
>> so in the next few messages i'll include my own PHP handlers.. it's 4
>> files, which i'll just post as ordinary text.. dunno and dont wanna test if
>> attaching works to the entire list architecture (web caches and stuff)..
>>
>> On Sun, Aug 28, 2016 at 5:07 AM, Rene Veerman <
>> rene.veerman.netherlands@xxxxxxxxx> wrote:
>>
>>> Hi.
>>>
>>> Once again, thanks for keeping PHP free to use and so widely and easily
>>> installed..
>>>
>>> I have another feature request (sent earlier tonight)..
>>>
>>> I quite often, much more than i like, *need* a stacktrace and *proper*
>>> variable listings for each function called in PHP when it barfs out nothing
>>> more than an apache error log entry..
>>> And can we please show such entries in the browser *as well as the
>>> apache log*? Or if nothing else, *just* in the browser?
>>>
>>> Rather than going "all the way" and making variable contents (which can
>>> grow quite large) collapsable and shit *right away*, you could simply add
>>> the right <span> and <p> class="" names and supply a CSS file. I use it in
>>> all error handling that does make it to set_error_handler(myHandler), and
>>> that really is what makes things like my obfuscator (also posted about to
>>> the php-general@xxxxxxxxxxxxx earlier tonight) possible.
>>> And taking things that far allows guys like me to provide you with a
>>> collapsable large-JSON-decoding viewer addon for such logfiles later (rest
>>> assured that that'll get done once you do this for me).. i call it
>>> jsonViewer and i should have it back up at
>>> http://seductiveapps.com/tools/json (or /jsonViewer) once the
>>> obfuscator is fully done in a few weeks, at most..
>>>
>>> if you want me to build (and opensource) things like that
>>> true-obfuscator and my JSON scalable database architecture using just
>>> apache2+ and php5+, it would really cut my development time in more than
>>> half if you could add "all of this" (it's deadsimple and a few hours work
>>> imo) to the next versions of PHP (and please make it the default, you can
>>> include sample CSS or read in a CSS file that you set in php.ini (comment
>>> on how to do this in the logfile html please))..
>>>
>>> see https://github.com/seductiveapps/folderDB/blob/master/todo.p
>>> latform.txt for all relevant updates concerning these developments
>>> mentioned here..
>>>
>>> Thanks in advance for considering and likely adopting the 2 small
>>> changes i need in the next versions of PHP.. I run ubuntu btw.. I'll be
>>> checking the php.net pages for your future updates..
>>>
>>> If anyone can gimme a duration-to-completion for each of my requests of
>>> tonight, that'd be awesome. I'll take a "wild guess", or any serious
>>> objections that i might be able to sway out of the way..
>>>
>>>
>>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux