]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/installation.php
For api_timer_loop() also execute the command immediately.
[irc/unrealircd/unrealircd-webpanel.git] / api / installation.php
1 <?php
2
3 /** For handling installation BEFORE any backend and user is configured */
4
5 require_once "../inc/common.php";
6
7 /* only let this happen pre-config */
8 if (file_exists("../config/config.php"))
9 die(json_encode(["error" => "Configuration file exists."]));
10
11 if (!isset($_POST) || empty($_POST))
12 die(json_encode(["error" => "Incorrect parameters"]));
13
14 if ($_POST['method'] == "sql")
15 {
16 try {
17 $conn = mysqli_connect($_POST['host'], $_POST['user'], $_POST['password'], $_POST['database']);
18 } catch(Exception $e)
19 {
20 }
21 // check connection
22 if (mysqli_connect_errno())
23 die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()]));
24
25 $sql = "SHOW TABLES LIKE '".$conn->real_escape_string($_POST['table_prefix'])."%'"; // SQL query to check if table exists
26 $result = $conn->query($sql);
27 if ($result->num_rows > 0)
28 die(json_encode(["warn" => "Database already has data"]));
29
30 // close connection
31 mysqli_close($conn);
32 die(json_encode(["success" => "SQL Connection successful"]));
33
34 }