forked from dox/energy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
91 lines (75 loc) · 2.93 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
<?php
include_once("inc/include.php");
if (isset($_POST['install_attempt'])) {
$filename = "sql_import.sql";
if (!file_exists($filename)) {
die('mySQL import file does not exist!');
}
$command = "mysql --user='" . db_username . "' --password='" . db_password . "' -h '" . db_host . "' -D '" . db_name . "' < " . $filename;
$output = shell_exec($command);
echo "Install complete. Please visit your site.";
exit;
}
?>
<!DOCTYPE html>
<html lang="en" class="h-100">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Andrew Breakspear">
<title>energy: Installer</title>
<!-- Bootstrap core CSS/JS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<!--<body>-->
<body class="bg-light">
<div class="container d-flex w-100 h-100 p-3 mx-auto flex-column">
<div class="px-3 py-3 pt-md-5 pb-md-4 text-center">
<h1 class="display-4">Energy DB Installer</h1>
<p class="lead">Create the required tables in your database.</p>
</div>
<?php
$buttonStatus = "";
?>
<!-- CHECK FOR DATABASE -->
<?php
if (isset($db)) {
$content = "<strong>DATABASE</strong> connection to database '" . db_name . "' on '" . db_host. "' successful";
echo makeAlert($content, "alert-success");
} else {
$content = "<strong>DATABASE</strong> Cannot connect to database '" . db_name . "' on '" . db_host. "'";
echo makeAlert($content, "alert-danger");
$buttonStatus = "disabled";
}
?>
<!-- CHECK FOR PRE-EXISTING INSTALL -->
<?php
$sql = "SHOW tables";
$tables = $db->query($sql)->fetchAll();
if (count($tables) == 0) {
$content = "<strong>TABLES</strong> Database has no tables (which is good!). Ready to install";
echo makeAlert($content, "alert-success");
} else {
$content = "<strong>TABLES</strong> Database already has tables present";
echo makeAlert($content, "alert-danger");
$buttonStatus = "disabled";
}
?>
<form method="post" id="install_attempt_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" novalidate>
<input type="hidden" name="install_attempt" value="true" />
<button <?php echo $buttonStatus; ?> type="submit" class="btn btn-primary" id="install_attempt_button">CLICK HERE TO SETUP TABLES IN YOUR DATABASE</button>
</form>
<?php include_once("views/footer.php"); ?>
</div>
</body>
</html>
<?php
function makeAlert($content = null, $class = "alert-dark") {
$output = "<div class=\"alert " . $class . "\" role=\"alert\">";
$output .= $content;
$output .= "</div>";
return $output;
}
?>