-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.php
More file actions
151 lines (145 loc) · 5.33 KB
/
install.php
File metadata and controls
151 lines (145 loc) · 5.33 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
<?php
if($_POST) {
$host = $_POST['host'];
$dbName = $_POST['db_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$n = 0;
$s = false;
//Check they all have a value
foreach ($_POST as $key => $value) {
if($value != '') {
$n++;
}
}
if($n >= 4) {
$err = 0;
$eStr = '';
try {
//Try connect to the database
$dsn = 'mysql:host='.$host.';dbname='.$dbName.';port=3306;connect_timeout=15';
$testDb = new PDO($dsn, $username, $password);
} catch(PDOException $e) {
$eStr = $e->getMessage();
$err = 1;
}
if($err == 0) {
//Write the config
$file = file_get_contents('classes/config.class.sample.php');
$file = str_replace("{DBHOST}", $host, $file);
$file = str_replace("{DBNAME}", $dbName, $file);
$file = str_replace("{DBUSER}", $username, $file);
$file = str_replace("{DBPASSWORD}", $password, $file);
//Check BaseUrl has http
$baseUrl = $_POST['baseUrl'];
require_once('classes/config.class.php');
if(isset(Config::$confArray['baseUrl']) && Config::$confArray['baseUrl'] != '{BASEURL}') $baseUrl = Config::$confArray['baseUrl'];
if (strpos($baseUrl,'http://') === false){
$baseUrl = 'http://'.$baseUrl;
}
$file = str_replace("{BASEURL}", $baseUrl, $file);
if(file_put_contents('classes/config.class.php', $file)) {
require_once('classes/core.class.php');
$core = Core::getInstance();
$s = true; //Set success to true
} else {
echo 'An Error occured, please ensure config.class.php is writeable';
}
//Perform the SQL
$q = $core->dbh->prepare('CREATE TABLE IF NOT EXISTS `pages` (`id` int(11) NOT NULL AUTO_INCREMENT,`content` text NOT NULL,`title` varchar(255) NOT NULL,PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(255) NOT NULL,`password` varchar(255) NOT NULL,PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ');
$q->execute();
//Add the admin user
$adminUser = $_POST['adminUser'];
$adminPassword = $_POST['adminPassword'];
$hashedPass = Core::getHash($adminUser,$adminPassword);
$q = $core->dbh->prepare('INSERT INTO `users` (`username`,`password`) VALUES(?,?)');
$q->execute(array($adminUser,$hashedPass));
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Install - CMS</title>
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<script src="resources/scripts/jquery-1.10.1.min.js"></script>
<link rel="stylesheet" type="text/css" href='resources/styles/style.css' />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>CMS Installation</h1>
<p>This will create your config and install the database</p>
</div>
<div id="main">
<?php if($s == true) { ?><div id="success">Successfully created config file and setup database, you may view your admin at <a href="<?php echo $baseUrl.'/admin'; ?>"><?php echo $baseUrl.'/admin'; ?></a></div><?php } ?>
<?php if($eStr) { ?><div id="error"><?php echo $eStr; ?></div><?php } ?>
<h2>Please fill in your database details below</h2>
<form action="" method="POST">
<div class="item">
<label>Base URL</label>
<input type="text" value="<?php echo isset($baseUrl) ? $baseUrl : $_SERVER['HTTP_HOST']?>" name="baseUrl" />
<div class="err">Please fill in a base URL value</div>
</div>
<div class="item">
<label>Host</label>
<input type="text" value="<?php echo isset($host) ? $host : '';?>" name="host" />
<div class="err">Please fill in a host value</div>
</div>
<div class="item">
<label>Database name</label>
<input type="text" value="<?php echo isset($dbName) ? $dbName : '';?>" name="db_name" />
<div class="err">Please fill in your database name</div>
</div>
<div class="item">
<label>Username</label>
<input type="text" value="<?php echo isset($username) ? $username : '';?>" name="username" />
<div class="err">Please fill in your database username</div>
</div>
<div class="item">
<label>Password</label>
<input type="text" value="<?php echo isset($password) ? $password : '';?>" name="password" />
<div class="err">Please fill in your password</div>
</div>
<div class="item">
<label>Admin Username</label>
<input type="text" value="<?php echo isset($adminUser) ? $adminUser : '';?>" name="adminUser" />
<div class="err">Please fill in your password</div>
</div>
<div class="item">
<label>Admin Password</label>
<input type="text" value="<?php echo isset($adminPassword) ? $adminPassword : '';?>" name="adminPassword" />
<div class="err">Please fill in your password</div>
</div>
<div class="item">
<input type="submit" value="Submit" name="submit" />
</div>
</form>
<script>
$(document).ready(function() {
$("#success").fadeIn(2000);
$("#error").fadeIn(2000);
});
$("form").submit(function(e) {
c = 0;
$("form input[type=text]").each(function() {
if($(this).val() == '') {
c+=1;
$(this).parent().children(".err").fadeIn("slow");
} else {
$(this).parent().children(".err").fadeOut("slow");
}
});
if(c == 0) {
return true;
} else {
return false;
}
});
</script>
</div>
</div>
</body>
</html>