-
Notifications
You must be signed in to change notification settings - Fork 130
/
init.php
235 lines (205 loc) · 7.09 KB
/
init.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
<?php
/*
*
* PHP configuration
*
*/
ini_set("arg_separator.output", "&");
//default to utf8
ini_set("default_charset", "utf-8");
//allow larger and more file uploads than default
ini_set("post_max_size", "256M");
ini_set("upload_max_filesize", "256M");
ini_set("max_file_uploads", "100");
// uncomment next line for debugging
error_reporting(E_ALL || E_STRICT);
/*
*
* Webserver / Headers
*
*/
// Set content security policy header. This instructs the browser to block various unsafe behaviours.
header("Content-Security-Policy:style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self';");
// Start output buffering with gzip compression and start the session
ob_start('ob_gzhandler');
session_start();
/*
*
* Collabtive Constants
*
*/
// get full path to collabtive
define("CL_ROOT", realpath(dirname(__FILE__)));
define("CL_DIRECTORY",basename(__DIR__));
// configuration to load
define("CL_CONFIG", "standard");
// collabtive release date
define("CL_PUBDATE", "1484175600");
// set the version number for display
define("CL_PUBLIC_VERSION", "3.2");
/*
*
* Imports / globals
*
*/
// include config file , pagination and global functions
require(CL_ROOT . "/config/" . CL_CONFIG . "/config.php");
//include composer dependencies
require(CL_ROOT . "/vendor/autoload.php");
// load init functions
require(CL_ROOT . "/include/initfunctions.php");
require(CL_ROOT . "/include/pluginFunctions.php");
//initialise HTMLPurifier XSS protection filter
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', CL_ROOT . "/files/standard/ics");
$purifier = new HTMLPurifier($config);
// Start template engine
$template = new Smarty();
// Smarty config
// STOP smarty from spewing notices all over the html code
$template->error_reporting = E_ALL & ~E_NOTICE;
$template->force_compile = true;
//$template->force_compile = true;
/* Smarty 3 seems to have a problem with re-compiling the config if the user config is different than the system config.
* this forces a compile of the config.
* uncomment this if you have issues with language switching
*/
// $template->compileAllConfig('.config',true);
// get the available languages
$languages = getAvailableLanguages();
// get URL to this instance
$url = getMyUrl();
// assign values to templates
$template->assign("url", $url);
$template->assign("languages", $languages);
$template->assign("cl_config", CL_CONFIG);
$template->assign("myversion", CL_PUBLIC_VERSION);
//assume mysql as the default db
if (!isset($db_driver)) {
$db_driver = "mysql";
}
/*
*
* Database
*
*/
// Start database connection
// Depending on the DB driver, instantiate a PDO object with the necessary credentials.
$db_drivers = PDO::getAvailableDrivers();
if (!in_array($db_driver, $db_drivers)) {
die('Requested to use ' . $db_driver . ', which is not enabled!');
}
switch ($db_driver) {
case "mysql":
if (empty($db_name) or empty($db_user)) {
die("You must set db_name and db_user in /config/" . CL_CONFIG . "/config.php to use mysql, or set db_driver to \"sqlite\" to use an SQLite database!");
}
$conn = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_user, $db_pass);
$conn->exec("SET GLOBAL sql_mode='STRICT_TRANS_TABLES';");
break;
case "sqlite":
$conn = new PDO("sqlite:" . CL_ROOT . "/files/collabtive.sdb");
break;
}
// database connection established
if (isset($conn)) {
// Set PDO options
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_BOTH);
//$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// create a global mylog object for loging system events
$mylog = new mylog();
// get a settings object, and fetch an array containing the system settings
$settingsObj = (object)new settings();
$settings = $settingsObj->getSettings();
$template->assign("settings", $settings);
// define a constant that holds the default dateformat
define("CL_DATEFORMAT", $settings["dateformat"]);
// set the default TZ for date etc
date_default_timezone_set($settings["timezone"]);
} else {
$settings = array();
}
/*
*
* Locale
*
*/
// Set template directory
// If no directory is set in the system settings, default to the standard theme
if (isset($settings['template'])) {
$template->setTemplateDir(CL_ROOT . "/templates/" . $settings["template"] . "/");
} else {
$template->setTemplateDir(CL_ROOT . "/templates/standard/");
}
// If no locale is set, get the settings locale or default to english
if (!isset($locale)) {
if (isset($settings["locale"])) {
$locale = $settings['locale'];
} else {
$locale = "en";
}
$_SESSION['userlocale'] = $locale;
}
// if detected locale doesnt have a corresponding langfile , use system default locale
// if, for whatever reason, no system default language is set, default to english as a last resort
if (!file_exists(CL_ROOT . "/language/$locale/lng.conf")) {
$locale = $settings['locale'];
$_SESSION['userlocale'] = $locale;
}
// Set locale directory
$template->setConfigDir(CL_ROOT . "/language/$locale/");
// read language file into PHP array
$langfile = readLangfile($locale);
$template->assign("langfile", $langfile);
$template->assign("locale", $locale);
// css classes for headmenue
// this indicates which of the 3 main stages the user is on
$mainclasses = array("desktop" => "desktop",
"profil" => "profil",
"admin" => "admin"
);
$template->assign("mainclasses", $mainclasses);
/*
*
* User
*
*/
// If a user is logged in , assign globals to all templates
if (isset($_SESSION["userid"])) {
// get current year and month
$template->assign("theM", date("n"));
$template->assign("theY", date("Y"));
// unique ID of the user
$userid = $_SESSION["userid"];
// name of the user
$username = $_SESSION["username"];
// timestamp of last login
$lastlogin = $_SESSION["lastlogin"];
// selected locale
$locale = $_SESSION["userlocale"];
// gender
$gender = $_SESSION["usergender"];
// what the user may or may not do
$userpermissions = $_SESSION["userpermissions"];
// update user lastlogin for the onlinelist
$mynow = time();
if (isset($conn)) {
$conn->exec("UPDATE LOW_PRIORITY user SET lastlogin='$mynow' WHERE ID = $userid");
}
$project = new project();
//create plugins manager
$pluginManager = new pluginManager();
$pluginManager->loadPlugins();
// assign it all to the templates
$template->assign("userid", $userid);
$template->assign("username", $username);
$template->assign("lastlogin", $lastlogin);
$template->assign("userpermissions", $userpermissions);
$template->assign("loggedin", 1);
} else {
$template->assign("loggedin", 0);
$userpermissions = array();
$settings = array();
$userid = 0;
}