|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The phpMyFAQ instances setup class. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5.5 |
|
7
|
|
|
* |
|
8
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
|
9
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
|
10
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
|
11
|
|
|
* |
|
12
|
|
|
* @category phpMyFAQ |
|
13
|
|
|
* |
|
14
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
15
|
|
|
* @copyright 2012-2015 phpMyFAQ Team |
|
16
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
|
17
|
|
|
* |
|
18
|
|
|
* @link http://www.phpmyfaq.de |
|
19
|
|
|
* @since 2012-04-04 |
|
20
|
|
|
*/ |
|
21
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
|
22
|
|
|
exit(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* PMF_Instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @category phpMyFAQ |
|
29
|
|
|
* |
|
30
|
|
|
* @author Thorsten Rinne <[email protected]> |
|
31
|
|
|
* @copyright 2012-2015 phpMyFAQ Team |
|
32
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
|
33
|
|
|
* |
|
34
|
|
|
* @link http://www.phpmyfaq.de |
|
35
|
|
|
* @since 2012-04-04 |
|
36
|
|
|
*/ |
|
37
|
|
|
class PMF_Instance_Setup |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $_rootDir; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @return PMF_Instance_Setup |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->setRootDir(PMF_INCLUDE_DIR); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Sets the root directory of the phpMyFAQ instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $rootDir |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setRootDir($rootDir) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->_rootDir = $rootDir; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Creates the anonymous default user. |
|
66
|
|
|
* |
|
67
|
|
|
* @param PMF_Configuration $faqConfig |
|
68
|
|
|
*/ |
|
69
|
|
|
public function createAnonymousUser(PMF_Configuration $faqConfig) |
|
70
|
|
|
{ |
|
71
|
|
|
$anonymous = new PMF_User($faqConfig); |
|
72
|
|
|
$anonymous->createUser('anonymous', null, -1); |
|
73
|
|
|
$anonymous->setStatus('protected'); |
|
74
|
|
|
$anonymousData = array( |
|
75
|
|
|
'display_name' => 'Anonymous User', |
|
76
|
|
|
'email' => null, |
|
77
|
|
|
); |
|
78
|
|
|
$anonymous->setUserData($anonymousData); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Checks basic folders and creates them if necessary. |
|
83
|
|
|
* |
|
84
|
|
|
* @param array $dirs |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function checkDirs(Array $dirs) |
|
89
|
|
|
{ |
|
90
|
|
|
$failedDirs = []; |
|
91
|
|
|
|
|
92
|
|
|
foreach ($dirs as $dir) { |
|
93
|
|
|
if (false === is_writable($this->_rootDir.$dir)) { |
|
94
|
|
|
$failedDirs[] = $dir; |
|
95
|
|
|
} elseif (false === is_dir($this->_rootDir.$dir)) { |
|
96
|
|
|
if (false === mkdir($this->_rootDir.$dir, 0775)) { |
|
97
|
|
|
$failedDirs[] = $dir; |
|
98
|
|
|
} |
|
99
|
|
|
} else { |
|
100
|
|
|
copy( |
|
101
|
|
|
$this->_rootDir.'/setup/index.html', |
|
102
|
|
|
$this->_rootDir.$dir.'/index.html' |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $failedDirs; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Creates the file /config/database.php. |
|
112
|
|
|
* |
|
113
|
|
|
* @param array $data Array with database credentials |
|
114
|
|
|
* @param string $folder Folder |
|
115
|
|
|
* |
|
116
|
|
|
* @return int |
|
117
|
|
|
*/ |
|
118
|
|
|
public function createDatabaseFile(Array $data, $folder = '/config') |
|
119
|
|
|
{ |
|
120
|
|
|
$ret = file_put_contents( |
|
121
|
|
|
$this->_rootDir.$folder.'/database.php', |
|
122
|
|
|
"<?php\n". |
|
123
|
|
|
"\$DB['server'] = '".$data['dbServer']."';\n". |
|
124
|
|
|
"\$DB['user'] = '".$data['dbUser']."';\n". |
|
125
|
|
|
"\$DB['password'] = '".$data['dbPassword']."';\n". |
|
126
|
|
|
"\$DB['db'] = '".$data['dbDatabaseName']."';\n". |
|
127
|
|
|
"\$DB['prefix'] = '".$data['dbPrefix']."';\n". |
|
128
|
|
|
"\$DB['type'] = '".$data['dbType']."';", |
|
129
|
|
|
LOCK_EX |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
return $ret; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Creates the file /config/ldap.php. |
|
137
|
|
|
* |
|
138
|
|
|
* @param array $data Array with LDAP credentials |
|
139
|
|
|
* @param string $folder Folder |
|
140
|
|
|
* |
|
141
|
|
|
* @return int |
|
142
|
|
|
*/ |
|
143
|
|
|
public function createLdapFile(Array $data, $folder = '/config') |
|
144
|
|
|
{ |
|
145
|
|
|
$ret = file_put_contents( |
|
146
|
|
|
$this->_rootDir.$folder.'/config/ldap.php', |
|
147
|
|
|
"<?php\n". |
|
148
|
|
|
"\$PMF_LDAP['ldap_server'] = '".$data['ldapServer']."';\n". |
|
149
|
|
|
"\$PMF_LDAP['ldap_port'] = '".$data['ldapPort']."';\n". |
|
150
|
|
|
"\$PMF_LDAP['ldap_user'] = '".$data['ldapUser']."';\n". |
|
151
|
|
|
"\$PMF_LDAP['ldap_password'] = '".$data['ldapPassword']."';\n". |
|
152
|
|
|
"\$PMF_LDAP['ldap_base'] = '".$data['ldapBase']."';", |
|
153
|
|
|
LOCK_EX |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
return $ret; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Creates the file /config/elasticsearch.php |
|
161
|
|
|
* |
|
162
|
|
|
* @param array $data Array with LDAP credentials |
|
163
|
|
|
* @param string $folder Folder |
|
164
|
|
|
* |
|
165
|
|
|
* @return int |
|
166
|
|
|
*/ |
|
167
|
|
|
public function createElasticsearchFile(Array $data, $folder = '/config') |
|
168
|
|
|
{ |
|
169
|
|
|
$ret = file_put_contents( |
|
170
|
|
|
$this->_rootDir.$folder.'/config/elasticsearch.php', |
|
171
|
|
|
"<?php\n". |
|
172
|
|
|
"\$ES['hosts'] = ['".implode("'], ['", $data['hosts'])."'];\n". |
|
173
|
|
|
"\$ES['index'] = '".$data['index']."';\n". |
|
174
|
|
|
"\$ES['type'] = 'faqs';", |
|
175
|
|
|
LOCK_EX |
|
176
|
|
|
); |
|
177
|
|
|
|
|
178
|
|
|
return $ret; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Creates a new folder. |
|
183
|
|
|
* |
|
184
|
|
|
* @param string $name Name of the new folder |
|
185
|
|
|
* @param string $path Path to the new folder |
|
186
|
|
|
* |
|
187
|
|
|
* @return bool |
|
188
|
|
|
*/ |
|
189
|
|
|
public function createFolder($name, $path) |
|
190
|
|
|
{ |
|
191
|
|
|
// @todo add code here |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|