-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.php
More file actions
243 lines (225 loc) · 8.75 KB
/
install.php
File metadata and controls
243 lines (225 loc) · 8.75 KB
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
<?php
/**
* @copyright (C) 2024, 299Ko, based on code (2010-2021) 99ko https://github.com/99kocms/
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPLv3
* @author Jonathan Coulet <j.coulet@gmail.com>
* @author Maxence Cauderlier <mx.koder@gmail.com>
* @author Frédéric Kaplon <frederic.kaplon@me.com>
* @author Florent Fortat <florent.fortat@maxgun.fr>
*
* @package 299Ko https://github.com/299Ko/299ko
*/
ini_set('display_errors', 1);
const ROOT = '.' . DIRECTORY_SEPARATOR;
const DS = DIRECTORY_SEPARATOR;
include_once(ROOT . 'common/common.php');
if (file_exists(DATA . 'config.json'))
die('A config file is already exist');
$core = core::getInstance();
$pluginsManager = pluginsManager::getInstance();
$url = core::getInstance()->makeSiteUrl() . '/install.php';
// ----------------- Begin tests
// Test PHP Version
$minPHPVersion = 7.4;
$errorPHP = !((float) substr(phpversion(), 0, 3) >= $minPHPVersion);
$errorFopen = true;
if( filter_var( ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN ) ) {
$errorFopen = false;
}
$errorCurl = false;
if (!function_exists('curl_init')) {
$errorCurl = true;
}
$errorZip = true;
if(extension_loaded('zip')) {
$errorZip = false;
}
// Test mod_rewrite
if (function_exists('apache_get_modules')) {
// PHP is installed as an Apache module
$errorRewrite = !in_array('mod_rewrite', apache_get_modules()) ? true : false;
} else {
// PHP is installed as a CGI
$errorRewrite = 'CGI';
}
// Test writable
if (!is_dir(DATA)) {
@mkdir(DATA);
}
$errorDataWrite = !is_writable(DATA);
$availablesLocales = lang::$availablesLocales;
if (count($_POST) > 0) {
if ($core->install()) {
$plugins = $pluginsManager->getPlugins();
if ($plugins != false) {
foreach ($plugins as $plugin) {
if ($plugin->getLibFile()) {
include_once($plugin->getLibFile());
$plugin->loadLangFile();
if (!$plugin->isInstalled())
$pluginsManager->installPlugin($plugin->getName(), true);
$plugin->setConfigVal('activate', '1');
$pluginsManager->savePluginConfig($plugin);
}
}
}
}
include(DATA . 'key.php');
$adminPwd = UsersManager::encrypt($_POST['adminPwd']);
$adminEmail = $_POST['adminEmail'];
$config = array(
'siteName' => "SiteName",
'siteDesc' => "Description",
'siteUrl' => $core->makeSiteUrl(),
'theme' => 'default',
'hideTitles' => '0',
'defaultPlugin' => 'page',
'debug' => '0',
'defaultAdminPlugin' => 'page',
'siteLang' => $_POST['lang-select'],
);
if (!file_put_contents(DATA . 'config.json', json_encode($config)) || !chmod(DATA . 'config.json', 0600)) {
logg('Error while writing config file', 'ERROR');
show::msg(lang::get('install-problem-during-install'), 'error');
header('location:' . $core->makeSiteUrl() );
die();
} else {
$_SESSION['installOk'] = true;
logg('Plugins installation done', 'SUCCESS');
$user = new User();
$user->email = $adminEmail;
$user->pwd = $adminPwd;
$user->save();
logg('Admin user created, end of install', 'SUCCESS');
show::msg(lang::get('install-successfull'), 'success');
header('location:' . $core->makeSiteUrl() );
die();
}
}
?>
<!doctype html>
<html lang="<?php echo lang::getLocale() ?>">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>299ko - <?php echo lang::get('install-installation'); ?></title>
<link rel="stylesheet" href="admin/styles.css" media="all">
<link rel="stylesheet" href="<?php echo FONTICON; ?>" />
</head>
<body class="login">
<div id="alert-msg">
<?php show::displayMsg(); ?>
</div>
<section id="install">
<header>
<h1 class="text-center"><?php echo lang::get('install-installation'); ?></h1>
</header>
<?php
if ($errorPHP) {
echo '<div class="msg error">';
echo lang::get('install-php-version-error', (float) substr(phpversion(), 0, 3), $minPHPVersion);
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-version-ok', $minPHPVersion);
echo '</div>';
}
if ($errorRewrite === 'CGI') {
echo '<div class="msg warning">';
echo lang::get('install-php-rewrite-cgi');
echo '</div>';
} elseif ($errorRewrite) {
echo '<div class="msg error">';
echo lang::get('install-php-rewrite-error');
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-rewrite-ok');
echo '</div>';
}
if ($errorDataWrite) {
echo '<div class="msg error">';
echo lang::get('install-php-data-write-error');
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-data-write-ok');
echo '</div>';
}
if ($errorFopen) {
echo '<div class="msg warning">';
echo lang::get('install-php-fopen-error');
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-fopen-ok');
echo '</div>';
}
if ($errorCurl) {
echo '<div class="msg warning">';
echo lang::get('install-php-curl-error');
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-curl-ok');
echo '</div>';
}
if ($errorZip) {
echo '<div class="msg warning">';
echo lang::get('install-php-zip-error');
echo '</div>';
} else {
echo '<div class="msg success">';
echo lang::get('install-php-zip-ok');
echo '</div>';
}
if ($errorDataWrite || $errorPHP || $errorRewrite === true) {
echo lang::get('install-please-check-errors');
} else {
?>
<form method="post" action="">
<?php echo '<h3>'.lang::get('install-please-fill-fields').'</h3>';
?>
<p><label for="lang-select"><?php echo lang::get('install-lang-choice'); ?></label>
<select name="lang-select" id="lang-select" onchange="langChange()">
<?php
foreach (lang::$availablesLocales as $k => $v) {
if (lang::getLocale() === $k) {
echo '<option value="' . $k . '" selected>' . $v . '</option>';
} else {
echo '<option value="' . $k . '">' . $v . '</option>';
}
}
?>
</select>
</p>
<p>
<label for="adminEmail"><?php echo lang::get('email'); ?></label><br>
<input type="email" name="adminEmail" required="required">
</p>
<p>
<label for="adminPwd"><?php echo lang::get('password'); ?></label><br>
<input type="password" name="adminPwd" id="adminPwd" required="required">
</p>
<p>
<a id="showPassword" href="javascript:showPassword()" class="button success"><?php echo lang::get('install-show-password'); ?></a>
<button type="submit" class="button success"><?php echo lang::get('submit'); ?></button>
</p>
</form>
<footer><a target="_blank" href="https://github.com/299ko/"><?php echo lang::get('site-just-using', VERSION); ?></a>
</footer>
<?php
}
?>
</section>
<script type="text/javascript">
function showPassword() {
document.getElementById("adminPwd").setAttribute("type", "text");
document.getElementById("showPassword").style.display = 'none';
}
function langChange() {
window.location.href = '<?php echo $url; ?>?lang=' + document.getElementById("lang-select").value;
}
</script>
</body>
</html>