forked from socialigniter/socialigniter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
226 lines (208 loc) · 9.43 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
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
<?php
// Config File Constants
define('CONFIG_PATH', './application/config/config.php');
define('DATABASE_PATH', './application/config/database.php');
define('ROUTES_PATH', "./application/config/routes.php");
define('SOCIAL_IGNITER_PATH', './application/config/social_igniter.php');
// Proceed with DB Setup?
$proceedWithSetup = isset($_POST["hostname"]);
if ($proceedWithSetup) {
// Database
// We should probably clean these, as they could in theory come from anywhere on the web
$hostname = $_POST["hostname"];
$username = $_POST["username"];
$password = $_POST["password"];
$database_name = $_POST["database"];
// Before we change any files, we should try connecting to the db using the given credentials
try {
$db = new PDO('mysql:host=' . $hostname . ';dbname=' . $database_name, $username, $password, array(
PDO::ATTR_PERSISTENT => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_TIMEOUT => 10));
}
catch (PDOException $e) {
// If it went wrong: complain
header('HTTP/1.0 500 Server Error'); // TODO: Check if this works across most PHP platforms
echo $e -> getMessage();
exit;
}
// If all's good: woo! Edit the config files
$database_file = file_get_contents("./application/config/database.php.TEMPLATE", FILE_USE_INCLUDE_PATH);
$database_file = str_replace("{INSTALL_DB_HOSTNAME}", $hostname, $database_file);
$database_file = str_replace("{INSTALL_DB_USERNAME}", $username, $database_file);
$database_file = str_replace("{INSTALL_DB_PASSWORD}", $password, $database_file);
$database_file = str_replace("{INSTALL_DB_DATABASE}", $database_name, $database_file);
file_put_contents(DATABASE_PATH, $database_file);
// Config
$config_file = "./application/config/config.php.TEMPLATE";
$encryption_key = sha1(microtime(true).mt_rand(10000,90000));
$config_current = file_get_contents($config_file, FILE_USE_INCLUDE_PATH);
$config_current = str_replace("{INSTALL_BASE_URL}", $_POST["base_url"], $config_current);
$config_current = str_replace("{INSTALL_ENCRYPTION_KEY}", $encryption_key, $config_current);
file_put_contents(CONFIG_PATH, $config_current);
// Make Files
copy("./application/config/routes.php.TEMPLATE", ROUTES_PATH);
copy("./application/config/social_igniter.php.TEMPLATE", SOCIAL_IGNITER_PATH);
echo json_encode(
array(
'status' => 'success',
'message' => 'Created files & folders',
'data' => $_POST
)
);
} else {
// Write HTML for setup Forms etc
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Install Social-Igniter</title>
<link rel="stylesheet" type="text/css" href="/css/install.css" />
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/social.core.js"></script>
<script type="text/javascript" src="/js/installer/setup.js"></script>
</head>
<body>
<div id="container">
<div class="content norm_top"></div>
<div class="content norm_mid">
<div id="welcome" class="content_wrap">
<img id="logo" src="images/si_logo.png">
<h1>Install Social-Igniter</h1>
<p>Welcome and thanks for downloading Social-Igniter, you have taken the first step to setting up your own little corner on the web. Great job!</p>
<p>Next, we need you to tell us a few things before your site will work properly.</p>
<div class="clear"></div>
</div>
<div class="norm_separator"></div>
<div class="content_wrap">
<?php
// Check all the files we want to write are writable
$all_writable = true;
$errors = '<ul>';
if (is_writable(CONFIG_PATH))
{
$all_writable = false;
$errors .= '<li><code>' . CONFIG_PATH . '</code></li>';
}
if (is_writable(DATABASE_PATH))
{
$all_writable = false;
$errors .= '<li><code>' . DATABASE_PATH . '</code></li>';
}
if (is_writable(ROUTES_PATH))
{
$all_writable = false;
$errors .= '<li><code>' . ROUTES_PATH . '</code></li>';
}
if (is_writable(SOCIAL_IGNITER_PATH))
{
$all_writable = false;
$errors .= '<li><code>' . SOCIAL_IGNITER_PATH . '</code></li>';
}
$errors .= '</ul>';
if (!$all_writable)
{
// Echo error messages
echo '<div class="warning"><strong>Oops! SocialIgniter can\'t install itself because it can\'t update some config files.</strong><p>To fix this, the following files must be made writable by PHP or your web server:</p>';
echo $errors;
echo '<p>The <a href="http://codex.wordpress.org/Changing_File_Permissions">WordPress Codex has a good page on permissions</a>. If you need more help, ask your sysadmin or get in contact with the <a href="https://github.com/socialigniter/socialigniter/">SocialIgniter Developers</a></p><p>Once you\'ve fixed this, try refreshing this page.</p></div>';
}
else
{
?>
<!-- step 1 -->
<div id="step_1" class="hide">
<form name="install_step_1" id="install_step_1" method="POST">
<h2>Site URL</h2>
<p><label>Of your website: <input type="text" name="base_url" id="base_url" placeholder="http://example.com/"></label></p>
<h2>Database Settings</h2>
<p>If you're on shared hosting, your provider should have sent you MySQL database credentials -- if not, contact them and ask for hostname, username, password and database name required to connect.</p>
<div id="warning-container"></div>
<ol>
<li><label>The hostname of your database server: <input type="text" id="db_hostname" placeholder="localhost" name="hostname"></label></li>
<li><label>The username used to connect to the database: <input type="text" id="db_username" placeholder="root" name="username"></label></li>
<li><label>The password used to connect to the database: <input type="password" id="db_password" placeholder="" name="password"></label></li>
<li><label>The name of the database you want to connect to: <input type="text" id="db_database" placeholder="social-igniter" name="database"></label></li>
<li><button type="submit" id="install_step_1_submit">Create Database tables and Continue</button></li>
</ol>
</form>
</div>
<!-- step 2 -->
<div id="step_2" class="hide">
<h2 id="step_2_title">Creating Database...</h2>
</div>
<!-- step 3 -->
<div id="step_3" class="hide">
<form name="install_step_3" id="install_step_3" method="POST">
<h2>Your Information</h2>
<p>Enter information for who will be owning or controlling this website</p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Name</td>
<td>
<input type="text" name="name" id="signup_name" placeholder="Joe Smith" value="">
<span id="signup_name_error"></span>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="text" name="email" id="signup_email" placeholder="[email protected]" value="">
<span id="signup_email_error"></span>
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" name="password" id="signup_password" placeholder="********" value="">
<span id="signup_password_error"></span>
</td>
</tr>
<tr>
<td>Confirm Password</td>
<td>
<input type="password" name="password_confirm" id="signup_password_confirm" placeholder="********" value="">
<span id="signup_password_confirm_error"></span>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Signup"></td>
</tr>
</table>
<input type="hidden" name="session" value="1">
<input type="hidden" name="remember" value="1">
</form>
</div>
<!-- step 4 -->
<div id="step_4" class="hide">
<form name="install_step_4" id="install_step_4" method="POST">
<h2>Website Information</h2>
<p>So people know what website they are visiting :)</p>
<p>Site Name<br> <input type="text" name="title" id="site_title" placeholder="My Awesome Website" value=""></p>
<p>Tagline<br> <input type="text" name="tagline" id="site_tagline" placeholder="Where I Post All My Awesome Things" value=""></p>
<p>Keywords<br> <input type="text" name="keywords" id="site_keywords" placeholder="awesome, things, pictures, videos, poems, watermelons, cats, ninjas" value=""></p>
<p>Description<br> <textarea name="description" id="site_description" placeholder="This is my awesome website where I post awesome stuff. Some of my favorite things are ninjas, watermelons, and cats" cols="40" rows="7"></textarea>
<p><input type="submit" value="Continue"></p>
</form>
</div>
<!-- step 5 -->
<div id="step_5" class="hide">
<h2>Your Site is Now Setup</h2>
<p>Good job old sport, you're awesome. Now go em get em tiger!</p>
<h3>Get Started Exploring</h3>
<p><a id="go_to_website" href=""><img src="application/views/dashboard_default/assets/icons/globe_24.png"> Site</a>
<p><a id="go_to_dashboard" href=""><img src="application/views/dashboard_default/assets/icons/home_24.png"> Home</a>
<p><a id="go_to_apps" href=""><img src="application/views/dashboard_default/assets/icons/installer_24.png"> Apps</a>
<p><a id="go_to_design" href=""><img src="application/views/dashboard_default/assets/icons/colors_24.png"> Design</a>
</div>
<?php
}
?>
</div>
</div>
<div class="content norm_bot"></div>
</div>
</body>
</html>
<?php } ?>