forked from andresamayadiaz/FrontAccountingSimpleAPI
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsession-custom.inc
More file actions
executable file
·184 lines (147 loc) · 5.94 KB
/
session-custom.inc
File metadata and controls
executable file
·184 lines (147 loc) · 5.94 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL,
as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
This program 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 License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
if (!isset($path_to_root))
{
$path_to_root = "../..";
}
// Prevent register_globals vulnerability
if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
die("Restricted access");
include_once($path_to_root . "/includes/errors.inc");
// colect all error msgs
set_error_handler('error_handler' /*, errtypes */);
include_once("session_utils.inc");
include_once($path_to_root . "/includes/current_user.inc");
include_once($path_to_root . "/frontaccounting.php");
include_once($path_to_root . "/admin/db/security_db.inc");
include_once($path_to_root . "/includes/lang/language.inc");
include_once($path_to_root . "/includes/lang/gettext.inc");
include_once($path_to_root . "/config_db.php");
include_once($path_to_root . "/includes/ajax.inc");
include_once($path_to_root . "/includes/ui/ui_msgs.inc");
include_once($path_to_root . "/includes/prefs/sysprefs.inc");
include_once($path_to_root . "/includes/hooks.inc");
//
// include all extensions hook files.
//
foreach ($installed_extensions as $ext)
{
if (file_exists($path_to_root.'/'.$ext['path'].'/hooks.php'))
include_once($path_to_root.'/'.$ext['path'].'/hooks.php');
}
$Session_manager = new SessionManager();
$Session_manager->sessionStart('FA'.md5(dirname(__FILE__)));
$_SESSION['SysPrefs'] = new sys_prefs();
$SysPrefs = &$_SESSION['SysPrefs'];
//----------------------------------------------------------------------------------------
// set to reasonable values if not set in config file (pre-2.3.12 installations)
if ((!isset($SysPrefs->login_delay)) || ($SysPrefs->login_delay < 0))
$SysPrefs->login_delay = 10;
if ((!isset($SysPrefs->login_max_attempts)) || ($SysPrefs->login_max_attempts < 0))
$SysPrefs->login_max_attempts = 3;
if ($SysPrefs->go_debug > 0)
error_reporting(-1);
else
error_reporting(E_USER_WARNING|E_USER_ERROR|E_USER_NOTICE);
ini_set("display_errors", "On");
if ($SysPrefs->error_logfile != '') {
ini_set("error_log", $SysPrefs->error_logfile);
ini_set("ignore_repeated_errors", "On");
ini_set("log_errors", "On");
}
/*
Uncomment the setting below when using FA on shared hosting
to avoid unexpeced session timeouts.
Make sure this directory exists and is writable!
*/
// ini_set('session.save_path', VARLIB_PATH.'/');
ini_set('session.gc_maxlifetime', 36000); // 10hrs
hook_session_start(@$_POST["company_login_name"]);
// this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks
header("Cache-control: private");
get_text_init();
if ($SysPrefs->login_delay > 0 && file_exists(VARLIB_PATH."/faillog.php"))
@include_once(VARLIB_PATH."/faillog.php");
// Page Initialisation
if (!isset($_SESSION['wa_current_user']) || !$_SESSION['wa_current_user']->logged_in()
|| !isset($_SESSION['language']) || !method_exists($_SESSION['language'], 'set_language'))
{
$l = array_search_value($dflt_lang, $installed_languages, 'code');
$_SESSION['language'] = new language($l['name'], $l['code'], $l['encoding'],
(isset($l['rtl']) && $l['rtl'] === true) ? 'rtl' : 'ltr');
}
$_SESSION['language']->set_language($_SESSION['language']->code);
include_once($path_to_root . "/includes/access_levels.inc");
include_once($path_to_root . "/version.php");
include_once($path_to_root . "/includes/main.inc");
include_once($path_to_root . "/includes/app_entries.inc");
// Ajax communication object
$Ajax = new Ajax();
// js/php validation rules container
$Validate = array();
// bindings for editors
$Editors = array();
// page help. Currently help for function keys.
$Pagehelp = array();
$Refs = new references();
// intercept all output to destroy it in case of ajax call
register_shutdown_function('end_flush');
ob_start('output_html',0);
if (!isset($_SESSION["wa_current_user"]))
$_SESSION["wa_current_user"] = new current_user();
html_cleanup($_GET);
html_cleanup($_POST);
html_cleanup($_REQUEST);
html_cleanup($_SERVER);
// logout.php is the only page we should have always
// accessable regardless of access level and current login status.
if (!defined('FA_LOGOUT_PHP_FILE')){
login_timeout();
if (!$_SESSION["wa_current_user"]->old_db)
include($path_to_root . '/company/'.user_company().'/installed_extensions.php');
install_hooks();
if (!$_SESSION["wa_current_user"]->logged_in())
{
// Show login screen
if (!isset($_POST["user_name_entry_field"]) or $_POST["user_name_entry_field"] == "")
{
// strip ajax marker from uri, to force synchronous page reload
$_SESSION['timeout'] = array( 'uri'=>preg_replace('/JsHttpRequest=(?:(\d+)-)?([^&]+)/s',
'', html_specials_encode($_SERVER['REQUEST_URI'])),
'post' => $_POST);
// include($path_to_root . "/access/login.php");
// if (in_ajax())
// $Ajax->activate('_page_body');
// exit;
} else {
$succeed = isset($db_connections[$_POST["company_login_name"]]) &&
$_SESSION["wa_current_user"]->login($_POST["company_login_name"],
$_POST["user_name_entry_field"], $_POST["password"]);
// select full vs fallback ui mode on login
$_SESSION["wa_current_user"]->ui_mode = $_POST['ui_mode'];
if (!$succeed)
{
// Incorrect password
login_fail();
}
$lang = &$_SESSION['language'];
$lang->set_language($_SESSION['language']->code);
}
}
if (!isset($_SESSION["App"])) {
$_SESSION["App"] = new front_accounting();
$_SESSION["App"]->init();
}
}
// POST vars cleanup needed for direct reuse.
// We quote all values later with db_escape() before db update.
$_POST = strip_quotes($_POST);