-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.php
More file actions
287 lines (239 loc) · 8.51 KB
/
install.php
File metadata and controls
287 lines (239 loc) · 8.51 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
// password hashing library
require_once 'core/lib/password.php';
// import MeekroDB for database querying
require_once 'core/lib/meekrodb.2.2.class.php';
if (isset($_POST['submit']) && $_POST['submit'] == 'Install Now') {
//lets install the cms
DB::$host = $_POST['dbhost'];
DB::$dbName = $_POST['dbname'];
DB::$user = $_POST['dbuser'];
DB::$password = $_POST['dbpass'];
DB::$encoding = 'utf8';
DB::$port = $_POST['dbport'];
//first, lets create the config file
$config_file = 'config.php';
$config_creation = fopen($config_file, 'w') or die('Cannot open file: '. $config_file); //implicitly creates file
$config_creation = fopen($config_file, 'w') or die('Cannot open file: '. $config_file);
$config_data = '
<?php
session_start();
error_reporting(E_ALL);
ini_set(\'display_errors\', true);
$CONFIG = new stdClass();
// database config etc
$CONFIG->db_host = \'' . $_POST['dbhost'] . '\';
$CONFIG->db_name = \'' . $_POST['dbname'] . '\';
$CONFIG->db_user = \'' . $_POST['dbuser'] . '\';
$CONFIG->db_pass = \'' . $_POST['dbpass'] . '\';
$CONFIG->db_enco = \'utf8\';
$CONFIG->db_port = \'' . $_POST['dbport'] . '\';
$CONFIG->db_prfx = \'' . $_POST['dbpref'] . '\'; // database prefix, no underscore!
$CONFIG->dir = __dir__; // NO TRAILING SLASH!
$CONFIG->www = \'' . $_POST['webroot'] . '\'; // NO TRAILING SLASH!
define(\'DIR\', $CONFIG->dir);
define(\'WWW\', $CONFIG->www);
// import string library
// require_once \'lib/strings.php\';
// password hashing library
require_once \'core/lib/password.php\';
// import MeekroDB for database querying
require_once \'core/lib/meekrodb.2.2.class.php\';
DB::$host = $CONFIG->db_host;
DB::$dbName = $CONFIG->db_name;
DB::$user = $CONFIG->db_user;
DB::$password = $CONFIG->db_pass;
DB::$encoding = $CONFIG->db_enco;
DB::$port = $CONFIG->db_port;
// import the core
require_once DIR . \'/core/core.php\';
// core instance to use through system
$CORE = new Core();
// import user class
require_once \'core/user.class.php\';
if (isset($_POST[\'submit\']))
{
$CORE->handle_submit($_POST[\'submit\']);
} else if (isset($_GET[\'submit\']))
{
if ($_GET[\'submit\'] == "Logout")
{
$CORE->handle_submit($_GET[\'submit\']);
}
}
$logged_in = $CORE->check_if_logged_in();
if ($logged_in == true) {
echo "<div id = \"logged_in_bar\">";
echo "Well hello there, " . $CORE->get_username();
if ($CORE->is_admin()) {
echo " (Admin) <a href = " . WWW . "/admin/index.php>Administration</a> <a href = " . WWW . "/login.php?submit=Logout>Logout</a>";
} else {
}
echo \'</div>\';
}
?>
';
fwrite($config_creation, $config_data);
//next, lets create the tables in the database
$newtable = "";
$pref = '';
if (isset($_POST['dbpref'])) {
$pref = $_POST['dbpref'];
}
$newtable = $pref . "users";
DB::query("CREATE TABLE $newtable(
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(25),
password varchar(255),
f_name varchar(255),
l_name varchar(255),
useremail varchar(255),
admin int(1),
PRIMARY KEY (id)
); ");
$newtable = $pref . "logins";
DB::query("CREATE TABLE $newtable(
id int(11) NOT NULL AUTO_INCREMENT,
userid int(11),
user_ip text,
user_ip_2 text,
last_action text,
PRIMARY KEY (id)
); ");
$newtable = $pref . "menu_items";
DB::query("CREATE TABLE $newtable(
id int(11) NOT NULL AUTO_INCREMENT,
name tinytext,
menuid int(11),
type varchar(255),
data text,
PRIMARY KEY (id)
); ");
$newtable = $pref . "menu";
DB::query("CREATE TABLE $newtable(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255),
PRIMARY KEY (id)
); ");
$newtable = $pref . "config";
DB::query("CREATE TABLE $newtable(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255),
description text,
value text,
PRIMARY KEY (id)
); ");
//populate tables
$newtable = $pref . "users";
DB::insert($newtable, array(
'username' => $_POST['cmsadmin'],
'password' => password_hash($_POST['cmsadminpass'], PASSWORD_DEFAULT),
'f_name' => $_POST['cmsadminfirst'],
'l_name' => $_POST['cmsadminlast'],
'useremail' => $_POST['cmsadminemail'],
'admin' => 1
));
$newtable = $pref . "menu";
DB::insert($newtable, array(
'name' => 'Main menu'
));
//set config settings
require_once 'config.php';
$CORE->setSetting('currenttheme', 'bootstrap', 'The current theme');
$CORE->setSetting('homepage', 'article', 'The contents of the homepage.');
$CORE->setSetting('Mod_Rewrite', 0, 'Takes out index.php from url');
$CORE->setSetting('custom_homepage_content', 'Here is some basic content on your home page.', 'Home page content if component is not chosen for homepage.');
$CORE->setSetting('site_title', 'Inkstand', 'The overall title for the site');
$CORE->setSetting('custom_homepage_layout', 'homepage', 'What layout file the custom homepage should use');
$CORE->setSetting('custom_homepage_slideshow', 1, '');
$newtable = $pref . "menu_items";
DB::insert($newtable, array(
'name' => 'Blog link',
'menuid' => 1,
'data' => 'a:2:{s:4:"text";s:4:"Blog";s:3:"url";s:42:"http://localhost/modular/index.php/article";}',
'type' => 'link'
));
$newtable = $pref . "menu_items";
DB::insert($newtable, array(
'name' => 'About page',
'menuid' => 1,
'data' => 'a:3:{s:4:"text";s:5:"About";s:3:"url";s:23:"https://www.google.com/";s:6:"target";s:6:"_blank";}',
'type' => 'link'
));
$newtable = $pref . "menu_items";
DB::insert($newtable, array(
'name' => 'Google',
'menuid' => 1,
'data' => 'a:3:{s:4:"text";s:8:"Download";s:3:"url";s:23:"https://www.google.com/";s:6:"target";s:6:"_blank";}',
'type' => 'link'
));
//use sql from components to create and populate tables
require_once('components/article/article.sql.php');
require_once('components/page/page.sql.php');
require_once('components/contact/contact.sql.php');
}
if (file_exists('config.php')) {
//should already be installed. Lets redirect to home
require_once('config.php');
header("Location: " . WWW);
} else {
//config has not been created, so we must install the cms
$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
$url .= $_SERVER["REQUEST_URI"];
$index = strpos($url, '/install.php');
$url = substr($url, 0, $index);
?>
<link rel="stylesheet" href="plugin/theme/bootstrap/css/bootstrap.min.css">
<style>
form {
max-width: 800px;
width: 80%;
margin-left: auto;
margin-right: auto;
}
#background {
background-image:url(core/resources/images/building.jpg);
width:100%;
height:100%;
position:fixed;
top:0;
left:0;
z-index:-9999;
}
h1 {
text-align:center;
margin-bottom:75px;
}
h2 {
text-align:right;
}
h1, h2 {
color:#fff;
text-shadow:0px 0px 1px #000;
}
form {
margin-bottom:75px;
}
</style>
<h1>Let's install your Inkstand</h1>
<form action = "install.php" method = "post">
<h2>Server Credentials</h2>
<span class="input-group-addon">Database Host</span> <input class="form-control" type = "text" name = "dbhost" value="localhost" /> <br>
<span class="input-group-addon">Database Name</span> <input class="form-control" type = "text" name = "dbname" /> <br>
<span class="input-group-addon">Database User</span> <input class="form-control" type = "text" name = "dbuser" /> <br>
<span class="input-group-addon">Database Password</span> <input class="form-control" type = "text" name = "dbpass" /> <br>
<span class="input-group-addon">Database Port</span> <input class="form-control" type = "text" name = "dbport" /> <br>
<span class="input-group-addon">Database Prefix</span> <input class="form-control" type = "text" name = "dbpref" value="ink_" /> <br>
<span class="input-group-addon">Web Root (NO TRAILING SLASH)</span> <input class="form-control" type = "text" name = "webroot" value="<?php echo $url ?>"/> <br><br>
<h2>Admin Credentials</h2>
<span class="input-group-addon">Admin Username</span> <input class="form-control" type = "text" name = "cmsadmin" /> <br>
<span class="input-group-addon">Admin Password</span> <input class="form-control" type = "password" name = "cmsadminpass" /> <br>
<span class="input-group-addon">First Name</span> <input class="form-control" type = "text" name = "cmsadminfirst" /> <br>
<span class="input-group-addon">Last Name</span> <input class="form-control" type = "text" name = "cmsadminlast" /> <br>
<span class="input-group-addon">Email</span> <input class="form-control" type = "text" name = "cmsadminemail" /> <br><br>
<input class="form-control" type = "submit" name = "submit" value = "Install Now" />
</form>
<div id='background'></div>
<?php
}
?>