forked from chilek/lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
258 lines (205 loc) · 8.84 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
/*
* LMS version 1.11-cvs
*
* (C) Copyright 2001-2012 LMS Developers
*
* Please, see the doc/AUTHORS for more information about authors!
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id$
*/
// REPLACE THIS WITH PATH TO YOUR CONFIG FILE
$CONFIG_FILE = '/etc/lms/lms.ini';
// PLEASE DO NOT MODIFY ANYTHING BELOW THIS LINE UNLESS YOU KNOW
// *EXACTLY* WHAT ARE YOU DOING!!!
// *******************************************************************
define('START_TIME', microtime(true));
define('LMS-UI', true);
ini_set('error_reporting', E_ALL&~E_NOTICE);
// find alternative config files:
if(is_readable('lms.ini'))
$CONFIG_FILE = 'lms.ini';
elseif(is_readable('/etc/lms/lms-'.$_SERVER['HTTP_HOST'].'.ini'))
$CONFIG_FILE = '/etc/lms/lms-'.$_SERVER['HTTP_HOST'].'.ini';
elseif(!is_readable($CONFIG_FILE))
die('Unable to read configuration file ['.$CONFIG_FILE.']!');
$CONFIG = (array) parse_ini_file($CONFIG_FILE, true);
// Check for configuration vars and set default values
$CONFIG['directories']['sys_dir'] = (!isset($CONFIG['directories']['sys_dir']) ? getcwd() : $CONFIG['directories']['sys_dir']);
$CONFIG['directories']['lib_dir'] = (!isset($CONFIG['directories']['lib_dir']) ? $CONFIG['directories']['sys_dir'].'/lib' : $CONFIG['directories']['lib_dir']);
$CONFIG['directories']['doc_dir'] = (!isset($CONFIG['directories']['doc_dir']) ? $CONFIG['directories']['sys_dir'].'/documents' : $CONFIG['directories']['doc_dir']);
$CONFIG['directories']['modules_dir'] = (!isset($CONFIG['directories']['modules_dir']) ? $CONFIG['directories']['sys_dir'].'/modules' : $CONFIG['directories']['modules_dir']);
$CONFIG['directories']['backup_dir'] = (!isset($CONFIG['directories']['backup_dir']) ? $CONFIG['directories']['sys_dir'].'/backups' : $CONFIG['directories']['backup_dir']);
$CONFIG['directories']['config_templates_dir'] = (!isset($CONFIG['directories']['config_templates_dir']) ? $CONFIG['directories']['sys_dir'].'/config_templates' : $CONFIG['directories']['config_templates_dir']);
$CONFIG['directories']['smarty_compile_dir'] = (!isset($CONFIG['directories']['smarty_compile_dir']) ? $CONFIG['directories']['sys_dir'].'/templates_c' : $CONFIG['directories']['smarty_compile_dir']);
$CONFIG['directories']['smarty_templates_dir'] = (!isset($CONFIG['directories']['smarty_templates_dir']) ? $CONFIG['directories']['sys_dir'].'/templates' : $CONFIG['directories']['smarty_templates_dir']);
define('SYS_DIR', $CONFIG['directories']['sys_dir']);
define('LIB_DIR', $CONFIG['directories']['lib_dir']);
define('DOC_DIR', $CONFIG['directories']['doc_dir']);
define('BACKUP_DIR', $CONFIG['directories']['backup_dir']);
define('MODULES_DIR', $CONFIG['directories']['modules_dir']);
define('SMARTY_COMPILE_DIR', $CONFIG['directories']['smarty_compile_dir']);
define('SMARTY_TEMPLATES_DIR', $CONFIG['directories']['smarty_templates_dir']);
// Do some checks and load config defaults
require_once(LIB_DIR.'/checkdirs.php');
require_once(LIB_DIR.'/config.php');
// Init database
$_DBTYPE = $CONFIG['database']['type'];
$_DBHOST = $CONFIG['database']['host'];
$_DBUSER = $CONFIG['database']['user'];
$_DBPASS = $CONFIG['database']['password'];
$_DBNAME = $CONFIG['database']['database'];
$_DBDEBUG = (isset($CONFIG['database']['debug']) ? chkconfig($CONFIG['database']['debug']) : FALSE);
require(LIB_DIR.'/LMSDB.php');
$DB = DBInit($_DBTYPE, $_DBHOST, $_DBUSER, $_DBPASS, $_DBNAME, $_DBDEBUG);
if(!$DB)
{
// can't working without database
die();
}
// Call any of upgrade process before anything else
require_once(LIB_DIR.'/upgradedb.php');
// Initialize templates engine (must be before locale settings)
require_once(LIB_DIR.'/Smarty/Smarty.class.php');
$SMARTY = new Smarty;
// test for proper version of Smarty
if (defined('Smarty::SMARTY_VERSION'))
$ver_chunks = preg_split('/[- ]/', Smarty::SMARTY_VERSION);
else
$ver_chunks = NULL;
if (count($ver_chunks) != 2 || version_compare('3.0', $ver_chunks[1]) > 0)
die('<B>Wrong version of Smarty engine! We support only Smarty-3.x greater than 3.0.</B>');
define('SMARTY_VERSION', $ver_chunks[1]);
// uncomment this line if you're not gonna change template files no more
//$SMARTY->compile_check = false;
// Read configuration of LMS-UI from database
if($cfg = $DB->GetAll('SELECT section, var, value FROM uiconfig WHERE disabled=0'))
foreach($cfg as $row)
$CONFIG[$row['section']][$row['var']] = $row['value'];
// Redirect to SSL
$_FORCE_SSL = (isset($CONFIG['phpui']['force_ssl']) ? chkconfig($CONFIG['phpui']['force_ssl']) : FALSE);
if($_FORCE_SSL && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
{
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit(0);
}
// Include required files (including sequence is important)
require_once(LIB_DIR.'/language.php');
require_once(LIB_DIR.'/unstrip.php');
require_once(LIB_DIR.'/definitions.php');
require_once(LIB_DIR.'/common.php');
require_once(LIB_DIR.'/checkip.php');
require_once(LIB_DIR.'/LMS.class.php');
require_once(LIB_DIR.'/Auth.class.php');
require_once(LIB_DIR.'/accesstable.php');
require_once(LIB_DIR.'/Session.class.php');
// Initialize Session, Auth and LMS classes
$SESSION = new Session($DB, $CONFIG['phpui']['timeout']);
$AUTH = new Auth($DB, $SESSION);
$LMS = new LMS($DB, $AUTH, $CONFIG);
$LMS->ui_lang = $_ui_language;
$LMS->lang = $_language;
// Set some template and layout variables
$SMARTY->template_dir = SMARTY_TEMPLATES_DIR;
$SMARTY->compile_dir = SMARTY_COMPILE_DIR;
$SMARTY->debugging = (isset($CONFIG['phpui']['smarty_debug']) ? chkconfig($CONFIG['phpui']['smarty_debug']) : FALSE);
$layout['logname'] = $AUTH->logname;
$layout['logid'] = $AUTH->id;
$layout['lmsdbv'] = $DB->_version;
$layout['smarty_version'] = SMARTY_VERSION;
$layout['hostname'] = hostname();
$layout['lmsv'] = '1.11-git';
//$layout['lmsvr'] = $LMS->_revision.'/'.$AUTH->_revision;
$layout['lmsvr'] = '';
$layout['dberrors'] =& $DB->errors;
$layout['dbdebug'] = $_DBDEBUG;
$layout['popup'] = isset($_GET['popup']) ? true : false;
$SMARTY->assignByRef('layout', $layout);
$SMARTY->assignByRef('LANGDEFS', $LANGDEFS);
$SMARTY->assignByRef('_ui_language', $LMS->ui_lang);
$SMARTY->assignByRef('_language', $LMS->lang);
$error = NULL; // initialize error variable needed for (almost) all modules
// Load menu
if(!$layout['popup'])
{
require_once(LIB_DIR.'/menu.php');
$SMARTY->assign('newmenu', $menu);
}
header('X-Powered-By: LMS/'.$layout['lmsv']);
// Check privileges and execute modules
if($AUTH->islogged)
{
$module = isset($_GET['m']) ? preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['m']) : '';
$deny = $allow = FALSE;
if($module == '')
{
$module = $CONFIG['phpui']['default_module'];
}
// Load plugin files and register hook callbacks
$plugins = preg_split('/[;,\s\t\n]+/', $CONFIG['phpui']['plugins'], -1, PREG_SPLIT_NO_EMPTY);
if (!empty($plugins)) {
foreach ($plugins as $plugin_name) {
require LIB_DIR . '/plugins/' . $plugin_name . '.php';
}
}
if(file_exists(MODULES_DIR.'/'.$module.'.php'))
{
$allow = !$AUTH->id || (!empty($access['allow']) && preg_match('/'.$access['allow'].'/i', $module));
if($AUTH->id && ($rights = $LMS->GetUserRights($AUTH->id)))
foreach($rights as $level)
{
if($level === 0) {
$CONFIG['privileges']['superuser'] = true;
}
if(!$allow) {
if(isset($access['table'][$level]['deny_reg']))
$deny = (bool) preg_match('/'.$access['table'][$level]['deny_reg'].'/i', $module);
elseif(isset($access['table'][$level]['allow_reg']))
$allow = (bool) preg_match('/'.$access['table'][$level]['allow_reg'].'/i', $module);
}
if(isset($access['table'][$level]['privilege']))
$CONFIG['privileges'][$access['table'][$level]['privilege']] = TRUE;
}
if($allow && ! $deny)
{
$layout['module'] = $module;
$LMS->InitUI();
include(MODULES_DIR.'/'.$module.'.php');
}
else
$SMARTY->display('noaccess.html');
}
else
{
$layout['module'] = 'notfound';
$layout['pagetitle'] = trans('Error!');
$SMARTY->assign('layout', $layout);
$SMARTY->assign('server', $_SERVER);
$SMARTY->display('notfound.html');
}
if($SESSION->get('lastmodule') != $module)
$SESSION->save('lastmodule', $module);
}
else
{
$SMARTY->assign('error', $AUTH->error);
$SMARTY->assign('target','?'.$_SERVER['QUERY_STRING']);
$SMARTY->display('login.html');
}
$SESSION->close();
$DB->Destroy();
?>