-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·232 lines (196 loc) · 7.55 KB
/
install
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
#!/usr/bin/php
<?php
ob_implicit_flush();
error_reporting(E_ALL);
header('Content-Type: text/html; charset=utf-8');
if(!defined('SITEPATH')) {
define('SITEPATH', dirname(__FILE__));
}
chdir(SITEPATH);
require_once 'lib/Object.class.php';
require_once 'lib/CLICommand.class.php';
require_once 'lib/Core.php';
require_once 'lib/CliHelper.class.php';
class soopfw_install {
private $config;
public function __construct() {
CliHelper::console_log('Soopfw installation script.', 'plain');
if(!CliHelper::get_boolean_input("Do you really want to install soopfw?", true)) {
exit;
}
if(!CliHelper::get_boolean_input("!!! Please run this installation with the same user as the webserver would run.!!! continue?", true)) {
exit;
}
$this->main_check();
$this->main_configuration();
}
/**
* Checks if the base is setup correctly (write permissions ...)
*/
private function main_check() {
CliHelper::console_log('Main check', 'plain');
$this->check_writeable('uploads');
$this->check_writeable('templates_c');
if(!file_exists('config/core.php')) {
CliHelper::console_log('Could not find main configuration file, try to get it', 'info');
if(!file_exists('config/core.php.default')) {
CliHelper::console_log('Could not find default configuration file, aborting...', 'error');
exit;
}
$this->check_writeable('config');
if(copy('config/core.php.default', 'config/core.php')) {
CliHelper::console_log('Recovered config/core.php', 'ok');
}
}
else {
CliHelper::console_log('config/core.php exists', 'ok');
}
if(!file_exists('config/classes.php')) {
CliHelper::console_log('Could not find classes, try to get it', 'info');
if(!file_exists('config/classes.php.default')) {
CliHelper::console_log('Could not find default classes, aborting...', 'error');
exit;
}
$this->check_writeable('config');
if(copy('config/classes.php.default', 'config/classes.php')) {
CliHelper::console_log('Recovered config/classes.php', 'ok');
}
}
else {
CliHelper::console_log('config/classes.php exists', 'ok');
}
if(!file_exists('config/smarty.php')) {
CliHelper::console_log('Could not find smarty secure directory configuration file, try to get it', 'info');
if(!file_exists('config/smarty.php.default')) {
CliHelper::console_log('Could not find default smarty secure directory configuration file, aborting...', 'error');
exit;
}
$this->check_writeable('config');
if(copy('config/smarty.php.default', 'config/smarty.php')) {
CliHelper::console_log('Recovered config/smarty.php', 'ok');
}
}
else {
CliHelper::console_log('config/smarty.php exists', 'ok');
}
if(!file_exists('config/mime_types.php')) {
CliHelper::console_log('Could not find mime type list, try to get it', 'info');
if(!file_exists('config/mime_types.php.default')) {
CliHelper::console_log('Could not find default mime type list, aborting...', 'error');
exit;
}
$this->check_writeable('config');
if(copy('config/mime_types.php.default', 'config/mime_types.php')) {
CliHelper::console_log('Recovered config/mime_types.php', 'ok');
}
}
else {
CliHelper::console_log('config/mime_types.php exists', 'ok');
}
}
private function main_configuration() {
CliHelper::console_log('Main configuration', 'plain');
include 'config/core.php';
if(!empty($this->config['db']['host'])) {
$res = @mysql_connect($this->config['db']['host'], $this->config['db']['user'], $this->config['db']['pass']);
if (!isset($this->config['db']['table_prefix'])) {
$this->config['db']['table_prefix'] = "";
}
if(@mysql_select_db($this->config['db']['database'], $res)) {
$sql = "SELECT value FROM `" . mysql_real_escape_string($this->config['db']['table_prefix']) . "core_modul_config` WHERE modul='system' AND `key`='installed'";
$r = @mysql_fetch_assoc(mysql_query($sql));
if(!empty($r) && $r['value'] == '1') {
CliHelper::console_log('Soopfw is already installed, can not install it twice.', 'error');
exit;
}
}
}
foreach($this->config AS $section => &$section_values) {
CliHelper::console_log(' Section:' . $section, 'plain');
foreach ($section_values AS $k => $default) {
$section_values[$k] = CliHelper::get_string_input(' '.$k.':', $default);
}
}
$this->config['db']['use'] = !empty($this->config['db']['use']);
if($this->config['db']['use'] === true) {
$res = @mysql_connect($this->config['db']['host'], $this->config['db']['user'], $this->config['db']['pass']);
if(empty($res)) {
CliHelper::console_log('Database connection could not be established, please try again.', 'error');
$this->main_configuration();
return;
}
else if(!mysql_select_db($this->config['db']['database'], $res)) {
CliHelper::console_log('Database could not be selected, please try again.', 'error');
$this->main_configuration();
return;
}
}
if(file_put_contents('config/core.php', "<?php\n\n \$this->config = " . var_export($this->config, true) . ';')) {
CliHelper::console_log('Configuration saved', 'ok');
$this->install_system();
}
}
private function install_system() {
global $_SESSION, $core;
$core = Core::get_instance(true);
$core->boot('', true);
if (!empty($core->memcache_obj)) {
$core->memcache_obj->flush();
}
$obj = new cli_generate_classlist($core);
$obj->start();
$obj = new cli_generate_smartylist($core);
$obj->start();
if($this->config['db']['use'] !== true) {
CliHelper::console_log('Soopfw is now installed without a database connection.', 'ok');
return;
}
$core = Core::get_instance(true, Core::RUN_MODE_DEVELOPEMENT, true);
$core->boot();
$system = new System($core);
$system->install_module();
$system->install_module('user');
foreach($_SESSION['message'] AS $type => $messages) {
foreach($messages AS $message) {
CliHelper::console_log($message, $type);
}
}
$username = CliHelper::get_string_input('Please select the administration username', 'admin');
$email = CliHelper::get_string_input('Please choose an email address', $this->config['core']['debug_email']);
$password = CliHelper::get_silent_string_input('Please choose a password: ', '');
$password2 = CliHelper::get_silent_string_input('Please re-type the choosen password: ', '');
while($password != $password2) {
CliHelper::console_log('You misstyped the two passwords, both must be equals...please try again', 'plain');
$password = CliHelper::get_silent_string_input('Please choose a password: ', '');
$password2 = CliHelper::get_silent_string_input('Please re-type the choosen password: ', '');
}
$user_obj = new UserObj();
$user_obj->username = $username;
$user_obj->password = $password;
$user_obj->active = 'yes';
$user_obj->insert();
$user_right_obj = new UserRightObj();
$user_right_obj->user_id = $user_obj->user_id;
$user_right_obj->permissions = "*";
$user_right_obj->insert();
$user_address_obj = new UserAddressObj();
$user_address_obj->email = $email;
$user_address_obj->user_id = $user_obj->user_id;
$user_address_obj->insert();
$mime_type_cli = new cli_generate_mimetype_list();
$mime_type_cli->start();
$core->dbconfig("system", "installed", "1");
CliHelper::console_log('Soopfw is now installed. You can no navigate to http://' . $this->config['core']['domain'] . '/user/login', 'ok');
}
private function check_writeable($dir) {
$type = 'ok';
if(!is_dir($dir) || !is_readable($dir) || !is_writable($dir) || !is_executable($dir)) {
$type = 'error';
}
if(!CliHelper::console_log('Directory writeable: ' . $dir, $type)) {
echo "\n";
exit;
}
}
}
new soopfw_install();