forked from uzerpllp/uzerp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·148 lines (128 loc) · 4.88 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* uzERP Start-up Entry Point
*
* @version $Revision: 1.12 $
* @package uzerp
* @author uzERP LLP and Steve Blamey <[email protected]>
* @license GPLv3 or later
* @copyright (c) 2017 uzERP LLP (support#uzerp.com). All rights reserved.
*
* This file is part of uzERP.
*
* uzERP is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* uzERP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with uzERP. If not, see <http://www.gnu.org/licenses/>.
**/
session_start();
// define time at start of request
define('START_TIME', microtime(TRUE));
require 'system.php';
$system = system::Instance();
// *******
// CONFIG
// we have to load parts of system to load the config
$system->check_system();
$system->load_essential();
// **************************
// ERROR REPORTING & LOGGING
if (defined('SENTRY_DSN')) {
// custom exception handler, sends to sentry
set_exception_handler('sentry_exception_handler');
// send fatals to sentry
try {
$client = new Raven_Client(SENTRY_DSN, unserialize(SENTRY_CONFIG));
$client->tags_context(array(
'source' => 'fatal'
));
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerShutdownFunction();
} catch (Exception $e) {
// If something went wrong, just continue.
}
} else {
// custom exception handler, show error to user
set_exception_handler('uzerp_exception_handler');
}
function sentry_exception_handler($exception)
{
try {
$client = new Raven_Client(SENTRY_DSN, unserialize(SENTRY_CONFIG));
$client->tags_context(array(
'source' => 'exception'
));
$config = Config::Instance();
$event_id = $client->getIdent($client->captureException($exception, array(
'extra' => array(
'uzerp_version' => $config->get('SYSTEM_VERSION')
)
)));
$smarty = new Smarty();
$smarty->assign('config', $config->get_all());
$smarty->compile_dir = DATA_ROOT . 'templates_c';
$smarty->assign('event_id', $event_id);
$smarty->assign('support_email', SUPPORT_EMAIL);
$email_body = "uzERP Exception logged to sentry with ID: " . $event_id;
$smarty->assign('email_body', rawurlencode($email_body));
$smarty->assign('xhr', false);
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$smarty->assign('xhr', true);
}
$smarty->display(STANDARD_TPL_ROOT . 'error.tpl');
} catch (Exception $e) {
// If something went wrong, just continue.
}
}
function uzerp_exception_handler($exception)
{
$smarty = new Smarty();
$config = Config::Instance();
$smarty->assign('config', $config->get_all());
$smarty->compile_dir = DATA_ROOT . 'templates_c';
$smarty->assign('exception_message', $exception->getMessage());
$smarty->assign('support_email', $config->get('ADMIN_EMAIL'));
$email_body = "Request: " . $_SERVER['REQUEST_URI'] . "\n";
$email_body .= "uzERP Version: " . $config->get('SYSTEM_VERSION') . "\n\n" . $exception->getMessage();
$smarty->assign('email_body', rawurlencode($email_body));
$smarty->assign('xhr', false);
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$smarty->assign('xhr', true);
}
$smarty->display(STANDARD_TPL_ROOT . 'error.tpl');
}
// set the error reporting based on the environment
switch (strtolower(get_config('ENVIRONMENT'))) {
case 'development':
error_reporting(E_ALL ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_NOTICE);
// error_reporting(E_ALL);
break;
case 'production':
default:
error_reporting(E_ERROR);
break;
}
// define where the log should go, syslog or a file of your liking with
$log = $_SERVER["DOCUMENT_ROOT"] . 'data/logs/' . session_id() . '.log';
// set the php_ini error log value with the log path
ini_set("error_log", $log);
// *******************
// LOAD THE FRAMEWORK
$system->display();
if (AUDIT || get_config('AUDIT_LOGIN')) {
if (is_array($system->controller->_data) && isset($system->controller->_data['password'])) {
$system->controller->_data['password'] = '********************';
}
$audit = Audit::Instance();
$audit->write(print_r($system->controller->_data, TRUE) . print_r($system->flash, TRUE), TRUE, (microtime(TRUE) - START_TIME));
$audit->update();
}
?>