This repository was archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
65 lines (51 loc) · 1.59 KB
/
install.php
File metadata and controls
65 lines (51 loc) · 1.59 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
<?php
require("./install/config.php");
if(!isset($admin_account)) {
die("Missing array with admin account info");
}
else if(!isset($database_info)) {
die("Missing array with database info");
}
$conf_template = fopen("./install/ConfDB.template.php", "r");
$conf = fopen("./src/models/ConfDB.inc.php", "w");
if(!$conf_template) {
die("Fail to open input file, check permissions");
}
else if(!$conf) {
die("Fail to open output file, check permissions");
}
while(!feof($conf_template)) {
$line = fgets($conf_template);
if(preg_match("#%(.*)%#", $line, $matches)) {
$line = str_replace($matches[0], $database_info[$matches[1]], $line);
}
fputs($conf, $line);
}
require("./src/models/ConfDB.inc.php");
$admin_account["password"] = hash("sha256", $admin_account["password"]);
$DB_script = file_get_contents("./install/DB.sql");
if(!$DB_script) {
die("Impossible to create database without script");
}
try {
$database->exec('BEGIN;');
$create = $database->exec($DB_script);
$insert = $database->prepare("INSERT INTO account (first_name, last_name, mail, password) VALUES (:first_name, :last_name, :mail, :password);");
$insert->execute($admin_account);
// Check mails are working properly
$to = $admin_account['mail'];
$subject = 'IntershipManager Setup';
$message = "Well done. Your mail system is working properly.";
$headers = array(
'From' => '',
'X-Mailer' => 'PHP/' . phpversion()
);
mail($to, $subject, $message, $headers);
$database->exec("COMMIT;");
echo "Installation done!";
}
catch (Exception $e) {
$database->exec("ROLLBACK;");
die("ERREUR : ".$e->getMessage());
}
?>