-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinstall-doika.php
More file actions
114 lines (107 loc) · 4.44 KB
/
install-doika.php
File metadata and controls
114 lines (107 loc) · 4.44 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
<?php
error_reporting(E_ERROR | E_PARSE);
session_start();
$step = (!empty($_GET['step'])) ? intval($_GET['step']) : 1;
$error = false;
$install_folder = 'doika/'; // папка установки дойки
$mysqlImportFilename = 'doika.sql';
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<style><?php include($install_folder . 'install/style.css') ?></style>
</head>
<body>
<p id="logo"><a href="http://doika.falanster.by/" tabindex="-1">Doika</a></p>
<?php
switch ($step) {
case 1: // приветствие
include($install_folder . 'install/steps/hello.html');
break;
case 2: // системные требования
include($install_folder . 'install/steps/system-requirements.php');
$nextStep = "?step=3";
$repeatStep = "?step=2";
include($install_folder . 'install/next-step.php');
break;
case 3: // проверка прав на папки
include($install_folder . 'install/steps/folder-permisson.php');
$nextStep = "?step=4";
$repeatStep = "?step=3";
include($install_folder . 'install/next-step.php');
break;
case 4: // доступ к базе данных
$action = "?step=5";
include($install_folder . 'install/steps/db-form.php');
break;
case 5:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// example: mysql:dbname=testdb;host=127.0.0.1
$dsn = "{$_POST['dbtype']}:host={$_POST['dbhost']};dbname={$_POST['dbname']};port={$_POST['dbport']}";
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
try {
$pdoConnection = new \PDO($dsn, $_POST['uname'], $_POST['pwd'], $options );
} catch (\PDOException $exception) {
echo "<q>{$exception->getMessage()}</q>";
$pdoConnection === null;
}
if (!$pdoConnection) {
$_SESSION['dbhost'] = $_POST['dbhost'];
$_SESSION['dbtype'] = $_POST['dbtype'];
$_SESSION['dbport'] = $_POST['dbport'];
$_SESSION['dbname'] = $_POST['dbname'];
$_SESSION['uname'] = $_POST['uname'];
$_SESSION['pwd'] = $_POST['pwd'];
$action = '?step=4';
include($install_folder . 'install/db-error.php');
} else {
echo "Усановка:<br>";
try {
$pdoConnection->exec(file_get_contents($mysqlImportFilename));
} catch (\Exception $exception) {
die("<div class=\"error-response sql-import-response\">Problem in executing the SQL query: <b>{$exception->getMessage()}</b></div>");
}
echo "Файл $mysqlImportFilename успешно загружен в базу данных<br>";
$my_file = $install_folder.'.env';
$handle = fopen($my_file, 'w');
$params = [
'APP_NAME' => 'Doika',
'APP_ENV' => 'production',
'APP_KEY' => 'base64:' . base64_encode(random_bytes(32)),
'DB_CONNECTION' => $_POST['dbtype'],
'DB_HOST' => $_POST['dbhost'],
'DB_PORT' => $_POST['dbport'],
'DB_DATABASE' => $_POST['dbname'],
'DB_USERNAME' => $_POST['uname'],
'DB_PASSWORD' => $_POST['pwd']
];
$data = '';
foreach ($params as $key => $value) {
$data .= $key . '=' . $value . PHP_EOL;
}
fwrite($handle, $data);
fclose($handle);
echo "Файл конфигурации создан<br>";
if (!$error) {
echo '<meta http-equiv="refresh" content="2;URL=?step=6" />';
} else {
echo "<p class='error'>Что-то прошло не так.</p>";
}
}
}
break;
case 6:
include($install_folder . 'install/steps/finish.html');
session_destroy();
unlink('install-doika.php');
unlink('doika.sql');
break;
default:
echo '<meta http-equiv="refresh" content="2;URL=?step=1" />';
}
?>
</body>
</html>