-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.php
executable file
·182 lines (167 loc) · 8.19 KB
/
config.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
if(isset($_POST["host"]) && isset($_POST["port"]) && isset($_POST["database"]) && isset($_POST["link"])
&& isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["lang"]) && isset($_POST["servername"])
&& isset($_POST["webusername"]) && isset($_POST["webpassword"])) {
$host = $_POST["host"];
$port = $_POST["port"];
$database = $_POST["database"];
$link = $_POST["link"];
$username = $_POST["username"];
$password = $_POST["password"];
$lang = $_POST["lang"];
$serverName = $_POST["servername"];
$webUsername = $_POST["webusername"];
$webPassword = $_POST["webpassword"];
$limit_per_page = $_POST["limit_per_page"];
$conn = new PDO('mysql:host=' . $host . ':' . $port . ';dbname=' . $database, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$content = json_encode(array("init" => true, "host" => $host, "port" => $port, "database" => $database,
"link" => $link, "username" => $username, "password" => $password, "lang" => $lang, "server_name" => $serverName,
"limit_per_page" => $limit_per_page));
exec("chmod -R 0777 ./include");
file_put_contents("./include/settings.txt", $content);
chmod("./include/settings.txt", 0755);
$hisCreate = $conn->prepare("INSERT INTO negativity_migrations_history (version, subsystem) VALUES (0, 'positivity_user')");
$hisCreate->execute();
$hisCreate = $conn->prepare("CREATE TABLE IF NOT EXISTS positivity_user (
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(16) NOT NULL,
password TEXT NOT NULL,
admin BOOLEAN NOT NULL,
special VARCHAR(256) NOT NULL
);");
$hisCreate->execute();
$userDel = $conn->prepare("INSERT INTO positivity_user (username, password, admin, special) VALUES (?,?,?,?);");
$userDel->execute(array($webUsername, hash("sha256", $webPassword), true, "un_removable"));
$userDel->closeCursor();
header("Location: ./index.php");
exit();
}
if(file_exists("./include/settings.txt")) {
$tempSettings = json_decode(file_get_contents("./include/settings.txt"), true);
if(isset($tempSettings["init"]) && $tempSettings["init"] == "true"){
header("Location: ./error/already-config.php");
die();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link href="./include/css/main.css" rel="stylesheet">
<link rel="icon" type="image/png" href="./include/img/favicon.png"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<title>Positivity - Config</title>
<script type="text/javascript">
function checkDbConnection(argument) {
var host = document.getElementById("host").value;
var port = document.getElementById("port").value;
var database = document.getElementById("database").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if(host == "" || database == "" || username == "") {
document.getElementById("db-result").innerHTML = "Database field not filled";
} else {
document.getElementById("db-result").innerHTML = "Checking ...";
var xhr = new XMLHttpRequest();
// we defined the xhr
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;
if (this.status == 200) {
document.getElementById("db-result").innerHTML = this.responseText;
}
// end of state change: it can be after some time (async)
};
xhr.open("POST", "./include/tester.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("request=bdd&host=" + host + "&port=" + port + "&database=" + database + "&username=" + username + "&password=" + password);
}
}
</script>
<style type="text/css">
label {
padding-top: 10px;
}
</style>
</head>
<body>
<div class="container solo">
<h2>Configuration</h2>
<p>Welcome to the Negativity web interface!</p><br>
<form id="config" method="POST" action="./config.php">
<div class="table-config">
<div class="table-left">
<div class="row">
<label for="host">The database IP: </label>
<input type="text" name="host" id="host" required>
</div>
<div class="row">
<label for="port">The database port: </label>
<input type="text" name="port" id="port" value="3306" required>
</div>
<div class="row">
<label for="database">Database name: </label>
<input type="text" name="database" id="database" required>
</div>
<div class="row">
<label for="username">User name: </label>
<input type="text" name="username" id="username" placeholder="root" required>
</div>
<div class="row">
<label for="password">User password: </label>
<input type="password" name="password" id="password" placeholder="myPassword">
</div>
<div class="row">
<div></div>
<button class="btn-outline" type="button" onclick="checkDbConnection()" style="padding: 5px 15px;"><div class="text">Check database connection</div></button>
</div>
<div class="row">
<div></div>
<div id="db-result"></div>
</div>
</div>
<div class="table-right">
<div class="row">
<label for="link">Link (on header): </label>
<input type="text" name="link" value="/">
</div>
<div class="row">
<label for="servername">Server name (on header): </label>
<input type="text" name="servername" placeholder="MyServer" required>
</div>
<div class="row">
<label for="web-username">Web admin user name: </label>
<input type="text" name="webusername" required>
</div>
<div class="row">
<label for="web-password">Web admin password: </label>
<input type="password" name="webpassword" required>
</div>
<div class="row number-wrapper">
<label for="limit_per_page">Limit per page: </label>
<input class="number-input" type="number" name="limit_per_page" value="15">
</div>
<div class="row select-container">
<label for="lang">Choose lang: </label>
<select name="lang">
<option value="en_US" selected="selected">Lang</option>
<?php
foreach (scandir("./lang/") as $value) {
$langName = explode(".", $value)[0];
if($langName != "")
echo '<option value="' . str_replace(".php", "", $value) . '">' . $langName . '</option>';
}
?>
</select>
</div>
</div>
</div>
<br/>
<button style="width:40%;" class="btn-outline" type="submit" form="config" value="Submit"><div class="text">Save config</div></button>
</form>
</div>
</body>
</html>