-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
184 lines (157 loc) · 7.18 KB
/
install.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
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
<?php
/* Developed by Juno_okyo */
define('ROOT', __DIR__ . DIRECTORY_SEPARATOR);
require_once ROOT . 'vendor/autoload.php';
$error = FALSE;
if (file_exists(ROOT . 'config.php.example')) {
if (isset($_POST['db_host'], $_POST['db_user'], $_POST['db_pass'], $_POST['db_pass'])) {
// Check Database connection
try {
$db = new MysqliDb($_POST['db_host'], $_POST['db_user'], $_POST['db_pass'], $_POST['db_name']);
// $db->ping();
if ( ! $db->tableExists('messages')) {
$sql = "CREATE TABLE `messages` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`content` VARCHAR(800) NOT NULL,
`favorited` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;";
$db->rawQuery($sql);
}
/* Generate hash for your password */
$_POST['password'] = password_hash($_POST['password'], PASSWORD_DEFAULT);
/* Render template for config.php */
$keys = array(
'db_host',
'db_user',
'db_pass',
'db_name',
'username',
'password',
'sitekey',
'secret',
'access_token',
'your_name',
'text_direction'
);
$template = file_get_contents(ROOT . 'config.php.example');
foreach ($keys as $i => $key) {
$template = str_replace('{' . ($i + 1) . '}', addslashes($_POST[$key]), $template);
}
unset($keys);
/* Create config.php */
file_put_contents(ROOT . 'config.php', $template, LOCK_EX);
/* Self remove */
unlink(ROOT . 'config.php.example');
unlink(ROOT . 'install.php');
header('Location: index.php', TRUE, 302);
exit;
} catch(Exception $e) {
$error = $e->getMessage();
}
}
} else {
die('Error: The template file does not exist!');
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Juno_okyo">
<meta name="copyright" content="J2TEAM">
<title>Sarahah clone by Juno_okyo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="css/main.css">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include(ROOT . '_templates/navbar.php'); ?>
<div class="container" style="width: 600px;">
<div class="row">
<div class="col-xs-12">
<?php if ($error !== FALSE): ?>
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Error!</strong> <?php echo $error; ?>
</div>
<?php endif; ?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><span class="glyphicon glyphicon-cog" aria-hidden="true"></span> Config</h3>
</div>
<div class="panel-body">
<form action="install.php" method="POST" role="form">
<legend>Database</legend>
<div class="form-group">
<label for="db_host">Host</label>
<input type="text" class="form-control" name="db_host" id="db_host" placeholder="localhost" value="localhost" autofocus required>
</div>
<div class="form-group">
<label for="db_user">Username</label>
<input type="text" class="form-control" name="db_user" id="db_user" placeholder="root" required>
</div>
<div class="form-group">
<label for="db_pass">Password</label>
<input type="password" class="form-control" name="db_pass" id="db_pass" placeholder="password">
</div>
<div class="form-group">
<label for="db_name">DB Name</label>
<input type="text" class="form-control" name="db_name" id="db_name" placeholder="sarahah" required>
</div>
<legend>Authentication</legend>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" id="username" placeholder="admin" value="admin" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="password" required>
</div>
<legend>reCaptcha</legend>
<div class="form-group">
<label for="sitekey">Sitekey</label>
<input type="text" class="form-control" name="sitekey" id="sitekey" placeholder="sitekey" required>
</div>
<div class="form-group">
<label for="secret">Secret</label>
<input type="text" class="form-control" name="secret" id="secret" placeholder="secret" required>
</div>
<legend>Facebook</legend>
<div class="form-group">
<label for="access_token">Access Token</label>
<input type="text" class="form-control" name="access_token" id="access_token" placeholder="access_token" required>
</div>
<legend>Other</legend>
<div class="form-group">
<label for="your_name">Your name</label>
<input type="text" class="form-control" name="your_name" id="your_name" placeholder="Example: Manh Tuan" required>
</div>
<div class="form-group">
<label for="text_direction">Text direction</label>
<select name="text_direction" id="text_direction" class="form-control" required>
<option value="ltr" selected>Left-to-right (LTR)</option>
<option value="rtl">Right-to-left (RTL)</option>
</select>
</div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Install</button>
<button type="reset" class="btn btn-danger"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Reset</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>