· 7 years ago · Jan 13, 2019, 10:06 AM
1?php
2/**
3* Confessions
4*
5* @package Confessions
6* @author LeoCoding
7* @copyright 2017
8* @terms any use of this script without a legal license is prohibited
9* all the content of Confessions is the propriety of LeoCoding and Cannot be
10* used for another project.
11*/
12
13if (file_exists('../config.php')) {
14 header("Location: ../index.php");
15 exit;
16}
17
18//get db input
19
20$dbname = str_replace(' ', '', $_POST["epiz_22664540_1"]);
21$dbuser = str_replace(' ', '', $_POST["epiz_22664540"]);
22$dbpass = $_POST["n3kt5zsc"];
23$host = str_replace(' ', '', $_POST["sql205.epizy.com"]);
24
25if (!empty($dbname) && !empty($dbuser) && !empty($dbpass) && !empty($host)) {
26 $conn = new mysqli($host, $dbuser, $dbpass, $dbname);
27 if ($conn->connect_error) {
28 $die = "<p class='error'>Connection failed and rumor has it: " . $conn->connect_error . "</p>";
29 } else {
30 $tbl1 = $conn->query('select 1 from `confessions` LIMIT 1');
31 $tbl2 = $conn->query('select 1 from `comments` LIMIT 1');
32
33 if ($tbl1 !== false && $tbl2 !== false) {
34 $exists = "<p class='info'>Database is already installed</p>";
35 } else {
36 $sql = "CREATE TABLE `confessions` (
37 `ID` int(11) NOT NULL AUTO_INCREMENT,
38 `message` TEXT,
39 `votesUp` varchar(30) NOT NULL,
40 `votesDown` varchar(30) NOT NULL,
41 `status` int(11) COLLATE utf8_unicode_ci NOT NULL,
42 `time` TEXT,
43 `ip` char(15) NOT NULL,
44 PRIMARY KEY (`ID`)
45 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
46 $result = $conn->query($sql);
47 if ($result && !empty($result)) {
48 $results .= "<p class='success'>Table <i>confessions</i> created</p>";
49 } else {
50 $results .= "<p class='error'>Can't create table <i>confessions</i> and rumor has it: " . $conn->error . "</p>";
51 }
52
53 $sql = "CREATE TABLE `comments` (
54 `ID` int(11) NOT NULL AUTO_INCREMENT,
55 `conf_id` int(11) NOT NULL,
56 `message` TEXT,
57 `votesUp` varchar(30) NOT NULL,
58 `votesDown` varchar(30) NOT NULL,
59 `status` int(11) COLLATE utf8_unicode_ci NOT NULL,
60 `time` TEXT,
61 `ip` char(15) NOT NULL,
62 PRIMARY KEY (`ID`)
63 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
64 $result = $conn->query($sql);
65 if ($result && !empty($result)) {
66 $results .= "<p class='success'>Table <i>comments</i> created</p>";
67 } else {
68 $results .= "<p class='error'>Can't create table <i>comments</i> and rumor has it: " . $conn->error . "</p>";
69 }
70
71 $myfile = "config.php";
72 $txt = "<?php
73
74return (object) array(
75 'host' => '".$host."',
76 'username' => '".$dbuser."',
77 'pass' => '".$dbpass."',
78 'database' => '".$dbname."'
79 );
80";
81 $crconf = file_put_contents("../".$myfile, $txt);
82
83 if ($crconf === false) {
84 $esc_conf = htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');
85 $confstatus = "<p class='error'>We couldn't create config.php file, please create config.php in root of script with this content: <pre>".$esc_conf."</pre></p>";
86 } else {
87 $confstatus = "<p class='success'>Config file created</p>";
88 }
89 }
90
91 $conn->close();
92 }
93}
94?>
95<html>
96<head>
97<link rel="stylesheet" href="style.css">
98<title>Confessions | Installer</title>
99</head>
100<body>
101
102<div class="center">
103<h1>Confessions v1.6 Installer</h1>
104<form action="install.php" method="post">
105<ul class="form-style-1">
106<li>
107<label>Database name <span class="required">*</span></label>
108<input type="text" placeholder="DB_name" name="dbname" <?php echo isset($dbname) ? "value='".$dbname."'" : ''; ?>>
109</li>
110
111<li>
112<label>Database username <span class="required">*</span></label>
113<input type="text" placeholder="DB_username" name="dbuser" <?php echo isset($dbuser) ? "value='".$dbuser."'" : ''; ?>>
114</li>
115
116<li>
117<label>Database password <span class="required">*</span></label>
118<input type="password" placeholder="DBpassword" name="dbpass">
119</li>
120
121<li>
122<label>Database host <span class="required">*</span></label>
123<input type="text" placeholder="localhost" name="host" <?php echo isset($host) ? "value='".$host."'" : ''; ?>>
124</li>
125
126<li>
127<input type="submit" value="Start Installation">
128</li>
129</ul>
130</form>
131
132<br />
133
134<?php
135echo isset($exists) ? $exists : '';
136echo isset($die) ? $die : '';
137echo isset($results) ? $results : '';
138echo isset($confstatus) ? $confstatus : '';
139?>
140</div>
141
142
143</body>
144</html>