forked from LeedRSS/Leed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.class.php
202 lines (182 loc) · 6.81 KB
/
Install.class.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
<?php
class Install {
const DEFAULT_TABLES_PREFIX = 'leed__';
const CONSTANT_FILE = 'constant.php';
public $finished = false;
public $logs = array(
'errors' => array(),
'notices' => array()
);
public $options = array(
'user' => array(
'login' => "",
'password' => ""
),
'db' => array(
'mysqlBase' => "",
'mysqlHost' => "",
'mysqlLogin' => "",
'mysqlMdp' => "",
'mysqlPrefix' => self::DEFAULT_TABLES_PREFIX
)
);
protected $salt;
public function __construct() {
require_once('Logger.class.php');
$this->logger = new Logger('install');
}
protected function overrideDefaultValues($_) {
foreach ($this->options as $type => $options) {
foreach ($options as $var => $defaultValue) {
if (!empty($_[$var])) {
$val = $type === 'db' ? str_replace("'", "\'", $_[$var]) : Functions::secure($_[$var]);
$this->options[$type][$var] = $val;
}
}
}
}
public function launch($_, $installActionName) {
$this->checkFunctionsExists();
if(!isset($_[$installActionName])) {
return false;
}
$this->overrideDefaultValues($_);
$this->checkLoginPassword();
$this->checkdb();
if(!$this->hasErrors()) {
$this->createConstantFile();
require_once('constant.php');
require_once('MysqlEntity.class.php');
class_exists('Update') or require_once('Update.class.php');
Update::ExecutePatch(true);
require_once('Feed.class.php');
require_once('Event.class.php');
require_once('User.class.php');
require_once('Folder.class.php');
require_once('Configuration.class.php');
$this->createConfig();
$this->createUser();
$this->setFinished(true);
$this->logger->destroy();
}
}
public function getDefaultRoot() {
$urlParts = explode('/', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
array_pop($urlParts);
return implode('/', $urlParts);
}
protected function createConstantFile() {
$constant = "<?php
//Host de Mysql, le plus souvent localhost ou 127.0.0.1
define('MYSQL_HOST','{$this->options['db']['mysqlHost']}');
//Identifiant MySQL
define('MYSQL_LOGIN','{$this->options['db']['mysqlLogin']}');
//mot de passe MySQL
define('MYSQL_MDP','{$this->options['db']['mysqlMdp']}');
//Nom de la base MySQL ou se trouvera leed
define('MYSQL_BDD','{$this->options['db']['mysqlBase']}');
//Prefix des noms des tables leed pour les bases de données uniques
define('MYSQL_PREFIX','{$this->options['db']['mysqlPrefix']}');
?>";
file_put_contents(self::CONSTANT_FILE, $constant);
if (!is_readable(self::CONSTANT_FILE))
die('"'.self::CONSTANT_FILE.'" not found!');
}
protected function createConfig() {
$configurationManager = new Configuration();
if ($configurationManager->tableExists()) {
$configurationManager->truncate();
}
$configurationManager->create();
$configurationManager->setDefaults();
$this->salt = $configurationManager->get('cryptographicSalt');
}
protected function createUser() {
$userManager = new User();
if ($userManager->tableExists()) {
$userManager->truncate();
}
$userManager->create();
$userManager->add($this->options['user']['login'], $this->options['user']['password'], $this->salt, $this->logger);
$_SESSION['currentUser'] = serialize($userManager->get($this->options['user']['login']));
}
protected function checkLoginPassword() {
if(
empty($this->options['user']['password'])
|| empty($this->options['user']['login'])
) {
$this->logs['errors'][] = _t('INSTALL_ERROR_USERPWD');
return false;
}
return true;
}
protected function checkDb() {
if(
empty($this->options['db']['mysqlHost'])
|| empty($this->options['db']['mysqlLogin'])
|| empty($this->options['db']['mysqlBase'])
) {
$this->logs['errors'][] = _t('INSTALL_ERROR_DB_INFOS');
return false;
}
if (!Functions::testDb(
$this->options['db']['mysqlHost'], $this->options['db']['mysqlLogin'], $this->options['db']['mysqlMdp'], $this->options['db']['mysqlBase']
)) {
$this->logs['errors'][] = _t('INSTALL_ERROR_CONNEXION');
} else {
$this->logs['notices'][] = _t('INSTALL_INFO_CONNEXION');
}
return true;
}
public function hasErrors() {
return count($this->logs['errors']) > 0;
}
public function checkFunctionsExists() {
if(!is_writable('./')){
$this->logs['errors'][] = _t('INSTALL_ERROR_RIGHT', array(str_replace(basename(__FILE__),'',__FILE__)));
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_RIGHT');
}
if (!@function_exists('mysqli_connect')){
$this->logs['errors'][] = _t('INSTALL_ERROR_MYSQLICONNECT');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_MYSQLICONNECT');
}
if (!@function_exists('file_get_contents')){
$this->logs['errors'][] = _t('INSTALL_ERROR_FILEGET');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_FILEGET');
}
if (!@function_exists('file_put_contents')){
$this->logs['errors'][] = _t('INSTALL_ERROR_FILEPUT');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_FILEPUT');
}
if (!@function_exists('curl_exec')){
$this->logs['errors'][] = _t('INSTALL_ERROR_CURL');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_CURL');
}
if (!@function_exists('gd_info')){
$this->logs['errors'][] = _t('INSTALL_ERROR_GD');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_GD');
}
if (@version_compare(PHP_VERSION, '5.1.0') <= 0){
$this->logs['errors'][] = _t('INSTALL_ERROR_PHPV', array(PHP_VERSION));
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_PHPV', array(PHP_VERSION));
}
if(ini_get('safe_mode') && ini_get('max_execution_time')!=0){
$this->logs['errors'][] = _t('INSTALL_ERROR_SAFEMODE');
}else{
$this->logs['notices'][] = _t('INSTALL_INFO_SAFEMODE');
}
}
public function setFinished($finished) {
$this->finished = $finished;
}
public function getFinished() {
return $this->finished;
}
}