Function get_magic_quotes_gpc() is deprecated php7.4. /install/isession.inc. Fixed.
[fa-stable.git] / install / isession.inc
1 <?php
2 /**********************************************************************
3         Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL,
5         as published by the Free Software Foundation, either version 3
6         of the License, or (at your option) any later version.
7         This program is distributed in the hope that it will be useful,
8         but WITHOUT ANY WARRANTY; without even the implied warranty of
9         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10         See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 define('VARLIB_PATH', $path_to_root.'/tmp');
13 define('VARLOG_PATH', $path_to_root.'/tmp');
14
15 function output_html($text)
16 {
17         global $before_box, $Ajax, $messages;
18         // Fatal errors are not send to error_handler,
19         // so we must check the output
20         if ($text && preg_match('/\bFatal error(<.*?>)?:(.*)/i', $text, $m)) {
21                 $Ajax->aCommands = array();  // Don't update page via ajax on errors
22                 $text = preg_replace('/\bFatal error(<.*?>)?:(.*)/i','', $text);
23                 $messages[] = array(E_ERROR, $m[2], null, null);
24         }
25         $Ajax->run();
26         return  in_ajax() ? fmt_errors() : ($before_box.fmt_errors().$text);
27 }
28
29 //-----------------------------------------------------------------------------
30 //      Removing magic quotes from nested arrays/variables
31 //
32 function strip_quotes($data)
33 {
34         if(version_compare(phpversion(), '5.4', '<') && get_magic_quotes_gpc()) {
35                 if(is_array($data)) {
36                         foreach($data as $k => $v) {
37                                 $data[$k] = strip_quotes($data[$k]);
38                         }
39                 } else
40                         return stripslashes($data);
41         }
42         return $data;
43 }
44
45 function html_specials_encode($str)
46 {
47         return htmlspecialchars($str, ENT_QUOTES, $_SESSION['language']->encoding=='iso-8859-2' ? 'ISO-8859-1' : $_SESSION['language']->encoding);
48 }
49
50 function html_cleanup(&$parms)
51 {
52         foreach($parms as $name => $value) {
53                 if (is_array($value))
54                         html_cleanup($parms[$name]);
55                 else
56                         $parms[$name] = html_specials_encode($value);
57         }
58         reset($parms); // needed for direct key() usage later throughout the sources
59 }
60
61 function check_page_security($page_security)
62 {
63 }
64
65 /*
66  Ensure file is re-read on next request if php caching is active
67 */
68 function cache_invalidate($filename)
69 {
70     if (function_exists('opcache_invalidate')) // OpCode extension
71         opcache_invalidate($filename);
72 }
73 //============================================================================
74 if (!isset($path_to_root))
75 {
76         $path_to_root = ".";
77 }
78
79 // Prevent register_globals vulnerability
80 if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
81         die("Restricted access");
82
83 include_once($path_to_root . "/includes/errors.inc");
84 // collect all error msgs
85 set_error_handler('error_handler' /*, errtypes */);
86
87 include_once($path_to_root . "/includes/current_user.inc");
88 include_once($path_to_root . "/includes/lang/language.inc");
89 include_once($path_to_root . "/includes/ajax.inc");
90 include_once($path_to_root . "/includes/ui/ui_msgs.inc");
91 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
92
93 session_name('FAinstall');
94 session_start();
95
96 // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks
97 header("Cache-control: private");
98
99 include_once($path_to_root . "/config.default.php");
100
101 $_SESSION['SysPrefs'] = new sys_prefs();
102 $SysPrefs = &$_SESSION['SysPrefs'];
103
104 $inst_langs = array(
105   'C' => array ( 'name' => 'English',   'code' => 'C',          'encoding' => 'iso-8859-1'),
106   'ar_EG' => array ( 'name' => 'Arabic',        'code' => 'ar_EG',      'encoding' => 'utf-8', 'rtl' => true),
107   'da_DK' => array ( 'name' => 'Dansk', 'code' => 'da_DK',      'encoding' => 'iso-8859-1'),
108   'de_DE' => array ( 'name' => 'Deutsch',       'code' => 'de_DE',      'encoding' => 'iso-8859-1'),
109   'el_GR' => array ( 'name' => 'Greek', 'code' => 'el_GR',      'encoding' => 'utf-8'),
110   'es_MX' => array ( 'name' => 'Spanish',       'code' => 'es_MX',      'encoding' => 'iso-8859-1'),
111   'fr_FR' => array ( 'name' => 'Français',      'code' => 'fr_FR',      'encoding' => 'iso-8859-1'),
112   'hi_IN' => array ( 'name' => 'Hindi', 'code' => 'hi_IN',      'encoding' => 'utf-8'),
113   'id_ID' => array ( 'name' => 'Indonesian','code' => 'id_ID',  'encoding' => 'iso-8859-1'),
114   'it_IT' => array ( 'name' => 'Italian','code' => 'it_IT',     'encoding' => 'iso-8859-1'),
115   'ka_GE' => array ( 'name' => 'Georgian','code' => 'ka_GE',    'encoding' => 'utf-8'),
116   'nb_NO' => array ( 'name' => 'Norwegian','code' => 'nb_NO',   'encoding' => 'iso-8859-1'),
117   'nl_BE' => array ( 'name' => 'Nederlands (Belgian)','code' => 'nl_BE',        'encoding' => 'iso-8859-1'),
118   'nl_NL' => array ( 'name' => 'Nederlands (Netherlands)','code' => 'nl_NL',    'encoding' => 'iso-8859-1'),
119   'pl_PL' => array ( 'name' => 'Polski',        'code' => 'pl_PL',      'encoding' => 'iso-8859-2'),
120   'pt_BR' => array ( 'name' => 'Português (Brasilia)','code' => 'pt_BR',        'encoding' => 'iso-8859-1'),
121   'pt_PT' => array ( 'name' => 'Português','code' => 'pt_PT',   'encoding' => 'iso-8859-1'),
122   'sv_SE' => array ( 'name' => 'Svenska',       'code' => 'sv_SE',      'encoding' => 'iso-8859-1'),
123   'ta_IN' => array ( 'name' => 'Tamil', 'code' => 'ta_IN',      'encoding' => 'utf-8'),
124   'vi_VN' => array ( 'name' => 'Vietnamese',    'code' => 'vi_VN',      'encoding' => 'utf-8'),
125   'zh_CN' => array ( 'name' => 'Chinese Simplifed',     'code' => 'zh_CN',      'encoding' => 'utf-8'),
126 );
127
128 $Ajax = new Ajax();
129
130 get_text_init();
131
132 $i_lang = isset($_POST['inst_lang']) ? $_POST['inst_lang'] : 
133         (isset($_SESSION['inst_set']['inst_lang']) ? $_SESSION['inst_set']['inst_lang'] : 'C');
134
135 // Page Initialisation
136 if (!isset($_SESSION['language']) || !method_exists($_SESSION['language'], 'set_language')
137         || $_SESSION['language']->code != $i_lang) 
138 {
139         $l = array_search_value($i_lang, $inst_langs,  'code');
140         $_SESSION['language'] = new language($l['name'], $l['code'], $l['encoding'],
141          @isset($l['rtl']) ? 'rtl' : 'ltr');
142
143 }
144 if (!isset($installed_languages))
145         $installed_languages = array();
146
147 $_SESSION['language']->set_language($_SESSION['language']->code);
148 $GetText->add_domain( $_SESSION['language']->code, $path_to_root."/install/lang");
149
150 include_once($path_to_root . "/version.php");
151 include_once($path_to_root . "/includes/main.inc");
152
153 // js/php validation rules container
154 $Validate = array();
155 // bindings for editors
156 $Editors = array();
157 // page help. Currently help for function keys.
158 $Pagehelp = array();
159
160 //$Ajax = new Ajax();
161
162 // intercept all output to destroy it in case of ajax call
163 register_shutdown_function('end_flush');
164 ob_start('output_html',0);
165
166 if (!isset($_SESSION["wa_current_user"]))
167         $_SESSION["wa_current_user"] = new current_user();
168
169 html_cleanup($_GET);
170 html_cleanup($_POST);
171 html_cleanup($_REQUEST);
172 html_cleanup($_SERVER);
173
174 // POST vars cleanup needed for direct reuse.
175 // We quote all values later with db_escape() before db update.
176         $_POST = strip_quotes($_POST);
177