forked from Alanaktion/phproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
122 lines (103 loc) · 2.94 KB
/
Copy pathinstall.php
File metadata and controls
122 lines (103 loc) · 2.94 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
<?php
// Initialize core
$f3=require("lib/base.php");
$f3->mset(array(
"UI" => "app/view/",
"LOGS" => "log/",
"TEMP" => "tmp/",
"PREFIX" => "dict.",
"LOCALES" => "app/dict/",
"FALLBACK" => "en",
"CACHE" => false,
"AUTOLOAD" => "app/",
"PACKAGE" => "Phproject",
"site.url" => $f3->get("SCHEME") . "://" . $f3->get("HOST") . $f3->get("BASE") . "/"
));
// Check if already installed
if(is_file("config.ini")) {
$f3->set("success", "Phproject is already installed.");
}
// Check PCRE version
if((float)PCRE_VERSION < 7.9) {
$f3->set("error", "PCRE version is out of date");
}
// Check for MySQL PDO
if(!in_array("mysql", PDO::getAvailableDrivers())) {
$f3->set("error", "MySQL PDO driver is not avaialble.");
}
// Check for GD library
if(!function_exists("imagecreatetruecolor")) {
$f3->set("warning", "GD library is not available. Profile pictures and file thumbnails will not work until it is installed.");
}
// Run installation process if post data received
if($_POST) {
$post = $_POST;
try {
// Connect to database
$db = new \DB\SQL(
"mysql:host=" . $post["db-host"] . ";port=" . $post["db-port"] . ";dbname=" . $post["db-name"],
$post["db-user"],
$post["db-pass"]
);
// Run installation scripts
$install_db = file_get_contents("db/database.sql");
$db->exec(explode(";", $install_db));
// Create admin user
$f3->set("db.instance", $db);
$security = \Helper\Security::instance();
$user = new \Model\User;
$user->role = "admin";
$user->rank = 5; // superadmin
$user->name = "Admin";
$user->username = $post["user-username"] ?: "admin";
$user->email = $post["user-email"];
$user->salt = $security->salt();
$user->password = $security->hash($post["user-password"] ?: "admin", $user->salt);
$user->api_key = $security->salt_sha1();
$user->save();
} catch(PDOException $e) {
$f3->set("warning", $e->getMessage());
return false;
}
// Ensure required directories exist
if(!is_dir("tmp/cache")) {
mkdir("tmp/cache", 0777, true);
}
if(!is_dir("log")) {
mkdir("log", 0777, true);
}
// Build custom config string
$config = "[globals]";
if(!empty($post["language"])) {
$config .= "\nLANGUAGE={$post['language']}";
}
if($post["parser"] != "both") {
$config .= "\n\n; Parser options";
if($post["parser"] != "markdown") {
$config .= "\nparse.markdown=false";
}
if($post["parser"] != "textile") {
$config .= "\nparse.textile=false";
}
}
// Write configuration file
file_put_contents("config.ini",
"$config
; Database
db.host={$post['db-host']}
db.port={$post['db-port']}
db.user={$post['db-user']}
db.pass={$post['db-pass']}
db.name={$post['db-name']}
; Global site configuration
site.name={$post['site-name']}
site.timezone={$post['site-timezone']}
site.public_registration={$post['site-public_registration']}
site.db_sessions=1
; Email
mail.from={$post['mail-from']}
");
$f3->set("success", "Installation complete.");
}
// Render installer template
echo Template::instance()->render("install.html");