-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
144 lines (125 loc) · 3.61 KB
/
index.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
<?php
$request_path = rtrim($_SERVER['REQUEST_URI'], '/') . '/';
if (file_exists('.env')) {
header("Location: " . $request_path . "crm");
exit;
} elseif (isset($_POST['submit'])) {
if (!empty($_POST['login']) and !empty($_POST['password']) and strlen($_POST['password']) > 4 and strlen($_POST['login']) > 2) {
$login = $_POST['login'];
$password = hash('sha256', $_POST['password']);
$key = hash('sha256', time());
$create_env_string = 'JWT_SECRET=' . $key . "\r\n";
$create_env_string .= 'SECURE=false' . "\r\n";
$create_env_string .= 'LOGIN=' . $login . "\r\n";
$create_env_string .= 'PASSWORD=' . $password . "\r\n";
$env = fopen('.env', 'w');
if(empty($env)) {
echo '<div class="error">Error, Unable to create .env file<br>Check files permisions</div>';
return;
}
fwrite($env, $create_env_string);
$request_uri = $request_path . 'crm';
$htaccess = '<IfModule mod_rewrite.c>' . "\r\n";
$htaccess .= 'RewriteEngine On' . "\r\n";
$htaccess .= 'RewriteBase ' . $request_uri . "\r\n";
$htaccess .= 'RewriteRule ^index\.html$ - [L]' . "\r\n";
$htaccess .= 'RewriteCond %{REQUEST_FILENAME} !-f' . "\r\n";
$htaccess .= 'RewriteCond %{REQUEST_FILENAME} !-d' . "\r\n";
$htaccess .= 'RewriteRule (.*) index.html [L]' . "\r\n";
$htaccess .= '</IfModule>';
$htaccess_file = fopen('crm/.htaccess', 'w');
fwrite($htaccess_file, $htaccess);
fclose($htaccess_file);
$index_html_content = file_get_contents('crm/index.html');
$index_html_file = fopen('crm/index.html', 'w');
$index_html_content = str_replace('<head>', '<head><base href="' . $request_uri . '/">', $index_html_content);
fwrite($index_html_file, $index_html_content);
fclose($index_html_file);
$env = fopen('.env', 'w');
fwrite($env, $create_env_string);
fclose($env);
header("Location: " . $request_uri);
exit;
} else {
echo '<div class="error">Error, Password must be minimum 5 symbols<br>Login minimum 3 symbols</div>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create New User</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="<?php echo $request_path; ?>css/foundation.css">
<style>
.error {
position: absolute;
text-align: center;
width: 100%;
left: 0;
top: 0;
padding: 5px;
color: red;
background: black;
font-weight: bold;
}
.all-wrap {
position: relative;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-ms-align-items: center;
align-items: center;
justify-content: center;
width: 100%;
height: 100vh;
padding: 0 15px;
}
.all-wrap-inner {
width: 100%;
max-width: 600px;
border: solid 1px silver;
padding: 30px 24px;
}
input {
height: 50px !important;
font-size: 24px !important;
font-weight: normal;
box-shadow: none !important;
}
h1 {
font-size: 36px;
font-weight: bold;
text-align: center;
margin-bottom: 40px;
}
label {
font-size: 18px;
}
</style>
</head>
<body>
<div class="all-wrap">
<div class="all-wrap-inner">
<h1>Create Admin Account</h1>
<form id="login" method="post" autocomplete="off">
<p>
<label>LOGIN <small>(*minimum 3 symbols)</small>
<input type="text" name="login">
</label>
</p>
<p>
<label>PASSWORD <small>(*minimum 5 symbols)</small>
<input type="password" name="password" autocomplete="new-password">
</label>
</p>
<br>
<p><button class="button large expanded warning" type="submit" name="submit">CREATE ADMIN</button></p>
</form>
</div>
</div>
</body>
</html>