Exemplo n.º 1
0
 /**
  * EP_Controller::__construct()
  *
  * @return - No Return Value
  */
 public function __construct()
 {
     parent::__construct();
     if ('CLI' === APPLICATION) {
         set_error_handler('errorsHandler', E_ALL);
         set_exception_handler('exceptionsHandler');
     }
     // this is loaded at this point so we can use it to determine what EMR we're accessing
     $this->load->helper('url');
     if ('EMR' === APPLICATION || 'ADMIN' === APPLICATION) {
         // this returns the domain from the url only
         //$sDomain = $_SERVER['HTTP_HOST'];
         $sDomain = parse_url(base_url(), PHP_URL_HOST);
         //die($sDomain);
         if (isset($_SERVER['HOSTIGNORE'])) {
             $sDomain = str_replace($_SERVER['HOSTIGNORE'] . '.', '', $sDomain);
         }
         $aDomainPieces = explode('.', $sDomain);
         $aDomainPieces = array_reverse($aDomainPieces);
         // remove the last two pieces of the domain the host and the extension
         $aDomainPieces = array_slice($aDomainPieces, 2);
         // determine the environment
         $this->sEnvironment = ENVIRONMENT;
         if (count($aDomainPieces) > 1) {
             $aDomainPieces = array_slice($aDomainPieces, 1);
         }
         // if the server environment variable has been set use it to override the environment
         if (isset($_SERVER['ENVIRONMENT'])) {
             $this->sEnvironment = $_SERVER['ENVIRONMENT'];
         }
         if (isset($_SERVER['PREFIX'])) {
             $this->sPrefix = $_SERVER['PREFIX'] . '_';
         }
         // make sure there's at least one domain piece working so that we can attempt to find an account
         // also make sure the array element isn't an empty string or something similar
         if (count($aDomainPieces) > 0 && !empty($aDomainPieces[0])) {
             $sSubdomain = $aDomainPieces[0];
         } else {
             exit("<tt style=\"color: red; font-weight: bold\">Account Not Found</tt>.");
         }
     }
     // build up the configuration information here
     $this->load->database();
     //$this->load->config('database', FALSE, TRUE);
     //$this->load->config($this->getEnvironment(), FALSE, TRUE);
     if ('PORTAL' !== APPLICATION) {
         // setup the connection to ep_master
         $this->switchDatabase('ep_master');
     }
     if ('EMR' === APPLICATION) {
         // query the database for the correct account information
         $this->db->from('subdomain');
         $this->db->join('account', 'subdomain.account_id = account.id', 'left');
         $this->db->where('value', $sSubdomain);
         $oQuery = $this->db->get();
         // query the database for the maintenance_mode information
         $this->db->from('maintenance_mode');
         $pQuery = $this->db->get();
         $pRow = $pQuery->row();
         // make sure that only one result is found
         if (1 !== $oQuery->num_rows()) {
             exit("<tt style=\"color: red; font-weight: bold\">Account Not Found</tt>.");
         }
         // actually get the result
         $oRow = $oQuery->row();
         $this->nAccount = $oRow->id;
         if ($oRow->maintenance_mode || $pRow->maintenance_mode) {
             while (ob_get_level()) {
                 ob_end_clean();
             }
             include APPPATH . '/errors/maintenance.php';
             exit(0);
         }
         if ($oRow->is_disabled) {
             while (ob_get_level()) {
                 ob_end_clean();
             }
             include APPPATH . '/errors/account_canceled.php';
             exit(0);
         }
         /*
         			if ($row->is_cancelled)
         			{
         				exit("<tt style=\"color: red; font-weight: bold\">This account is currently unavailable.  Please contact support.</tt>.");
         			}
         */
         // switch to the client's database for future accesses
         $this->switchDatabase($oRow->db_name);
     }
     // set the current instance of the object to this if it's not already set
     if (!isset(self::$_instance)) {
         self::$_instance =& $this;
     }
     // load any remaining libraries that are necessary
     $this->loadLibraries();
     $this->load->model('UserSettings');
     if ('EMR' === APPLICATION) {
         // if there is no session id, then it means we aren't logged in and should redirect to the login page
         /*	        if (!$this->input->is_ajax_request())
         			{
         				if (!isset($_SESSION['id']) || (isset($_SESSION['id']) && 0 == $_SESSION['id']))
         				{
         					header("Location: /user/login");
         				}
         			}
         */
         $sUri = substr($_SERVER['REQUEST_URI'], 0, 35);
         if (!isset($_SESSION['id']) || isset($_SESSION['id']) && 0 == $_SESSION['id']) {
             // allow ajax and hijack requests to go through, otherwise redirect to login
             if ($this->input->is_ajax_request() || '/user/hijack' === substr($sUri, 0, 12)) {
                 // do nothing
             } else {
                 if ('/user/' !== substr($sUri, 0, 6)) {
                     // redirect to the login page
                     redirect('/user/login');
                 }
             }
         }
         // set the public instance of the user id that is stored in the session
         if (isset($_SESSION['id'])) {
             $this->nUserId = $_SESSION['id'];
         }
         // set the public instance of the user name that is stored in the session
         if (isset($_SESSION['uname'])) {
             $this->sUserName = $_SESSION['uname'];
         }
         // if it's an AJAX POST or an application page request, reset the session time
         if ($this->input->is_ajax_request() && 'POST' === $_SERVER['REQUEST_METHOD'] || !$this->input->is_ajax_request()) {
             EP_Session::extendSession();
         }
         if (FALSE === self::$environment_flag) {
             $this->js->addJsCode('var environment_flag = "' . ENVIRONMENT . '";');
             $this->js->addJsCode('var show_prerelease = ' . ($this->config->item('show_prerelease') ? 1 : 0) . ';');
             $emr_version = $this->config->item('emr_version');
             $this->js->addJsCode('var emr_version = ' . (!empty($emr_version) ? $emr_version : 1.4));
             self::$environment_flag = true;
         }
     } else {
         if ('ADMIN' === APPLICATION) {
             $ip_address = explode('.', $this->input->ip_address());
             $ip_whitelist = new ip_whitelist();
             $ip = '';
             for ($i = 0; $i < count($ip_address); $i++) {
                 if (0 !== $i) {
                     $ip .= '.';
                 }
                 $ip .= $ip_address[$i];
                 $ip_whitelist->orWhere('value', $ip);
             }
             $ip_whitelist->result();
             if (0 === $ip_whitelist->count()) {
                 log_message('error', 'User Failed IP Check with IP of ' . $this->input->ip_address());
                 die('You don\'t have permission to access this application please contact the administrator.');
             }
             if (isset($this->session->userdata)) {
                 $this->nUserId = intval($this->session->userdata('user_id'));
             }
         }
     }
     // set up any library path chaining for specific applications
     switch (APPLICATION) {
         case 'CLI':
             $this->load->_ci_library_paths[] = SHAREPATH . '/library/';
             // this is supposed to fall through
         // this is supposed to fall through
         case 'ADMIN':
             //		case 'PORTAL':
             //log_message('error', 'adding [' . dirname(SHAREPATH) . '/application/] to model paths');
             $this->load->_ci_model_paths[] = dirname(SHAREPATH) . '/application/';
             //log_message('error', '  paths=' . var_export($this->load->_ci_model_paths, TRUE));
             break;
         case 'EMR':
             $this->load->_ci_library_paths[] = SHAREPATH . '/library/';
             break;
     }
 }
Exemplo n.º 2
0
 private function storeError($sSeverity, $sMessage, $sFile, $nLine, $aBacktrace = NULL, $nSkip = 0)
 {
     // get the controller instance so we can get session data
     if (class_exists('EP_Controller')) {
         $ctrl = EP_Controller::getInstance();
     } else {
         $ctrl = get_instance();
     }
     //log_message('error', '***Error occured: ' . print_r($sMessage, TRUE) . ' in file ' . $sFile . ':' . $nLine);
     // collect information on current request
     $aErrData = array();
     $aErrData['msg'] = $sMessage;
     $aErrData['backtrace'] = $this->getErrorHtml($sMessage, $aBacktrace);
     // 'old style' stuff from Jared...ew
     //		$aErrData['backtrace'] = $this->formatBacktrace($aBacktrace, $nSkip);	// 'new style' stores serialized version of backtrace array
     $aErrData['account_id'] = NULL;
     $aErrData['user_id'] = NULL;
     $aErrData['user_login'] = NULL;
     if (is_a($ctrl, 'EP_Controller')) {
         $aErrData['account_id'] = $ctrl->nAccount;
         $aErrData['user_id'] = $ctrl->nUserId;
         $aErrData['user_login'] = $ctrl->sUserName;
     }
     $aErrData['environment'] = ENVIRONMENT;
     $aErrData['http_host'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
     $aErrData['uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
     $aErrData['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
     $aErrData['remote_addr'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     $aErrData['get_array'] = serialize(isset($_GET) ? $_GET : null);
     $aErrData['post_array'] = serialize(isset($_POST) ? $_POST : null);
     $aErrData['session_array'] = serialize(isset($_SESSION) ? $_SESSION : null);
     $aErrData['session_key'] = session_id();
     $aErrData['created_at'] = time();
     //		$aErrData['ci'] = 1;
     /*
     select id,msg,environment,date_format(from_unixtime(created_at), '%m/%d/%y') as date from error_log order by id desc limit 1;
     delete from error_log where ci=1;
     */
     if ('The page you requested was not found.' !== $sMessage) {
         $db = $ctrl->db;
         // TODO: implement in a model
         $db->insert('ep_master.error_log', $aErrData);
     }
     $this->aErrInfo = $aErrData;
 }