code != RackTablesError::NOT_AUTHENTICATED) { // in debug mode, dump backtrace instead of standard page // NOT_AUTHENTICATED exception does not need debugging, so it is skipped printGenericException ($this); return; } header ('Content-Type: text/html; charset=UTF-8'); echo ''."\n"; echo ''."\n"; echo "${title}"; echo "${text}"; if (isset ($helpdesk_banner)) echo '
' . $helpdesk_banner; echo ''; } protected static function formatString ($string) { return isCLIMode() ? $string : stringForLabel ($string, 80); } public function dispatch() { $msgheader = array ( self::MISCONFIGURED => 'Configuration error', self::INTERNAL => 'Internal error', self::DB_WRITE_FAILED => 'Database write failed', ); $msgbody = array ( self::MISCONFIGURED => '

Configuration error


' . $this->message, self::INTERNAL => '

Internal error


' . $this->message, self::DB_WRITE_FAILED => '

Database write failed


' . $this->message, ); switch ($this->code) { case self::NOT_AUTHENTICATED: header ('WWW-Authenticate: Basic realm="' . getConfigVar ('enterprise') . ' RackTables access"'); header ('HTTP/1.1 401 Unauthorized'); $this->genHTMLPage ('Not authenticated', '

This system requires authentication. You should use a username and a password.

'); break; case self::MISCONFIGURED: case self::INTERNAL: case self::DB_WRITE_FAILED: $this->genHTMLPage ($msgheader[$this->code], $msgbody[$this->code]); break; default: throw new RackTablesError ('Dispatching error, unknown code ' . $this->code, RackTablesError::INTERNAL); } } } class EntityNotFoundException extends RackTablesError { function __construct ($realm, $id) { parent::__construct ("Record '${realm}'#'${id}' does not exist"); } public function dispatch() { global $debug_mode; if ($debug_mode) { printGenericException ($this); return; } showError ($this->message); redirectUser (buildRedirectURL ('index', 'default')); } } class ERetryNeeded extends RackTablesError { function __construct ($message) { $this->code = parent::INTERNAL; parent::__construct ($message); } } class InvalidArgException extends RackTablesError { // derive an instance of InvalidRequestArgException function newIRAE ($argname = NULL) { if ($argname === NULL) return new InvalidRequestArgException ($this->name, $this->value, $this->reason); return new InvalidRequestArgException ($argname, $_REQUEST[$argname], $this->reason); } function __construct ($name, $value, $reason = NULL) { $message = 'Argument \'' . self::formatString ($name) . '\'' . ' of value ' . self::formatString (var_export ($value, TRUE), 200) . ' is invalid' . (is_null ($reason) ? '' : ' (' . self::formatString ($reason, 100) . ')') . '.'; parent::__construct ($message, parent::INTERNAL); $this->name = $name; $this->value = $value; $this->reason = $reason; } } // this simplifies construction and helps in catching "soft" // errors (invalid input from the user) class InvalidRequestArgException extends InvalidArgException { public function dispatch() { RackTablesError::genHTMLPage ('Assertion failed', '

Assertion failed


' . $this->message); } } // this wraps certain known PDO errors and is caught in process.php // as a "soft" error class RTDatabaseError extends RackTablesError { public function dispatch() { RackTablesError::genHTMLPage ('Database soft error', '

Database soft error


' . $this->message); } } // gateway failure is a common case of a "soft" error, some functions do catch this class RTGatewayError extends RackTablesError { public function dispatch() { RackTablesError::genHTMLPage ('Gateway error', '

Gateway error


' . $this->message); } } # "Permission denied" is a very common case, which in some situations is # treated as a "soft" error. class RTPermissionDenied extends RackTablesError { public function dispatch() { global $pageno, $tabno, $user_given_tags, $target_given_tags, $auto_tags, $expl_tags, $impl_tags; header ('Content-Type: text/html; charset=UTF-8'); echo '' . "\n"; echo '' . "\n"; echo "RackTables: access denied\n"; printPageHeaders(); echo ''; echo "\n"; echo ''; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "\n"; echo "\n"; echo "\n"; echo "

' . getImageHREF ('DENIED') . ' access denied '; echo getImageHREF ('DENIED') . '

User given tags:'; echo serializeTags ($user_given_tags) . " 
Target given tags:'; echo serializeTags ($target_given_tags) . " 
Effective explicit tags:'; echo serializeTags ($expl_tags) . " 
Effective implicit tags:'; echo serializeTags ($impl_tags) . " 
Automatic tags:'; echo serializeTags ($auto_tags) . " 
Requested page:${pageno}
Requested tab:${tabno}
Click here to logout.
\n"; echo ''; } } class RackCodeError extends RackTablesError { protected $lineno; function __construct ($message, $lineno = 'unknown') { # RackCodeError without a catch-block is very likely an internal error parent::__construct ($message, self::INTERNAL); $this->lineno = $lineno; } public function dispatch() { parent::genHTMLPage ('RackCode error', '

RackCode error on line ' . $this->lineno . '


' . $this->message); } } // Whether there is a failure to produce a normal image, this class will emit one // of the hardcoded last-resort images without the dependency on PHP-GD. class RTImageError extends RackTablesError { protected $imgbin; function __construct ($subject = NULL) { $map = array ( 'pbar_error' => IMG_100x10_PBAR_ERROR, 'pbar_php_gd_error' => IMG_100x10_PHP_GD_NA, 'pbar_arg_error' => IMG_100x10_ARG_ERROR, 'rack_php_gd_error' => IMG_45x90_PHP_GD_NA, 'rack_not_found' => IMG_45x90_RACK_NOT_FOUND, 'rack_arg_error' => IMG_45x90_MALF_REQ, 'access_denied' => IMG_1x1_BLACK, ); $this->imgbin = base64_decode (array_fetch ($map, $subject, IMG_76x17_ERROR)); } public function dispatch() { header ('Content-Type: image/png'); echo $this->imgbin; } } function dumpArray ($arr) { echo ''; foreach ($arr as $key => $value) echo ''; echo '
' . stringForTD ($key) . '' . stringForTD ($value, 100) . '
'; } function stringTrace ($trace) { $ret = ''; foreach ($trace as $line) { if (isset ($line['file']) && isset ($line['line'])) $ret .= $line['file'] . ':' . $line['line'] . ' '; $ret .= $line['function'] . '('; $f = TRUE; if (isset ($line['args']) && is_array ($line['args'])) foreach ($line['args'] as $arg) { if (! $f) $ret .= ', '; if (is_string ($arg)) $printarg = '\'' . $arg . '\''; elseif (is_null ($arg)) $printarg = 'NULL'; elseif (is_array ($arg)) $printarg = print_r ($arg, 1); elseif (is_object ($arg)) $printarg = 'Object(' . get_class ($arg) . ')'; else $printarg = $arg; $ret .= $printarg; $f = FALSE; } $ret .= ")\n"; } return $ret; } function printPDOException ($e) { header ('HTTP/1.1 500 Internal Server Error'); header ('Content-Type: text/html; charset=UTF-8'); echo '' . "\n"; echo '' . "\n"; echo " PDO Exception \n"; echo "\n"; echo "\n"; echo ' '; echo '

Pdo exception: ' . get_class ($e) . '

' . $e->getMessage() . ' (' . $e->getCode() . ')'; echo '

at file ' . $e->getFile() . ', line ' . $e->getLine() . '

';
	echo stringTrace ($e->getTrace());
	echo '
'; echo '

Error info:

'; echo '
';
	print_r ($e->errorInfo);
	echo '
'; echo '

Parameters:

'; echo '

GET

'; dumpArray ($_GET); echo '

POST

'; dumpArray ($_POST); echo '

COOKIE

'; dumpArray ($_COOKIE); echo ''; } function printGenericException ($e) { header('HTTP/1.1 500 Internal Server Error'); header ('Content-Type: text/html; charset=UTF-8'); echo '' . "\n"; echo '' . "\n"; echo " Exception \n"; echo "\n"; echo "\n"; echo ' '; echo '

Uncaught exception: ' . get_class ($e) . '

' . $e->getMessage() . ' (' . $e->getCode() . ')'; echo '

at file ' . $e->getFile() . ', line ' . $e->getLine() . '

';
	echo stringTrace ($e->getTrace());
	echo '
'; echo '

Parameters:

'; echo '

GET

'; dumpArray ($_GET); echo '

POST

'; dumpArray ($_POST); echo '

COOKIE

'; dumpArray ($_COOKIE); echo ''; } function printException ($e) { if ($e instanceof RackTablesError) $e->dispatch(); elseif ($e instanceof PDOException) printPDOException ($e); else printGenericException ($e); } ?>