Source for file exceptions.inc

Documentation is available at exceptions.inc

  1. <?php
  2. /**
  3.  * exceptions.inc
  4.  *
  5.  * This is the default exception handler, thown by the web gui
  6.  * We will log information about the error and send the user to
  7.  * a n approriate error page
  8.  *
  9.  * Parameters:
  10.  *    $in_exception         - the exception that was thrown.
  11.  * Long description for file:
  12.  * Class to handle User login, authetication, authorisation
  13.  *
  14.  * @package     FreeNAC
  15.  * @author      Sean Boran (FreeNAC Core Team)
  16.  * @copyright   2008 FreeNAC
  17.  * @license     http://www.gnu.org/copyleft/gpl.html   GNU Public License Version 3
  18.  * @version     SVN: $Id: exceptions.inc,v 1.1 2008/02/22 13:04:57 root Exp root $
  19.  * @link        http://freenac.net
  20.  *
  21.  */
  22.  
  23.  
  24. ## install our custom exception handler.
  25. set_error_handler('app_error_handler');
  26. set_exception_handler('exception_handler');
  27.  
  28.  
  29. function error_page($msg)
  30. {
  31.   #echo print_header();
  32.   echo <<<XX
  33.   <p class='UpdateMsg'>$msg</p>
  34.   <p>Please go <a HREF='javascript:javascript:history.go(-1)'>back to the previous screen</a>, or the 
  35.   <a href='./index.php' >Main Menu</a> and start again, or try again later.  </p>
  36. XX;
  37.  
  38.   #echo read_footer();
  39. }
  40.  
  41.  
  42. function exception_handler($ex)
  43. {
  44.   $logger=Logger::getInstance();
  45.   ## If we already have an error, then do no more.
  46.   if (isset($_SESSIONand (isset($_SESSION['errstr']or isset($_SESSION['exception']))) {
  47.     return;
  48.   }
  49.  
  50.   $class get_class($ex);
  51.   //if ($class == "DatabaseErrorException" ) {
  52.   //  return;   // its already handled seperately
  53.   //}
  54.   $msg $ex->getMessage();
  55.   $user_msg =$ex->getFile(.' line '  .$ex->getLine();
  56.   error_page($user_msg);
  57.  
  58.   // log the error: full to syslog, summary to webserver log
  59.   // LOG_ERROR=3
  60.   $logger->logit   ('EXCEPTION: class ' .$class .', line '  .$ex->getLine(
  61.                . ', '.$ex->getTraceAsString());
  62.   $logger->loghttpd('web1 ERROR: file/line: ' $ex->getFile(.' ' .$ex->getLine(
  63.                                         . ' ' $ex->getCode());
  64.  
  65.   ## Now try to send the user to a better error page, saving
  66.   ## more helpful information before we go.
  67.   #if (isset($_SESSION)) {
  68.   #  $_SESSION['exception'] = $in_exception;
  69.   #}
  70.   #header('Location: error.php');
  71. }
  72.  
  73. class DatabaseErrorException extends Exception
  74. {
  75.   function __construct($in1{
  76.     logit('DatabaseErrorException: ' .$in1);
  77.     error_page("Database error");
  78.     $_SESSION['exception']=true;    // indicate that we've handled it
  79.     parent::__construct("DB: $in1")
  80.   }
  81. }
  82. class DatabaseInsertException extends Exception
  83. {
  84.   function __construct($in1{
  85.     logit('DatabaseErrorInsertException: ' .$in1);
  86.     error_page("ERROR: The entry could not be inserted "$in1);
  87.     $_SESSION['exception']=true;    // indicate that we've handled it
  88.     parent::__construct("DB: $in1")
  89.   }
  90. }
  91.  
  92.  
  93. class FileMissingException extends Exception
  94. {
  95.   function __construct($in{
  96.     $_SESSION['exception']=true;    // indicate that we've handled it
  97.     logit("FileMissingException: $in");
  98.     parent::__construct($in)
  99.   }
  100. }
  101.  
  102.  
  103. class ArgumentTypeException extends Exception
  104. {
  105.   function __construct($in_type$in_expected{
  106.     $_SESSION['exception']=true;    // indicate that we've handled it
  107.     logit("ArgumentTypeException: Expected: $in_expected, received: $in_type");
  108.     parent::__construct("Expected: $in_expected, received: $in_type")
  109.   }
  110. }
  111.  
  112. class ArgumentRangeException extends Exception
  113. {
  114.   function __construct($in_value$in_bottom$in_top{
  115.     $_SESSION['exception']=true;    // indicate that we've handled it
  116.     parent::__construct("Value $in_value was not in the range $in_bottom .. $in_top")
  117.   }
  118. }
  119. class InsufficientRightsException extends Exception
  120. {
  121.   function __construct($in1=''{
  122.     logit('InsufficientRightsException: logindata/uid/nac_rights' 
  123.       .$_SESSION['login_data'.", " .$_SESSION['uid'.", " .$_SESSION['nac_rights'
  124.       .' from ' .$_SERVER['REMOTE_ADDR']);
  125.     $_SESSION['exception']=true;    // indicate that we've handled it
  126.     parent::__construct("Insufficient rights: "$_SESSION['login_data'])
  127.   }
  128. }
  129. {
  130.   function __construct($in1=''{
  131.     error_page("Insufficients rights: $in1");
  132.     logit('InsufficientRightsExceptionPrompt: ' .$in1);
  133.     $_SESSION['exception']=true;    // indicate that we've handled it
  134.     parent::__construct($in1)
  135.   }
  136. }
  137. class InvalidLoginException extends Exception
  138. {
  139.   function __construct($in1=''{
  140.     error_page("Invalid Login: $in1");
  141.     logit('InvalidLoginException: ' .$in1 .' from ' .$_SERVER['REMOTE_ADDR']);
  142.     $_SESSION['exception']=true;    // indicate that we've handled it
  143.     parent::__construct("Login failed: $in1")
  144.   }
  145. }
  146. class InvalidWebInputException extends Exception
  147. {
  148.   function __construct($in1=''{
  149.     echo print_header();
  150.     error_page("Invalid Argument");
  151.     logit('InvalidWebInputException: ' .$in1);
  152.     $_SESSION['exception']=true;    // indicate that we've handled it
  153.     parent::__construct($in1)
  154.   }
  155. }
  156. class InvalidWebInputShowException extends Exception
  157. {
  158.   function __construct($in1=''{
  159.     echo print_header();
  160.     error_page("$in1");
  161.     logit('InvalidWebInputShowException: ' .$in1);
  162.     $_SESSION['exception']=true;    // indicate that we've handled it
  163.     parent::__construct($in1)
  164.   }
  165. }
  166.  
  167.  
  168.  
  169. function app_error_handler $in_errno$in_errstr$in_errfile$in_errline$in_errcontext)
  170. {
  171.   $logger=Logger::getInstance();
  172.   ## If we already have an error, then do no more.
  173.   if (isset($_SESSIONand (isset($_SESSION['errstr']or isset($_session['exception']))) {
  174.     return;
  175.   }
  176.  
  177.   #error_log(date('c')
  178.   #          . " Unhandled Error ($in_errfile, $in_errline): "
  179.   #          . "$in_errno, '$in_errstr'\r\n", 3, LOGFILE_PATH);
  180.   $logger->logit("app_error_handler: $in_errstr"
  181.             . ", in $in_errfile, line: $in_errline, errno=$in_errno");
  182.  
  183.   #/**
  184.   # * if we have session information, send the user to more
  185.   # * helpful pastures.
  186.   # */
  187.   #if (isset($_SESSION))
  188.   #{
  189.   #  $_SESSION['errstr'] = "$in_errstr ($in_errfile, line $in_errline)";
  190.   #}
  191.   #header('Location: error.php');
  192. }
  193.  
  194. ?>

Documentation generated on Mon, 17 Nov 2008 01:10:31 +0100 by phpDocumentor 1.4.0